Skip to content

Commit

Permalink
Merge 2c59eb2 into 5105dfb
Browse files Browse the repository at this point in the history
  • Loading branch information
mirceaulinic committed May 5, 2020
2 parents 5105dfb + 2c59eb2 commit e978da2
Show file tree
Hide file tree
Showing 9 changed files with 222 additions and 14 deletions.
38 changes: 27 additions & 11 deletions napalm/junos/junos.py
Expand Up @@ -391,9 +391,20 @@ def get_interfaces_counters(self):

def get_environment(self):
"""Return environment details."""
environment = junos_views.junos_environment_table(self.device)
routing_engine = junos_views.junos_routing_engine_table(self.device)
temperature_thresholds = junos_views.junos_temperature_thresholds(self.device)
if self.device.facts.get("srx_cluster", False):
environment = junos_views.junos_environment_table_srx_cluster(self.device)
routing_engine = junos_views.junos_routing_engine_table_srx_cluster(
self.device
)
temperature_thresholds = junos_views.junos_temperature_thresholds_srx_cluster(
self.device
)
else:
environment = junos_views.junos_environment_table(self.device)
routing_engine = junos_views.junos_routing_engine_table(self.device)
temperature_thresholds = junos_views.junos_temperature_thresholds(
self.device
)
power_supplies = junos_views.junos_pem_table(self.device)
environment.get()
routing_engine.get()
Expand Down Expand Up @@ -546,15 +557,20 @@ def get_environment(self):
if i.isdigit()
)
)
# Junos gives us RAM in %, so calculation has to be made.
# Sadly, bacause of this, results are not 100% accurate to the truth.
environment_data["memory"]["used_ram"] = int(
round(
environment_data["memory"]["available_ram"]
/ 100.0
* structured_routing_engine_data["memory-buffer-utilization"]
if not structured_routing_engine_data["memory-system-total-used"]:
# Junos gives us RAM in %, so calculation has to be made.
# Sadly, bacause of this, results are not 100% accurate to the truth.
environment_data["memory"]["used_ram"] = int(
round(
environment_data["memory"]["available_ram"]
/ 100.0
* structured_routing_engine_data["memory-buffer-utilization"]
)
)
)
else:
environment_data["memory"]["used_ram"] = structured_routing_engine_data[
"memory-system-total-used"
]

return environment_data

Expand Down
29 changes: 27 additions & 2 deletions napalm/junos/utils/junos_views.yml
Expand Up @@ -157,6 +157,14 @@ junos_environment_table:
key: name
view: junos_environment_view

junos_environment_table_srx_cluster:
rpc: get-environment-information
args:
node: primary
item: multi-routing-engine-item/environment-information/environment-item
key: name
view: junos_environment_view

junos_environment_view:
fields:
class: class
Expand All @@ -183,11 +191,20 @@ junos_routing_engine_table:
key: slot
view: junos_routing_engine_view

junos_routing_engine_table_srx_cluster:
rpc: get-route-engine-information
args:
node: primary
item: multi-routing-engine-item/route-engine-information/route-engine
key: ../../re-name
view: junos_routing_engine_view

junos_routing_engine_view:
fields:
cpu-idle: { cpu-idle: int }
memory-dram-size: memory-dram-size
memory-buffer-utilization : { memory-buffer-utilization: int }
memory-dram-size: memory-dram-size | memory-system-total
memory-buffer-utilization: { memory-buffer-utilization: int }
memory-system-total-used: { memory-system-total-used: int }

junos_temperature_thresholds:
rpc: get-temperature-threshold-information
Expand All @@ -196,6 +213,14 @@ junos_temperature_thresholds:
key: name
view: junos_temperature_thresholds_view

junos_temperature_thresholds_srx_cluster:
rpc: get-temperature-threshold-information
args:
node: primary
item: multi-routing-engine-item/temperature-threshold-information/temperature-threshold
key: name
view: junos_temperature_thresholds_view

junos_temperature_thresholds_view:
fields:
name: name
Expand Down
2 changes: 1 addition & 1 deletion test/junos/conftest.py
Expand Up @@ -53,6 +53,7 @@ def __init__(self):
self._conn = FakeConnection(self.rpc)
self.alternative_facts_file = "facts.yml"
self.ON_JUNOS = True # necessary for fake devices
self.hostname = "test"
self.default_facts = {
"domain": None,
"hostname": "vsrx",
Expand Down Expand Up @@ -132,7 +133,6 @@ def response(self, **rpc_args):
filename = "{item}{instance}.xml".format(item=self.item, instance=instance)
filepathpath = self._device.find_file(filename)
xml_string = self._device.read_txt_file(filepathpath)

return lxml.etree.fromstring(xml_string)

def get_config(self, get_cmd=None, filter_xml=None, options={}):
Expand Down
@@ -0,0 +1,49 @@
{
"temperature": {
"Routing Engine": {
"temperature": 39,
"is_alert": false,
"is_critical": false
},
"Routing Engine CPU": {
"temperature": 68,
"is_alert": true,
"is_critical": false
}
},
"fans": {
"SRX340 Chassis fan 0": {
"status": true
},
"SRX340 Chassis fan 1": {
"status": true
},
"SRX340 Chassis fan 2": {
"status": true
},
"SRX340 Chassis fan 3": {
"status": true
}
},
"power": {
"Power Supply 0": {
"capacity": -1,
"output": -1,
"status": true
},
"Power Supply 1": {
"capacity": -1,
"output": -1,
"status": true
}
},
"cpu": {
"node0": {
"%usage": 8
}
},
"memory": {
"available_ram": 4096,
"used_ram": 1311
}
}
@@ -0,0 +1 @@
srx_cluster: true
@@ -0,0 +1,52 @@
<multi-routing-engine-results>
<multi-routing-engine-item>
<re-name>node0</re-name>
<environment-information>
<environment-item>
<name>Routing Engine</name>
<class>Temp</class>
<status>OK</status>
<temperature celsius="39">39 degrees C / 102 degrees F</temperature>
</environment-item>
<environment-item>
<name>Routing Engine CPU</name>
<status>OK</status>
<temperature celsius="68">68 degrees C / 154 degrees F</temperature>
</environment-item>
<environment-item>
<name>SRX340 Chassis fan 0</name>
<class>Fans</class>
<status>OK</status>
<comment>Spinning at normal speed</comment>
</environment-item>
<environment-item>
<name>SRX340 Chassis fan 1</name>
<class>Fans</class>
<status>OK</status>
<comment>Spinning at normal speed</comment>
</environment-item>
<environment-item>
<name>SRX340 Chassis fan 2</name>
<class>Fans</class>
<status>OK</status>
<comment>Spinning at normal speed</comment>
</environment-item>
<environment-item>
<name>SRX340 Chassis fan 3</name>
<class>Fans</class>
<status>OK</status>
<comment>Spinning at normal speed</comment>
</environment-item>
<environment-item>
<name>Power Supply 0</name>
<class>Power</class>
<status>OK</status>
</environment-item>
<environment-item>
<name>Power Supply 1</name>
<class>Power</class>
<status>OK</status>
</environment-item>
</environment-information>
</multi-routing-engine-item>
</multi-routing-engine-results>
@@ -0,0 +1,4 @@
<power-usage-information>
<power-usage-item>
</power-usage-item>
</power-usage-information>
@@ -0,0 +1,34 @@
<multi-routing-engine-results>
<multi-routing-engine-item>
<re-name>node0</re-name>
<route-engine-information>
<route-engine>
<status>OK</status>
<temperature celsius="35">35 degrees C / 95 degrees F</temperature>
<cpu-temperature celsius="63">63 degrees C / 145 degrees F</cpu-temperature>
<memory-system-total>4096</memory-system-total>
<memory-system-total-used>1311</memory-system-total-used>
<memory-system-total-util>32</memory-system-total-util>
<memory-control-plane>2624</memory-control-plane>
<memory-control-plane-used>682</memory-control-plane-used>
<memory-control-plane-util>26</memory-control-plane-util>
<memory-data-plane>1472</memory-data-plane>
<memory-data-plane-used>618</memory-data-plane-used>
<memory-data-plane-util>42</memory-data-plane-util>
<cpu-user>6</cpu-user>
<cpu-background>0</cpu-background>
<cpu-system>2</cpu-system>
<cpu-interrupt>0</cpu-interrupt>
<cpu-idle>92</cpu-idle>
<model>RE-SRX345-DUAL-AC</model>
<serial-number>DS1319AF0037</serial-number>
<start-time seconds="1584485864">2020-03-17 22:57:44 UTC</start-time>
<up-time seconds="3626317">41 days, 23 hours, 18 minutes, 37 seconds</up-time>
<last-reboot-reason>0x1:power cycle/failure </last-reboot-reason>
<load-average-one>0.19</load-average-one>
<load-average-five>0.09</load-average-five>
<load-average-fifteen>0.02</load-average-fifteen>
</route-engine>
</route-engine-information>
</multi-routing-engine-item>
</multi-routing-engine-results>
@@ -0,0 +1,27 @@
<multi-routing-engine-results>
<multi-routing-engine-item>
<re-name>node0</re-name>
<temperature-threshold-information>
<temperature-threshold>
<name>Chassis default</name>
<fan-normal-speed>35</fan-normal-speed>
<fan-high-speed>56</fan-high-speed>
<bad-fan-yellow-alarm>40</bad-fan-yellow-alarm>
<bad-fan-red-alarm>65</bad-fan-red-alarm>
<yellow-alarm>60</yellow-alarm>
<red-alarm>75</red-alarm>
<fire-shutdown>100</fire-shutdown>
</temperature-threshold>
<temperature-threshold>
<name>Routing Engine</name>
<fan-normal-speed>35</fan-normal-speed>
<fan-high-speed>56</fan-high-speed>
<bad-fan-yellow-alarm>40</bad-fan-yellow-alarm>
<bad-fan-red-alarm>65</bad-fan-red-alarm>
<yellow-alarm>60</yellow-alarm>
<red-alarm>75</red-alarm>
<fire-shutdown>100</fire-shutdown>
</temperature-threshold>
</temperature-threshold-information>
</multi-routing-engine-item>
</multi-routing-engine-results>

0 comments on commit e978da2

Please sign in to comment.