cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1957
Views
10
Helpful
9
Replies

Change ned-settings to run 'term shell' when connecting

tsiemers1
Spotlight
Spotlight

Does NSO have a way to inject a command during connection for the cisco-ios ned? Looking at adding this command to all our devices using the cisco-ios-cli ned

'term shell'

I didn't see a way in the ned-settings to inject a new login command.

9 Replies 9

RichardD2
Level 1
Level 1

Hi Tom,

I don't believe there's a way to do that. Another post has the most complete list of options I have seen: https://community.cisco.com/t5/nso-developer-hub-discussions/how-do-i-add-a-device-with-no-authentication/td-p/3837650

An alternative approach would be to add the device(s) and run a command to add the term shell. 

# devices device mydevice live-status exec any "term shell"

 

I need them to run within one ssh connection. The 'term shell' is only stays configured during that shell session. Trying to run the advanced cli commands in XE. Something like this

 

Lab_XE#term shell
Lab_XE#show run | grep -e "^interface|^ service instance|^  description"

the grep command only works with 'term shell' which only stays configured until you exit that shell session.

Tom,

Have the devices already been added to NSO?

NSO caches ssh sessions so if you run the 'term shell' command followed by your command, they normally would be in the same session. Since NSO supports by default parallel sessions to the same device, to be  sure that you are in the same session you have to configure,

devices device ex1 session-limits max-sessions 1

Also I would execute `term no shell` after the command so if any other code were to reuse that cached session it would not be affected.

 

Your specific example though looks like you want to just get some specific data from running config, you could simply query cdb in  this case, then the device need not even be involved. Of course there will be other examples to query operational data where term shell can be  useful.

 

Yea we tried the xpath way of the cdb but it becomes a pain to loop over all interfaces a device could have to pull sub interface descriptions. Ended up having queries that started getting cumbersome and long to pull data

 

"/devices/device/config/ios:interface/GigabitEthernet/service/instance"
"/devices/device/config/ios:interface/TenGigabitEthernet/service/instance"
"/devices/device/config/ios:interface/Port-Channel/service/instance"
......

unless somebody knows a slick way to run a cdb query like this that goes into each possible interface type and pulls data. 

Also found a command that turns configures 'term shell' forever on the device 'shell processing full'

Hello,

 

my 2 cents for this one using Query API

 

Here is my cdb - one service instance under a Gig interface, one under a Port-Channel:

admin@ncs# show running-config devices device ios config interface
devices device ios
 config
  interface Port-channel42
   no switchport
   service instance 43 ethernet
    description Port-channel desc
   exit
   no shutdown
  exit
  interface GigabitEthernet0/0
   no switchport
   service instance 42 ethernet
    description GigEthernet desc
   exit
   no shutdown
  exit
 !
!

Using Query API you can do:

curl --location --request POST 'http://127.0.0.1:8080/restconf/tailf/query' \
--header 'Accept: application/yang-data+xml' \
--header 'Content-Type: application/yang-data+xml' \
--header 'Authorization: Basic YWRtaW46YWRtaW4=' \
--header 'Cookie: sessionid_8080=sess73IJkxprLjP/rOpaO41ujw==' \
--data-raw '<immediate-query xmlns="http://tail-f.com/ns/tailf-rest-query">
  <foreach>
    /devices/device[name='\''ios'\'']/config/interface/*/service/instance
  </foreach>
  <select>
    <label>Instance</label>
    <expression>id</expression>
    <result-type>string</result-type>
  </select>
    <select>
    <label>Desc</label>
    <expression>description</expression>
    <result-type>string</result-type>
  </select>
  <sort-by>name</sort-by>
  <timeout>600</timeout>
</immediate-query>'

And this will get you:

 

 
<query-result xmlns="http://tail-f.com/ns/tailf-rest-query">
    <result>
        <select>
            <label>Instance</label>
            <value>43</value>
        </select>
        <select>
            <label>Desc</label>
            <value>Port-channel desc</value>
        </select>
    </result>
    <result>
        <select>
            <label>Instance</label>
            <value>42</value>
        </select>
        <select>
            <label>Desc</label>
            <value>GigEthernet desc</value>
        </select>
    </result>
</query-result>

Which looks like what you are looking for (of course my query needs to be adapted to your need probably returning the Interface Id and stuff) - info on the query API: https://developer.cisco.com/docs/nso/guides/#!the-restconf-api/the-restconf-query-api 

 

vleijon
Cisco Employee
Cisco Employee

If there are no ned-settings you can try modifying the connector. If you unpack the NED there is a directory src/metadata, checkout the README-file there. 

 

If that isn't enough you may have to raise a ticket to add the things you need to the NED.

Will have to dig into that more. Would be nice for a deep dive session to dig into modifying that metadata directory for advanced ned topics.


I was able to get this to work with RESTCONF api after seeing that the xpath is a leaf-list of args I used this

https://labnso.localhost/restconf/operations/devices/device=XE-Lab-0/live-status/tailf-ned-cisco-ios-stats:exec/any

 

{
  "input":
  {
    "args": "term shell",
    "args": ";",
    "args": "show run | grep -e \"^interface|^ service instance|^  description\""
  }
}

which sets the term shell and runs the command. Still confused as to why the ';' is needed but from what I could see its used to define multiple commands.

 

Thanks

RichardD2
Level 1
Level 1

I did run across a bit of Python that you could adapt to get the list of interfaces/properties

https://github.com/CiscoDevNet/python_code_samples_network/blob/master/restconf_update_ipaddress/updateip.py