mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-23 19:01:26 -07:00
Add vyos changes for Python3 (#24603)
* Add vyos changes for Python3 Make `execute_command` arguments and its return value complaint to PY3 changes made in PR #24431 pep8 fixes * Fix CI issues
This commit is contained in:
parent
f4e1dc503b
commit
16d610c1de
3 changed files with 20 additions and 18 deletions
|
@ -25,6 +25,7 @@
|
|||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
||||
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
from ansible.module_utils._text import to_text
|
||||
from ansible.module_utils.basic import env_fallback, return_values
|
||||
from ansible.module_utils.network_common import to_list
|
||||
from ansible.module_utils.connection import exec_command
|
||||
|
@ -43,18 +44,19 @@ vyos_argument_spec = {
|
|||
'provider': dict(type='dict'),
|
||||
}
|
||||
|
||||
|
||||
def check_args(module, warnings):
|
||||
provider = module.params['provider'] or {}
|
||||
for key in vyos_argument_spec:
|
||||
if key != 'provider' and module.params[key]:
|
||||
warnings.append('argument %s has been deprecated and will be '
|
||||
'removed in a future version' % key)
|
||||
warnings.append('argument %s has been deprecated and will be removed in a future version' % key)
|
||||
|
||||
if provider:
|
||||
for param in ('password',):
|
||||
if provider.get(param):
|
||||
module.no_log_values.update(return_values(provider[param]))
|
||||
|
||||
|
||||
def get_config(module, target='commands'):
|
||||
cmd = ' '.join(['show configuration', target])
|
||||
|
||||
|
@ -63,24 +65,26 @@ def get_config(module, target='commands'):
|
|||
except KeyError:
|
||||
rc, out, err = exec_command(module, cmd)
|
||||
if rc != 0:
|
||||
module.fail_json(msg='unable to retrieve current config', stderr=err)
|
||||
cfg = str(out).strip()
|
||||
module.fail_json(msg='unable to retrieve current config', stderr=to_text(err, errors='surrogate_or_strict'))
|
||||
cfg = to_text(out, errors='surrogate_or_strict').strip()
|
||||
_DEVICE_CONFIGS[cmd] = cfg
|
||||
return cfg
|
||||
|
||||
|
||||
def run_commands(module, commands, check_rc=True):
|
||||
responses = list()
|
||||
for cmd in to_list(commands):
|
||||
rc, out, err = exec_command(module, cmd)
|
||||
if check_rc and rc != 0:
|
||||
module.fail_json(msg=err, rc=rc)
|
||||
responses.append(out)
|
||||
module.fail_json(msg=to_text(err, errors='surrogate_or_strict'), rc=rc)
|
||||
responses.append(to_text(out, errors='surrogate_or_strict'))
|
||||
return responses
|
||||
|
||||
|
||||
def load_config(module, commands, commit=False, comment=None):
|
||||
rc, out, err = exec_command(module, 'configure')
|
||||
if rc != 0:
|
||||
module.fail_json(msg='unable to enter configuration mode', output=err)
|
||||
module.fail_json(msg='unable to enter configuration mode', output=to_text(err, errors='surrogate_or_strict'))
|
||||
|
||||
for cmd in to_list(commands):
|
||||
rc, out, err = exec_command(module, cmd)
|
||||
|
@ -92,9 +96,10 @@ def load_config(module, commands, commit=False, comment=None):
|
|||
diff = None
|
||||
if module._diff:
|
||||
rc, out, err = exec_command(module, 'compare')
|
||||
out = to_text(out, errors='surrogate_or_strict')
|
||||
if not out.startswith('No changes'):
|
||||
rc, out, err = exec_command(module, 'show')
|
||||
diff = str(out).strip()
|
||||
diff = to_text(out, errors='surrogate_or_strict').strip()
|
||||
|
||||
if commit:
|
||||
cmd = 'commit'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue