roll up of fixes for nxos_facts (#21954)

* fixes commands to work with nxapi
* updates test case timeouts
pull/21960/head
Peter Sprygada 8 years ago committed by GitHub
parent 16a39639f5
commit a284c3f7ea

@ -208,7 +208,7 @@ class Nxapi:
return dict(ins_api=msg)
def send_request(self, commands, output='text'):
def send_request(self, commands, output='text', check_status=True):
# only 10 show commands can be encoded in each request
# messages sent to the remote device
if output != 'config':
@ -255,12 +255,13 @@ class Nxapi:
except ValueError:
self._module.fail_json(msg='unable to parse response')
output = response['ins_api']['outputs']['output']
for item in to_list(output):
if item['code'] != '200':
self._error(output=output, **item)
else:
result.append(item['body'])
if check_status:
output = response['ins_api']['outputs']['output']
for item in to_list(output):
if item['code'] != '200':
self._error(output=output, **item)
else:
result.append(item['body'])
return result
@ -288,7 +289,7 @@ class Nxapi:
queue = list()
responses = list()
_send = lambda commands, output: self.send_request(commands, output)
_send = lambda commands, output: self.send_request(commands, output, check_status=check_rc)
for item in to_list(commands):
if is_json(item['command']):

@ -16,9 +16,11 @@
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
#
ANSIBLE_METADATA = {'status': ['preview'],
'supported_by': 'community',
'version': '1.0'}
ANSIBLE_METADATA = {
'status': ['preview'],
'supported_by': 'community',
'version': '1.0'
}
DOCUMENTATION = """
---
@ -181,7 +183,6 @@ import re
from ansible.module_utils.nxos import run_commands
from ansible.module_utils.nxos import nxos_argument_spec, check_args
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.connection import exec_command
from ansible.module_utils.six import iteritems
@ -239,7 +240,7 @@ class Config(FactsBase):
class Hardware(FactsBase):
COMMANDS = [
'dir',
{'command': 'dir', 'output': 'text'},
'show system resources | json'
]
@ -287,13 +288,12 @@ class Interfaces(FactsBase):
data = run_commands(self.module, ['show interface | json'])[0]
self.facts['interfaces'] = self.populate_interfaces(data)
rc, out, err = exec_command(self.module, 'show ipv6 interface | json')
if rc == 0:
if out:
self.parse_ipv6_interfaces(out)
out = run_commands(self.module, ['show ipv6 interface | json'])
if out[0]:
self.parse_ipv6_interfaces(out)
rc, out, err = exec_command(self.module, 'show lldp neighbors')
if rc == 0:
out = run_commands(self.module, ['show lldp neighbors'], check_rc=False)
if out and out[0]:
self.facts['neighbors'] = self.populate_neighbors(out)
def populate_interfaces(self, data):

@ -7,6 +7,7 @@
provider: "{{ nxapi }}"
gather_subset:
- all
timeout: 60
register: result

@ -7,6 +7,7 @@
provider: "{{ nxapi }}"
gather_subset:
- "!hardware"
timeout: 30
register: result
- assert:

Loading…
Cancel
Save