def add_devices(n_devices): """ create n_devices devices with random ip and device class """ device_classes = get_device_classes(dmd) for i in range(n_devices): ip = generate_random_ip() device_class = random.choice(device_classes) device_class = device_class[18:] # remove "/zport/dmd/Devices" print "Creating device {0} / {1}".format(ip, device_class) device = JobDeviceLoader(dmd).load_device(ip, device_class, 'none', 'localhost', manageIp=ip) assign_random_ips_to_device(device) commit()
dmd = ZenScriptBase(connect=True).dmd from transaction import commit from Products.AdvancedQuery import Eq, Or, Generic, And, In, MatchRegexp from Products.Zuul.catalog.interfaces import IModelCatalogTool from Products.Zuul.interfaces.tree import ICatalogTool from zenoss.modelindex.searcher import SearchParams from zenoss.modelindex.exceptions import SearchException import random import time from utils import get_device_classes, get_mib_organizers DEVICE_CLASSES = get_device_classes(dmd) class GlobalCatalogTester(object): def __init__(self): pass def test_device_classes_devices(self): """ Check devices under device classes are the same """ failed_device_classes = [] for dc in DEVICE_CLASSES: dc_object = dmd.unrestrictedTraverse(dc) # Devices under device class in global catalog global_catalog = ICatalogTool(dc_object) global_catalog_brains = global_catalog.search('Products.ZenModel.Device.Device')