11-20-2017 02:37 PM - edited 03-01-2019 04:02 AM
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.
Solved! Go to Solution.
11-29-2017 12:56 PM
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
11-29-2017 12:56 PM
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
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide