napalm-automation / napalm

Network Automation and Programmability Abstraction Layer with Multivendor support
Apache License 2.0
2.26k stars 555 forks source link

nxos get_environment does not parse power supply output with alternate key name #1372

Closed kaibabbob closed 7 months ago

kaibabbob commented 3 years ago

Description of Issue/Question

Some Nexus models or NXOS versions have a different key for the power load. The function is expecting 'watts' but some switches return the key 'actual_out' instead.

I propose the following update to the _process_pdus() function in nxos.py

''' < normalized[psinfo["psnum"]]["output"] = float(psinfo.get("watts", -1.0))

            # Some models or versions return 'watts' as the key and others 'actual_out'
            if psinfo.get("watts") != None:
                normalized[psinfo["psnum"]]["output"] = float(psinfo.get("watts", -1.0))
            else:
                normalized[psinfo["psnum"]]["output"] = float(psinfo.get("actual_out", -1.0).split()[0])

'''

Did you follow the steps from https://github.com/napalm-automation/napalm#faq

(Place an x between the square brackets where applicable)

Setup

napalm version

(Paste verbatim output from pip freeze | grep napalm between quotes below)

napalm==3.2.0
napalm-panos==0.5.2

Network operating system version

(Paste verbatim output from show version - or equivalent - between quotes below)

Cisco Nexus Operating System (NX-OS) Software
TAC support: http://www.cisco.com/tac
Documents: http://www.cisco.com/en/US/products/ps9372/tsd_products_support_series_home.html
Copyright (c) 2002-2019, Cisco Systems, Inc. All rights reserved.
The copyrights to certain works contained in this software are
owned by other third parties and used and distributed under
license. Certain components of this software are licensed under
the GNU General Public License (GPL) version 2.0 or the GNU
Lesser General Public License (LGPL) Version 2.1. A copy of each
such license is available at
http://www.opensource.org/licenses/gpl-2.0.php and
http://www.opensource.org/licenses/lgpl-2.1.php

Software
  BIOS:      version 2.12.0
  kickstart: version 7.3(5)D1(1)
  system:    version 7.3(5)D1(1)
  BIOS compile time:       05/29/2013
  kickstart image file is: bootflash:///n7000-s2-kickstart.7.3.5.D1.1.bin
  kickstart compile time:  9/30/2019 21:00:00 [11/09/2019 05:55:30]
  system image file is:    bootflash:///n7000-s2-dk9.7.3.5.D1.1.bin
  system compile time:     9/30/2019 21:00:00 [11/09/2019 08:12:42]

Hardware
  cisco Nexus7000 C7004 (4 Slot) Chassis ("Supervisor Module-2")
  Intel(R) Xeon(R) CPU         with 32940104 kB of memory.
  Processor Board ID Jxxx

  Device name: my_router
  bootflash:    1966080 kB
  slot0:              0 kB (expansion flash)

Kernel uptime is 352 day(s), 7 hour(s), 13 minute(s), 16 second(s)

Last reset at 966994 usecs after  Tue Feb 25 09:19:35 2020

  Reason: Reset due to upgrade
  System version: 7.3(3)D1(1)
  Service:

plugin
  Core Plugin, Ethernet Plugin

Active Package(s)

Steps to Reproduce the Issue

The output is shown as -1 from the following command

''' salt my_router napalm.call get_environment my_router:

comment:
out:
    ----------
    cpu:
        ----------
        0:
            ----------
            %usage:
                -1.0
    fans:
        ----------
        Fan1(sys_fan1):
            ----------
            status:
                True
    memory:
        ----------
        available_ram:
            178000
        used_ram:
            55000
    power:
        ----------
        1:
            ----------
            capacity:
                3000.0
            output:
                -1.0
            status:
                True
        2:
            ----------
            capacity:
                0.0
            output:
                -1.0
            status:
                False

'''

Here is what you get from the rpc call:

''' salt sb1agrt732 napalm.nxos_apirpc 'show environment' sb1agrt732: |

  command:
      show environment
  id:
      1
  jsonrpc:
      2.0
  result:
      ----------
      body:
          ----------
powersup: ---------- TABLE_psinfo: ---------- ROW_psinfo: |_ ---------- actual_out: 782 W ps_status: Ok psmodel: N7K-AC-3KW psnum: 1 tot_capa: 3000 W |_ ---------- actual_out: 0 W ps_status: Shutdown psmodel: N7K-AC-3KW psnum: 2 tot_capa: 0 W |_ ''' ### Error Traceback (Paste the complete traceback of the exception between quotes below) ``` none ```
mirceaulinic commented 7 months ago

Resolved via #1809.