def get_boot_device(self): service_profile = get_mo_by_dn(self.__handle, self.__service_profile_dn) operation = "get_boot_device" if not service_profile: raise exception.UcsOperationError(operation=operation, error="Invalid Service Profile") if not service_profile.BootPolicyName: boot_dn = UcsUtils.MakeDn( [self.__service_profile_dn, "boot-policy"]) class_id = "LsbootDef" else: boot_dn = UcsUtils.MakeDn([ self.__org_dn, "boot-policy-%s" % service_profile.BootPolicyName ]) class_id = "LsbootPolicy" operation = "get_boot_device" try: boot_device = None boot_devices = get_children_by_dn(self.__handle, boot_dn) if boot_devices: for boot_device_mo in boot_devices: if int(boot_device_mo.Order) == 1: boot_device = boot_device_rn[boot_device_mo.Rn] break return {'boot_device': boot_device, 'persistent': None} except UcsException as ex: print "Cisco client exception: %ss." % (ex) raise exception.UcsOperationError(operation=operation, error=ex)
def FromManagedObject(self): import os if (isinstance(self.mo, ManagedObject) == True): self.classId = self.mo.classId if self.mo.getattr('Dn'): self.dn = self.mo.getattr('Dn') if self.mo.getattr('Rn'): self.rn = self.mo.getattr('Rn') elif self.dn: self.rn = os.path.basename(self.dn) for property in UcsUtils.GetUcsPropertyMetaAttributeList( self.mo.classId): self.properties[property] = self.mo.getattr(property) if len(self.mo.child): for ch in self.mo.child: if not ch.getattr('Dn'): _Dn = self.mo.getattr('Dn') + "/" + ch.getattr('Rn') ch.setattr('Dn', _Dn) gmo = _GenericMO(mo=ch) self.child.append(gmo)
def LoadFromXml(self, node): import os self.classId = node.localName metaClassId = UcsUtils.FindClassIdInMoMetaIgnoreCase(self.classId) if metaClassId: self.classId = metaClassId if node.hasAttribute(NamingPropertyId.DN): self.dn = node.getAttribute(NamingPropertyId.DN) if self.dn: self.rn = os.path.basename(self.dn) # Write the attribute and value to dictionary properties, as it is . self.WriteToAttributes(node) # Run the LoadFromXml for each childNode recursively and populate child list too. if (node.hasChildNodes()): childList = node._get_childNodes() childCount = childList._get_length() for i in range(childCount): childNode = childList.item(i) if (childNode.nodeType != Node.ELEMENT_NODE): continue c = _GenericMO() self.child.append(c) c.LoadFromXml(childNode)
def WriteXml(self, w, option, elementName=None): if elementName == None: x = w.createElement(self.classId) else: x = w.createElement(elementName) for prop in self.__dict__['properties'].keys(): x.setAttribute(UcsUtils.WordL(prop), self.__dict__['properties'][prop]) x_child = self.childWriteXml(w, option) for xc in x_child: if (xc != None): x.appendChild(xc) return x
def __config_boot_device(self, parent_dn, boot_device_meta, order): child_class_id = boot_device_meta.class_id child_dn = UcsUtils.MakeDn([parent_dn, boot_device_meta.rn]) child_config = boot_device_meta.config if child_config.has_key("Order"): child_config["Order"] = order operation = "create %s" % (child_dn) try: device_obj = add_mo_by_dn_overwrite(self.__handle, child_class_id, child_dn, **child_config) except UcsException as ex: raise exception.UcsOperationError(operation=operation, error=ex) if boot_device_meta.child: child_device_name = boot_device_meta.child[0] child_device_meta = BootDeviceMeta( *boot_device_meta_dict[child_device_name]) self.__config_boot_device(device_obj.Dn, child_device_meta, order)
def _write_mo(mo): from UcsBase import UcsUtils classNotFound = False if (UcsUtils.FindClassIdInMoMetaIgnoreCase(mo.classId) == None): classNotFound = True tabsize = 8 outstr = "\n" if classNotFound: outstr += "Managed Object\t\t\t:\t" + str(UcsUtils.WordU( mo.classId)) + "\n" else: outstr += "Managed Object\t\t\t:\t" + str(mo.propMoMeta.name) + "\n" outstr += "-" * len("Managed Object") + "\n" if (not classNotFound): for prop in UcsUtils.GetUcsPropertyMetaAttributeList( mo.propMoMeta.name): propMeta = UcsUtils.GetUcsPropertyMeta(mo.propMoMeta.name, prop) if (propMeta.access == UcsPropertyMeta.Internal): continue val = mo.getattr(prop) #if val != None and val != "": outstr += str(prop).ljust(tabsize * 4) + ':' + str(val) + "\n" else: for prop in mo.__dict__.keys(): if (prop in [ 'classId', 'XtraProperty', 'handle', 'propMoMeta', 'dirtyMask', 'child' ]): continue val = mo.__dict__[prop] outstr += str(UcsUtils.WordU(prop)).ljust( tabsize * 4) + ':' + str(val) + "\n" if mo.__dict__.has_key('XtraProperty'): for xtraProp in mo.__dict__['XtraProperty'].keys(): outstr += '[X]' + str(UcsUtils.WordU(xtraProp)).ljust( tabsize * 4) + ':' + str( mo.__dict__['XtraProperty'][xtraProp]) + "\n" outstr += "\n" return outstr
def ToManagedObject(self): from Ucs import ClassFactory cln = UcsUtils.WordU(self.classId) mo = ClassFactory(cln) if mo and (isinstance(mo, ManagedObject) == True): metaClassId = UcsUtils.FindClassIdInMoMetaIgnoreCase(self.classId) for property in self.properties.keys(): if UcsUtils.WordU( property) in UcsUtils.GetUcsPropertyMetaAttributeList( metaClassId): mo.setattr(UcsUtils.WordU(property), self.properties[property]) else: WriteUcsWarning("Property %s Not Exist in MO %s" % (UcsUtils.WordU(property), metaClassId)) if len(self.child): for ch in self.child: moch = ch.ToManagedObject() mo.child.append(moch) return mo else: return None
def add_boot_device(self, boot_device_name, order=None): operation = "add_boot_device" boot_device_meta = BootDeviceMeta( *boot_device_meta_dict[boot_device_name]) boot_device_dn = UcsUtils.MakeDn( [self.__boot_policy_dn, boot_device_meta.rn]) try: boot_policy = get_mo_by_dn(self.__handle, self.__boot_policy_dn) if not boot_policy: raise exception.UcsOperationError( operation=operation, error="Unknown BootPolicy %s" % (self.__boot_policy_dn)) existing_boot_devices = get_children_by_dn(self.__handle, self.__boot_policy_dn) if existing_boot_devices: boot_order_dict = {} boot_device_present = False boot_device_order = None for existing_boot_device in existing_boot_devices: boot_order_dict[int( existing_boot_device.Order)] = existing_boot_device if boot_device_dn == existing_boot_device.Dn: boot_device_present = True boot_device_order = int(existing_boot_device.Order) if order and boot_device_order != order: continue return max_boot_order = max(boot_order_dict) if boot_device_present: my_boot_device = boot_order_dict[boot_device_order] other_boot_device = boot_order_dict[order] self.__handle.StartTransaction() self.__modify_boot_device(my_boot_device, order) self.__modify_boot_device(other_boot_device, boot_device_order) # modify_mo(self.__handle, input_mo=my_boot_device, # Order=order) # modify_mo(self.__handle, input_mo=other_boot_device, # Order=boot_device_order) self.__handle.CompleteTransaction() else: if not order: self.__config_boot_device(self.__boot_policy_dn, boot_device_meta, max_boot_order + 1) elif order and order in boot_order_dict: other_boot_device = boot_order_dict[order] self.__handle.StartTransaction() self.__config_boot_device(self.__boot_policy_dn, boot_device_meta, order) self.__modify_boot_device(other_boot_device, max_boot_order + 1) # modify_mo(self.__handle, input_mo=other_boot_device, # Order=max_boot_order + 1) self.__handle.CompleteTransaction() else: self.__config_boot_device(self.__boot_policy_dn, boot_device_meta, order) else: if not order: self.__config_boot_device(self.__boot_policy_dn, boot_device_meta, 1) else: self.__config_boot_device(self.__boot_policy_dn, boot_device_meta, order) except UcsException as ex: raise exception.UcsOperationError(operation=operation, error=ex)