|
|
@ -126,9 +126,11 @@ ansible_net_neighbors:
|
|
|
|
import re
|
|
|
|
import re
|
|
|
|
import itertools
|
|
|
|
import itertools
|
|
|
|
|
|
|
|
|
|
|
|
from ansible.module_utils.basic import get_exception
|
|
|
|
import ansible.module_utils.ios
|
|
|
|
from ansible.module_utils.netcli import CommandRunner, AddCommandError
|
|
|
|
from ansible.module_utils.netcli import CommandRunner, AddCommandError
|
|
|
|
from ansible.module_utils.ios import NetworkModule
|
|
|
|
from ansible.module_utils.network import NetworkModule
|
|
|
|
|
|
|
|
from ansible.module_utils.six import iteritems
|
|
|
|
|
|
|
|
from ansible.module_utils.six.moves import zip
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def add_command(runner, command):
|
|
|
|
def add_command(runner, command):
|
|
|
@ -147,6 +149,9 @@ class FactsBase(object):
|
|
|
|
|
|
|
|
|
|
|
|
self.commands()
|
|
|
|
self.commands()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def commands(self):
|
|
|
|
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
|
|
|
|
class Default(FactsBase):
|
|
|
|
class Default(FactsBase):
|
|
|
|
|
|
|
|
|
|
|
|
def commands(self):
|
|
|
|
def commands(self):
|
|
|
@ -199,7 +204,7 @@ class Hardware(FactsBase):
|
|
|
|
self.facts['filesystems'] = self.parse_filesystems(data)
|
|
|
|
self.facts['filesystems'] = self.parse_filesystems(data)
|
|
|
|
|
|
|
|
|
|
|
|
data = self.runner.get_command('show memory statistics | include Processor')
|
|
|
|
data = self.runner.get_command('show memory statistics | include Processor')
|
|
|
|
match = re.findall('\s(\d+)\s', data)
|
|
|
|
match = re.findall(r'\s(\d+)\s', data)
|
|
|
|
if match:
|
|
|
|
if match:
|
|
|
|
self.facts['memtotal_mb'] = int(match[0]) / 1024
|
|
|
|
self.facts['memtotal_mb'] = int(match[0]) / 1024
|
|
|
|
self.facts['memfree_mb'] = int(match[1]) / 1024
|
|
|
|
self.facts['memfree_mb'] = int(match[1]) / 1024
|
|
|
@ -244,7 +249,7 @@ class Interfaces(FactsBase):
|
|
|
|
|
|
|
|
|
|
|
|
def populate_interfaces(self, interfaces):
|
|
|
|
def populate_interfaces(self, interfaces):
|
|
|
|
facts = dict()
|
|
|
|
facts = dict()
|
|
|
|
for key, value in interfaces.iteritems():
|
|
|
|
for key, value in iteritems(interfaces):
|
|
|
|
intf = dict()
|
|
|
|
intf = dict()
|
|
|
|
intf['description'] = self.parse_description(value)
|
|
|
|
intf['description'] = self.parse_description(value)
|
|
|
|
intf['macaddress'] = self.parse_macaddress(value)
|
|
|
|
intf['macaddress'] = self.parse_macaddress(value)
|
|
|
@ -266,11 +271,11 @@ class Interfaces(FactsBase):
|
|
|
|
return facts
|
|
|
|
return facts
|
|
|
|
|
|
|
|
|
|
|
|
def populate_ipv6_interfaces(self, data):
|
|
|
|
def populate_ipv6_interfaces(self, data):
|
|
|
|
for key, value in data.iteritems():
|
|
|
|
for key, value in iteritems(data):
|
|
|
|
self.facts['interfaces'][key]['ipv6'] = list()
|
|
|
|
self.facts['interfaces'][key]['ipv6'] = list()
|
|
|
|
addresses = re.findall(r'\s+(.+), subnet', value, re.M)
|
|
|
|
addresses = re.findall(r'\s+(.+), subnet', value, re.M)
|
|
|
|
subnets = re.findall(r', subnet is (.+)$', value, re.M)
|
|
|
|
subnets = re.findall(r', subnet is (.+)$', value, re.M)
|
|
|
|
for addr, subnet in itertools.izip(addresses, subnets):
|
|
|
|
for addr, subnet in zip(addresses, subnets):
|
|
|
|
ipv6 = dict(address=addr.strip(), subnet=subnet.strip())
|
|
|
|
ipv6 = dict(address=addr.strip(), subnet=subnet.strip())
|
|
|
|
self.add_ip_address(addr.strip(), 'ipv6')
|
|
|
|
self.add_ip_address(addr.strip(), 'ipv6')
|
|
|
|
self.facts['interfaces'][key]['ipv6'].append(ipv6)
|
|
|
|
self.facts['interfaces'][key]['ipv6'].append(ipv6)
|
|
|
@ -297,6 +302,7 @@ class Interfaces(FactsBase):
|
|
|
|
|
|
|
|
|
|
|
|
def parse_interfaces(self, data):
|
|
|
|
def parse_interfaces(self, data):
|
|
|
|
parsed = dict()
|
|
|
|
parsed = dict()
|
|
|
|
|
|
|
|
key = ''
|
|
|
|
for line in data.split('\n'):
|
|
|
|
for line in data.split('\n'):
|
|
|
|
if len(line) == 0:
|
|
|
|
if len(line) == 0:
|
|
|
|
continue
|
|
|
|
continue
|
|
|
@ -444,7 +450,7 @@ def main():
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|