Menu

Lab 4: Configuring Device using NSO CLI Mode

Lab 4: Configuring Device using NSO CLI Mode

Task 1: Use NSO CLI to Configure simple IOS cmd:

This Before beginning this lab on your workstation, install a standard set of development applications, tools, and interfaces.

Introduction

In this task we are going to:

View the data of a device in XML, JSON and XPATH.

Save the data to a file.

Configure a device using CLI commands.

Rollback the change.

Step 1: Login into NSO CLI mode to view device configuration

Type following commands on UNIX terminal:

rst@rst-nso:~$ cd nso-5.3/packages/neds/nso-instance/
rst@rst-nso:~/nso-5.3/packages/neds/nso-instance$ source $HOME/nso-5.3/ncsrc
rst@rst-nso:~/nso-5.3/packages/neds/nso-instance$ ncs_cli -C -u admin

NSO stores a snapshot of each device configuration, which is updated after each sync-from.

You can view the configuration of a device using the following command

(outside config mode in the NCS CLI)

Step 2: Show running config using NSO CLI:

Type following command in NSO CLI mode:

admin@ncs# show running-config devices device RSTXR-1 config
devices device RSTXR-1
    config
    admin
    username test
    group root-system
    secret 5 $1$9.2E$ZfCsCgp9Rvc9flNvGN1Yc/
    exit
    exit-admin-config
    !
    hostname RSTXR-1
    service timestamps debug datetime msec
    service timestamps log datetime msec
    domain lookup disable
    domain name rstforum.net
    netconf agent tty
    exit
    netconf-yang agent
    ssh
    exit
    telnet vrf default ipv4 server max-servers 10
    username cisco secret 5 $1$erBJ$6XP1BjhA4qXUvV186rlzO1
    exit
    line console
    exec-timeout 0 0
    absolute-timeout 0
    session-timeout 0
    exit
    line default
    exec-timeout 0 0
    absolute-timeout 0
    session-timeout 0
    exit
    line template vty
    timestamp
    exec-timeout 720 0
    exit
    vty-pool default 0 50
    control-plane
    management-plane
    inband
        interface all
        allow all
        exit
    ssh server session-limit 10
    ssh server v2
    ssh server vrf default
    interface MgmtEth 0/0/CPU0/0
    ipv4 address 10.0.0.1 255.255.255.0
    no shutdown
    exit
    interface GigabitEthernet 0/0/0/0
    shutdown       

Step 3:Type following commands in NSO CLI mode to view interface configuration:

admin@ncs# show running-config devices device RSTXR-1 config interface
devices device RSTXR-1
 config
  interface MgmtEth 0/0/CPU0/0
   ipv4 address 10.0.0.1 255.255.255.0
   no shutdown
  exit
  interface GigabitEthernet 0/0/0/0
   shutdown
  exit
  interface GigabitEthernet 0/0/0/1
   shutdown
  exit
  interface GigabitEthernet 0/0/0/2
   shutdown
  exit
  interface GigabitEthernet 0/0/0/3
   shutdown
  exit
!

We can view the same information in multiple formats, such as XML, CLI, and others.

Step 4: Type following commands in NSO CLI mode to view interface configuration in XML Format:

admin@ncs# show running-config devices device RSTXR-1 config interface | display xml

<config xmlns="http://tail-f.com/ns/config/1.0">
    <devices xmlns="http://tail-f.com/ns/ncs">
    <device>
    <name>RSTXR-1</name>
        <config>
        <interface xmlns="http://tail-f.com/ned/cisco-ios-xr">
        <MgmtEth>
            <id>0/0/CPU0/0</id>
            <ipv4>
            <address>
                <ip>10.0.0.1</ip>
                <mask>255.255.255.0</mask>
            </address>
            </ipv4>
        </MgmtEth>
        <GigabitEthernet>
            <id>0/0/0/0</id>
            <shutdown/>
        </GigabitEthernet>
        <GigabitEthernet>
            <id>0/0/0/1</id>
            <shutdown/>
        </GigabitEthernet>
        <GigabitEthernet>
            <id>0/0/0/2</id>
            <shutdown/>
        </GigabitEthernet>
        <GigabitEthernet>
            <id>0/0/0/3</id>
            <shutdown/>
        </GigabitEthernet>
        </interface>
        </config>
    </device>
    </devices>
</config>    

Let us now view the same information in JSON formats

Step 5: Type following commands in NSO CLI mode to view interface configuration in json

admin@ncs# show running-config devices device RSTXR-1 config interface | display json

{
    "data": {
    "tailf-ncs:devices": {
        "device": [
        {
            "name": "RSTXR-1",
            "config": {
            "tailf-ned-cisco-ios-xr:interface": {
                "MgmtEth": [
                {
                    "id": "0/0/CPU0/0",
                    "ipv4": {
                    "address": {
                        "ip": "10.0.0.1",
                        "mask": "255.255.255.0"
                    }
                    }
                }
                ],
                "GigabitEthernet": [
                {
                    "id": "0/0/0/0",
                    "shutdown": [null]
                },
                {
                    "id": "0/0/0/1",
                    "shutdown": [null]
                },
                {
                    "id": "0/0/0/2",
                    "shutdown": [null]
                },
                {
                    "id": "0/0/0/3",
                    "shutdown": [null]
                },

Let us view the same information with its xpath:

Step 6:Type following commands in NSO CLI mode to view interface configuration with xpath

admin@ncs# show running-config devices device RSTXR-1 config interface | display xpath
/devices/device[name='RSTXR-1']/config/cisco-ios-xr:interface/MgmtEth[id='0/0/CPU0/0']/ipv4/address/ip 10.0.0.1
/devices/device[name='RSTXR-1']/config/cisco-ios-xr:interface/MgmtEth[id='0/0/CPU0/0']/ipv4/address/mask 255.255.255.0
/devices/device[name='RSTXR-1']/config/cisco-ios-xr:interface/GigabitEthernet[id='0/0/0/0']/shutdown
/devices/device[name='RSTXR-1']/config/cisco-ios-xr:interface/GigabitEthernet[id='0/0/0/1']/shutdown
/devices/device[name='RSTXR-1']/config/cisco-ios-xr:interface/GigabitEthernet[id='0/0/0/2']/shutdown
/devices/device[name='RSTXR-1']/config/cisco-ios-xr:interface/GigabitEthernet[id='0/0/0/3']/shutdown   

Using the NSO CLI for displaying the running-config of existing CLI devices in a structured way is very useful. Now let us save the output to a file for later reference.

Step 7:Type the following commands in NSO CLI mode to Save output to a file:

show running-config devices device RSTXR-1 config interface | display xml | save rstxr1.xml

The file is then saved to the location where you started your NSO CLI. From that working directory, see the rstxr1.xml file in the following Home directory: /home/rst/nso-5.3/package/neds/nso-instance$

rst@rst-nso:~/nso-5.3/packages/neds/nso-instance$ ls rstxr1.xml
rstxr1.xml
rst@rst-nso:~/nso-5.3/packages/neds/nso-instance$

A simple way to view the output of the file is to use the cat rstxr1.xml bash command:

rst@rst-nso:~/nso-5.3/packages/neds/nso-instance$ cat rstxr1.xml

<config xmlns="http://tail-f.com/ns/config/1.0">
    <devices xmlns="http://tail-f.com/ns/ncs">
    <device>
    <name>RSTXR-1</name>
        <config>
        <interface xmlns="http://tail-f.com/ned/cisco-ios-xr">
        <MgmtEth>
            <id>0/0/CPU0/0</id>
            <ipv4>
            <address>
                <ip>10.0.0.1</ip>
                <mask>255.255.255.0</mask>
            </address>
            </ipv4>
        </MgmtEth>
        <GigabitEthernet>
            <id>0/0/0/0</id>
            <shutdown/>
        </GigabitEthernet>
        <GigabitEthernet>
            <id>0/0/0/1</id>
            <shutdown/>
        </GigabitEthernet>
        <GigabitEthernet>
            <id>0/0/0/2</id>
            <shutdown/>
        </GigabitEthernet>
        <GigabitEthernet>
            <id>0/0/0/3</id>
            <shutdown/>
        </interface>
        </config>
    </device>
    </devices>
</config>....    

NSO allows us to configure IOS devices using the CLI in an IOS style. You can use ? to navigate and typeconfiguration commands to devices.

Step 8: Configure IOS devices using the NSO CLI mode:

Note: We have to issue a namespace prefix before configuring the top of a configuration hierarchy. Log into NSO from the Linux Bash terminal, and enter config mode if not already. Make sure your devices are state admin-state unlocked, if for some reason you locked them before. Pick a device and enter into that device tree like below and check out the config options for that device and then configure an interface description.

ncs_cli -C -u admin 
conf 
devices device RSTXR-1 
config 

Note: We enter the config mode twice: Once to enter the NSO configure mode, and a second time after you have navigated to a device to enter that particular device’s configuration mode.

For example, to configure ip address on an interface, add the namespace prefix for the NED and see the options:

admin@ncs(config-config)# interface ?
Possible completions:
  ATM               ATM Network Interface(s)
  BVI               Bridge-Group Virtual Interface
  Bundle-Ether      Aggregated Ethernet interface(s)
  Bundle-POS        Aggregated POS interface(s)
  CEM               Circuit Emulation interface(s)
  CSI               Cross SDR interface(s) | short name is csi
  FastEthernet      FastEthernet/IEEE 802.3 interface(s)
  FiftyGigE         FiftyGigEthernet
  FortyGigE         FortyGigEthernet
  FourHundredGigE   FourHundredGigEthernet
  GCC0              OTN GCC0 interface(s) | short name is G0
  GigabitEthernet   GigabitEthernet/IEEE 802.3 interface(s)
  HundredGigE       HundredGigEthernet
  Loopback          Loopback interface
  MgmtEth           Ethernet/IEEE 802.3 interface(s)
  Multilink         Multilink network interface(s)
  Null              Null interface | short name is Nu
  POS               Packet over SONET/SDH network interface(s)
  PTP               FastEthernet/IEEE 802.3 interface(s) | short name is PTP
  PW-Ether          Pseudo-Wire Ethernet interface(s)
  Port-channel      Ethernet Channel of interfaces
  SRP               SRP interface(s)
  Serial            Serial network interface(s)
  TenGigE           TenGigabitEthernet/IEEE 802.3 interface(s)
  TwentyFiveGigE    TwentyFiveGigabitEthernet/IEEE 802.3 interface(s) |
                    short name is Tw
  TwoHundredGigE    TwoHundredGigEthernet
  Vlan              Iosxr Vlans
  nve               Network Virtualization Endpoint Interface(s)
  preconfigure      Specify a preconfig
  tunnel-ip         GRE/IPinIP Tunnel Interface(s)
  tunnel-ipsec      IPSec Tunnel interface(s)
  tunnel-mte        MPLS Traffic Engineering P2MP Tunnel interface(s)
  tunnel-te         MPLS Traffic Engineering Tunnel interface(s)
  tunnel-tp         MPLS Transport Protocol Tunnel interface

After exploring the options, make the following change,

admin@ncs(config-config)# interface GigabitEthernet 0/0/0/3
admin@ncs(config-if)# ipv4 address 222.222.222.222 /24
admin@ncs(config-if)# no shutdown
admin@ncs(config-if)# exit
    

Now we will take a look and see what commands NSO will send, outformating the change into native which is standard Cisco CLI syntax.

Step 9: Commit dry run:

admin@ncs(config-config)# commit dry-run outformat native
native {
    device {
        name RSTXR-1
        data interface GigabitEthernet 0/0/0/3
              ipv4 address 222.222.222.222/24
              no shutdown
             exit
    }
}

To configure the device (sending the commands to the device), you can then send:

commit

note: We can rollback the commit. This process is usually easiest to see in the NSO GUI.