1. Technologies Technologies
  2. Networking
  3. NX-OS
  • Docs
  • Community
  • Support
portal-open-nxos
  • Guides
    • Getting Started
      • Introduction
      • Open NX-OS Programmability
      • Configuration
      • Reserve a sandbox lab
      • Interface
      • VLAN
      • OSPF
      • TACACS
      • AAA
      • SNMP
      • Monitoring
      • Interface
      • Hardware Buffer
      • Troubleshooting
      • Ping
      • TraceRoute
    • Developer Guide
      • Introduction
      • Open NX-OS and Linux
        • Introduction
        • Cisco Nexus Switch as a Linux Device
          • Open NX-OS Linux
          • Linux Kernel Stack
          • Open NX-OS Linux Network Architecture
          • Linux Shell Tools
          • Package Management Infrastructure
          • RedHat Package Manager (RPM)
          • Persistently Daemonizing a Third Party
          • Linux Networking
          • Linux Network Namespaces and NX-OS Virtual Routing and Forwarding (VRF)
        • Linux Containers and the Guest Shell
          • Guest Shell
          • Application Persistence within the Guest Shell Environment
          • Working with Sockets in the Guest Shell
        • Open NX-OS Architecture
          • An Extensible Network OS
          • Flexible Programming Options
          • Support for Automation Tools
          • Integrating Third-party Applications
          • Open NX-OS Modular Architecture
          • Interactive Programmability with Python
          • ASIC-level Shell Access
          • Summary
          • Third Party Application Integration
          • Telemetry Applications
          • Open Source Protocols
      • Network Programmability Fundamentals
        • Introduction
        • Conventional Network Interfaces
          • Command Line Interface (CLI)
          • Simple Network Management Protocol (SNMP)
          • NETCONF
        • Programmable Network Elements
          • Device Layer
          • Controller Layer
          • Higher Layer Orchestration
        • Cisco NX-API CLI
          • NX-API CLI Security
          • Working with NX-API CLI
          • Summary
      • Model Driven Programming
        • Introduction
        • Model Driven Programming
          • The Nature of Data Models
          • The Value of Data Models
        • Cisco Open NX-OS MDP Architecture
          • Data Management Engines
          • Management Information Tree
          • Everything is an Object
          • Identifying Objects in the MIT
          • Accessing Objects with Queries
        • REST API Primer
          • Application Programming Interface - API
          • HTTP
          • REpresentational State Transfer - REST
        • Cisco NX-API REST Interface
          • Transactional
          • Backwards Compatible
          • Event-Driven
          • Secure
          • Flexible
          • Standards-based
        • Cisco NX-API WebSocket Notifications
          • Subscribing to Query Results
      • Configuration Management and Automation
        • Introduction
        • Device Power-On Automation
          • Day-0 (zero) Provisioning
          • POAP/PXE Components and Architecture
          • POAP Process
          • PXE Process
          • Loading RPMs and Agents using POAP/PXE
          • Day-0 Automation Tool - Ignite
          • Getting Started with Ignite
        • Configuration and Lifecycle Management
          • Models: Imperative vs. Declarative
          • Configuration Management in Open NX-OS
          • Agent-less Management
          • Agent-based Management
        • IT Automation Tools
          • Ansible
          • Chef
          • Puppet
          • Manifests
          • Puppet Reference Links
      • Practical Applications of Network Programmability
        • Introduction
        • Infrastructure Provisioning Automation
          • Problem Statement
          • Solution
          • Solution Approach
          • Conclusion
        • Automating Access Configuration with Ansible
          • Problem Statement
          • Solution
          • Solution Approach
          • Conclusion
        • Workload On-Boarding
          • Problem Statement
          • Solution
          • Solution Approach
          • Conclusion
        • Infrastructure as Code
          • Problem Statement
          • Solution
          • Solution Approach
          • Conclusion
        • Troubleshooting with Linux Capabilities
          • Problem Statement
          • Solution
          • Solution Approach
          • Conclusion
        • Network Monitoring with Splunk
          • Problem Statement
          • Solution
          • Solution Approach
          • Conclusion
        • Network Monitoring with Open Source Tools
          • Problem Statement
          • Solution
          • Solution Approach
          • Conclusion
        • Automating Network Auditing and Compliance
          • Problem Statement
          • Solution
          • Solution Approach
          • Script Output
          • Conclusion
        • Automated Network Topology Verification
          • Problem Statement
          • Solution
          • Cable-Plan from the Command Line
          • Conclusion
        • Event Based Workload Mobility
          • Problem Statement
          • Solution
          • Solution Approach
          • Conclusion
        • Network Resiliency
          • Problem Statement
          • Solution
          • Solution Approach
          • Conclusion
        • Programmability Tools for Network Engineers
          • Introduction
          • Languages and Environments
        • Development and Testing Tools
          • Postman
          • NX-API CLI Developer Sandbox
          • Visore
          • Firebug
          • Virtual Internet Routing Lab (VIRL) and NX-OSv
        • Source Code and Version Control
          • Why Version Control?
          • Git
          • GitHub
        • Cisco DevNet for Open NX-OS
        • Learning and Helpful Resources
          • Learning a Language
          • Getting Help
    • Developer Tooling
    • Guest Shell
    • Telemetry
    • Telemetry Deployment for VXLAN EVPN
  • APIs
    • Model Driven Programmability with YANG
    • NX-API REST
    • NX-API DME Reference
    • Python
      • Cisco Nexus 9000 Series Python SDK User Guide and API Reference
      • ACL Module
      • BGP Module
      • CLI Module
      • FEATURE Module
      • INTERFACE Module
      • KEY Module
      • MAC_ADDRESS_TABLE Module
      • OSPFSession Module
      • ROUTEMAP Module
      • ROUTES Module
      • SSH Module
      • SYSTEM Module
      • TACACS Module
      • VLAN Module
      • VRF Module
      • Running the Python API from the Guest Shell
      • Example Scripts
  • Automation
    • POAP
    • Configuration Management
    • Ansible
    • Puppet
    • Chef
  • Extensibility
    • Kstack
    • Guest Shell
    • iPXE
  • Resources
    • Sandbox
    • Blog
    • Forum
    • Support

Introduction

Open NX-OS Programmability

Open NX-OS on the Cisco Nexus platform is a rich software suite built on a Linux foundation that exposes APIs, data models, and programmatic constructs. Using Application Programmatic Interfaces (APIs) and configuration agents, operators can affect configuration changes in a more programmatic way. Cisco provides various tools and frameworks to enable developers to automate and program Nexus devices, including - NX-API REST brings Model Driven Programmability (MDP) to standalone, Python, Puppet, Chef, Ansible etc.

This section provides basic Open NX-OS configuration use cases, such as - interface config, VLAN config & management, OSPF config etc. Examples are written in most widely used config tools/programmatic interfaces - Puppet, NX-API and Python.

In addition to code snippets on the right, we are happy to provide users with access to Cisco's DevNet Sandbox lab resources. Instructions on accessing DevNet Sandbox Labs and instructions to run the script are provided below.

Configuration

Reserve a sandbox lab

The Open NX-OS sandbox is a testing environment that enables developers to experiment from the production environment or repository of CISCO lab. A developer can use this sandbox to program the switch through various configuration management tools and scripts like bash, python, puppet, chef and ansible.

  1. Go to the DevNet Sandbox data center labs
  2. Click on the Open NX-OS box to read more about the lab or click on "Reserve" to reserve the lab.
  3. Upon successful reservation you will receive an email from the DevNet Sandbox team that describes further instructions to access the sandbox.

Interface

Program and manage interfaces. You can configure interfaces using different configuration management tools. Following example shows how to display Nexus 9000 interfaces, bring the interfaces up or down, configure IP address.

Configure physical ethernet port for various interface properties on eth1/1:

http
python
puppet
POST http://SWITCH_IP/api/mo/sys/intf/phys-[eth1/1].json?query-target=self HTTP/1.1
Content-Type: application/json
Cache-Control: no-cache

{
    "l1PhysIf": {
        "attributes": {
            "accessVlan": "vlan-321",
            "adminSt": "down",
            "bw": "0",
            "childAction": "",
            "delay": "1",
            "descr": "Sample test",
            "duplex": "auto",
            "id": "eth1/1",
            "layer": "Layer2",
            "lcOwn": "local",
            "linkDebounce": "100",
            "mdix": "auto",
            "mode": "access",
            "mtu": "1500",
            "portT": "leaf",
            "snmpTrapSt": "enable",
            "speed": "auto",
            "trunkLog": "default",
            "trunkVlans": "1-4094"
        }
    }
}
# Sample file to configure Interface
# Import Interface class
from .interface import  Interface
from .nxcli import NXCLI
import traceback

# Fillup the Interface details to be configured
interfaceName="Ethernet1/6"
interfaceIpaddress="192.168.17.12/24"
interfaceDescription="Interface6"
interfaceState="no shut"

def is_interface_available(interfaceName):
        """
        Checks if interface is available or not.
        return True if interface is available, else return False
        """

        try:
                interface = NXCLI('show run interface %s' %interfaceName)
                return True
        except:
                return False

def configure_terminal(cmd):
        """
        Configure terminal based on the commands given
        """

        NXCLI._run_cfg(cmd)

def convert_to_routed_interface(interfaceName):
        """
        Convert interface mode from access to routed
        """

        cmd = "interface %s ; no switchport" %interfaceName
        configure_terminal(cmd)

if __name__=="__main__":

        try:
                if not is_interface_available(interfaceName):
                        raise Exception("Interface not available. \nPlease give different interface. To list available interfaces, just go to switch-prompt and type : \nshow int br")

                switch=Interface(interfaceName)

                print "Before Interface Configuration"
                configurationResults=switch.config()
                print configurationResults

                convert_to_routed_interface(interfaceName)

                if interfaceIpaddress:
                        #set Ip address
                        ipaddress=switch.set_ipaddress(interfaceIpaddress)

                        #set Description
                        if interfaceDescription:
                                description=switch.set_description(interfaceDescription)

                        #set mode and state
                        switch.set_state(interfaceState)

                print "After interface  Configuration"
                configurationResults=switch.config()
                print configurationResults


        except Exception,e:
                traceback.print_exc()
# Configuring Interface eth1/1
     cisco_interface { "Ethernet1/1" :
        shutdown            => true,
        switchport_mode     => disabled,
        description         => 'managed by puppet',
        ipv4_address        => '1.1.43.43',
        ipv4_netmask_length => 24,
      }
# Configuring interface eth1/2
     cisco_interface { "Ethernet1/2" :
        description => 'default',
        shutdown    => 'default',
        access_vlan => 'default',
        switchport_mode => access,
     }
# Configuring interface
     cisco_interface { "Vlan22" :
        svi_autostate => false,
        svi_management => true,
     }

Using NX-API REST in the sandbox

Follow below the steps below to execute NX-API REST code snippet on a nx9000 switch.

On the nx9000 switch perform following operation.

  1. SSH to switch using provided credentials. (If credentials are not provided Default username is 'admin' and password 'cisco123'
  2. Run 'config t' on the switch prompt.
  3. Enable nxapi by running 'feature nxapi'.
  4. Exit to switch prompt by running 'exit'.
  5. Run 'copy r s' to save the configuration.

Setup postman Code snippet: In order to execute NXAPI from postman, login needs to be performed. The cookie would get generated and stored for subsequent execution.

POST-URL : http://SWITCH-IP/api/aaaLogin.json
Content-Type: application/json
Cache-Control: no-cache
POST BODY :
{
"aaaUser" : {
"attributes" : {
"name" : "SWITCH_USER",
"pwd" : "SWITCH_PASSWORD"
}
}
}

Executing NXAPI using postman for first time:

  1. Copy POST URL, mentioned in 'setup postman' section above, after replacing SWITCH-IP with IP address of Nexus switch .
  2. Select method as POST
  3. Open raw JSON section.
  4. Copy POST-BODY JSON to raw JSON body section of postman.
  5. Replace SWITCH_USERNAME with switch user.
  6. Replace SWITCH_PASSWORD with switch password.
  7. Click send button

    Note: If the cookie gets expired, you might have to perform the above steps again.

For subsequent NXAPI call:

  1. Copy POST URL, after replacing SWITCH-IP with IP address of Nexus switch.
  2. Select method as POST
  3. Open raw JSON section.
  4. Copy POST-BODY JSON to raw JSON body section of postman.
  5. Click send button

Using python in the sandbox

Follow following steps to execute the python scripts on Nexus switch.

  1. Login to switch using provided credentials. Example username is 'admin' and password 'cisco123'.
  2. If bash is not enabled, Goto 'config t' and enable it by running 'feature bash-shell'
  3. Run 'run bash' to go to bash shell.
  4. Run sudo su
  5. Copy the required script to /isan/python/scripts/cisco directory. For example, if you want to manage Interface configuration using python, create test_interface.py using vi editor like this: vi test_interface.py
  6. Now copy the script to this file. Save and exit.
  7. Execute following command to run the script '/isan/bin/python –m cisco.test_interface
  8. The format of the command to be executed is, '/isan/bin/python -m'

Using puppet in the sandbox

Following steps would execute the manifest files on nx9000 switch.

  1. SSH to toolserver host using provided credentials. (If credentials are not provided Default username is 'cisco' and password 'cisco123'.)
  2. Copy the respective manifest script to /etc/puppetlabs/code/environments/production/manifests directory. For example, if you want to configure interface then create manifest file configure_interface.pp using vi editor and paste the respective script in this file.

    Note: All the manifest scripts are available "/etc/puppetlabs/code/environments/production/modules/ciscolib_nxos/manifests" for reference.

  3. Save and exit.

  4. Run 'sudo su'
  5. Start the puppetserver service. Run 'service puppetserver start' or '/opt/puppetlabs/puppet/bin/ruby /opt/puppetlabs/bin/puppet master'
  6. Run 'export PATH=$PATH:/opt/puppetlabs/bin:/opt/puppetlabs/lib' on toolserver
  7. Run 'puppet cert list -a'

Note : If agent hostname is not listed in the certificates in step 7 then we need to add the certificate first. Follow the steps mentioned in "Steps to add the certificates" section.

Note : Make sure "/etc/hosts" file has correct IP and hostname mapping for toolserver
Example: toolserver IP: 10.10.10.114
hostname: toolserver-devnet.insieme.local
Then, "/etc/hosts" should contain "10.10.10.114 toolserver-devnet.insieme.local toolserver-devnet"

  1. Login to Switch sandbox.
  2. On the switch console run 'run bash'
  3. Run 'sudo ip netns exec management bash'
  4. Run 'export PATH=$PATH:/opt/puppetlabs/puppet/bin:/opt/puppetlabs/puppet/lib'
  5. export http and https proxy by executing these commands. Run 'export http_proxy=http://proxy.esl.cisco.com:8080' Run 'export https_proxy=http://proxy.esl.cisco.com:8080'
  6. Install "install cisco_node_utils" package by executing following command, Run 'gem install cisco_node_utils'
  7. Run 'puppet agent -t'. The configuration would be updated automatically on the switch.
  8. Go to switch prompt and run 'copy r s'

Steps to add the certificates :

  1. Login to Switch sandbox.
  2. On the switch console run 'run bash'
  3. Run 'sudo ip netns exec management bash'
  4. Run 'export PATH=$PATH:/opt/puppetlabs/puppet/bin:/opt/puppetlabs/puppet/lib'
  5. Run 'rm -rf /etc/puppetlabs/puppet/ssl' to clean all the old certificates.
  6. Run 'puppet agent -t' on bash shell. This will create a new certificate.
  7. Now login to toolserver.
  8. Run 'sudo su'
  9. Start the puppetserver service. Run 'service puppetserver start' or '/opt/puppetlabs/puppet/bin/ruby /opt/puppetlabs/bin/puppet master'
  10. Run 'export PATH=$PATH:/opt/puppetlabs/bin:/opt/puppetlabs/lib' on toolserver
  11. Run 'puppet cert list -a' . It should list the certificate sent by agent #agent hostname should be present.
  12. Run 'puppet cert sign '. For example, puppet cert sign "n9kvswitchfcs.cisco.com"​ ## agent hostname

VLAN

Program and manage Virtual LAN(VLAN). You can use VLANs to divide the network into separate logical areas. VLANs can also be considered as broadcast domains. Any Nexus 9000 switch port can belong to a VLAN, and unicast, broadcast, and multicast packets are forwarded and flooded only to end stations in that VLAN. Each VLAN is considered a logical network, and packets destined for stations that do not belong to the VLAN must be forwarded through a router. This section describe how you can manage and configure VLAN on a CISCO Nexus 9000 switch using different configuration management code snippet.

http
python
puppet
> Create VLAN 100
POST http://SWITCH-IP/api/node/mo/sys/bd/bd-[vlan-100].json HTTP/1.1
Content-Type: application/json
Cache-Control: no-cache

{
  "l2BD": {
    "attributes": {
      "fabEncap": "vlan-100",
      "id": "100"
    }
  }
}



> Configure eth1/1 as Access Interface with VLAN 300
POST http://SWITCH-IP/api/mo/sys/intf/phys-[eth1/1]/.json HTTP/1.1
Content-Type: application/json
Cache-Control: no-cache

{
  "l1PhysIf": {
    "attributes": {
      "accessVlan": "vlan-300",
      "layer": "Layer2",
      "mode": "access"
    }
  }
}



>Configure trunk interface of VLAN 100 and 200 on interface eth1/1
POST http://SWITCH-IP/api/mo/sys/intf/phys-[eth1/1]/.json HTTP/1.1
Content-Type: application/json
Cache-Control: no-cache

{
  "l1PhysIf": {
    "attributes": {
      "layer": "Layer2",
      "mode": "trunk",
      "trunkVlans": "100,200"
    }
  }
}



>Delete VLAN 200
DELETE http://SWITCH-IP/api/node/mo/sys/bd/bd-[vlan-100].json HTTP/1.1
Content-Type: application/json
Cache-Control: no-cache
from .vlan import Vlan

# Mention vlan id to be created
vlan_id = 40

v = Vlan()
print "Before adding vlan"
print v.show_vlan().get_vlans()

print "\nCreating Vlan with vlan id %s" %vlan_id
v.create_vlan(vlan_id)

print "\nAfter adding vlan"
print v.show_vlan().get_vlans()

print "\nDeleting vlan with vlan id %s" %vlan_id
v.delete_vlan(vlan_id)

print "\nAfter deleting vlan id %s " %vlan_id
print v.show_vlan().get_vlans()
# Configuring vlan
     cisco_vlan { "220":
        ensure => present,
        vlan_name => 'newtest',
        shutdown => 'true',
        state => 'active',
     }

Using NX-API REST in the sandbox

Follow below steps to execute NX-API REST code snippet on nx9000 switch.

On the nx9000 switch perform following operation.

  1. SSH to switch using provided credentials. (If credentials are not provided Default username is 'admin' and password 'cisco123'
  2. Run 'config t' on the switch prompt.
  3. Enable nxapi by running 'feature nxapi'.
  4. Exit to switch prompt by running 'exit'.
  5. Run 'copy r s' to save the configuration.

Setup postman Code snippet: In order to execute the the NXAPI from postman the login needs to be performed first. The cookie would get generated and stored for subsequent execution.

POST-URL :
http://SWITCH-IP/api/aaaLogin.json
Content-Type: application/json
Cache-Control: no-cache
POST BODY :
{
"aaaUser" : {
"attributes" : {
"name" : "SWITCH_USER",
"pwd" : "SWITCH_PASSWORD"
} } }

Executing NXAPI using postman for first time:

  1. Copy POST URL, mentioned in 'setup postman' section above, after replacing SWITCH-IP with IP address of Nexus switch .
  2. Select method as POST
  3. Open raw JSON section.
  4. Copy POST-BODY JSON to raw JSON body section of postman.
  5. Replace SWITCH_USERNAME with switch user.
  6. Replace SWITCH_PASSWORD with switch password.
  7. Click send button

Note: If the cookie gets expired you might have to perform the above steps again.

For subsequent NXAPI call:

  1. Copy POST URL, after replacing SWITCH-IP with IP address of Nexus switch.
  2. Select method as POST
  3. Open raw JSON section.
  4. Copy POST-BODY JSON to raw JSON body section of postman.
  5. Click send button.

Using python in the sandbox

Follow following steps to execute the python scripts on Nexus switch.

  1. Login to switch using provided credentials. Example username is 'admin' and password 'cisco123'.
  2. If bash is not enabled, Goto 'config t' and enable it by running 'feature bash-shell'
  3. Run 'run bash' to go to bash shell.
  4. Run sudo su
  5. Copy the required script to /isan/python/scripts/cisco directory. For example, if you want to manage vlan configuration using python, create test_vlan.py using vi editor like this:
    vi test_vlan.py
  6. Now copy the script to this file. Save and exit.
  7. Execute following command to run the script '/isan/bin/python –m cisco.test_vlan
  8. The format of the command to be executed is, '/isan/bin/python -m'

Using puppet in the sandbox

Following steps would execute the manifest files on nx9000 switch.

  1. SSH to toolserver host using provided credentials. (If credentials are not provided Default username is 'cisco' and password 'cisco123'
  2. Copy the respective manifest script to /etc/puppetlabs/code/environments/production/manifests directory. For example, if you want to configure interface then create manifest file configure_interface.pp using vi editor and paste the respective script in this file.

    Note: All the manifest scripts are available "/etc/puppetlabs/code/environments/production/modules/ciscolib_nxos/manifests" for reference.

  3. Save and exit.

  4. Run 'sudo su'
  5. Start the puppetserver service. Run 'service puppetserver start' or '/opt/puppetlabs/puppet/bin/ruby /opt/puppetlabs/bin/puppet master'
  6. Run 'export PATH=$PATH:/opt/puppetlabs/bin:/opt/puppetlabs/lib' on toolserver
  7. Run 'puppet cert list -a'

Note : If agent hostname is not listed in the certificates in step 7 then we need to add the certificate first. Follow the steps mentioned in "Steps to add the certificates" section.
Note : Make sure "/etc/hosts" file has correct IP and hostname mapping for toolserver.
Example: toolserver IP: 10.10.10.114
hostname: toolserver-devnet.insieme.local
Then, "/etc/hosts" should contain "10.10.10.114 toolserver-devnet.insieme.local toolserver-devnet"

  1. Login to Switch sandbox.
  2. On the switch console run 'run bash'
  3. Run 'sudo ip netns exec management bash'
  4. Run 'export PATH=$PATH:/opt/puppetlabs/puppet/bin:/opt/puppetlabs/puppet/lib'
  5. export http and https proxy by executing these commands. Run 'export http_proxy=http://proxy.esl.cisco.com:8080' Run 'export https_proxy=http://proxy.esl.cisco.com:8080'
  6. Install "install cisco_node_utils" package by executing following command, Run 'gem install cisco_node_utils'
  7. Run 'puppet agent -t'. The configuration would be updated automatically on the switch.
  8. Go to switch prompt and run 'copy r s'

Steps to add the certificates :

  1. Login to Switch sandbox.
  2. On the switch console run 'run bash'
  3. Run 'sudo ip netns exec management bash'
  4. Run 'export PATH=$PATH:/opt/puppetlabs/puppet/bin:/opt/puppetlabs/puppet/lib'
  5. Run 'rm -rf /etc/puppetlabs/puppet/ssl' to clean all the old certificates.
  6. Run 'puppet agent -t' on bash shell. This will create a new certificate.
  7. Now login to toolserver.
  8. Run 'sudo su'
  9. Start the puppetserver service. Run 'service puppetserver start' or '/opt/puppetlabs/puppet/bin/ruby /opt/puppetlabs/bin/puppet master'
  10. Run 'export PATH=$PATH:/opt/puppetlabs/bin:/opt/puppetlabs/lib' on toolserver
  11. Run 'puppet cert list -a' . It should list the certificate sent by agent #agent hostname should be present.
  12. Run 'puppet cert sign '. For example, puppet cert sign "n9kvswitchfcs.cisco.com" ## agent hostname

OSPF

Implement Open Shortest Path First (OSPF) supports IP subnetting and tagging of externally derived routing information. OSPF also allows packet authentication and uses IP multicast when sending and receiving packets. This section describe how you can manage and configure OSPF on a CISCO Nexus 9000 switch using different configuration management code snippet.

http
python
puppet
NX-API REST script not available
from .ospf import OSPFSession
from .nxcli import NXCLI
import traceback

instance = '49'
interface_name = 'eth1/6'
area = '20'
distance = 41
ospf_cost = 45
hello_interval = 61
dead_interval = 55
priority = 51

def start_ospf_session():
        '''
        starts ospf session.
        Do show run ospf on switch to see the changes.
        '''

        ospf_session = OSPFSession(instance)
        ospf_interface = OSPFSession.OSPFInterface(interface_name, area)

        ospf_session.start()
        return (ospf_session, ospf_interface)


def shutdown_ospf_session(ospf_session):
        ospf_session.shutdown()


def start_ospf_if_down(ospf_session):
        if ospf_session.is_shutdown():
                start_ospf_session()


def configure_distance(ospf_session):
        ospf_session.cfg_distance(distance)


def add_interface_to_ospf(ospf_interface):
        ospf_interface.add()


def configure_ospf_cost(ospf_interface):
        ospf_interface.cfg_ospf_cost(ospf_cost)


def configure_ospf_hello_interval(ospf_interface):
        ospf_interface.cfg_hello_interval(hello_interval)


def configure_dead_interval(ospf_interface):
        ospf_interface.cfg_dead_interval(dead_interval)


def configure_priority(ospf_interface):
        ospf_interface.cfg_ospf_priority(priority)


def interface_shutdown(ospf_interface):
        ospf_interface.shutdown()


def is_interface_available(interface_name):
        """
        Checks if interface is available or not.
        return True if interface ia available, else returns False
        """

        try:
                interface = NXCLI('show run interface %s' %interface_name)
                return True
        except:
                return False

def configure_terminal(cmd):
        """
        Configure terminal based on the commands given
        """

        NXCLI._run_cfg(cmd)


def convert_to_routed_interface(interface_name):
        """
        Convert interface mode from access to routed
        """

        cmd = "interface %s ; no switchport" %interface_name
        configure_terminal(cmd)


def enable_feature_ospf():
        """
        Enable feature on switch
        """

        cmd = "feature ospf"
        configure_terminal(cmd)


def configure_switch_for_ospf():
        if not is_interface_available(interface_name):
                raise Exception("Interface not available. \nPlease give different interface. To list available interfaces, just go to switch-prompt and type : \nshow int br")

        convert_to_routed_interface(interface_name)

        enable_feature_ospf()

        return start_ospf_session()


def configure_ospf():
        '''
        Use above mention functions as per requirement.
        Sample configuration is shown below.
        To check the result of any fucntion after using it here, do a
        show run ospf on switch.
        '''
        try:
                #Switch is configured for OSPF. This is basic operation and should not be omitted.
                ospf_session, ospf_interface = configure_switch_for_ospf()

                #All of the functions below are independent of each other.
                configure_distance(ospf_session)
                add_interface_to_ospf(ospf_interface)
                configure_ospf_cost(ospf_interface)
                configure_ospf_hello_interval(ospf_interface)
                configure_dead_interval(ospf_interface)
                configure_priority(ospf_interface)

                print "After ospf configuration:"
                NXCLI('show run ospf')

        except Exception, e:
                traceback.print_exc()


if __name__ == '__main__':
        configure_ospf()
# Configuring the interface to routed interface
cisco_interface { "Ethernet1/1" :
        switchport_mode     => disabled,
      }

# Configuring Ospf
cisco_ospf { "Sample":
ensure => present,
}

# Configuring interface ospf
cisco_interface_ospf { "Ethernet1/1 Sample":
ensure => present,
area => "200",
cost => "200",
hello_interval => "default",
dead_interval => "200",
message_digest => true,
message_digest_key_id => 30,
message_digest_algorithm_type => md5,
message_digest_encryption_type => cisco_type_7,
message_digest_password => "046E1803362E595C260E0B240619050A2D",
passive_interface => true,
}

# Configuring ospf vrf
cisco_ospf_vrf { 'dark_blue default':
ensure => 'present',
auto_cost => '45000',
default_metric => '5',
log_adjacency => 'detail',
timer_throttle_lsa_hold => '5500',
timer_throttle_lsa_max => '5600',
timer_throttle_lsa_start => '5',
timer_throttle_spf_hold => '1500',
timer_throttle_spf_max => '5500',
timer_throttle_spf_start => '250',
}

cisco_ospf_vrf { 'dark_blue vrf1':
ensure => 'present',
auto_cost => '46000',
default_metric => '10',
log_adjacency => 'log',
timer_throttle_lsa_hold => '5600',
timer_throttle_lsa_max => '5800',
timer_throttle_lsa_start => '8',
timer_throttle_spf_hold => '1700',
timer_throttle_spf_max => '5700',
timer_throttle_spf_start => '277',
}

Using python in the sandbox

Follow following steps to execute the python scripts on Nexus switch.

  1. Login to switch using provided credentials. Example username is 'admin' and password 'cisco123'.
  2. If bash is not enabled, Goto 'config t' and enable it by running 'feature bash-shell'
  3. Run 'run bash' to go to bash shell.
  4. Run sudo su
  5. Copy the required script to /isan/python/scripts/cisco directory. For example, if you want to manage OSPF
    configuration using python, create test_ospf.py using vi editor like this:
    vi test_ospf.py
  6. Now copy the script to this file. Save and exit.
  7. Execute following command to run the script '/isan/bin/python –m cisco.test_ospf
  8. The format of the command to be executed is, '/isan/bin/python -m'

Using puppet in the sandbox

Following steps would execute the manifest files on nx9000 switch.

  1. SSH to toolserver host using provided credentials. (If credentials are not provided Default username is 'cisco' and password 'cisco123'
  2. Copy the respective manifest script to /etc/puppetlabs/code/environments/production/manifests directory. For example, if you want to configure interface then create manifest file configure_interface.pp using vi editor and paste the respective script in this file.

    Note: All the manifest scripts are available "/etc/puppetlabs/code/environments/production/modules/ciscolib_nxos/manifests" for reference.

  3. Save and exit.

  4. Run 'sudo su'
  5. Start the puppetserver service. Run 'service puppetserver start' or '/opt/puppetlabs/puppet/bin/ruby /opt/puppetlabs/bin/puppet master'
  6. Run 'export PATH=$PATH:/opt/puppetlabs/bin:/opt/puppetlabs/lib' on toolserver
  7. Run 'puppet cert list -a'

Note : If agent hostname is not listed in the certificates in step 7 then we need to add the certificate first. Follow the steps mentioned in "Steps to add the certificates" section.
Note : Make sure "/etc/hosts" file has correct IP and hostname mapping for toolserver
Example: toolserver IP: 10.10.10.114
hostname: toolserver-devnet.insieme.local
Then, "/etc/hosts" should contain "10.10.10.114 toolserver-devnet.insieme.local toolserver-devnet"

  1. Login to Switch sandbox.
  2. On the switch console run 'run bash'
  3. Run 'sudo ip netns exec management bash'
  4. Run 'export PATH=$PATH:/opt/puppetlabs/puppet/bin:/opt/puppetlabs/puppet/lib'
  5. export http and https proxy by executing these commands. Run 'export http_proxy=http://proxy.esl.cisco.com:8080' Run 'export https_proxy=http://proxy.esl.cisco.com:8080'
  6. Install "install cisco_node_utils" package by executing following command, Run 'gem install cisco_node_utils'
  7. Run 'puppet agent -t'. The configuration would be updated automatically on the switch.
  8. Go to switch prompt and run 'copy r s'

Steps to add the certificates :

  1. Login to Switch sandbox.
  2. On the switch console run 'run bash'
  3. Run 'sudo ip netns exec management bash'
  4. Run 'export PATH=$PATH:/opt/puppetlabs/puppet/bin:/opt/puppetlabs/puppet/lib'
  5. Run 'rm -rf /etc/puppetlabs/puppet/ssl' to clean all the old certificates.
  6. Run 'puppet agent -t' on bash shell. This will create a new certificate.
  7. Now login to toolserver.
  8. Run 'sudo su'
  9. Start the puppetserver service. Run 'service puppetserver start' or '/opt/puppetlabs/puppet/bin/ruby /opt/puppetlabs/bin/puppet master'
  10. Run 'export PATH=$PATH:/opt/puppetlabs/bin:/opt/puppetlabs/lib' on toolserver
  11. Run 'puppet cert list -a' . It should list the certificate sent by agent #agent hostname should be present.
  12. Run 'puppet cert sign '. For example, puppet cert sign "n9kvswitchfcs.cisco.com"​ ## agent hostname

TACACS

Terminal Access Controller Access Control System(TACACS) is an authentication protocol that allows a remote access server to forward a user's logon password to an authentication server to determine whether access can be allowed to a given system. On Nexus 9000 switch TACACS provide a centralized validation of users who are attempting to gain access to a router or network access server. This section describe how you can manage and program TACACS on a CISCO Nexus 9000 switch using different configuration management code snippet.

http
python
puppet
NX-API REST script not available
from .tacacs import *

tacacsServerIp="10.10.2.1" #TACACS+ server's DNS name or its IP address
port="" #TACACS+ server port
key="" #Global TACACS+ server shared secret
timeout="" #TACACS+ server timeout period in seconds
deleteIp="" #server Ip for removing

# used to remove server configuration
def deleteServer(tacacs,server):


        tacacs.add_server(server,no="True")
        print "Successfuly deleted configuration of server ",server


def enable_feature_tacacs():
        cmd = 'feature tacacs'
        configure_terminal(cmd)

def configure_terminal(cmd):
        """
        Configure terminal based on the commands given
        """

        NXCLI._run_cfg(cmd)


if __name__=="__main__":

        enable_feature_tacacs()
        #show TACACS Server
        showTacacs=ShTacasServer()
        print "Before TACACS+ Configuration"
        if showTacacs.servers():
                print showTacacs.servers()
        else:
                print "no server configured"

        tacacs=Tacacs()

        if deleteIp !="" and tacacs._is_server_configured(deleteIp):
                #delete server Ip
                deleteServer(tacacs,deleteIp)

        if tacacsServerIp:

                #add th TACACS+ server
                tacacs.add_server(tacacsServerIp)
                #tacacs.src_interface("Ethernet1/2")
                #tacacs.commit()
                #tacacs.add_group("ciscogroup1",tacacsServerIp)


        showTacacs=ShTacasServer()
        print "After TACACS+ Configuration:",showTacacs.servers()
# Configure tacacs server
 cisco_tacacs_server {"default":
    ensure              => present,
    timeout             => 10,
    directed_request    => true,
    deadtime            => 20,
    encryption_type     => clear,
    encryption_password => 'test123',
    source_interface    => 'Ethernet1/2',
 }

Using python in the sandbox

Follow following steps to execute the python scripts on Nexus switch.

  1. Login to switch using provided credentials. Example username is 'admin' and password 'cisco123'.
  2. If bash is not enabled, Goto 'config t' and enable it by running 'feature bash-shell'
  3. Run 'run bash' to go to bash shell.
  4. Run sudo su
  5. Copy the required script to /isan/python/scripts/cisco directory. For example, if you want to manage TACACS configuration using python, create test_tacacs.py using vi editor like this: vi test_tacacs.py
  6. Now copy the script to this file. Save and exit.
  7. Execute following command to run the script '/isan/bin/python –m cisco.test_tacacs
  8. The format of the command to be executed is, '/isan/bin/python -m'

Using puppet in the sandbox

Following steps would execute the manifest files on nx9000 switch.

  1. SSH to toolserver host using provided credentials. (If credentials are not provided Default username is 'cisco' and password 'cisco123'
  2. Copy the respective manifest script to /etc/puppetlabs/code/environments/production/manifests directory. For example, if you want to configure interface then create manifest file configure_interface.pp using vi editor and paste the respective script in this file.

    Note: All the manifest scripts are available "/etc/puppetlabs/code/environments/production/modules/ciscolib_nxos/manifests" for reference.

  3. Save and exit.

  4. Run 'sudo su'
  5. Start the puppetserver service. Run 'service puppetserver start' or '/opt/puppetlabs/puppet/bin/ruby /opt/puppetlabs/bin/puppet master'
  6. Run 'export PATH=$PATH:/opt/puppetlabs/bin:/opt/puppetlabs/lib' on toolserver
  7. Run 'puppet cert list -a'

Note: If agent hostname is not listed in the certificates in step 7 then we need to add the certificate first. Follow the steps mentioned in "Steps to add the certificates" section.
Note: Make sure "/etc/hosts" file has correct IP and hostname mapping for toolserver
Example: toolserver IP: 10.10.10.114
hostname: toolserver-devnet.insieme.local
Then, "/etc/hosts" should contain "10.10.10.114 toolserver-devnet.insieme.local toolserver-devnet"

  1. Login to Switch sandbox.
  2. On the switch console run 'run bash'
  3. Run 'sudo ip netns exec management bash'
  4. Run 'export PATH=$PATH:/opt/puppetlabs/puppet/bin:/opt/puppetlabs/puppet/lib'
  5. export http and https proxy by executing these commands. Run 'export http_proxy=http://proxy.esl.cisco.com:8080' Run 'export https_proxy=http://proxy.esl.cisco.com:8080'
  6. Install "install cisco_node_utils" package by executing following command, Run 'gem install cisco_node_utils'
  7. Run 'puppet agent -t'. The configuration would be updated automatically on the switch.
  8. Go to switch prompt and run 'copy r s'

Steps to add the certificates:

  1. Login to Switch sandbox.
  2. On the switch console run 'run bash'
  3. Run 'sudo ip netns exec management bash'
  4. Run 'export PATH=$PATH:/opt/puppetlabs/puppet/bin:/opt/puppetlabs/puppet/lib'
  5. Run 'rm -rf /etc/puppetlabs/puppet/ssl' to clean all the old certificates.
  6. Run 'puppet agent -t' on bash shell. This will create a new certificate.
  7. Now login to toolserver.
  8. Run 'sudo su'
  9. Start the puppetserver service. Run 'service puppetserver start' or '/opt/puppetlabs/puppet/bin/ruby /opt/puppetlabs/bin/puppet master'
  10. Run 'export PATH=$PATH:/opt/puppetlabs/bin:/opt/puppetlabs/lib' on toolserver
  11. Run 'puppet cert list -a' . It should list the certificate sent by agent #agent hostname should be present.
  12. Run 'puppet cert sign '. For example, puppet cert sign "n9kvswitchfcs.cisco.com" ## agent hostname

AAA

Access control is the way you control who is allowed access to the network server and what services they are allowed to use once they have access. Authentication, authorization, and accounting (AAA) network security services provide the primary framework through which you set up access control on your router or access server. Following example shows how to enable authentication login ascii-authentication and error-enable.

Configure aaa authentication to show or display of error message on login failures and ascii authentication:

http
python
puppet
POST http://SWITCH_IP/api/node/mo/sys/userext/authrealm.json HTTP/1.1
Content-Type: application/json

{
      "aaaDefaultAuth": {
        "attributes": {
          "authProtocol": "ascii",
          "errEn": "no"
        }
    }
}
# Sample file to configure AAA authentication login ascii and error-enable

from .nxcli import NXCLI
import traceback

def show_config_info():
        """
        Show the running aaa configuration
        """

        try:
                interface = NXCLI('show run aaa')
                return True
        except:
                return False

def configure_terminal(cmd):
        """
        Configure terminal based on the commands given
        """

        NXCLI._run_cfg(cmd)

def enable_aaa_ascii_error():
        """
        Configure the default aaa authentication login features
        """

        cmd = "aaa authentication login ascii-authentication ; aaa authentication login error-enable"
        configure_terminal(cmd)

if __name__=="__main__":

        try:
                enable_aaa_ascii_error()
                show_config_info()
        except Exception,e:
                traceback.print_exc()
Puppet script not available

Using NX-API REST in the sandbox

Follow below steps to execute NX-API REST code snippet on nx9000 switch.

On the nx9000 switch perform following operation.

  1. SSH to switch using provided credentials. (If credentials are not provided Default username is 'admin' and password 'cisco123'
  2. Run 'config t' on the switch prompt.
  3. Enable nxapi by running 'feature nxapi'.
  4. Exit to switch prompt by running 'exit'.
  5. Run 'copy r s' to save the configuration.

Setup postman Code snippet: In order to execute NXAPI from postman, login needs to be performed. The cookie would get generated and stored for subsequent execution.

POST-URL : http://SWITCH-IP/api/aaaLogin.json
Content-Type: application/json
Cache-Control: no-cache
POST BODY :
{
"aaaUser" : {
"attributes" : {
"name" : "SWITCH_USER",
"pwd" : "SWITCH_PASSWORD"
}
}
}

Executing NXAPI using postman for first time:

  1. Copy POST URL, mentioned in 'setup postman' section above, after replacing SWITCH-IP with IP address of Nexus switch .
  2. Select method as POST
  3. Open raw JSON section.
  4. Copy POST-BODY JSON to raw JSON body section of postman.
  5. Replace SWITCH_USERNAME with switch user.
  6. Replace SWITCH_PASSWORD with switch password.
  7. Click send button

    Note: If the cookie gets expired, you might have to perform the above steps again.

For subsequent NXAPI call:

  1. Copy POST URL, after replacing SWITCH-IP with IP address of Nexus switch.
  2. Select method as POST
  3. Open raw JSON section.
  4. Copy POST-BODY JSON to raw JSON body section of postman.
  5. Click send button

How to connect to sandbox lab:

  1. Go to the sandbox homepage: https://developer.cisco.com/site/devnet/sandbox/
  2. Login. Hit the yellow button "Get Started!" button
  3. In the upper-right corner click on "DEVNET".
  4. Now you are in Cisco's Devnet domain and it would list the labs hosted under the domain.
  5. You can find the 8 tiles for the NX-OS labs. The tiles are named as "Open NX-OS Lab -1(through 8)"
  6. Click on 'Reserve' a lab. Upon successful reservation you would receive a mail from "devnetsandbox@cisco.com" that describes further instructions to access the sandbox.

Using python in the sandbox

Follow following steps to execute the python scripts on Nexus switch.

  1. Login to switch using provided credentials. Example username is 'admin' and password 'cisco123'.
  2. If bash is not enabled, Goto 'config t' and enable it by running 'feature bash-shell'
  3. Run 'run bash' to go to bash shell.
  4. Run sudo su
  5. Copy the required script to /isan/python/scripts/cisco directory. For example, if you want to manage AAA configuration using python, create test_aaa.py using vi editor like this: vi test_aaa.py
  6. Now copy the script to this file. Save and exit.
  7. Execute following command to run the script '/isan/bin/python “m cisco.test_aaa
  8. The format of the command to be executed is, '/isan/bin/python -m'

SNMP

The Simple Network Management Protocol (SNMP) is an application-layer protocol that provides a message format for communication between SNMP managers and agents. SNMP provides a standardized framework and a common language used for the monitoring and management of devices in a network. Following example shows snmp community configuration.

http
python
puppet
NX-API REST script not available
# Sample file to configure snmp community

from .nxcli import NXCLI
import traceback

def config_snmp_community():
        """
        Configure the snmp community
        """
        try:
            cmd = 'snmp-server community test group network-operator ; snmp-server community test use-acl aclname'
            NXCLI._run_cfg(cmd)
            return True
        except:
            return False


if __name__=="__main__":

        try:
            config_snmp_community()
        except Exception,e:
            traceback.print_exc()
# Configure snmp community

class snmp_community_test {

  cisco_snmp_community { "test":
    ensure => present,
    group  => "network-operator",
    acl    => "aclname",
  }

}

class { 'snmp_community_test': }

Using python in the sandbox

Follow the following steps to execute the python scripts on Nexus switch.

  1. Login to switch using provided credentials. Example username is 'admin' and password 'cisco123'.
  2. If bash is not enabled, Goto 'config t' and enable it by running 'feature bash-shell'
  3. Run 'run bash' to go to bash shell.
  4. Run sudo su
  5. Copy the required script to /isan/python/scripts/cisco directory. For example, if you want to manage snmp configuration using python, create test_snmp.py using vi editor like this: vi test_snmp.py
  6. Now copy the script to this file. Save and exit.
  7. Execute following command to run the script '/isan/bin/python –m cisco.test_aaa
  8. The format of the command to be executed is, '/isan/bin/python -m'

Using puppet in the sandbox

Following steps would execute the manifest files on nx9000 switch.

  1. SSH to toolserver host using provided credentials. (If credentials are not provided Default username is 'cisco' and password 'cisco123'
  2. Copy the respective manifest script to /etc/puppetlabs/code/environments/production/manifests directory. For example, if you want to configure interface then create manifest file configure_interface.pp using vi editor and paste the respective script in this file.
  3. Save and exit.
  4. Run 'sudo su'
  5. Start the puppetserver service. Run 'service puppetserver start' or '/opt/puppetlabs/puppet/bin/ruby /opt/puppetlabs/bin/puppet master'
  6. Run 'export PATH=$PATH:/opt/puppetlabs/bin:/opt/puppetlabs/lib' on toolserver
  7. Run 'puppet cert list -a'

Note: If agent hostname is not listed in the certificates in step 7 then we need to add the certificate first. Follow the steps mentioned in "Steps to add the certificates" section.
Note: Make sure "/etc/hosts" file has correct IP and hostname mapping for toolserver
Example: toolserver IP: 10.10.10.114
hostname: toolserver-devnet.insieme.local
Then, "/etc/hosts" should contain "10.10.10.114 toolserver-devnet.insieme.local toolserver-devnet"

  1. Login to Switch sandbox.
  2. On the switch console run 'run bash'
  3. Run 'sudo ip netns exec management bash'
  4. Run 'export PATH=$PATH:/opt/puppetlabs/puppet/bin:/opt/puppetlabs/puppet/lib'
  5. export http and https proxy by executing these commands. Run 'export http_proxy=http://proxy.esl.cisco.com:8080' Run 'export https_proxy=http://proxy.esl.cisco.com:8080'
  6. Install "install cisco_node_utils" package by executing following command, Run 'gem install cisco_node_utils'
  7. Run 'puppet agent -t'. The configuration would be updated automatically on the switch.
  8. Go to switch prompt and run 'copy r s'

Steps to add the certificates :

  1. Login to Switch sandbox.
  2. On the switch console run 'run bash'
  3. Run 'sudo ip netns exec management bash'
  4. Run 'export PATH=$PATH:/opt/puppetlabs/puppet/bin:/opt/puppetlabs/puppet/lib'
  5. Run 'rm -rf /etc/puppetlabs/puppet/ssl' to clean all the old certificates.
  6. Run 'puppet agent -t' on bash shell. This will create a new certificate.
  7. Now login to toolserver.
  8. Run 'sudo su'
  9. Start the puppetserver service. Run 'service puppetserver start' or '/opt/puppetlabs/puppet/bin/ruby /opt/puppetlabs/bin/puppet master'
  10. Run 'export PATH=$PATH:/opt/puppetlabs/bin:/opt/puppetlabs/lib' on toolserver
  11. Run 'puppet cert list -a' . It should list the certificate sent by agent #agent hostname should be present.
  12. Run 'puppet cert sign '. For example, puppet cert sign "n9kvswitchfcs.cisco.com"? ## agent hostname

Monitoring

Interface

Program and manage interfaces. You can configure interfaces using different configuration management tools. Following example shows the details of an interface.

Show physical ethernet port:

http
GET http://SWITCH_IP/api/mo/sys/intf/phys-[eth1/1].json?query-target=self HTTP/1.1
Host: switch_ip
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: f92aa2b5-ac52-a3ff-60fa-348a69faf3e0

Get Interface statistics:

http
python
puppet
GET http://SWITCH_IP/api/mo/sys/intf/phys-[eth1/5].json?rsp-subtree=full&rsp-subtree-include=stats HTTP/1.1
Host: switch_ip
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: 61080f1e-cd96-5e9c-8797-a6e9936bc7e5
# Sample file to Show Interface details
# Import Interface class
from .interface import  Interface
from .nxcli import NXCLI
import traceback

interfaceName = "Ethernet1/6"

def available_interface(interfaceName):
        """
        Display interface details.
        """
        interface = NXCLI('show interface %s' % interfaceName)


if __name__=="__main__":
        try:
                available_interface(interfaceName)
        except Exception,e:
                traceback.print_exc()
Puppet script not available

Using NX-API REST in the sandbox

Follow following steps to execute the nxapi code snippet files on nx9000 switch.

On the nx9000 switch perform following operation.

  1. SSH to switch using provided credentials. (If credentials are not provided Default username is 'admin' and password 'cisco123'
  2. Run 'config t' on the switch prompt.
  3. Enable nxapi by running 'feature nxapi'.
  4. Exit to switch prompt by running 'exit'.
  5. Run 'Copy r s' to save the configuration.

Setup postman Code snippet: In order to execute the the NXAPI from postman the login needs to be performed first. The cookie would get generated and stored for subsequent execution.

POST-URL : http://SWITCH-IP/api/aaaLogin.json
Content-Type: application/json
Cache-Control: no-cache
POST BODY :
{
"aaaUser" : {
"attributes" : {
"name" : "SWITCH_USER",
"pwd" : "SWITCH_PASSWORD"
}
}
}

Executing NXAPI using postman for first time:

  1. Copy POST URL, mentioned in 'setup postman' section above, after replacing SWITCH-IP with IP address of Nexus switch .
  2. Select method as POST
  3. Open raw JSON section.
  4. Copy POST-BODY JSON to raw JSON body section of postman.
  5. Replace SWITCH_USERNAME with switch user.
  6. Replace SWITCH_PASSWORD with switch password.
  7. Click send button

Note: If the cookie gets expired you might have to perform the above steps again.

For subsequent NXAPI call:

  1. Copy POST URL, after replacing SWITCH-IP with IP address of Nexus switch.
  2. Select method as POST
  3. Open raw JSON section.
  4. Copy POST-BODY JSON to raw JSON body section of postman.
  5. Click send button

Using python in the sandbox

Follow following steps to execute the python scripts on Nexus switch.

  1. Login to switch using provided credentials. Example username is 'admin' and password 'cisco123'.
  2. If bash is not enabled, Goto 'config t' and enable it by running 'feature bash-shell'
  3. Run 'run bash' to go to bash shell.
  4. Run sudo su
  5. Copy the required script to /isan/python/scripts/cisco directory. For example, if you want to manage Interface configuration using python, create test_interface.py using vi editor like this: vi test_interface.py
  6. Now copy the script to this file. Save and exit.
  7. Execute following command to run the script '/isan/bin/python –m cisco.test_interface
  8. The format of the command to be executed is, '/isan/bin/python -m'

Hardware Buffer

Program and manage the hardware buffer. Following example shows the internal buffer packet statistics details.

http
python
puppet
NX-API REST script not available
# Sample file to display the switch hardware buffer info

from .nxcli import NXCLI
import traceback

def show_hardware_buffer():
        """
        Show the switch hardware buffer info
        """
        try:
                interface = NXCLI('show hardware internal buffer info pkt-stats detail')
                return True
        except:
                return False

if __name__=="__main__":

        try:
                show_hardware_buffer()
        except Exception,e:
                traceback.print_exc()
Puppet script not available

Using python in the sandbox

Follow the following steps to execute the python scripts on Nexus switch.

  1. Login to switch using provided credentials. Example username is 'admin' and password 'cisco123'.
  2. If bash is not enabled, Goto 'config t' and enable it by running 'feature bash-shell'
  3. Run 'run bash' to go to bash shell.
  4. Run sudo su
  5. Copy the required script to /isan/python/scripts/cisco directory. For example, if you want to manage Hardware Buffer stats configuration using python, create test_hardware_buff_stats.py using vi editor like this: vi test_hardware_buff_stats.py
  6. Now copy the script to this file. Save and exit.
  7. Execute following command to run the script '/isan/bin/python 'm cisco.test_hardware_buff_stats
  8. The format of the command to be executed is, '/isan/bin/python -m'

Troubleshooting

Ping

Ping is a networking utility program or a tool to test if a particular host is reachable. It is a diagnostic that checks if your computer is connected to a server. Ping, a term taken from the echo location of a submarine, sends data packet to a server and if it receives a data packet back, then you have a connection. Following example shows usage of ping in nexus devices.

http
python
puppet
NX-API REST script not available
# Sample file to troubleshoot using ping

from .nxcli import NXCLI
import traceback

# Fill the details to troubleshoot using ping
host = '172.31.219.60'
count = '4'
vrf = 'management'


def check_ping_ops():
        """
        Checks if the host is reachable
        """
        try:
                interface = NXCLI('ping %s count %s vrf %s' % (host, count, vrf))
                return True
        except:
                return False

if __name__=="__main__":

        try:
                check_ping_ops()
        except Exception,e:
                traceback.print_exc()
Puppet script not available

Using python in the sandbox

Follow following steps to execute the python scripts on Nexus switch.

  1. Login to switch using provided credentials. Example username is 'admin' and password 'cisco123'.
  2. If bash is not enabled, Goto 'config t' and enable it by running 'feature bash-shell'
  3. Run 'run bash' to go to bash shell.
  4. Run sudo su
  5. Copy the required script to /isan/python/scripts/cisco directory. For example, if you want to manage ping configuration using python, create test_ping.py using vi editor like this: vi test_ping.py
  6. Now copy the script to this file. Save and exit.
  7. Execute following command to run the script '/isan/bin/python 'm cisco.test_ping
  8. The format of the command to be executed is, '/isan/bin/python -m'

TraceRoute

Traceroute is a computer network diagnostic tool for displaying the route (path) and measuring transit delays of packets across an Internet Protocol (IP) network. Following example shows the usage of traceroute in nexus devices.

http
python
puppet
NX-API REST script not available
# Sample file to troubleshoot using traceroute

from .nxcli import NXCLI
import traceback

# Fill the details to troubleshoot using traceroute
host = '172.31.219.60'
vrf = 'management'

def check_traceroute_ops():
        """
        traceroute the host
        """
        try:
                interface = NXCLI('traceroute %s vrf %s' % (host, vrf))
                return True
        except:
                return False

if __name__=="__main__":

        try:
                check_traceroute_ops()
        except Exception,e:
                traceback.print_exc()
Puppet script is not available

Using python in the sandbox

Follow following steps to execute the python scripts on Nexus switch.

  1. Login to switch using provided credentials. Example username is 'admin' and password 'cisco123'.
  2. If bash is not enabled, Goto 'config t' and enable it by running 'feature bash-shell'
  3. Run 'run bash' to go to bash shell.
  4. Run sudo su
  5. Copy the required script to /isan/python/scripts/cisco directory. For example, if you want to manage Traceroute configuration using python, create test_traceroute.py using vi editor like this: vi test_traceroute.py
  6. Now copy the script to this file. Save and exit.
  7. Execute following command to run the script '/isan/bin/python -m cisco.test_traceroute
  8. The format of the command to be executed is, '/isan/bin/python -m'
Next