Skip to content

Commit

Permalink
junos_facts: Add Hardware facts. (ansible#30304)
Browse files Browse the repository at this point in the history
* Add Routing Engine Facts

 - Map routing engine output information to routing_engines facts dict.
 - Add fact 'has_2RE', which is a quick way to determine how many REs
   the chassis has.

* Fix a typo

* Fix more typos

* Add slot number to routing_engine dict

* Add facts about the installed chassis modules

* Fix typo

* Fixed another typo

* Fix Path

* Change path again.

* More Typos

* Add some deubgging

* Add additional information for hardware components.

 - Return information about the Routing Engines.
 - Return a fact to easily determine if the device
   has two routing engines.
 - Return information about the hardware modules.

* Addressed pep8 stardard failures.

* Add unit test fixtures.

* Rename fixture.

* Fix unit test failures.

 - Rename the fixture file to what the unit test expects.
 - Strip out junos namespace attributes.
Rename file to match what the unit test expects.

* Scrubbed the routing engine serial numbers.

* Add unit test facts for new tests.

 - Add unit test for ansible_net_routing_engines fact
 - Add unit test for ansible_net_modules fact
 - Add unit test for ansible_net_has_2RE

* Fixed spacing.
  • Loading branch information
dteach authored and ganeshrn committed Sep 20, 2017
1 parent d395166 commit ca56a24
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 1 deletion.
34 changes: 33 additions & 1 deletion lib/ansible/modules/network/junos/junos_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
from ansible.module_utils.netconf import send_request
from ansible.module_utils.six import iteritems


try:
from lxml.etree import Element, SubElement, tostring
except ImportError:
Expand Down Expand Up @@ -138,7 +139,6 @@ def populate(self):

reply = self.rpc('get-chassis-inventory')
data = reply.find('.//chassis-inventory/chassis')

self.facts['serialnum'] = self.get_text(data, 'serial-number')


Expand Down Expand Up @@ -183,6 +183,38 @@ def populate(self):
filesystems.append(self.get_text(obj, 'filesystem-name'))
self.facts['filesystems'] = filesystems

reply = self.rpc('get-route-engine-information')
data = reply.find('.//route-engine-information')

routing_engines = dict()
for obj in data:
slot = self.get_text(obj, 'slot')
routing_engines.update({slot: {}})
routing_engines[slot].update({'slot': slot})
for child in obj:
if child.text != "\n":
routing_engines[slot].update({child.tag.replace("-", "_"): child.text})

self.facts['routing_engines'] = routing_engines

if len(data) > 1:
self.facts['has_2RE'] = True
else:
self.facts['has_2RE'] = False

reply = self.rpc('get-chassis-inventory')
data = reply.findall('.//chassis-module')

modules = list()
for obj in data:
mod = dict()
for child in obj:
if child.text != "\n":
mod.update({child.tag.replace("-", "_"): child.text})
modules.append(mod)

self.facts['modules'] = modules


class Interfaces(FactsBase):

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<rpc-reply>
<route-engine-information>
<route-engine>
<slot>0</slot>
<mastership-state>master</mastership-state>
<mastership-priority>master (default)</mastership-priority>
<status>OK</status>
<temperature>30 degrees C / 86 degrees F</temperature>
<cpu-temperature>27 degrees C / 80 degrees F</cpu-temperature>
<memory-dram-size>16349 MB</memory-dram-size>
<memory-installed-size>(16384 MB installed)</memory-installed-size>
<memory-buffer-utilization>16</memory-buffer-utilization>
<cpu-user>3</cpu-user>
<cpu-background>0</cpu-background>
<cpu-system>5</cpu-system>
<cpu-interrupt>1</cpu-interrupt>
<cpu-idle>92</cpu-idle>
<model>RE-S-EX9200-1800X4</model>
<serial-number>0123456789</serial-number>
<start-time>2017-04-27 12:25:03 PDT</start-time>
<up-time>139 days, 3 hours, 12 minutes, 35 seconds</up-time>
<last-reboot-reason>Router rebooted after a normal shutdown.</last-reboot-reason>
<load-average-one>0.03</load-average-one>
<load-average-five>0.06</load-average-five>
<load-average-fifteen>0.02</load-average-fifteen>
</route-engine>
<route-engine>
<slot>1</slot>
<mastership-state>backup</mastership-state>
<mastership-priority>backup (default)</mastership-priority>
<status>OK</status>
<temperature>30 degrees C / 86 degrees F</temperature>
<cpu-temperature>27 degrees C / 80 degrees F</cpu-temperature>
<memory-dram-size>16349 MB</memory-dram-size>
<memory-installed-size>(16384 MB installed)</memory-installed-size>
<memory-buffer-utilization>10</memory-buffer-utilization>
<cpu-user>0</cpu-user>
<cpu-background>0</cpu-background>
<cpu-system>0</cpu-system>
<cpu-interrupt>0</cpu-interrupt>
<cpu-idle>100</cpu-idle>
<model>RE-S-EX9200-1800X4</model>
<serial-number>0123456789</serial-number>
<start-time>2017-09-13 10:24:59 PDT</start-time>
<up-time>5 hours, 12 minutes, 36 seconds</up-time>
<last-reboot-reason>Router rebooted after a normal shutdown.</last-reboot-reason>
<load-average-one>0.00</load-average-one>
<load-average-five>0.00</load-average-five>
<load-average-fifteen>0.00</load-average-fifteen>
</route-engine>
</route-engine-information>
</rpc-reply>
4 changes: 4 additions & 0 deletions test/units/modules/network/junos/test_junos_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
'get-interface-information': 'show interfaces details',
'get-system-memory-information': 'show system memory',
'get-chassis-inventory': 'show chassis hardware',
'get-route-engine-information': 'show chassis routing-engine',
'get-system-storage': 'show system storage'
}

Expand Down Expand Up @@ -72,6 +73,9 @@ def test_junos_get_facts(self):
self.assertEqual(facts['ansible_net_memtotal_mb'], 983500)
self.assertEqual(facts['ansible_net_filesystems'][0], '/dev/vtbd0s1a')
self.assertTrue('ansible_net_config' not in facts)
self.assertEqual(facts['ansible_net_routing_engines']["0"]['model'], 'RE-S-EX9200-1800X4')
self.assertEqual(facts['ansible_net_modules'][0]['name'], 'Midplane')
self.assertTrue(facts['ansible_net_has_2RE'])

def test_junos_get_facts_subset_config_set(self):
self.get_config.return_value = load_fixture('get_configuration_rpc_reply.txt')
Expand Down

0 comments on commit ca56a24

Please sign in to comment.