cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1102
Views
2
Helpful
1
Replies

how to generate XML/CLI capabilities from yang model?

pralala
Cisco Employee
Cisco Employee

Hi,

We need to generate XML capabilities from yang model that can be loaded in NSO using some tool instead of doing a sync-from from a device.
Is there a static way to generate those capabilities/modules?


I tried with pyang. I got the following output

PRALALA-M-27BM:yang pratik$ pyang -f capability viptela-system.yang --capability-entity

http://viptela.com/system?module=viptela-system&revision=2017-05-25&features=
I may have to write some kind of code to extract the URI, revision, modules etc from this string.

I need a solution which is similar to copy-capabalities. But, it is only available to generic or cli based device and not netconf device.
If there is a solution anyone is aware of then please do let me know.





1 Accepted Solution

Accepted Solutions

Dan.Sullivan
Cisco Employee
Cisco Employee

Hi Pratik,

For netcnonf devices you need to start with a real device and determine the capabilties you will need for you device. Once you understand you can "create" the capabilties fairly quickly. For example consider the following script that copies capabilities from one device to another:

-Dan

def deviceCapabilities(t, src, dst):

      global port

      spath = '/ncs:devices/device{"' + src + '"}'

      dpath = '/ncs:devices/device{"' + dst + '"}'

   

      cspath = spath + '/capability'

      dspath = dpath + '/capability'

      mspath = spath + '/module'

      mdpath = dpath + '/module'

      with t.cursor(cspath) as caps :

         for cap in caps :

           capability = str(cap[0])

           cp = cspath + '{"' + capability + '"}'

           dp = dspath + '{"' + capability + '"}'

           revision = "none"

           module = "none"

           if (t.exists(cp  + "/revision")) :

               revision = t.get_elem(cp + "/revision");

           if (t.exists(cp + "/module")) :

               module = t.get_elem(cp + "/module");

               msp = mspath + '{"' + str(module) + '"}'

               mdp = mdpath + '{"' + str(module) + '"}'

               if (t.exists(msp)) :

                  if not (t.exists(mdp)) :

                     t.create(mdp)

                  if not (revision == 'none') :

                     t.set_elem(revision, mdp + "/revision")

               if not (t.exists(dp)) :

                 t.create(dp)

                 if not (revision == 'none') :

                    t.set_elem(revision, dp + "/revision")

                 if not (module == 'none') :

                    t.set_elem(module, dp + "/module")

      return True

View solution in original post

1 Reply 1

Dan.Sullivan
Cisco Employee
Cisco Employee

Hi Pratik,

For netcnonf devices you need to start with a real device and determine the capabilties you will need for you device. Once you understand you can "create" the capabilties fairly quickly. For example consider the following script that copies capabilities from one device to another:

-Dan

def deviceCapabilities(t, src, dst):

      global port

      spath = '/ncs:devices/device{"' + src + '"}'

      dpath = '/ncs:devices/device{"' + dst + '"}'

   

      cspath = spath + '/capability'

      dspath = dpath + '/capability'

      mspath = spath + '/module'

      mdpath = dpath + '/module'

      with t.cursor(cspath) as caps :

         for cap in caps :

           capability = str(cap[0])

           cp = cspath + '{"' + capability + '"}'

           dp = dspath + '{"' + capability + '"}'

           revision = "none"

           module = "none"

           if (t.exists(cp  + "/revision")) :

               revision = t.get_elem(cp + "/revision");

           if (t.exists(cp + "/module")) :

               module = t.get_elem(cp + "/module");

               msp = mspath + '{"' + str(module) + '"}'

               mdp = mdpath + '{"' + str(module) + '"}'

               if (t.exists(msp)) :

                  if not (t.exists(mdp)) :

                     t.create(mdp)

                  if not (revision == 'none') :

                     t.set_elem(revision, mdp + "/revision")

               if not (t.exists(dp)) :

                 t.create(dp)

                 if not (revision == 'none') :

                    t.set_elem(revision, dp + "/revision")

                 if not (module == 'none') :

                    t.set_elem(module, dp + "/module")

      return True