Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing provider from facts, command and config #54623

Merged
merged 1 commit into from
Apr 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
67 changes: 5 additions & 62 deletions lib/ansible/modules/network/cnos/cnos_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,54 +37,14 @@
argument that will cause the module to wait for a specific condition
before returning or timing out if the condition is not met.
options:
provider:
version_added: "2.6"
description:
- A dict object containing connection details.
suboptions:
host:
description:
- Specifies the DNS host name or address for connecting to the remote
device over the specified transport. The value of host is used as
the destination address for the transport.
required: true
port:
description:
- Specifies the port to use when building the connection to the remote device.
default: 22
username:
description:
- Configures the username to use to authenticate the connection to
the remote device. This value is used to authenticate
the SSH session. If the value is not specified in the task, the
value of environment variable C(ANSIBLE_NET_USERNAME) will be used instead.
password:
description:
- Specifies the password to use to authenticate the connection to
the remote device. This value is used to authenticate
the SSH session. If the value is not specified in the task, the
value of environment variable C(ANSIBLE_NET_PASSWORD) will be used instead.
timeout:
description:
- Specifies the timeout in seconds for communicating with the network device
for either connecting or sending commands. If the timeout is
exceeded before the operation is completed, the module will error.
default: 10
ssh_keyfile:
description:
- Specifies the SSH key to use to authenticate the connection to
the remote device. This value is the path to the
key used to authenticate the SSH session. If the value is not specified
in the task, the value of environment variable C(ANSIBLE_NET_SSH_KEYFILE)
will be used instead.
commands:
version_added: "2.6"
description:
- List of commands to send to the remote device over the
configured provider. The resulting output from the command
is returned. If the I(wait_for) argument is provided, the
module is not returned until the condition is satisfied or
the number of retires as expired.
- List of commands to send to the remote device.
The resulting output from the command is returned.
If the I(wait_for) argument is provided, the module is not
returned until the condition is satisfied or the number of
retires is expired.
required: true
wait_for:
version_added: "2.6"
Expand Down Expand Up @@ -124,17 +84,6 @@
"""

EXAMPLES = """
# Note: examples below use the following provider dict to handle
# transport and authentication to the node.
---
vars:
cli:
host: "{{ inventory_hostname }}"
port: 22
username: admin
password: admin
timeout: 30

---
- name: test contains operator
cnos_command:
Expand All @@ -144,7 +93,6 @@
wait_for:
- "result[0] contains 'Lenovo'"
- "result[1] contains 'MemFree'"
provider: "{{ cli }}"
register: result

- assert:
Expand All @@ -155,7 +103,6 @@
- name: get output for single command
cnos_command:
commands: ['show version']
provider: "{{ cli }}"
register: result

- assert:
Expand All @@ -168,7 +115,6 @@
commands:
- show version
- show interface information
provider: "{{ cli }}"
register: result

- assert:
Expand Down Expand Up @@ -200,7 +146,6 @@

from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.network.cnos.cnos import run_commands, check_args
from ansible.module_utils.network.cnos.cnos import cnos_argument_spec
from ansible.module_utils.network.common.parsing import Conditional
from ansible.module_utils.six import string_types

Expand All @@ -224,8 +169,6 @@ def main():
interval=dict(default=1, type='int')
)

spec.update(cnos_argument_spec)

module = AnsibleModule(argument_spec=spec, supports_check_mode=True)
result = {'changed': False}

Expand Down
45 changes: 1 addition & 44 deletions lib/ansible/modules/network/cnos/cnos_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,48 +37,8 @@
an implementation for working with CNOS configuration sections in
a deterministic way.
notes:
- Tested against CNOS 10.8.1
- Tested against CNOS 10.9.1
options:
provider:
version_added: "2.6"
description:
- A dict object containing connection details.
suboptions:
host:
description:
- Specifies the DNS host name or address for connecting to the remote
device over the specified transport. The value of host is used as
the destination address for the transport.
required: true
port:
description:
- Specifies the port to use when building the connection to the remote device.
default: 22
username:
description:
- Configures the username to use to authenticate the connection to
the remote device. This value is used to authenticate
the SSH session. If the value is not specified in the task, the
value of environment variable C(ANSIBLE_NET_USERNAME) will be used instead.
password:
description:
- Specifies the password to use to authenticate the connection to
the remote device. This value is used to authenticate
the SSH session. If the value is not specified in the task, the
value of environment variable C(ANSIBLE_NET_PASSWORD) will be used instead.
timeout:
description:
- Specifies the timeout in seconds for communicating with the network device
for either connecting or sending commands. If the timeout is
exceeded before the operation is completed, the module will error.
default: 10
ssh_keyfile:
description:
- Specifies the SSH key to use to authenticate the connection to
the remote device. This value is the path to the
key used to authenticate the SSH session. If the value is not specified
in the task, the value of environment variable C(ANSIBLE_NET_SSH_KEYFILE)
will be used instead.
lines:
description:
- The ordered set of commands that should be configured in the
Expand Down Expand Up @@ -231,7 +191,6 @@
"""
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.network.cnos.cnos import load_config, get_config
from ansible.module_utils.network.cnos.cnos import cnos_argument_spec
from ansible.module_utils.network.cnos.cnos import check_args
from ansible.module_utils.network.common.config import NetworkConfig, dumps

Expand Down Expand Up @@ -320,8 +279,6 @@ def main():
admin=dict(type='bool', default=False)
)

argument_spec.update(cnos_argument_spec)

mutually_exclusive = [('lines', 'src'),
('parents', 'src')]

Expand Down
70 changes: 2 additions & 68 deletions lib/ansible/modules/network/cnos/cnos_facts.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# (C) 2017 Red Hat Inc.
# Copyright (C) 2017 Lenovo.
# (C) 2019 Red Hat Inc.
# Copyright (C) 2019 Lenovo.
#
# GNU General Public License v3.0+
#
Expand Down Expand Up @@ -55,50 +55,6 @@
on the remote device. If I(authorize) is false, then this argument
does nothing. If the value is not specified in the task, the value of
environment variable C(ANSIBLE_NET_AUTH_PASS) will be used instead.
provider:
version_added: "2.6"
description:
- A dict object containing connection details.
suboptions:
host:
description:
- Specifies the DNS host name or address for connecting to the remote
device over the specified transport. The value of host is used as
the destination address for the transport.
required: true
port:
description:
- Specifies the port to use when building the connection to the
remote device.
default: 22
username:
description:
- Configures the username to use to authenticate the connection to
the remote device. This value is used to authenticate
the SSH session. If the value is not specified in the task, the
value of environment variable C(ANSIBLE_NET_USERNAME) will be used
instead.
password:
description:
- Specifies the password to use to authenticate the connection to
the remote device. This value is used to authenticate
the SSH session. If the value is not specified in the task, the
value of environment variable C(ANSIBLE_NET_PASSWORD) will be used
instead.
timeout:
description:
- Specifies the timeout in seconds for communicating with the network
device for either connecting or sending commands. If the timeout
is exceeded before the operation is completed, the module will
error.
default: 10
ssh_keyfile:
description:
- Specifies the SSH key to use to authenticate the connection to
the remote device. This value is the path to the
key used to authenticate the SSH session. If the value is not
specified in the task, the value of environment variable
C(ANSIBLE_NET_SSH_KEYFILE) will be used instead.
gather_subset:
version_added: "2.6"
description:
Expand All @@ -116,36 +72,21 @@
---
- name: Test cnos Facts
cnos_facts:
provider={{ cli }}

vars:
cli:
host: "{{ inventory_hostname }}"
port: 22
username: admin
password: admin
transport: cli
timeout: 30
authorize: True
auth_pass:

---
# Collect all facts from the device
- cnos_facts:
gather_subset: all
provider: "{{ cli }}"

# Collect only the config and default facts
- cnos_facts:
gather_subset:
- config
provider: "{{ cli }}"

# Do not collect hardware facts
- cnos_facts:
gather_subset:
- "!hardware"
provider: "{{ cli }}"
'''
RETURN = '''
ansible_net_gather_subset:
Expand Down Expand Up @@ -207,7 +148,6 @@
import re

from ansible.module_utils.network.cnos.cnos import run_commands
from ansible.module_utils.network.cnos.cnos import cnos_argument_spec
from ansible.module_utils.network.cnos.cnos import check_args
from ansible.module_utils._text import to_text
from ansible.module_utils.basic import AnsibleModule
Expand Down Expand Up @@ -452,10 +392,6 @@ def parse_interfaces(self, data):
if match:
key = match.group(1)
parsed.append(line)
# match = re.match(r'^(loopback+)', line)
# if match:
# key = match.group(1)
# parsed.append(line)
return parsed

def set_ip_interfaces(self, line4):
Expand Down Expand Up @@ -545,8 +481,6 @@ def main():
gather_subset=dict(default=['!config'], type='list')
)

argument_spec.update(cnos_argument_spec)

module = AnsibleModule(argument_spec=argument_spec,
supports_check_mode=True)

Expand Down
2 changes: 1 addition & 1 deletion test/integration/targets/cnos_command/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ These are the various options the customer have in executing the cnos_command mo

Variable | Description
--- | ---
`commands` | List of commands to send to the remote device over the configured provider. The resulting output from the command is returned. If the I(wait_for) argument is provided, the module is not returned until the condition is satisfied or the number of retires as expired.
`commands` | List of commands to send to the remote device. The resulting output from the command is returned. If the I(wait_for) argument is provided, the module is not returned until the condition is satisfied or the number of retires as expired.
`wait_for` | List of conditions to evaluate against the output of the command. The task will wait for each condition to be true before moving forward. If the conditional is not true within the configured number of retries, the task fails. See examples.
`match` | The I(match) argument is used in conjunction with the I(wait_for) argument to specify the match policy. Valid values are C(all) or C(any). If the value is set to C(all) then all conditionals in the wait_for must be satisfied. If the value is set to C(any) then only one of the values must be satisfied.
`retries` | Specifies the number of retries a command should by tried before it is considered failed. The command is run on the target device every retry and evaluated against the I(wait_for) conditions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
- display interface brief
wait_for:
- result[0] contains 'Description: Foo'
provider: "{{ cli }}"
register: result
ignore_errors: yes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
wait_for:
- "result[0] contains 'Lenovo'"
- "result[1] contains 'Mem:'"
provider: "{{ cli }}"
register: result

- assert:
Expand Down
2 changes: 0 additions & 2 deletions test/integration/targets/cnos_command/tests/cli/invalid.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
- name: run invalid command
cnos_command:
commands: ['display foo']
provider: "{{ cli }}"
register: result
ignore_errors: yes

Expand All @@ -17,7 +16,6 @@
commands:
- display version
- display foo
provider: "{{ cli }}"
register: result
ignore_errors: yes

Expand Down
2 changes: 0 additions & 2 deletions test/integration/targets/cnos_command/tests/cli/output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
- name: get output for single command
cnos_command:
commands: ['display version']
provider: "{{ cli }}"
register: result

- assert:
Expand All @@ -17,7 +16,6 @@
commands:
- display version
- display interface brief
provider: "{{ cli }}"
register: result

- assert:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
- display version
wait_for:
- "result[0] contains bad_value_string"
provider: "{{ cli }}"
register: result
ignore_errors: yes

Expand Down
10 changes: 0 additions & 10 deletions test/integration/targets/cnos_command/vars/main.yaml

This file was deleted.