cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
332
Views
15
Helpful
8
Replies
Highlighted
Cisco Employee

Configure licensing token on IOS XR from NSO - supported by XR NED?

In this configuration guide it is explained how smart licensing is enabled and how a smart licensing token is registered in IOS XR (ASR9k): https://www.cisco.com/c/en/us/td/docs/routers/asr9000/software/asr9k-r6-6/system-management/configuration/guide/b-system-management-cg-asr9000-66x/b-system-management-cg-asr9000-66x_chapter_010100.html

My customer needs to do the enabling and token registration from NSO, however it seems to me like it is not supported by the XR NED yet. The guide explains that when enabling smart licensing, I am supposed to enter administration EXEC mode and then in there, config mode. But it is not possible to go to config mode within administration EXEC mode in NSO.

In administration EXEC mode I can do the enable command in NSO, but the commit fails. Please see 1) below.

When trying to do the license smart register idtoken <token> command, I do not get the option to type the "register" keyword in NSO.

I use NSO version 4.7.4.1 and the IOS XR NED is the latest for NSO 4.7.4.1; cisco-iosxr-7.12.3.

Of course it is possible that it has been corrected in NSO 5.1 NED, but probably not???

What do you think? Have you experienced this as well? I guess we should have the NED updated by the BU?

 

1)

 

admin@ncs(config-device-ncs55a2)# conf
admin@ncs(config-config)# cisco-ios-xr:admin 
admin@ncs(config-admin)# license ?   
Possible completions:
  smart   Smart Licensing
admin@ncs(config-admin)# license smart ?
Possible completions:
  enable   Enable Smart Licensing
admin@ncs(config-admin)# license smart enable ?
Possible completions:
  <cr>
admin@ncs(config-admin)# license smart enable 
admin@ncs(config-admin)# commit dry-run outformat xml 
result-xml {
    local-node {
        data <devices xmlns="http://tail-f.com/ns/ncs">
               <device>
                 <name>ncs55a2</name>
                 <config>
                   <admin xmlns="http://tail-f.com/ned/cisco-ios-xr">
                     <license>
                       <smart>
                         <enable/>
                       </smart>
                     </license>
                   </admin>
                 </config>
               </device>
             </devices>
    }
}
admin@ncs(config-admin)# commit 
Aborted: External error in the NED implementation for device ncs55a2: command: 
sysadmin-vm:0_RP0(config)# license smart enable 
---------------------------^
syntax error: unknown argument

 

 

Everyone's tags (3)
2 ACCEPTED SOLUTIONS

Accepted Solutions
Cisco Employee

Re: Configure licensing token on IOS XR from NSO - supported by XR NED?

It is supported, the problem is that the registration is not actually a piece of configuration but a command! So it has to be executed rather than just configured.
Cisco Employee

Re: Configure licensing token on IOS XR from NSO - supported by XR NED?

So, the action is actually called any, so you are looking for something like 

import ncs
with ncs.maapi.single_read_trans('admin', 'python') as t: 
    root = ncs.maagic.get_root(t) 
    devs = root.devices.device 
    any = devs['ios0'].live_status.ios_stats__exec.any
    inp = any.get_input() 
    inp.args = ['license register sdfsdfsdf'] 
    r = any.request(inp) 
    print(r.result) 

 

The last comment I made, well, it is a bit messy to do this in a service - because a service is assumed to be free of side-effects and license registration is a side-effect. You can still do it, but it is generally a bad idea - for instance it means that even doing a dry-run on the service would register the license, which is probably not what you want. 

8 REPLIES 8
Cisco Employee

Re: Configure licensing token on IOS XR from NSO - supported by XR NED?

It is supported, the problem is that the registration is not actually a piece of configuration but a command! So it has to be executed rather than just configured.
Cisco Employee

Re: Configure licensing token on IOS XR from NSO - supported by XR NED?

Yes, I see what you mean. So we cannot do the registration of tokens from NSO.

Cisco Employee

Re: Configure licensing token on IOS XR from NSO - supported by XR NED?

I am considering that maybe this could be done with RPC / MAAPI. Considering these ASR9k commands:

RP/0/RSP0/CPU0:router# admin
RP/0/RSP0/CPU0:router(admin)#license smart register idtoken NmE1Yzg0OWMtYmJ4

What would they look like using Python high-level API / maapi? If possible?

I am reading the "Python API Overview" section in the documentation, however I have not yet figured out how to do it. I do not know how to get to the admin EXEC mode.

Cisco Employee

Re: Configure licensing token on IOS XR from NSO - supported by XR NED?

It is quite doable in NSO and this particular use-case is pretty common as well. There was a thread a few days ago that talked about how to call actions from Python, among other things, that might be some help: https://community.cisco.com/t5/nso-developer-hub-discussions/how-to-send-nso-commands-from-python-code/m-p/3863823

 

Your action in nso will be under /devices/device{X}/live-status, I would recommend that you explore that through the NSO CLI first to see what you want.

 

What makes this a little bit complicated is that this will also force you into some variant of the reactive fastmap pattern. Which is not a horrible thing, but does increase the complexity just a little bit.

Cisco Employee

Re: Configure licensing token on IOS XR from NSO - supported by XR NED?

Thank you for the guidance. I managed to do what I want from NSO cli:

admin@ncs(config-device-asr9001)# live-status cisco-ios-xr-stats:exec any admin "license smart deregister"
result 
Wed Jun  5 19:14:26.523 CET

license smart deregister: Success 


License command "license smart deregister " completed successfully. 
RP/0/RSP0/CPU0:ASR9K-SP-LAB-OPENNET#
admin@ncs(config-device-asr9001)# live-status cisco-ios-xr-stats:exec any admin "license smart register idtoken .....ANjI4MDh8M0hFdytGNWhiRlhUT0o5U3F6UXByNzJ6YmJCeFpSWllGN....."
result 
Wed Jun  5 19:17:19.806 CET
 
license smart register: Registration process is in progress. Use the 'show license status' command to check the progress and result 

RP/0/RSP0/CPU0:ASR9K-SP-LAB-OPENNET#
admin@ncs(config-device-asr9001)#

Now, trying to do that using the API's is a bit more difficult for me. I can succeed with a show command, like this:

In [14]: with ncs.maapi.single_read_trans('admin', 'python') as t: 
    ...:     root = ncs.maagic.get_root(t) 
    ...:     devs = root.devices.device 
    ...:     show = devs['asr9001'].live_status.__getitem__('ios-stats:exec').show 
    ...:     inp = show.get_input() 
    ...:     inp.args = ['isis topology summary'] 
    ...:     r = show.request(inp) 
    ...:     print(r.result) 
    ...:                                                                                                                                                       

Thu Jun  6 07:23:25.235 CET

IS-IS BACKBONE IS Topology Summary IPv4 Unicast
                          L1                              L2
               Reach  UnReach   Total/All      Reach  UnReach  Total/All
                      In Top                          In Top
              ------- ------- -------------   ------- ------- -------------
Router nodes:       0       0      0/0              2       0      2/2     
Pseudo nodes:       0       0      0/0              0       0      0/0     

 Total nodes:       0       0      0/0              2       0      2/2     
RP/0/RSP0/CPU0:ASR9K-SP-LAB-OPENNET#

But I am not yet sure how to do the "admin" followed by e.g. "license smart deregister" or "show license status". Tried this:

In [15]: with ncs.maapi.single_read_trans('admin', 'python') as t: 
    ...:     root = ncs.maagic.get_root(t) 
    ...:     devs = root.devices.device 
    ...:     asadmin = devs['asr9001'].live_status.__getitem__('ios-stats:exec').admin 
    ...:     show = devs['asr9001'].live_status.__getitem__('ios-stats:exec').show 
    ...:     inp = show.get_input() 
    ...:     inp.args = ['license status'] 
    ...:     a = admin.request() 
    ...:     r = show.request(inp) 
    ...:     print(r.result) 
    ...:                                                                                                                                                       
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-15-6a051715b061> in <module>
      2     root = ncs.maagic.get_root(t)
      3     devs = root.devices.device
----> 4     asadmin = devs['asr9001'].live_status.__getitem__('ios-stats:exec').admin
      5     show = devs['asr9001'].live_status.__getitem__('ios-stats:exec').show
      6     inp = show.get_input()

~/ncs-4.7.4.1/src/ncs/pyapi/ncs/maagic.py in __getattr__(self, name)
    470                 return child
    471         else:
--> 472             super(Node, self).__getattribute__(name)
    473 
    474     def __setattr__(self, name, value):

AttributeError: 'Container' object has no attribute 'admin'

In [16]:

I guess I need to watch the videos and read the API documentation..

Not sure what you mean with the comment "What makes this a little bit complicated is that this will also force you into some variant of the reactive fastmap pattern. Which is not a horrible thing, but does increase the complexity just a little bit."?

Cisco Employee

Re: Configure licensing token on IOS XR from NSO - supported by XR NED?

So, the action is actually called any, so you are looking for something like 

import ncs
with ncs.maapi.single_read_trans('admin', 'python') as t: 
    root = ncs.maagic.get_root(t) 
    devs = root.devices.device 
    any = devs['ios0'].live_status.ios_stats__exec.any
    inp = any.get_input() 
    inp.args = ['license register sdfsdfsdf'] 
    r = any.request(inp) 
    print(r.result) 

 

The last comment I made, well, it is a bit messy to do this in a service - because a service is assumed to be free of side-effects and license registration is a side-effect. You can still do it, but it is generally a bad idea - for instance it means that even doing a dry-run on the service would register the license, which is probably not what you want. 

Cisco Employee

Re: Configure licensing token on IOS XR from NSO - supported by XR NED?

Thanks Viktor. That did the trick. Please find my results below. Please notice that:

- I had to use the 'admin' command before the actual license command. E.g. inp.args = ['admin','license smart deregister']

- Some strange errors when doing the show license status command. Please see in the bottom.

Deregister license:

In [8]: with ncs.maapi.single_read_trans('admin', 'python') as t: 
   ...:     root = ncs.maagic.get_root(t) 
   ...:     devs = root.devices.device 
   ...:     any = devs['asr9001'].live_status.ios_stats__exec.any 
   ...:     inp = any.get_input() 
   ...:     inp.args = ['admin','license smart deregister'] 
   ...:     r = any.request(inp) 
   ...:     print(r.result) 
   ...:                                                                                                                                                

Mon Jun 10 19:40:38.465 CET

license smart deregister: Success 


License command "license smart deregister " completed successfully. 
RP/0/RSP0/CPU0:ASR9K-SP-LAB-OPENNET#

Register license:

In [9]: with ncs.maapi.single_read_trans('admin', 'python') as t: 
   ...:     root = ncs.maagic.get_root(t) 
   ...:     devs = root.devices.device 
   ...:     any = devs['asr9001'].live_status.ios_stats__exec.any 
   ...:     inp = any.get_input() 
   ...:     inp.args = ['admin','license smart register idtoken ...mODctNjc3OWUxMWFmNDJmLTE1OTExNzUz%0ANjI4MDh8M0hFdytGNWhiRlhU
   ...: T0o5U3F6UXByNzJ6YmJC.......'] 
   ...:     r = any.request(inp) 
   ...:     print(r.result) 
   ...:                                                                                                                                                

Mon Jun 10 19:44:16.769 CET
 
license smart register: Registration process is in progress. Use the 'show license status' command to check the progress and result 

RP/0/RSP0/CPU0:ASR9K-SP-LAB-OPENNET#

Getting license status. Please see errors. Is there an error in the NED??

In [10]: with ncs.maapi.single_read_trans('admin', 'python') as t: 
    ...:     root = ncs.maagic.get_root(t) 
    ...:     devs = root.devices.device 
    ...:     any = devs['asr9001'].live_status.ios_stats__exec.any 
    ...:     inp = any.get_input() 
    ...:     inp.args = ['admin','show license status'] 
    ...:     r = any.request(inp) 
    ...:     print(r.result) 
    ...:                                                                                                                                               
---------------------------------------------------------------------------
Error                                     Traceback (most recent call last)
<ipython-input-10-320ad354aa03> in <module>
      5     inp = any.get_input()
      6     inp.args = ['admin','show license status']
----> 7     r = any.request(inp)
      8     print(r.result)
      9 

~/ncs-4.7.4.1/src/ncs/pyapi/ncs/maagic.py in request(self, params)
   1535         tv = params._tagvalues() if params else []
   1536         cs = self._cs_node.ns()
-> 1537         output = self._backend._request_action(tv, cs, self._path)
   1538         outparams = ActionParams(self._cs_node, parent=None, output=True)
   1539         outparams._from_tagvalues(output)

~/ncs-4.7.4.1/src/ncs/pyapi/ncs/maagic.py in _request_action(self, params, _ns, path)
    137 
    138     def _request_action(self, params, _ns, path):
--> 139         return self.request_action_th(params, path)
    140 
    141 

~/ncs-4.7.4.1/src/ncs/pyapi/ncs/maapi.py in proxy(self2, *args, **kwargs)
   1176             else:
   1177                 real = getattr(_tm.maapi, name)
-> 1178                 return real(self2.maapi.msock, self2.th, *args, **kwargs)
   1179         setattr(Transaction, name, proxy)
   1180         return getattr(self, name)

Error: external error (19): External error in the NED implementation for device asr9001: 
Mon Jun 10 19:45:45.192 CET

Smart Licensing is ENABLED
  Initial Registration: SUCCEEDED on Mon Jun 10 2019 19:44:26 CET
  Last Renewal Attempt: None
  Next Renewal Attempt: Sat Dec 07 2019 19:44:26 CET
  Registration Expires: Tue Jun 02 2020 10:53:30 CET

License Authorization: 
Missing answer to a device question:
+++
Mon Jun 10 19:45:45.192 CET

Smart Licensing is ENABLED
  Initial Registration: SUCCEEDED on Mon Jun 10 2019 19:44:26 CET
  Last Renewal Attempt: None
  Next Renewal Attempt: Sat Dec 07 2019 19:44:26 CET
  Registration Expires: Tue Jun 02 2020 10:53:30 CET

License Authorization: 
+++
Set auto-prompts ned-setting or add '| prompts <answer(s)>'

Note: Single letter <answer> is sent without LF. Use 'ENTER' for LF only.
      Add '| noprompts' in order to ignore all prompts.
Cisco Employee

Re: Configure licensing token on IOS XR from NSO - supported by XR NED?

So, the problem you see there is that the NED tries to be smart, since some IOS commands are interactive. This can be used for instance for commands that prompt you for verification before doing something.

 

But, what happens here is that the NED things that the : signifies a prompt (it matches some regexp it uses to find prompts). As the text hints you can use the ned settings (set devices device X ned-settings) to configure the behaviour of prompting, that might be your best option in this case.