3 Replies Latest reply on Jan 29, 2016 8:12 AM by Steven Klassen

    How can I execute CLI with python script.



      thanks for reading this articles.

      i did test the executing CLI script via NCM with powershell is works well.

      but want to know how can i execute the CLI via NCM with python script.


      connection and some test is finished. but have no idea with how can i execute the cli.

      still not developed using python for the NCM yet?

        • Re: How can I execute CLI with python script.

          From your PowerShell script in the other thread, you can see the sequence of Invoke operations needed to execute a CLI operation through NCM. And from your Python code in another thread, you are able to run basic SWIS operations over the REST endpoint from Python. Are you having trouble making the invoke calls from Python? What have you tried?

            • Re: How can I execute CLI with python script.

              Dear, Tdanner.

              thank you very much for interesting my thread,

              the python script included in the Orion SDK 1.8. understood basic SWIS operations over REST endpoint, such as create the custom properties, and delete it etc.

              i need to build a script for working with NCM operations

              i don't know how to make it with python script, so to fullfill the requirement making it with powershell script now.

              testing on the Nexus 3048 switches(at least hundreds of devices). to fullfill following requirements now.

              1. input the Vpc Config.

              2. input the VLAN Config.

              3. export the result on the 'show env power |grep fail'

              4. export the result only RX, TX between -4 dbm to -30 dbm on the 'show interface transceiver detail'


              How can i change below powershell script working with python script??


              ======IOS Version Check Sample script with powershell script=======

              # Nexus3048 IOS Version Check v1.0

              # Last Modified : 2014.05.13

              # Author : David, Shin

              # Email : david.shin@hostingglobal.co.kr


              if (! (Get-PSSnapin | where {$_.Name -eq "SwisSnapin"})) {

                  Add-PSSnapin "SwisSnapin"



              $date=Get-Date -format "yyMMddhh"

              $File = "C:\$date-OS_CHECK.txt"

              $hostname = ""

              $username = "admin"

              $password = New-Object System.Security.SecureString

              $cred = New-Object -typename System.Management.Automation.PSCredential -argumentlist $username, $password

              $swis = Connect-Swis -v2 -host $hostname -cred $cred

              $group=read-host "Location"

              $IOS=read-host "IOS version: "

              $nodeId = get-swisdata $swis "SELECT NodeID FROM Cirrus.Nodes WHERE NodeGroup='$group'"

              $count = 0

              foreach ($node in $nodeId) {

                $Caption = get-swisdata $swis "SELECT NodeCaption FROM Cirrus.Nodes WHERE NodeId='$node'"

                $IOS_Ver = get-swisdata $swis "SELECT OSVersion FROM Cirrus.Nodes WHERE NodeId='$node'"

                If ($IOS_Ver -match $IOS)


                 $output = "$Caption $IOS_Ver OK"

                 write-host $output

                 $output | Out-File $File -append




                $output = "$Caption $IOS_Ver FAIL"

                       write-host $output

                  $output | Out-File $File -append


                      $count = $count + 1


              $count = "Total : $count Devices"

              $count | Out-File $File -append

              Write-Host "$count Completed."

                • Re: How can I execute CLI with python script.
                  Steven Klassen

                  This is a nearly straight rewrite of what you had in Python. It requires the swisclient from pypi (pip install swisclient) and python3:


                  import swis
                  from datetime import datetime
                  """A conversion of the PowerShell script by David Shin."""
                  def main():
                      date = datetime.today('%y%m%d%H')
                      file = 'C:\{}-OS_CHECK.txt'.format(date)
                      hostname = ''
                      username = 'admin'
                      password = ''
                      swis = swis.SwisClient(hostname, username, password)
                      group = input('Location:')
                      ios = input('IOS version:')
                      nodeid = swis.query(
                              "SELECT NodeID FROM Cirrus.Nodes WHERE NodeGroup = @group_param",
                                  group_param = group)
                      count = 0
                      for node in nodeid:
                          caption = swis.query(
                                  "SELECT NodeCaption FROM Cirrus.Nodes WHERE NodeID = @nodeid_param",
                                      nodeid_param = node)
                          ios_ver = swis.query(
                                  "SELECT OSVersion FROM Cirrus.Nodes WHRE NodeID = @nodeid_param",
                                      nodeid_param = node)
                          if ios_ver == ios:
                              output = "{} {} OK".format(caption, ios_ver)
                              output = "{} {} FAIL".format(caption, ios_ver)
                          count += 1
                          with open(file, 'a') as myfile:
                      results = "Total : {} Devices".format(count)
                      with open(file, 'a') as myfile:
                  if __name__ == '__main__':



                  Steven Klassen

                  Developer Analyst @ Loop1 Systems, Inc.