mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
eos_facts cleanup (#5057)
* dict.iteritems does not exist in Python 3 Now just dict.items six.iteritems handles the change * Addresses point 1 Unsure if this is a good idea or not. * Addresses point 2 This shouldn't have any particular change, just marks load_comments as abstract * Remove unused import Addresses point 3 * Clarify invalid subset error message Addresses point 4
This commit is contained in:
parent
0e4b470ee2
commit
9b286b1775
1 changed files with 11 additions and 8 deletions
|
@ -141,8 +141,8 @@ ansible_net_neighbors:
|
||||||
"""
|
"""
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from ansible.module_utils.basic import get_exception
|
|
||||||
from ansible.module_utils.netcli import CommandRunner, AddCommandError
|
from ansible.module_utils.netcli import CommandRunner, AddCommandError
|
||||||
|
from ansible.module_utils.six import iteritems
|
||||||
from ansible.module_utils.eos import NetworkModule
|
from ansible.module_utils.eos import NetworkModule
|
||||||
|
|
||||||
|
|
||||||
|
@ -163,6 +163,10 @@ class FactsBase(object):
|
||||||
|
|
||||||
self.load_commands()
|
self.load_commands()
|
||||||
|
|
||||||
|
def load_commands(self):
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
class Default(FactsBase):
|
class Default(FactsBase):
|
||||||
|
|
||||||
SYSTEM_MAP = {
|
SYSTEM_MAP = {
|
||||||
|
@ -178,7 +182,7 @@ class Default(FactsBase):
|
||||||
|
|
||||||
def populate(self):
|
def populate(self):
|
||||||
data = self.runner.get_command('show version', 'json')
|
data = self.runner.get_command('show version', 'json')
|
||||||
for key, value in self.SYSTEM_MAP.iteritems():
|
for key, value in iteritems(self.SYSTEM_MAP):
|
||||||
if key in data:
|
if key in data:
|
||||||
self.facts[value] = data[key]
|
self.facts[value] = data[key]
|
||||||
|
|
||||||
|
@ -256,10 +260,10 @@ class Interfaces(FactsBase):
|
||||||
|
|
||||||
def populate_interfaces(self, data):
|
def populate_interfaces(self, data):
|
||||||
facts = dict()
|
facts = dict()
|
||||||
for key, value in data['interfaces'].iteritems():
|
for key, value in iteritems(data['interfaces']):
|
||||||
intf = dict()
|
intf = dict()
|
||||||
|
|
||||||
for remote, local in self.INTERFACE_MAP.iteritems():
|
for remote, local in iteritems(self.INTERFACE_MAP):
|
||||||
if remote in value:
|
if remote in value:
|
||||||
intf[local] = value[remote]
|
intf[local] = value[remote]
|
||||||
|
|
||||||
|
@ -336,7 +340,8 @@ def main():
|
||||||
exclude = False
|
exclude = False
|
||||||
|
|
||||||
if subset not in VALID_SUBSETS:
|
if subset not in VALID_SUBSETS:
|
||||||
module.fail_json(msg='Bad subset')
|
module.fail_json(msg='Subset must be one of [%s], got %s' %
|
||||||
|
(', '.join(VALID_SUBSETS), subset))
|
||||||
|
|
||||||
if exclude:
|
if exclude:
|
||||||
exclude_subsets.add(subset)
|
exclude_subsets.add(subset)
|
||||||
|
@ -365,11 +370,10 @@ def main():
|
||||||
inst.populate()
|
inst.populate()
|
||||||
facts.update(inst.facts)
|
facts.update(inst.facts)
|
||||||
except Exception:
|
except Exception:
|
||||||
raise
|
|
||||||
module.exit_json(out=module.from_json(runner.items))
|
module.exit_json(out=module.from_json(runner.items))
|
||||||
|
|
||||||
ansible_facts = dict()
|
ansible_facts = dict()
|
||||||
for key, value in facts.iteritems():
|
for key, value in iteritems(facts):
|
||||||
key = 'ansible_net_%s' % key
|
key = 'ansible_net_%s' % key
|
||||||
ansible_facts[key] = value
|
ansible_facts[key] = value
|
||||||
|
|
||||||
|
@ -378,4 +382,3 @@ def main():
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue