05-10-2017 01:33 AM - edited 03-01-2019 03:49 AM
Hi All,
I’m trying to get a clear idea what is needed to modify a leaf value in a service model.
Just running at an interactive prompt I’m trying the following:
import ncs
mr=ncs.maapi.Maapi()
mw=ncs.maapi.Maapi()
sr=ncs.maapi.Session(mr,'admin','admin')
sw=ncs.maapi.Session(mw,'admin','admin')
tw=mw.start_write_trans()
tr=mr.start_read_trans()
rroot=ncs.maagic.get_root(tr)
wroot=ncs.maagic.get_root(tw)
It’s likely not necessary, but I have a read(tr) and a write transaction(tw) setup.
>>> rroot.services.autovnfpair__autovnfpair["Auto1"]["mytest"]
'firstValue'
>>> wroot.services.autovnfpair__autovnfpair["Auto1"]["mytest"]='secondValue'
>>> rroot.services.autovnfpair__autovnfpair["Auto1"]["mytest"]
'firstValue'
###### The value doesn’t change #########
Questions:
- What is the proper call to commit the “tw” transaction? And will the existing read transaction “see” it immediately or do I need to re-establish a new read transaction?
- Am I going about this the hard way? Is there a wrapper function/class to open a write transaction, assign a value and commit it?
- Does setting this value directly (outside of the cb_create function) create any side effects ?
- What causes the naming convention of “autovnfpair__autovnfpair” ?
- I’ve seen other example code that doesn’t follow this pattern , but I can’t determine the difference in the yang model or code that would make this different.
05-10-2017 01:34 AM
Inline
Hi All,
I’m trying to get a clear idea what is needed to modify a leaf value in a service model.
Just running at an interactive prompt I’m trying the following:
import ncs
mr=ncs.maapi.Maapi()
mw=ncs.maapi.Maapi()
sr=ncs.maapi.Session(mr,'admin','admin')
sw=ncs.maapi.Session(mw,'admin','admin')
tw=mw.start_write_trans()
tr=mr.start_read_trans()
rroot=ncs.maagic.get_root(tr)
wroot=ncs.maagic.get_root(tw)
It’s likely not necessary, but I have a read(tr) and a write transaction(tw) setup.
>>> rroot.services.autovnfpair__autovnfpair["Auto1"]["mytest"]
'firstValue'
>>> wroot.services.autovnfpair__autovnfpair["Auto1"]["mytest"]='secondValue'
>>> rroot.services.autovnfpair__autovnfpair["Auto1"]["mytest"]
'firstValue'
###### The value doesn’t change #########
Questions:
- What is the proper call to commit the “tw” transaction? And will the existing read transaction “see” it immediately or do I need to re-establish a new read transaction?
tw.apply()
the read transaction will never see the new value because it read the old value beforehand and a read transaction is supposed to give you one consistent view of the DB.
See following trace, the read transaction maintains a consistent view of the DB, so exactly what is seen immediately depends on what the read transaction has already read and is now cached in the transaction
>>> tw=mw.start_write_trans()
>>> rroot.devices.device['testdev'].address
'1.2.3.4'
Now before making a change we read into the read transaction the device IP
>>> wroot.devices.device['testdev'].address='1.2.3.5'
>>> tw.apply()
>>> rroot.devices.device['testdev'].address
'1.2.3.4'
Even though the write transaction is applied, the old avalue of the IP is still in the read transaction.
>>>
- Am I going about this the hard way? Is there a wrapper function/class to open a write transaction, assign a value and commit it?
Probably not. Why not use a single transaction? There is nothing stopping you from reading in a write transaction.
No wrapper is provided, and I think in almost all cases there is more than one value to write.
- Does setting this value directly (outside of the cb_create function) create any side effects ?
It is persisted in the DB when you apply, that is an intended side effect. Otherwise no nothing harmful here at all.
- What causes the naming convention of “autovnfpair__autovnfpair” ?
- I’ve seen other example code that doesn’t follow this pattern , but I can’t determine the difference in the yang model or code that would make this different.
You have a list called autovnfpair in a namespace called autovnfpair, python does no allow identifiers with ‘:’ so it is replaced with ‘__’. Note that in yang ‘-‘ is also a common identifier in names, that is not useable in python, and this is replaced by ‘_’.
You could just use autovpnfpair as the identifier instead of the long form if it is unambiguous, just like I did not have to use ncs__devices
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