Skip to content

Commit

Permalink
Resolve #1181 and reduce the get_facts heavy workload
Browse files Browse the repository at this point in the history
Primarily resolving #1181, switching to querying the MemorySummary from
the Operational block, rather than AdminOperational for XR 7+.

At the same time, I'm updating the RPC request from ``get_facts`` to
reduce the amount of data received from the device; from a VM it's
probably not a lot being received, but from an actual production device
there are walls of XML to be processed. This should therefore
significantly improve the facts gathering and ``get_environment`` too.
  • Loading branch information
mirceaulinic committed Mar 22, 2021
1 parent a84793b commit 3db3ff0
Show file tree
Hide file tree
Showing 17 changed files with 79,311 additions and 4 deletions.
24 changes: 20 additions & 4 deletions napalm/iosxr/iosxr.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,12 @@ def get_facts(self):
"interface_list": [],
}

facts_rpc_request = "<Get><Operational><SystemTime/><PlatformInventory/>\
</Operational></Get>"
facts_rpc_request = (
"<Get><Operational><SystemTime/><PlatformInventory><RackTable>"
"<Rack><Naming><Name>0</Name></Naming>"
"<Attributes><BasicInfo/></Attributes>"
"</Rack></RackTable></PlatformInventory></Operational></Get>"
)

facts_rpc_reply = ETREE.fromstring(self.device.make_rpc_call(facts_rpc_request))
system_time_xpath = ".//SystemTime/Uptime"
Expand Down Expand Up @@ -660,12 +664,24 @@ def get_module_xml_query(module, selection):

facts = self.get_facts()
router_model = facts.get("model")
xr_version = facts.get("os_version")
major_version = (
int(xr_version.split(".")[0])
if xr_version
and isinstance(xr_version, str)
and xr_version.split(".")[0].isnumeric()
else 0
)
is_xrv = router_model.lower().startswith("xrv")
environment_status["memory"] = {"available_ram": 0.0, "used_ram": 0.0}

if not is_xrv:
rpc_command = "<Get><AdminOperational><MemorySummary>\
</MemorySummary></AdminOperational></Get>"
if major_version >= 7:
rpc_command = "<Get><Operational><MemorySummary>\
</MemorySummary></Operational></Get>"
else:
rpc_command = "<Get><AdminOperational><MemorySummary>\
</MemorySummary></AdminOperational></Get>"
result_tree = ETREE.fromstring(self.device.make_rpc_call(rpc_command))

for node in result_tree.xpath(".//Node"):
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,285 @@
<?xml version="1.0"?>
<Response MajorVersion="1" MinorVersion="0">
<Get>
<AdminOperational>
<EnvironmentalMonitoring MajorVersion="1" MinorVersion="1">
<RackTable MajorVersion="0" MinorVersion="0">
<Rack>
<Naming>
<rack>0</rack>
</Naming>
<SlotTable>
<Slot>
<Naming>
<slot>PM0</slot>
</Naming>
<ModuleTable>
<Module>
<Naming>
<Module>host</Module>
</Naming>
<SensorTypeTable>
<SensorType>
<Naming>
<Type>volt</Type>
</Naming>
<SensorNameTable>
<SensorName>
<Naming>
<Name>host__VOLT</Name>
</Naming>
<ValueBrief>55520</ValueBrief>
<ValueDetailed>
<FieldValidityBitmap>3071</FieldValidityBitmap>
<DeviceDescription>voltVOLT</DeviceDescription>
<Units>mV</Units>
<DeviceId>0</DeviceId>
<Value>55520</Value>
<AlarmType>0</AlarmType>
<DataType>4</DataType>
<Scale>8</Scale>
<Precision>0</Precision>
<Status>1</Status>
<AgeTimeStamp>0</AgeTimeStamp>
<UpdateRate>0</UpdateRate>
</ValueDetailed>
<ThresholdTable>
<Threshold>
<Naming>
<Type>minor_lo</Type>
</Naming>
<ValueBrief>-32768</ValueBrief>
<Trap>true</Trap>
<ValueDetailed>
<ThresholdSeverity>10</ThresholdSeverity>
<ThresholdRelation>2</ThresholdRelation>
<ThresholdValue>4294934528</ThresholdValue>
<ThresholdEvaluation>false</ThresholdEvaluation>
<ThresholdNotificationEnabled>true</ThresholdNotificationEnabled>
</ValueDetailed>
</Threshold>
<Threshold>
<Naming>
<Type>minor_hi</Type>
</Naming>
<ValueBrief>-32768</ValueBrief>
<Trap>true</Trap>
<ValueDetailed>
<ThresholdSeverity>10</ThresholdSeverity>
<ThresholdRelation>4</ThresholdRelation>
<ThresholdValue>4294934528</ThresholdValue>
<ThresholdEvaluation>false</ThresholdEvaluation>
<ThresholdNotificationEnabled>true</ThresholdNotificationEnabled>
</ValueDetailed>
</Threshold>
<Threshold>
<Naming>
<Type>major_lo</Type>
</Naming>
<ValueBrief>-32768</ValueBrief>
<Trap>true</Trap>
<ValueDetailed>
<ThresholdSeverity>20</ThresholdSeverity>
<ThresholdRelation>2</ThresholdRelation>
<ThresholdValue>4294934528</ThresholdValue>
<ThresholdEvaluation>false</ThresholdEvaluation>
<ThresholdNotificationEnabled>true</ThresholdNotificationEnabled>
</ValueDetailed>
</Threshold>
<Threshold>
<Naming>
<Type>major_hi</Type>
</Naming>
<ValueBrief>-32768</ValueBrief>
<Trap>true</Trap>
<ValueDetailed>
<ThresholdSeverity>20</ThresholdSeverity>
<ThresholdRelation>4</ThresholdRelation>
<ThresholdValue>4294934528</ThresholdValue>
<ThresholdEvaluation>false</ThresholdEvaluation>
<ThresholdNotificationEnabled>true</ThresholdNotificationEnabled>
</ValueDetailed>
</Threshold>
<Threshold>
<Naming>
<Type>critical_lo</Type>
</Naming>
<ValueBrief>-32768</ValueBrief>
<Trap>true</Trap>
<ValueDetailed>
<ThresholdSeverity>30</ThresholdSeverity>
<ThresholdRelation>2</ThresholdRelation>
<ThresholdValue>4294934528</ThresholdValue>
<ThresholdEvaluation>false</ThresholdEvaluation>
<ThresholdNotificationEnabled>true</ThresholdNotificationEnabled>
</ValueDetailed>
</Threshold>
<Threshold>
<Naming>
<Type>critical_hi</Type>
</Naming>
<ValueBrief>-32768</ValueBrief>
<Trap>true</Trap>
<ValueDetailed>
<ThresholdSeverity>30</ThresholdSeverity>
<ThresholdRelation>3</ThresholdRelation>
<ThresholdValue>4294934528</ThresholdValue>
<ThresholdEvaluation>false</ThresholdEvaluation>
<ThresholdNotificationEnabled>true</ThresholdNotificationEnabled>
</ValueDetailed>
</Threshold>
</ThresholdTable>
</SensorName>
</SensorNameTable>
</SensorType>
<SensorType>
<Naming>
<Type>pwrs</Type>
</Naming>
<SensorNameTable>
<SensorName>
<Naming>
<Name>host__PM</Name>
</Naming>
<ValueBrief>3000</ValueBrief>
<ValueDetailed>
<FieldValidityBitmap>3071</FieldValidityBitmap>
<DeviceDescription>pwrsPM</DeviceDescription>
<DeviceId>0</DeviceId>
<Value>3000</Value>
<AlarmType>0</AlarmType>
<DataType>6</DataType>
<Scale>9</Scale>
<Precision>0</Precision>
<Status>1</Status>
<AgeTimeStamp>0</AgeTimeStamp>
<UpdateRate>0</UpdateRate>
</ValueDetailed>
</SensorName>
</SensorNameTable>
</SensorType>
<SensorType>
<Naming>
<Type>curr</Type>
</Naming>
<SensorNameTable>
<SensorName>
<Naming>
<Name>host__CURR</Name>
</Naming>
<ValueBrief>8074</ValueBrief>
<ValueDetailed>
<FieldValidityBitmap>3071</FieldValidityBitmap>
<DeviceDescription>currCURR</DeviceDescription>
<Units>mA</Units>
<DeviceId>0</DeviceId>
<Value>8074</Value>
<AlarmType>0</AlarmType>
<DataType>5</DataType>
<Scale>8</Scale>
<Precision>0</Precision>
<Status>1</Status>
<AgeTimeStamp>0</AgeTimeStamp>
<UpdateRate>0</UpdateRate>
</ValueDetailed>
<ThresholdTable>
<Threshold>
<Naming>
<Type>minor_lo</Type>
</Naming>
<ValueBrief>-32768</ValueBrief>
<Trap>true</Trap>
<ValueDetailed>
<ThresholdSeverity>10</ThresholdSeverity>
<ThresholdRelation>2</ThresholdRelation>
<ThresholdValue>4294934528</ThresholdValue>
<ThresholdEvaluation>false</ThresholdEvaluation>
<ThresholdNotificationEnabled>true</ThresholdNotificationEnabled>
</ValueDetailed>
</Threshold>
<Threshold>
<Naming>
<Type>minor_hi</Type>
</Naming>
<ValueBrief>-32768</ValueBrief>
<Trap>true</Trap>
<ValueDetailed>
<ThresholdSeverity>10</ThresholdSeverity>
<ThresholdRelation>4</ThresholdRelation>
<ThresholdValue>4294934528</ThresholdValue>
<ThresholdEvaluation>false</ThresholdEvaluation>
<ThresholdNotificationEnabled>true</ThresholdNotificationEnabled>
</ValueDetailed>
</Threshold>
<Threshold>
<Naming>
<Type>major_lo</Type>
</Naming>
<ValueBrief>-32768</ValueBrief>
<Trap>true</Trap>
<ValueDetailed>
<ThresholdSeverity>20</ThresholdSeverity>
<ThresholdRelation>2</ThresholdRelation>
<ThresholdValue>4294934528</ThresholdValue>
<ThresholdEvaluation>false</ThresholdEvaluation>
<ThresholdNotificationEnabled>true</ThresholdNotificationEnabled>
</ValueDetailed>
</Threshold>
<Threshold>
<Naming>
<Type>major_hi</Type>
</Naming>
<ValueBrief>-32768</ValueBrief>
<Trap>true</Trap>
<ValueDetailed>
<ThresholdSeverity>20</ThresholdSeverity>
<ThresholdRelation>4</ThresholdRelation>
<ThresholdValue>4294934528</ThresholdValue>
<ThresholdEvaluation>false</ThresholdEvaluation>
<ThresholdNotificationEnabled>true</ThresholdNotificationEnabled>
</ValueDetailed>
</Threshold>
<Threshold>
<Naming>
<Type>critical_lo</Type>
</Naming>
<ValueBrief>-32768</ValueBrief>
<Trap>true</Trap>
<ValueDetailed>
<ThresholdSeverity>30</ThresholdSeverity>
<ThresholdRelation>2</ThresholdRelation>
<ThresholdValue>4294934528</ThresholdValue>
<ThresholdEvaluation>false</ThresholdEvaluation>
<ThresholdNotificationEnabled>true</ThresholdNotificationEnabled>
</ValueDetailed>
</Threshold>
<Threshold>
<Naming>
<Type>critical_hi</Type>
</Naming>
<ValueBrief>-32768</ValueBrief>
<Trap>true</Trap>
<ValueDetailed>
<ThresholdSeverity>30</ThresholdSeverity>
<ThresholdRelation>3</ThresholdRelation>
<ThresholdValue>4294934528</ThresholdValue>
<ThresholdEvaluation>false</ThresholdEvaluation>
<ThresholdNotificationEnabled>true</ThresholdNotificationEnabled>
</ValueDetailed>
</Threshold>
</ThresholdTable>
</SensorName>
</SensorNameTable>
</SensorType>
</SensorTypeTable>
</Module>
</ModuleTable>
</Slot>
</SlotTable>
</Rack>
</RackTable>
</EnvironmentalMonitoring>
</AdminOperational>
</Get>
<ResultSummary ErrorCount="0"/>
</Response>
Loading

0 comments on commit 3db3ff0

Please sign in to comment.