Difference between revisions of "Creating ZenDMD Tip - Delete List Of Locations"

From Zenoss Wiki
Jump to: navigation, search
(Category)
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
Initiated from http://community.zenoss.org/message/73758#73758
 
Initiated from http://community.zenoss.org/message/73758#73758
  
Lets say you have a large (or small I suppose) list of locations that you want to delete. The Web UI is less than desirable for this so you can use zendmd to pull this off.
+
Lets say you have a large (or small I supposed) list of locations that you want to delete. The Web UI is less than desirable for this so you can use zendmd to pull this off.
  
 
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
Line 40: Line 40:
  
 
</syntaxhighlight>
 
</syntaxhighlight>
 
[[Category:Tips]]
 
[[Category:ZenDMD]]
 

Revision as of 04:03, 28 June 2013

Initiated from http://community.zenoss.org/message/73758#73758

Lets say you have a large (or small I supposed) list of locations that you want to delete. The Web UI is less than desirable for this so you can use zendmd to pull this off.

loc_names_to_delete = ("Location1", "Location2")
for loc in dmd.Locations:
    if loc in loc_names_to_delete:
        dmd.Locations.manage_deleteOrganizer(loc)

For the skeptics in the audience, here you can see it in action.

Welcome to the Zenoss dmd command shell!
'dmd' is bound to the DataRoot. 'zhelp()' to get a list of commands.
Use TAB-TAB to see a list of zendmd related commands.
Tab completion also works for objects -- hit tab after an object name and '.'
 (eg dmd. + tab-key).
>>> # Show current Locations
>>> print dmd.Locations.getOrganizerNames()
['/', '/Location1', '/Location2', '/Location3']
>>>
>>> # Now define the locations you want to delete
>>> loc_names_to_delete = ("Location1", "Location2")
>>>
>>> # Now loop through the locations and delete the ones
>>> # you no longer want
>>> for loc in dmd.Locations:
...     if loc in loc_names_to_delete:
...         dmd.Locations.manage_deleteOrganizer(loc)
...
>>> # Now display your locations
>>> print dmd.Locations.getOrganizerNames()
['/', '/Location3']
>>>
>>> # And finally commit your deletes
>>> commit()
>>>
>>>