diff --git a/napalm_junos/junos.py b/napalm_junos/junos.py index 2de2648..cf0d0a5 100644 --- a/napalm_junos/junos.py +++ b/napalm_junos/junos.py @@ -321,6 +321,7 @@ def get_environment(self): environment = junos_views.junos_enviroment_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() temperature_thresholds.get() @@ -347,7 +348,6 @@ def get_environment(self): environment_data['power'] = {} environment_data['power'][sensor_object] = {} - # Set these values to -1, because Junos does not provide them environment_data['power'][sensor_object]['capacity'] = -1.0 environment_data['power'][sensor_object]['output'] = -1.0 @@ -399,6 +399,21 @@ def get_environment(self): elif structured_temperature_data['yellow-alarm'] <= temp: environment_data['temperature'][sensor_object]['is_alert'] = True + # Try to correct Power Supply information + pem_table = dict() + try: + power_supplies.get() + except RpcError: + # Not all platforms have support for this + pass + else: + # Format PEM information and correct capacity and output values + for pem in power_supplies.items(): + pem_name = pem[0].replace("PEM", "Power Supply") + pem_table[pem_name] = dict(pem[1]) + environment_data['power'][pem_name]['capacity'] = pem_table[pem_name]['capacity'] + environment_data['power'][pem_name]['output'] = pem_table[pem_name]['output'] + for routing_engine_object, routing_engine_data in routing_engine.items(): structured_routing_engine_data = {k: v for k, v in routing_engine_data} # Create dicts for 'cpu' and 'memory'. diff --git a/napalm_junos/utils/junos_views.yml b/napalm_junos/utils/junos_views.yml index 60cbd64..90be164 100644 --- a/napalm_junos/utils/junos_views.yml +++ b/napalm_junos/utils/junos_views.yml @@ -146,6 +146,18 @@ junos_enviroment_view: status: status temperature: { temperature/@celsius: int } +junos_pem_table: + rpc: get-power-usage-information-detail + args: + item: power-usage-item + key: name + view: junos_pem_view + +junos_pem_view: + fields: + capacity: { pem-capacity-detail/capacity-actual: float } + output: { dc-output-detail/dc-power: float } + junos_routing_engine_table: rpc: get-route-engine-information args: diff --git a/test/unit/mocked_data/test_get_environment/normal/get-power-usage-information-detail.xml b/test/unit/mocked_data/test_get_environment/normal/get-power-usage-information-detail.xml new file mode 100644 index 0000000..028bcc4 --- /dev/null +++ b/test/unit/mocked_data/test_get_environment/normal/get-power-usage-information-detail.xml @@ -0,0 +1,4 @@ + + + + diff --git a/test/unit/mocked_data/test_get_environment/virtualchassis/get-power-usage-information-detail.xml b/test/unit/mocked_data/test_get_environment/virtualchassis/get-power-usage-information-detail.xml new file mode 100644 index 0000000..028bcc4 --- /dev/null +++ b/test/unit/mocked_data/test_get_environment/virtualchassis/get-power-usage-information-detail.xml @@ -0,0 +1,4 @@ + + + +