Created
October 31, 2018 10:55
-
-
Save jcurry/54a938eeede27eaf75db763764b952c0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env zendmd | |
# | |
# Change ZenPack name | |
#dmd.ZenPackManager.packs._delObject('ZenPacks.zenoss.ZenPackName') | |
# commit() | |
packs = None | |
if hasattr(dmd, 'ZenPackManager'): | |
packs = dmd.ZenPackManager.packs | |
else: | |
packs = dmd.packs | |
phase2 = False | |
for pack in packs(): | |
try: | |
unused = pack.primaryAq() | |
print "%s is fine." % pack.id | |
except AttributeError: | |
print "Problem with %s ZenPack. Forcing removal." % pack.id | |
try: | |
#packs._remove(pack) | |
#print "Removed %s ZenPack." % pack.id | |
print "Removed (not actually) %s ZenPack." % pack.id | |
except AttributeError: | |
print "Unable to remove this ZenPack." | |
phase2 = True | |
# There were some packs we could not remove using the _remove method. Fall back to | |
# a deeper removal approach using pack ID. | |
# kludge this for now | |
phase2 = True | |
if phase2: | |
print "Starting Phase 2 removal" | |
all_pack_ids = [] | |
for pack_id in dmd.ZenPackManager.packs._objects: | |
all_pack_ids.append(pack_id) | |
valid_pack_ids = [] | |
for pack in dmd.ZenPackManager.packs(): | |
try: | |
valid_pack_ids.append(pack.id) | |
except: | |
pass | |
print "all_pack_ids is %s" % (all_pack_ids) | |
print "valid_pack_ids is %s" % (valid_pack_ids) | |
# iterate over all packs, if missing from valid packs, remove: | |
for pack_id in all_pack_ids: | |
if pack_id not in valid_pack_ids: | |
#print "Forced removal of %s" % pack_id | |
print "Forced (not actually) removal of %s" % pack_id | |
#del packs._objects[pack_id] | |
# Once happy this does what you want, uncomment the commit | |
#commit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment