cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
5117
Views
16
Helpful
0
Comments
Akira Iwamoto
Cisco Employee
Cisco Employee

About ncs_load command

ncs_load command is a tool to import and export the data in NSO. It can work with both config data and operational data.

Internally it uses the MAAPI APIs such as maapi_load_config function and maapi_save_config function.

The source code of this command is also included in NSO installer as like ncs_cmd command.

Please refer to the C API documentation manual for the details of each API.

Usage of the command

Command can show the help with each options.

The default behavior is to save (export), and giving -l changes it to load (import).

$ ncs_load -h

A utility that saves and loads the running configuration, usage:

    ncs_load [options] [filename]

    ncs_load -l [options] [filename...]

    ncs_load -C [-R] [filename...]

Valid options are (for further details, see the manpage):

    -d            debug flag

    -l            load config into NCS [default is to save]

    -j            disable NCS Fastmap during load

    -n            no networking, just apply the data to NCS

    -M            include NCS service-meta-data attributes

    -F x|p|o|j|c|i format (one of x(ml), p(retty xml), json or

                  j, c, i (-style cli)) [default is xml]

    -W            include default values

    -S            include default values as comments

    -m            when loading config, merge [default is delete and replace]

    -r            when loading config, replace [default is delete and replace]

    -H            hide all hidden nodes [default depends on transaction]

    -U            unhide all hidden nodes [default depends on transaction]

    -a            when loading 'c' or 'i' config, commit after each line

    -e            when loading, do not abort on errors

    -p  <path>    when saving the path to save

                  when loading this path will first be deleted

    -N            when saving, do Not include parents to the path

    -P  <xpath>   when saving apply this xpath filter

    -D            do maapi_delete_all(MAAPI_DEL_ALL) before loading

    -o            when saving include operational data

                  when loading ignore operational data

    -u  <user>    use this user

    -g  <group>   use this group (may be repeated)

    -c  <context> use this context [default is 'system']

    -i            attach to init session instead of starting new session

    -s            start transaction towards startup [default is running]

    -O            when saving, include only operational data, not config

                  when loading, start operational transaction (load oper

                  data via a transaction instead of via CDB)

    -t            measure how long the requested command takes

    -C            load filename into CDB operational

    -R            generate CDB operational subscription notifications

$

Examples

When ncs_load is executed without any options, config data in running NSO is printed to standard output.

If needed, you can save it into a file using shell redirection.

$ ncs_load

<config xmlns="http://tail-f.com/ns/config/1.0"><SNMP-COMMUNITY-MIB xmlns="http://tail-f.com/ns/mibs/SNMP-COMMUNITY-MIB/200308060000Z"><snmpCommunityTable><snmpCommunityEntry><snmpCommunityIndex>public</snmpCommunityIndex><snmpCommunityName>public</snmpCommunityName><snmpCommunitySecurityName>public</snmpCommunitySecurityName><snmpCommunityContextEngineID>80:00:7e:d9:04:74:65:73:74:69:6e:67</snmpCommunityContextEngineID></snmpCommunityEntry></snmpCommunityTable></SNMP-COMMUNITY-MIB><SNMP-NOTIFICATION-MIB xmlns="http://tail-f.com/ns/mibs/SNMP-NOTIFICATION-MIB/200210140000Z"><snmpNotifyTable><snmpNotifyEntry><snmpNotifyName>foo</snmpNotifyName><snmpNotifyTag>monitor</snmpNotifyTag><snmpNotifyType>trap</snmpNotifyType></snmpNotifyEntry></snmpNotifyTable></SNMP-NOTIFICATION-MIB><SNMP-TARGET-MIB xmlns="http://tail-f.com/ns/mibs/SNMP-TARGET-MIB/200210140000Z"><snmpTargetAddrTable><snmpTargetAddrEntry><snmpTargetAddrName>monitor</snmpTargetAddrName><snmpTargetAddrTDomain>1.3.6.1.2.1.100.1.1</snmpTargetAddrTDomain><snmpTargetAddrTAddress>127.0.0.1.0.162</snmpTargetAddrTAddress>


//snip//

$


If you specify a file name, the content is saved into that file.

$ ncs_load config_exported.xml


Change the output format

-F option allows to change the output format. The default format is raw xml.

-F xraw XML (default)
-F pPrettfied XML
-F oJSON
-F jJuniper Style
-F iIOS-XR Style
-F cIOS Style

Here's an example to export data in JSON.

$ ncs_load -F o

{

"data": {

"SNMP-COMMUNITY-MIB:SNMP-COMMUNITY-MIB": {

"snmpCommunityTable": {

"snmpCommunityEntry": [

{

"snmpCommunityIndex": "public",

"snmpCommunityName": "public",

"snmpCommunitySecurityName": "public",

"snmpCommunityContextEngineID": "80:00:7e:d9:04:74:65:73:74:69:6e:67"

}

]

}

},

"SNMP-NOTIFICATION-MIB:SNMP-NOTIFICATION-MIB": {

<snip>

Path filter

ncs_load command exports the all data with default option. We can filter it with -p or -P option to limit the exported data.

-p option accepts Keypath.

$ ncs_load -p /aaa/authentication/users/user{admin}

<config xmlns="http://tail-f.com/ns/config/1.0"><aaa xmlns="http://tail-f.com/ns/aaa/1.1"><authentication><users><user><name>admin</name><uid>1000</uid><gid>65534</gid><password>$6$JDc4ByTQVm1uNQyl$xSUpMTduc4KdcYOvhf76cS7EwDmzIBbBma.VqvZE4lxoqCHa4vqeNQBeUKK/6ewsWAH6c4FYXJzStm7Bi3vjX.</password><ssh_keydir>/var/ncs/homes/admin/.ssh</ssh_keydir><homedir>/var/ncs/homes/admin</homedir></user></users></authentication></aaa></config>

$

-P option accepts xpath.

$ ncs_load -P "/aaa/authentication/users/user[name='admin']"

<config xmlns="http://tail-f.com/ns/config/1.0"><aaa xmlns="http://tail-f.com/ns/aaa/1.1"><authentication><users><user><name>admin</name><uid>65534</uid><gid>65534</gid><password>$6$Yt0vQXRXJGmUm/Zf$.o0BLkkDqQY.y.rJtdqaWEP/DwF0doN6sB6E2i0JuDkcd/vOkinQuVB/1jDczgdX8R9/gZyzzxNNB4cJEdF8K1</password><ssh_keydir>/var/ncs/homes/admin/.ssh</ssh_keydir><homedir>/var/ncs/homes/admin</homedir></user></users></authentication></aaa></config>

$

Importing XML data

The exported data in XML can be imported. The default behavior is to replace the data with the content in XML, and the data in NSO is deleted.

The data can be generated by ncs_load command and any other tools. For example, when creating NETSIM instance, the connection information can be generated by ncs-netsim command, and it can be imported (merged) into the current running NSO.

Exporting NETSIM configuration data

$ ncs-netsim ncs-xml-init

<devices xmlns="http://tail-f.com/ns/ncs">

<device>

<name>c0</name>

<address>127.0.0.1</address>

<port>10022</port>

<ssh>

<host-key>

<algorithm>ssh-rsa</algorithm>

// snip //

We need to merge this into existing NSO CDB, please don't forget to give -m option.

$ ncs-netsim ncs-xml-init | ncs_load -lm

If the config is saved in a file, you can give the file name to load.

$ ncs-netsim ncs-xml-init > netsim.xml

$ ncs_load -lm netsim.xml

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the NSO Developer community:

Quick Links