Created
May 18, 2016 13:13
-
-
Save turingmachine/dbd3e42fb4ed41cad04c05d8168c6026 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import sys, time | |
from ZenPacks.community.CiscoEntityEnvMon.CiscoDevice import CiscoDevice | |
sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) | |
CHUNK_SIZE = 100 | |
ORGANIZERS = [ | |
dmd.Devices.Network.Switch.Cisco, | |
dmd.Devices.Network.Router.Cisco, ] | |
def chunks(bulk, chunk_size): | |
for i in range(0, len(bulk), chunk_size): | |
yield bulk[i:i+chunk_size] | |
def update_class(organizer): | |
print "migrate devices in %s" % organizer.getOrganizerName() | |
devices = filter(lambda x: not isinstance(x, CiscoDevice), | |
organizer.getSubDevices()) | |
if not devices: return | |
for chunk in chunks(devices, CHUNK_SIZE): | |
sys.stdout.write('.') | |
organizer.moveDevices( | |
organizer.getOrganizerName(), | |
map(lambda x: x.id, chunk)) | |
commit() | |
print "\n%i devices successfully migrated" % len(devices) | |
return devices | |
map(lambda x: update_class(x), ORGANIZERS) | |
if filter(lambda x: isinstance(x, CiscoDevice), | |
reduce(lambda x, y: x+y, map(lambda x: x.getSubDevices(), ORGANIZERS))): | |
print "\nall devices were successfully migrated" | |
else: | |
print "\nsome devices were not migrated, inspection needed" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment