Skip to content

Commit

Permalink
EdgeOS module improvements (ansible#39530)
Browse files Browse the repository at this point in the history
* Update docs and use to_text on strings

* Add warning to use network_cli
  • Loading branch information
samdoran authored and Timur Evdokimov committed Jun 26, 2018
1 parent 5d308e9 commit 869f942
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
10 changes: 7 additions & 3 deletions lib/ansible/modules/network/edgeos/edgeos_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
use a custom pager that can cause this module to hang. If the
value of the environment variable C(ANSIBLE_EDGEOS_TERMINAL_LENGTH)
is not set, the default number of 10000 is used.
- "This is a network module and requires C(connection: network_cli)
in order to work properly."
- For more information please see the L(Network Guide,../network/getting_started/index.html).
options:
commands:
description:
Expand Down Expand Up @@ -95,17 +98,18 @@

import time

from ansible.module_utils._text import to_text
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.network.common.utils import ComplexList
from ansible.module_utils.network.common.parsing import Conditional
from ansible.module_utils.network.common.utils import ComplexList
from ansible.module_utils.network.edgeos.edgeos import run_commands
from ansible.module_utils.six import string_types


def to_lines(stdout):
for item in stdout:
if isinstance(item, string_types):
item = str(item).split('\n')
item = to_text(item).split('\n')
yield item


Expand Down Expand Up @@ -149,7 +153,7 @@ def main():
try:
conditionals = [Conditional(c) for c in wait_for]
except AttributeError as e:
module.fail_json(msg=str(e))
module.fail_json(msg=to_text(e))

retries = module.params['retries']
interval = module.params['interval']
Expand Down
17 changes: 12 additions & 5 deletions lib/ansible/modules/network/edgeos/edgeos_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
configuration file and state of the active configuration. All
configuration statements are based on `set` and `delete` commands
in the device configuration.
- "This is a network module and requires the C(connection: network_cli) in order
to work properly."
- For more information please see the L(Network Guide,../network/getting_started/index.html).
notes:
- Tested against EdgeOS 1.9.7
- Setting C(ANSIBLE_PERSISTENT_COMMAND_TIMEOUT) to 30 is recommended since
Expand Down Expand Up @@ -54,10 +57,12 @@
choices: ['line', 'none']
backup:
description:
- The C(backup) argument will backup the current devices active
- The C(backup) argument will backup the current device's active
configuration to the Ansible control host prior to making any
changes. The backup file will be located in the backup folder
in the root of the playbook
in the playbook root directory or role root directory if the
playbook is part of an ansible role. If the directory does not
exist, it is created.
type: bool
default: 'no'
comment:
Expand Down Expand Up @@ -116,10 +121,12 @@

import re

from ansible.module_utils._text import to_native
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.network.common.config import NetworkConfig
from ansible.module_utils.network.edgeos.edgeos import load_config, get_config, run_commands


DEFAULT_COMMENT = 'configured by edgeos_config'

CONFIG_FILTERS = [
Expand All @@ -144,7 +151,7 @@ def config_to_commands(config):
commands = ['set %s' % cmd.replace(' {', '') for cmd in commands]

else:
commands = str(candidate).split('\n')
commands = to_native(candidate).split('\n')

return commands

Expand All @@ -159,13 +166,13 @@ def get_candidate(module):


def diff_config(commands, config):
config = [str(c).replace("'", '') for c in config.splitlines()]
config = [to_native(c).replace("'", '') for c in config.splitlines()]

updates = list()
visited = set()

for line in commands:
item = str(line).replace("'", '')
item = to_native(line).replace("'", '')

if not item.startswith('set') and not item.startswith('delete'):
raise ValueError('line must start with either `set` or `delete`')
Expand Down
2 changes: 2 additions & 0 deletions lib/ansible/plugins/action/edgeos_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
class ActionModule(_ActionModule):

def run(self, tmp=None, task_vars=None):
if self._play_context.connection != 'network_cli':
return {'failed': True, 'msg': 'Connection type %s is not valid for this module. Must use network_cli.' % self._play_context.connection}

if self._task.args.get('src'):
try:
Expand Down
3 changes: 1 addition & 2 deletions lib/ansible/plugins/terminal/edgeos.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Copyright: (c) 2018, Ansible Project
# GNU General Public License v3.0+
# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
Expand Down

0 comments on commit 869f942

Please sign in to comment.