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

From Zenoss Wiki
Jump to: navigation, search
(Created page with "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.<s...")
 
Line 1: Line 1:
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">
+
Initiated from http://community.zenoss.org/message/73758#73758
loc_names_to_delete = ("Location1", "Location2")for loc in dmd.Locations:   if loc in loc_names_to_delete:       dmd.Locations.manage_deleteOrganizer(loc)
+
 
 +
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">
 +
loc_names_to_delete = ("Location1", "Location2")
 +
for loc in dmd.Locations:
 +
    if loc in loc_names_to_delete:
 +
        dmd.Locations.manage_deleteOrganizer(loc)
 +
</syntaxhighlight>
 +
 
 +
For the skeptics in the audience, here you can see it in action.
 +
<syntaxhighlight lang="python">
 +
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()
 +
>>>
 +
>>>
 +
 
 
</syntaxhighlight>
 
</syntaxhighlight>

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()
>>>
>>>