08-12-2021 02:31 PM
I have a created the following leaf in a yang
leaf allocated-service-instance { type uint32; config false; tailf:cdb-oper { tailf:persistent true; } }
In the code how do you reference this during a re-deploy?
if int(proplist[0][1]) != 0:
print(root.nameOfService['key'].allocated_service_instance) print service.allocated_service_instance)
During the initial commit of this service the allocated_service_instance is set using a dynamic instance generated in code. I am trying to call this leaf during re-deploy to ensure it uses the existing instance that was generated.
08-12-2021 03:40 PM
Was able to figure this out. After reading you need to grab this value during pre_mod I think, not 100% on that. Then send the value in the service create within the proplist
@Service.pre_modification def cb_pre_modification(self, tctx, op, kp, root, proplist): self.log.info('Service premod(service=', kp, ')') self.log.info(f"python - user_info - PREMOD PROPLIST; {proplist}") info_from_kp = re.findall(r'{[A-Z0-9]+\.*[0-9]*}', str(kp)) keys_in_kp = [x.replace('{', '').replace('}', '') for x in info_from_kp] circuit_key = keys_in_kp[0] proplist = [('deploy_status', str(op), circuit_key)] self.log.info(proplist[0][2]) return proplist
Kind of weird that you have to regex out the service key(s). Anybody know of a way to pull keys send into a service without regexing out the kp?
Pulled the regex from this topic
08-16-2021 01:56 AM
with ncs.maapi.single_read_trans("admin", "python") as t: path = ncs.maagic.get_node(t, kp) id = path._parent.id. # depends on your model
You may get a service or action path and navigate from it. In my example, one step up to 'id' leaf.
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