def applyOtherProps(self, device, device_specs): """ Apply non-zProperty settings (if any) to the device. @parameter device: device to modify @type device: DMD device object @parameter device_specs: device creation dictionary @type device_specs: dictionary """ self.log.debug("Applying other properties...") internalVars = [ 'deviceName', 'devicePath', 'loader', 'loader_arg_keys', 'manageIp', ] @transactional def setNamedProp(self, org, name, description): setattr(org, name, description) for functor, value in device_specs.items(): if iszprop(functor) or \ iscustprop(functor) or functor in internalVars: continue # Special case for organizers which can take a description if functor in ('description', 'address', 'comments', 'rackSlot'): if hasattr(device, functor): setNamedProp(self, device, functor, value) continue try: self.log.debug("For %s, calling device.%s(%s)", device.id, functor, value) func = getattr(device, functor, None) if func is None or not callable(func): self.log.warn( "The function '%s' for device %s is not found.", functor, device.id) elif isinstance(value, (list, tuple)): # The function either expects a list or arguments # So, try as an arguments try: func(*value) # Try as a list except TypeError: func(value) else: func(value) except ConflictError: raise except Exception: msg = "Device %s device.%s(%s) failed" % (device.id, functor, value) self.reportException(msg, device.id)
def applyOtherProps(self, device, device_specs): """ Apply non-zProperty settings (if any) to the device. @parameter device: device to modify @type device: DMD device object @parameter device_specs: device creation dictionary @type device_specs: dictionary """ self.log.debug("Applying other properties...") internalVars = [ 'deviceName', 'devicePath', 'loader', 'loader_arg_keys', 'manageIp', ] @transactional def setNamedProp(self, org, name, description): setattr(org, name, description) for functor, value in device_specs.items(): if iszprop(functor) or \ iscustprop(functor) or functor in internalVars: continue # Special case for organizers which can take a description if functor in ('description', 'address', 'comments', 'rackSlot'): if hasattr(device, functor): setNamedProp(self, device, functor, value) continue try: self.log.debug( "For %s, calling device.%s(%s)", device.id, functor, value ) func = getattr(device, functor, None) if func is None or not callable(func): self.log.warn( "The function '%s' for device %s is not found.", functor, device.id ) elif isinstance(value, (list, tuple)): # The function either expects a list or arguments # So, try as an arguments try: func(*value) # Try as a list except TypeError: func(value) else: func(value) except ConflictError: raise except Exception: msg = "Device %s device.%s(%s) failed" % ( device.id, functor, value ) self.reportException(msg, device.id)
def applyCustProps(self, device, device_specs): """ Custom schema properties """ self.log.debug( "Applying custom schema properties..." ) dev_cprops = device.custPropertyMap() for cprop, value in device_specs.items(): if not iscustprop(cprop): continue matchProps = [prop for prop in dev_cprops if prop['id'] == cprop] if matchProps: ctype = matchProps[0]['type'] if ctype == 'password': ctype = 'string' if ctype in type_converters and value: value = type_converters[ctype](value) device.setZenProperty( cprop, value) else: self.log.warn( "The cproperty %s doesn't exist in %s" % ( cprop, device_specs.get('deviceName', device.id)))