cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1706
Views
5
Helpful
4
Replies

delete node from Python with service._path

Gastonper
Level 1
Level 1

Hi, I have the following problem:

 

I have a services (service A) that when is created populate his path in another service (Service B). Service B have multiple path of instances of service A.

I want to make an action that read all service path in Service B, and delete the corresponding services A.

 

Here is the problem, to get the service object in Python from the path string I use:

service_to_delete = ncs.maagic.get_node(t, service_path)
del service_to_delete

But this only delete the Python object service_to_delete, and not the CDB service, as is explained in the nso docs.

If I use:

del ncs.maagic.get_node(t, service_path)

I get an error on package reload:

*** ALARM package-load-failure: [SyntaxError: can't delete function call]

Is there a delete_node() function or a workaround to solve this?

1 Accepted Solution

Accepted Solutions

cealves
Cisco Employee
Cisco Employee

You have to delete the child(item) of the node so when you call the del statement you have to mention which item you want to delete. In this case we have to identify the instance to be deleted by its name, so it had to look something like this:

service_to_delete = ncs.maagic.get_node(t, service_path)
del service_to_delete[service_name]
t.apply

Hope it helps.

View solution in original post

4 Replies 4

yfherzog
Cisco Employee
Cisco Employee

WIth the first option, are you applying the transaction in which you use 'del service_to_delete'?

Yes I do, but as I say its only delete the Python pointer object and not the node in the CDB.

cealves
Cisco Employee
Cisco Employee

You have to delete the child(item) of the node so when you call the del statement you have to mention which item you want to delete. In this case we have to identify the instance to be deleted by its name, so it had to look something like this:

service_to_delete = ncs.maagic.get_node(t, service_path)
del service_to_delete[service_name]
t.apply

Hope it helps.

akumartm
Cisco Employee
Cisco Employee

You can delete the instance using _ncs.maapi.delete()

service_to_delete = ncs.maagic.get_node(t, service_path)
_ncs.maapi.delete(m.msock, t.th, service_to_delete._path)
t.apply()