def removeBadResources(self): self.TestBegin() print 'deleting Bad resources' bad_disk_rasd = CIMInstance('CIM_ResourceAllocationSettingData') bad_disk_rasd['PoolID'] = pywbem.Uint32(12345) bad_disk_rasd['Elementname'] = pywbem.Uint32(12345) bad_disk_rasd['ResourceType'] = "19" bad_disk_rasd['ResourceSubType'] = pywbem.Uint32(12345) bad_disk_rasd['VirtualQuantity'] = "2147483648" bad_disk_rasd['AllocationUnits'] = pywbem.Uint32(0) bad_network_rasd = CIMInstance('CIM_ResourceAllocationSettingData') bad_network_rasd['ResourceType'] = "33" bad_network_rasd['AllocationUnits'] = pywbem.Uint32(0) rasds_to_delete = [bad_disk_rasd, bad_network_rasd] in_params = {'ResourceSettings': rasds_to_delete} n = DeleteVMResources(self.conn, self.vsms[0], in_params) result = 0 if (n == 1): print "Deleted Bad resorces!!!" result = 0 else: result = 1 self.TestEnd(result)
def _create_test_instance(self, name_of_atom, number): """ Create a TestAtom instance. """ weight = _atomic_weights[name_of_atom] #new_instance['char16Prop'] = #new_instance['char16Propa'] = Null new_instance = pywbem.CIMInstance('TestAtom') new_instance['Name'] = name_of_atom new_instance['boolProp'] = False new_instance['dateProp'] = self.time new_instance['real32Prop'] = pywbem.Real32(weight) new_instance['real32Propa'] = [pywbem.Real32(weight), \ pywbem.Real32(weight), \ pywbem.Real32(weight)] new_instance['real64Prop'] = pywbem.Real64(weight) new_instance['real64Propa'] = [pywbem.Real64(weight), \ pywbem.Real64(weight), \ pywbem.Real64(weight)] new_instance['sint16Prop'] = pywbem.Sint16(number) new_instance['sint16Propa'] = [pywbem.Sint16(number), \ pywbem.Sint16(number), \ pywbem.Sint16(number)] new_instance['sint32Prop'] = pywbem.Sint32(number) new_instance['sint32Propa'] = [pywbem.Sint32(number), \ pywbem.Sint32(number), \ pywbem.Sint32(number)] new_instance['sint64Prop'] = pywbem.Sint64(number) new_instance['sint64Propa'] = [pywbem.Sint64(number), \ pywbem.Sint64(number), \ pywbem.Sint64(number)] new_instance['sint8prop'] = pywbem.Sint8(number) new_instance['sint8Propa'] = [pywbem.Sint8(number), \ pywbem.Sint8(number), \ pywbem.Sint8(number)] new_instance['stringProp'] = name_of_atom new_instance['stringPropa'] = ['proton', 'electron', 'neutron'] new_instance['uint16Prop'] = pywbem.Uint16(number) new_instance['uint16Propa'] = [pywbem.Uint16(number), \ pywbem.Uint16(number), \ pywbem.Uint16(number)] new_instance['uint32Prop'] = pywbem.Uint32(number) new_instance['uint32Propa'] = [pywbem.Uint32(number), \ pywbem.Uint32(number), \ pywbem.Uint32(number)] new_instance['uint64Prop'] = pywbem.Uint64(number) new_instance['uint64Propa'] = [pywbem.Uint64(number), \ pywbem.Uint64(number), \ pywbem.Uint64(number)] new_instance['uint8Prop'] = pywbem.Uint64(number) new_instance['uint8Propa'] = [pywbem.Uint64(number), \ pywbem.Uint64(number), \ pywbem.Uint64(number)] try: cipath = self.conn.CreateInstance(new_instance) new_instance.path = cipath self.inst_paths.append(cipath) except pywbem.CIMError, arg: return None, arg
def _typed_randrange(lo, hi, type): if type == 'sint8': return pywbem.Sint8( random.randrange(pywbem.Sint8(lo), pywbem.Sint8(hi))) elif type == 'sint16': return pywbem.Sint16( random.randrange(pywbem.Sint16(lo), pywbem.Sint16(hi))) elif type == 'sint32': return pywbem.Sint32( random.randrange(pywbem.Sint32(lo), pywbem.Sint32(hi))) elif type == 'sint64': return pywbem.Sint64( random.randrange(pywbem.Sint64(lo), pywbem.Sint64(hi))) elif type == 'uint8': return pywbem.Uint8( random.randrange(pywbem.Uint8(lo), pywbem.Uint8(hi))) elif type == 'uint16': return pywbem.Uint16( random.randrange(pywbem.Uint16(lo), pywbem.Uint16(hi))) elif type == 'uint32': return pywbem.Uint32( random.randrange(pywbem.Uint32(lo), pywbem.Uint32(hi))) elif type == 'uint64': return pywbem.Uint64( random.randrange(pywbem.Uint64(lo), pywbem.Uint64(hi))) elif type == 'real32': return pywbem.Real32( random.randrange(pywbem.Real32(lo), pywbem.Real32(hi))) elif type == 'real64': return pywbem.Real64( random.randrange(pywbem.Real64(lo), pywbem.Real64(hi)))
class PowerState(object): Full_Power = pywbem.Uint32(1) Power_Save___Low_Power_Mode = pywbem.Uint32(2) Power_Save___Standby = pywbem.Uint32(3) Power_Save___Other = pywbem.Uint32(4) Power_Cycle = pywbem.Uint32(5) Power_Off = pywbem.Uint32(6) Hibernate = pywbem.Uint32(7) Soft_Off = pywbem.Uint32(8)
class KillJob(object): Success = pywbem.Uint32(0) Not_Supported = pywbem.Uint32(1) Unknown = pywbem.Uint32(2) Timeout = pywbem.Uint32(3) Failed = pywbem.Uint32(4) Access_Denied = pywbem.Uint32(6) Not_Found = pywbem.Uint32(7)
class GetError(object): Success = pywbem.Uint32(0) Not_Supported = pywbem.Uint32(1) Unspecified_Error = pywbem.Uint32(2) Timeout = pywbem.Uint32(3) Failed = pywbem.Uint32(4) Invalid_Parameter = pywbem.Uint32(5) Access_Denied = pywbem.Uint32(6)
class ChangeAffectedElementsAssignedSequence(object): Completed_with_No_Error = pywbem.Uint32(0) Not_Supported = pywbem.Uint32(1) Error_Occured = pywbem.Uint32(2) Busy = pywbem.Uint32(3) Invalid_Reference = pywbem.Uint32(4) Invalid_Parameter = pywbem.Uint32(5) Access_Denied = pywbem.Uint32(6)
class Scan(object): Job_Completed_with_No_Error = pywbem.Uint32(0) Not_Supported = pywbem.Uint32(1) Unspecified_Error = pywbem.Uint32(2) Timeout = pywbem.Uint32(3) Failed = pywbem.Uint32(4) Invalid_Parameter = pywbem.Uint32(5) # DMTF_Reserved = .. Method_Parameters_Checked___Job_Started = pywbem.Uint32(4096)
class ClearLog(object): Completed_with_no_error = pywbem.Uint32(0) Not_Supported = pywbem.Uint32(1) Unspecified_Error = pywbem.Uint32(2) Timeout = pywbem.Uint32(3) Failed = pywbem.Uint32(4) Invalid_Parameter = pywbem.Uint32(5)
def getnum(num, datatype): try: result = { '8': pywbem.Uint8(num), '16': pywbem.Uint16(num), '32': pywbem.Uint32(num), '64': pywbem.Uint64(num) } result = result.get(datatype, num) except NameError: result = num return result
def start(): tester = IntelWbemTester(IntelWbemTester.NAMESPACE_INTEL) processes = tester.connection.EnumerateInstances('Intel_BaseServer') process = processes[0] print("Value: ", process.items()) process['LogLevel'] = pywbem.Uint16(0) process['LogMax'] = pywbem.Uint32(800) print("Process: ", process.items()) tester.connection.ModifyInstance(process, PropertyList=['LogLevel','LogMax']) print("Modifying done") processes1 = tester.connection.EnumerateInstances('Intel_BaseServer') process1 = processes1[0] print("Modified LogMax: ", process1.items())
def get_num(self, numStr, datatype): """Get the ecom int from the number. :param numStr: the number in string format :param datatype: the type to convert it to :returns: result """ try: result = { '8': pywbem.Uint8(numStr), '16': pywbem.Uint16(numStr), '32': pywbem.Uint32(numStr), '64': pywbem.Uint64(numStr) } result = result.get(datatype, numStr) except NameError: result = numStr return result
def get_value(string): vtype, value = string.split(',', 1) if vtype == 'str': return str(value) elif vtype == 'uint8': return pywbem.Uint8(value) elif vtype == 'sint8': return pywbem.Sint8(value) elif vtype == 'uint16': return pywbem.Uint16(value) elif vtype == 'sint16': return pywbem.Sint16(value) elif vtype == 'uint32': return pywbem.Uint32(value) elif vtype == 'sint32': return pywbem.Sint32(value) elif vtype == 'uint64': return pywbem.Uint64(value) elif vtype == 'sint64': return pywbem.Sint64(value) else: print "Input value is invalid : %s" % string sys.exit(1)
def get_historical_host_metrics(self): self.TestBegin() interval = 0 rc = 1 hosts = self.conn.EnumerateInstanceNames("Xen_HostComputerSystem") for host in hosts: in_params = { "System": host, "TimeDuration": pywbem.Uint32(60) } # last 1 hour of metrics print 'Getting Metrics for host %s from the last 60 mins' % ( host['Name']) try: [rc, out_params ] = self.conn.InvokeMethod("GetPerformanceMetricsForSystem", self.mss[0], **in_params) except pywbem.cim_operations.CIMError: print 'Exception caught getting metrics' if rc == 0: print ' Metrics: %s' % out_params["Metrics"] else: print ' NO METRICS AVAILABLE' self.TestEnd2(rc)
class RequestStateChange(object): Completed_with_No_Error = pywbem.Uint32(0) Not_Supported = pywbem.Uint32(1) Unknown_Unspecified_Error = pywbem.Uint32(2) Can_NOT_complete_within_Timeout_Period = pywbem.Uint32(3) Failed = pywbem.Uint32(4) Invalid_Parameter = pywbem.Uint32(5) In_Use = pywbem.Uint32(6) # DMTF_Reserved = .. Method_Parameters_Checked___Transition_Started = pywbem.Uint32( 4096) Invalid_State_Transition = pywbem.Uint32(4097) Use_of_Timeout_Parameter_Not_Supported = pywbem.Uint32(4098) Busy = pywbem.Uint32(4099) # Method_Reserved = 4100..32767 # Vendor_Specific = 32768..65535 class RequestedState(object): Start = pywbem.Uint16(2) Suspend = pywbem.Uint16(3) Terminate = pywbem.Uint16(4) Kill = pywbem.Uint16(5) Service = pywbem.Uint16(6)
def cim_method_requeststatechange(self, env, object_name, method, param_requestedstate, param_timeoutperiod): """Implements Py_LotsOfDataTypes.RequestStateChange() Requests that the state of the element be changed to the value specified in the RequestedState parameter. When the requested state change takes place, the EnabledState and RequestedState of the element will be the same. Invoking the RequestStateChange method multiple times could result in earlier requests being overwritten or lost. If 0 is returned, then the task completed successfully and the use of ConcreteJob was not required. If 4096 (0x1000) is returned, then the task will take some time to complete, ConcreteJob will be created, and its reference returned in the output parameter Job. Any other return code indicates an error condition. Keyword arguments: env -- Provider Environment object_name -- A CIMInstanceName or CIMCLassName specifying the object on which the method %(mname)s should be invoked method -- A CIMMethod representing the method meta-data param_requestedstate -- The input parameter RequestedState (type uint16) The state requested for the element. This information will be placed into the RequestedState property of the instance if the return code of the RequestStateChange method is 0 ('Completed with No Error'), 3 ('Timeout'), or 4096 (0x1000) ('Job Started'). Refer to the description of the EnabledState and RequestedState properties for the detailed explanations of the RequestedState values. param_timeoutperiod -- The input parameter TimeoutPeriod (type datetime) A timeout period that specifies the maximum amount of time that the client expects the transition to the new state to take. The interval format must be used to specify the TimeoutPeriod. A value of 0 or a null parameter indicates that the client has no time requirements for the transition. If this property does not contain 0 or null and the implementation does not support this parameter, a return code of 'Use Of Timeout Parameter Not Supported' must be returned. Returns a two-tuple containing the return value (type uint32) and a dictionary with the out-parameters Output parameters: Job -- (type REF CIM_ConcreteJob (CIMInstanceName)) Reference to the job (can be null if the task is completed). """ out_params = {} out_params['job'] = pywbem.CIMInstanceName( classname='CIM_ConcreteJob', namespace='root/cimv2', keybindings={ 'InstanceID': '%d:%s' % (param_requestedstate, str(param_timeoutperiod)) }) rval = pywbem.Uint32(0) return (rval, out_params)
def __init__(self, Ip, userName, password, need_shared_storage=False, create_vms=True, logfile=None): dir = os.getcwd() if logfile == None: self.logfilename = sys._getframe(2).f_code.co_filename + ".log" else: self.logfilename = logfile print "Location of result log : " + self.logfilename self.oldstdout = sys.stdout self.oldstderr = sys.stderr self.logfile = open(self.logfilename, 'w') sys.stdout = self.logfile sys.stderr = self.logfile print 'TestSetup...' verbose = "false" for arg in sys.argv: if arg == "verbose": verbose = "true" # some useful counters self.TestsPassed = 0 self.TestsFailed = 0 self.TestFailedDescriptions = "" #self.inputMsg = ">" self.IPAddress = Ip self.UserName = userName self.Password = password self.hvmname = 'test-hvm-vm' self.pvname = 'test-pv-vm' self.pv_test_vm = None self.hvm_test_vm = None # create a CIM connection to the server self.conn = pywbem.WBEMConnection('http://' + self.IPAddress, (self.UserName, self.Password)) # Enumerate the Xen Pool my_pool = None pools = self.conn.EnumerateInstances("Xen_HostPool") if len(pools) != 0: my_pool = pools[0] # Enumerate all networks and pick an appropriate network to use network_to_use = None networks = self.conn.EnumerateInstances("Xen_NetworkConnectionPool") for network in networks: network_to_use = network # pick the first one ? this will be what the VM will be connected on break print "Using Network: %s (%s)" % (network_to_use['PoolID'], network_to_use['Name']) # Pick an appropriate SR for use in tests self.sr_to_use = None sr_to_use_local = None if my_pool != None: # Try the default storage of the host pool, if available if my_pool['DefaultStoragePoolID'] != None and my_pool[ 'DefaultStoragePoolID'] != '': print 'default storage pool id %s' % my_pool[ 'DefaultStoragePoolID'] #query_str = "SELECT * FROM Xen_StoragePool WHERE InstanceID = \""+my_pool['DefaultStoragePoolID']+"\"" query_str = "SELECT * FROM Xen_StoragePool WHERE InstanceID LIKE \"%" + my_pool[ 'DefaultStoragePoolID'] + "%\"" print 'Executing query: %s' % query_str defsrs = self.conn.ExecQuery("WQL", query_str, "root/cimv2") sr_to_use_local = defsrs[0] #sr_ref = CIMInstanceName(classname="Xen_StoragePool", keybindings={"InstanceID":'Xen:Shared\\'+my_pool["DefaultStoragePoolID"]}) #sr_to_use_local = self.conn.GetInstance(sr_ref) if sr_to_use_local == None: # No default SR is available srs = self.conn.EnumerateInstances("Xen_StoragePool") for sr in srs: if sr['ResourceSubType'] == 'nfs' or sr[ 'ResourceSubType'] == 'lvmoiscsi': sr_to_use_local = sr break elif need_shared_storage == False and sr[ 'Name'] == 'Local storage': sr_to_use_local = sr break print "Using SR: %s (%s)" % (sr_to_use_local["PoolID"], sr_to_use_local['Name']) # create CIM reference out of CIM instance self.sr_to_use = CIMInstanceName( classname=sr_to_use_local.classname, keybindings={"InstanceID": sr_to_use_local["InstanceID"]}) self.DiskPoolID = sr_to_use_local['PoolID'] # Get instance of Virtual System Management Service self.vsms = self.conn.EnumerateInstanceNames( "Xen_VirtualSystemManagementService") ################ Virtual System Setting Data (VSSD) ################ # VSSD for a PV VM type self.pv_vssd = CIMInstance("Xen_ComputerSystemSettingData") self.pv_vssd['Description'] = 'Test PV VM' self.pv_vssd['ElementName'] = self.__class__.__name__ + '_PV' self.pv_vssd['VirtualSystemType'] = 'DMTF:xen:PV' self.pv_vssd['PV_Bootloader'] = 'pygrub' self.pv_vssd['AutomaticShutdownAction'] = pywbem.Uint8(2) self.pv_vssd['AutomaticStartupAction'] = pywbem.Uint8(3) self.pv_vssd['AutomaticRecoveryAction'] = pywbem.Uint8(3) self.pv_vssd['PV_Args'] = 'Term=xterm' self.pv_vssd['Other_Config'] = ['HideFromXenCenter=false'] # Virtual System setting data for an HVM type self.hvm_vssd = CIMInstance("Xen_ComputerSystemSettingData") self.hvm_vssd['Description'] = 'Test HVM VM' self.hvm_vssd['ElementName'] = self.__class__.__name__ + '_HVM' self.hvm_vssd['VirtualSystemType'] = 'DMTF:xen:HVM' self.hvm_vssd['HVM_Boot_Params'] = ['order=dc'] self.hvm_vssd['HVM_Boot_Policy'] = 'BIOS order' self.hvm_vssd['Platform'] = ['acpi=true', 'apic=true', 'pae=true'] ####################################################################### # define all the Virtual System Resource Allocation Setting Data (RASD) ####################################################################### ####################################################################### # RASD to specify processor allocation for the VM # Processor RASD self.proc_rasd = CIMInstance('CIM_ResourceAllocationSettingData') self.proc_rasd['ResourceType'] = pywbem.Uint16(3) self.proc_rasd['VirtualQuantity'] = pywbem.Uint64(1) self.proc_rasd['AllocationUnits'] = 'count' # Another processor RASD with different limit/weight values self.proc1_rasd = self.proc_rasd.copy() self.proc1_rasd['VirtualQuantity'] = pywbem.Uint64(1) self.proc1_rasd['Limit'] = pywbem.Uint32( 95) # max host CPU it could take up in % self.proc1_rasd['Weight'] = pywbem.Uint32( 512) # relative weight between VCPUs (1-65536) # Processor RASD with wrong resource type self.invalid_proc_rasd = self.proc_rasd.copy() self.invalid_proc_rasd['ResourceType'] = pywbem.Uint32(10000) # processor RASD with no resource type specified, the classname has to be base class self.nort_proc_rasd = CIMInstance('CIM_ResourceAllocationSettingData') self.nort_proc_rasd['VirtualQuantity'] = pywbem.Uint64(1) self.nort_proc_rasd['AllocationUnits'] = 'count' # processor RASD with invalid quantity specified self.invalid_vq_proc_rasd = self.proc_rasd.copy() self.invalid_vq_proc_rasd['VirtualQuantity'] = pywbem.Uint64(10000) # plain old bad processor rasd - mixed types for properties self.bad_proc_rasd = self.proc_rasd.copy() self.bad_proc_rasd['ResourceType'] = '3' # string instead of integer self.bad_proc_rasd['VirtualQuantity'] = '1' self.bad_proc_rasd['AllocationUnits'] = pywbem.Uint8( 1) # integer instead of string self.bad_proc_rasd['Limit'] = '100' # string instead of integer ####################################################################### # memory RASD to specify memory allocation settings for a VM self.mem_rasd = CIMInstance('Xen_MemorySettingData') self.mem_rasd['ResourceType'] = pywbem.Uint16(4) self.mem_rasd['VirtualQuantity'] = pywbem.Uint64(512) self.mem_rasd['AllocationUnits'] = 'byte*2^20' # 2nd RASD to specify more memory self.mem1_rasd = self.mem_rasd.copy() self.mem1_rasd['VirtualQuantity'] = pywbem.Uint64(1024) # mix in wrong types (integers for strings, and strings for integers) self.bad_mem_rasd = self.mem_rasd.copy() self.bad_mem_rasd['AllocationUnits'] = pywbem.Uint32(20) self.bad_mem_rasd['VirtualQuantity'] = "1024" self.bad_mem_rasd['ResourceType'] = "4" ####################################################################### # Resource Allocation Settings to specify Virtual Disk allocation # Start off with a CD drive self.disk0_rasd = CIMInstance('Xen_DiskSettingData') self.disk0_rasd['ElementName'] = self.__class__.__name__ + '_CDRom' self.disk0_rasd['ResourceType'] = pywbem.Uint16(15) # DVD Drive self.disk0_rasd['ResourceSubType'] = 'CD' # self.disk1_rasd['PoolID'] = '<SR ID>' # (No need to specify a SR or VDI, should create an empty DVD # self.disk1_rasd['HostResource'] = '<VDI ID>' # (No need to specify a SR or VDI, should create an empty DVD self.disk0_rasd['Bootable'] = True self.disk0_rasd['Access'] = pywbem.Uint8(1) # A virtual disk of 2 GB size self.disk1_rasd = self.disk0_rasd.copy() self.disk1_rasd['PoolID'] = sr_to_use_local['PoolID'] self.disk1_rasd['ElementName'] = self.__class__.__name__ + '_Disk1' self.disk1_rasd['ResourceType'] = pywbem.Uint16(19) # Storage extent self.disk1_rasd['ResourceSubType'] = 'Disk' self.disk1_rasd['VirtualQuantity'] = pywbem.Uint64(2147483648) # 2GB self.disk1_rasd['AllocationUnits'] = 'byte' # Another virtual disk of 2 GB size self.disk2_rasd = self.disk0_rasd.copy() self.disk2_rasd['PoolID'] = sr_to_use_local['PoolID'] self.disk2_rasd['ResourceType'] = pywbem.Uint16(19) # Storage extent self.disk2_rasd['ResourceSubType'] = 'Disk' self.disk2_rasd['ElementName'] = self.__class__.__name__ + '_Disk2' self.disk2_rasd['VirtualQuantity'] = pywbem.Uint64(2147483648) # 2GB self.disk2_rasd['AllocationUnits'] = 'byte' # mix in wrong types (integers for strings, and strings for integers) self.bad_disk_rasd = self.disk0_rasd.copy() self.bad_disk_rasd['PoolID'] = sr_to_use_local['PoolID'] self.bad_disk_rasd['ElementName'] = pywbem.Uint8(1) self.bad_disk_rasd['ResourceType'] = '15' self.bad_disk_rasd['HostResource'] = pywbem.Uint16(12345) self.bad_disk_rasd['Bootable'] = pywbem.Uint8(1) # create a disk out of a non-existent SR self.invalid_poolId_rasd = self.disk0_rasd.copy() self.invalid_poolId_rasd[ 'PoolId'] = 'ed1bd47e-1ab8-d80a-aecf-06447871211c' # Specify bad allocation units self.invalid_aunits_rasd = self.disk0_rasd.copy() self.invalid_aunits_rasd['PoolID'] = sr_to_use_local['PoolID'] self.invalid_poolId_rasd['AllocationUnits'] = 'KiloMeters' ####################################################################### # Specify the network connection resource allocation setting data # The system will create a virtual NIC for each resource # self.nic_rasd = CIMInstance('Xen_NetworkPortSettingData') self.nic_rasd['ResourceType'] = pywbem.Uint16( 33) # ethernet connection type self.nic_rasd[ 'Address'] = '00:13:72:24:32:f4' # manually generated MAC self.nic_rasd['PoolID'] = network_to_use['PoolID'] # NIC RASD With no mac address - generate one # NIC RASD with no ElementName either - pick next available address self.nic1_rasd = self.nic_rasd.copy() del self.nic1_rasd['Address'] # RASD with no resource type self.nort_nic_rasd = self.nic_rasd.copy() del self.nort_nic_rasd['ResourceType'] # RASD with bad MAC address specified self.invalid_nic_rasd = self.nic_rasd.copy() self.invalid_nic_rasd['Address'] = '00:13:72:24:32:rr' # mixed types for properties (strings for integers and vice versa) self.bad_nic_rasd = self.nic_rasd.copy() self.bad_nic_rasd['ResourceType'] = '33' # supposed to be a int self.bad_nic_rasd['ElementName'] = pywbem.Uint8( 0) # supposed to be a string self.bad_nic_rasd['Address'] = pywbem.Uint64( 001372243245) # supposed to be a string ####################################################################### # Create the test VMs if requested during the test # # Create the PV VM from the Demo Linux VM template (previously the Debian Etch Template) try: pv_template_list = self.conn.ExecQuery( "WQL", "SELECT * FROM Xen_ComputerSystemTemplate WHERE ElementName LIKE \"%XenServer Transfer VM%\"", "root/cimv2") self.pv_template = CIMInstanceName( classname=pv_template_list[0].classname, keybindings={"InstanceID": pv_template_list[0]["InstanceID"]}) self.rasds = [ self.proc_rasd, self.mem_rasd, self.disk0_rasd, self.disk1_rasd, self.nic_rasd ] self.hvm_params = { 'SystemSettings': self.hvm_vssd, 'ResourceSettings': self.rasds } self.pv_params = { 'SystemSettings': self.pv_vssd, 'ResourceSettings': self.rasds, 'ReferenceConfiguration': self.pv_template } self.pv_test_vm = None self.hvm_test_vm = None if create_vms: #print 'using template %s to create PV vm: ' % str(debian_template) print 'Creating PV vm' self.pv_test_vm = CreateVM(self.conn, self.vsms[0], self.pv_params) print 'Creating HVM vm' self.hvm_test_vm = CreateVM(self.conn, self.vsms[0], self.hvm_params) except Exception, e: print "Exception: %s. Has the TVM template been installed?" % e
rasd_with_wrong_resource_type['Connection'] = ["eth0"] rasd_with_wrong_resource_type['VlanTag'] = pywbem.Uint64(2) rasds = [rasd_with_wrong_resource_type] network = self.__CreateNetwork(rasds) if network != None: print 'Virtual Switch was created when it shouldnt have' result = 0 except Exception, e: print 'Exception: %s' % str(e) # RASD where Connection property is of invalid type print 'Error Test: bad RASD with bad Connection property' try: rasd_with_wrong_connection = CIMInstance( 'CIM_ResourceAllocationSettingData') rasd_with_wrong_connection['ResourceType'] = pywbem.Uint16(33) rasd_with_wrong_connection['Connection'] = pywbem.Uint32(1234) rasd_with_wrong_connection['VlanTag'] = pywbem.Uint64(2) rasds = [rasd_with_wrong_connection] network = self.__CreateNetwork(rasds) if network != None: print 'Virtual Switch was created when it shouldnt have' result = 0 except Exception, e: print 'Exception: %s' % str(e) self.TestEnd(result) def DeleteNetworkErrorTests(self): self.TestBegin() result = 1 # specify a bad (non-existent) switch reference
def create_new_PV_and_HVM_vms (conn, vsms): # # the metadata for a XenServer Paravirtualized VM we are going to create pv_virtualsystemsettingdata = pywbem.CIMInstance ("Xen_ComputerSystemSettingData") pv_virtualsystemsettingdata['Caption'] = "This is a PV VM" pv_virtualsystemsettingdata['ElementName'] = "test-pv-vm" pv_virtualsystemsettingdata['VirtualSystemType'] = "DMTF:xen:PV" pv_virtualsystemsettingdata['AutomaticShutdownAction'] = pywbem.Uint8(0) pv_virtualsystemsettingdata['AutomaticStarupAction'] = pywbem.Uint8(1) pv_virtualsystemsettingdata['AutomaticRecoveryAction'] = pywbem.Uint8(2) # the following are XenServer specific CIM extensions pv_virtualsystemsettingdata['PV_Bootloader'] = "pygrub" # use pygrub as the bootloader pv_virtualsystemsettingdata['PV_Bootloader_Args'] = "" pv_virtualsystemsettingdata['PV_Args'] = "Term=xterm" # We shall also base the PV VM on an existing XenServer template # This automatically allocates default proc/mem/disk/network resources specified by the template pv_template_list = conn.ExecQuery("WQL", "SELECT * FROM Xen_ComputerSystemTemplate WHERE ElementName LIKE \"%Debian Lenny%\"", "root/cimv2") reference_configuration = pywbem.CIMInstanceName(classname=pv_template_list[0].classname, keybindings={"InstanceID":pv_template_list[0]["InstanceID"]}) # The metadata settings for a XenServer HVM VM (Hardware Virtualized) we will create hvm_virtualsystemsettingdata = pywbem.CIMInstance("Xen_ComputerSystemSettingData") hvm_virtualsystemsettingdata['Caption'] = 'This is an HVM VM' hvm_virtualsystemsettingdata['ElementName'] = 'test-hvm-vm' hvm_virtualsystemsettingdata['VirtualSystemType'] = 'DMTF:xen:HVM' hvm_virtualsystemsettingdata['AutomaticShutdownAction'] = pywbem.Uint8(0) hvm_virtualsystemsettingdata['AutomaticStarupAction'] = pywbem.Uint8(1) hvm_virtualsystemsettingdata['AutomaticRecoveryAction'] = pywbem.Uint8(2) # the following are XenServer specific CIM extensions hvm_virtualsystemsettingdata['HVM_Boot_Params'] = ['order=dc'] # boot order is cd drive and then hard drive hvm_virtualsystemsettingdata['HVM_Boot_Policy'] = 'BIOS order' # boot based on the BIOS boot order specified above hvm_virtualsystemsettingdata['Platform'] = ['acpi=true','apic=true','pae=true'] # use ACPI, APIC, PAE emulation # # define all the resource settings (processor, memory, disk, network) # via ResourceAllocationSettingData instances # # processor proc_resource = pywbem.CIMInstance('CIM_ResourceAllocationSettingData') proc_resource['ResourceType'] = pywbem.Uint16(3) proc_resource['VirtualQuantity'] = pywbem.Uint64(1) proc_resource['AllocationUnits'] = "count" proc_resource['Limit'] = pywbem.Uint32(100) proc_resource['Weight'] = pywbem.Uint32(512) # memory mem_resource = pywbem.CIMInstance('CIM_ResourceAllocationSettingData') mem_resource['ResourceType'] = pywbem.Uint16(4) mem_resource['VirtualQuantity'] = pywbem.Uint64(512) mem_resource['AllocationUnits'] = 'byte*2^20' # DMTF way of specifying MegaBytes # disks sr_to_use = None # find all SRs available to us srs = conn.EnumerateInstances("Xen_StoragePool") for sr in srs: if sr['Name'] == 'Local storage': sr_to_use = sr disk_resource = pywbem.CIMInstance('Xen_DiskSettingData') disk_resource['Elementname'] = 'my_vm_disk' disk_resource['ResourceType'] = pywbem.Uint16(19) disk_resource['ResourceSubType'] = "Disk" # as opposed to "CD" disk_resource['VirtualQuantity'] = pywbem.Uint64(2048) disk_resource['AllocationUnits'] = "byte*2^20" # DMTF way of specifying MegaBytes disk_resource['Access'] = pywbem.Uint8(3) disk_resource['Bootable'] = False disk_resource['PoolID'] = sr_to_use['PoolID']# XenServer SR to allocate the disk out of # nic network_to_use = None # find all network switch connection pools available to us networks = conn.EnumerateInstances("Xen_NetworkConnectionPool") for network in networks: if network['Name'].find('eth0') != -1: network_to_use = network # only RASDs of type NetworkConnection (33) are supported nic_resource = pywbem.CIMInstance('Xen_NetworkPortSettingData') nic_resource['ResourceType'] = pywbem.Uint16(33) nic_resource['ElementName'] = "0" nic_resource['PoolID'] = network_to_use['PoolID']# Virtual Switch to connect to rasds = [proc_resource, mem_resource, disk_resource, nic_resource] hvm_params = {'SystemSettings': hvm_virtualsystemsettingdata, 'ResourceSettings': rasds } pv_params = {'SystemSettings': pv_virtualsystemsettingdata, 'ReferenceConfiguration': reference_configuration} print '*** Creating PV VM %s' % (pv_virtualsystemsettingdata['ElementName']) new_pv_vm_reference = create_vm_helper(conn, vsms, pv_params) print '*** Creating HVM VM %s' % (hvm_virtualsystemsettingdata['ElementName']) new_hvm_vm_reference = create_vm_helper(conn, vsms, hvm_params) if new_pv_vm_reference == None: print 'PV VM was not created' sys.exit(1) if new_hvm_vm_reference == None: print 'HVM VM was not created' sys.exit(1) return [new_pv_vm_reference, new_hvm_vm_reference]
class TestMethods(unittest.TestCase): limits = { 'sint8_min': pywbem.Sint8(-128), 'sint8_max': pywbem.Sint8(127), 'sint16_min': pywbem.Sint16(-32768), 'sint16_max': pywbem.Sint16(32767), 'sint32_min': pywbem.Sint32(-2147483648), 'sint32_max': pywbem.Sint32(2147483647), 'sint64_min': pywbem.Sint64(-92233736854775808L), 'sint64_max': pywbem.Sint64(9223372036854775807L), 'uint8_min': pywbem.Uint8(0), 'uint8_max': pywbem.Uint8(0xFF), 'uint16_min': pywbem.Uint16(0), 'uint16_max': pywbem.Uint16(0xFFFF), 'uint32_min': pywbem.Uint32(0), 'uint32_max': pywbem.Uint32(0xFFFFFFFF), 'uint64_min': pywbem.Uint64(0L), 'uint64_max': pywbem.Uint64(0x7FFFFFFFFFFFFFFFL), 'real32_min': pywbem.Real32(-123456.78), 'real32_max': pywbem.Real32(123456.78), 'real64_min': pywbem.Real64(-12345678987654.32), 'real64_max': pywbem.Real64(12345678987654.32) } # note: the last Uint64 value should be 0xFFFFFFFFFFFFFFFF but there is a bug somewhere... inttypes = [ 'sint8', 'sint16', 'sint32', 'sint64', 'uint8', 'uint16', 'uint32', 'uint64' ] realtypes = ['real32', 'real64'] zeros = { 'sint8': pywbem.Sint8(0), 'sint16': pywbem.Sint16(0), 'sint32': pywbem.Sint32(0), 'sint64': pywbem.Sint64(0), 'uint8': pywbem.Uint8(0), 'uint16': pywbem.Uint16(0), 'uint32': pywbem.Uint32(0), 'uint64': pywbem.Uint64(0), 'real32': pywbem.Real32(0), 'real64': pywbem.Real64(0) } ones = { 'sint8': pywbem.Sint8(1), 'sint16': pywbem.Sint16(1), 'sint32': pywbem.Sint32(1), 'sint64': pywbem.Sint64(1), 'uint8': pywbem.Uint8(1), 'uint16': pywbem.Uint16(1), 'uint32': pywbem.Uint32(1), 'uint64': pywbem.Uint64(1), 'real32': pywbem.Real32(0), 'real64': pywbem.Real64(0) } tens = { 'sint8': pywbem.Sint8(10), 'sint16': pywbem.Sint16(10), 'sint32': pywbem.Sint32(10), 'sint64': pywbem.Sint64(10), 'uint8': pywbem.Uint8(10), 'uint16': pywbem.Uint16(10), 'uint32': pywbem.Uint32(10), 'uint64': pywbem.Uint64(10), 'real32': pywbem.Real32(10), 'real64': pywbem.Real64(10) } twenties = { 'sint8': pywbem.Sint8(20), 'sint16': pywbem.Sint16(20), 'sint32': pywbem.Sint32(20), 'sint64': pywbem.Sint64(20), 'uint8': pywbem.Uint8(20), 'uint16': pywbem.Uint16(20), 'uint32': pywbem.Uint32(20), 'uint64': pywbem.Uint64(20), 'real32': pywbem.Real32(20), 'real64': pywbem.Real64(20) } numlists = { 'sint8': [ pywbem.Sint8(8), pywbem.Sint8(2), pywbem.Sint8(5), pywbem.Sint8(6), pywbem.Sint8(3), pywbem.Sint8(9), pywbem.Sint8(7), pywbem.Sint8(1), pywbem.Sint8(4) ], 'sint16': [ pywbem.Sint16(8), pywbem.Sint16(2), pywbem.Sint16(5), pywbem.Sint16(6), pywbem.Sint16(3), pywbem.Sint16(9), pywbem.Sint16(7), pywbem.Sint16(1), pywbem.Sint16(4) ], 'sint32': [ pywbem.Sint32(8), pywbem.Sint32(2), pywbem.Sint32(5), pywbem.Sint32(6), pywbem.Sint32(3), pywbem.Sint32(9), pywbem.Sint32(7), pywbem.Sint32(1), pywbem.Sint32(4) ], 'sint64': [ pywbem.Sint64(8), pywbem.Sint64(2), pywbem.Sint64(5), pywbem.Sint64(6), pywbem.Sint64(3), pywbem.Sint64(9), pywbem.Sint64(7), pywbem.Sint64(1), pywbem.Sint64(4) ], 'uint8': [ pywbem.Uint8(8), pywbem.Uint8(2), pywbem.Uint8(5), pywbem.Uint8(6), pywbem.Uint8(3), pywbem.Uint8(9), pywbem.Uint8(7), pywbem.Uint8(1), pywbem.Uint8(4) ], 'uint16': [ pywbem.Uint16(8), pywbem.Uint16(2), pywbem.Uint16(5), pywbem.Uint16(6), pywbem.Uint16(3), pywbem.Uint16(9), pywbem.Uint16(7), pywbem.Uint16(1), pywbem.Uint16(4) ], 'uint32': [ pywbem.Uint32(8), pywbem.Uint32(2), pywbem.Uint32(5), pywbem.Uint32(6), pywbem.Uint32(3), pywbem.Uint32(9), pywbem.Uint32(7), pywbem.Uint32(1), pywbem.Uint32(4) ], 'uint64': [ pywbem.Uint64(8), pywbem.Uint64(2), pywbem.Uint64(5), pywbem.Uint64(6), pywbem.Uint64(3), pywbem.Uint64(9), pywbem.Uint64(7), pywbem.Uint64(1), pywbem.Uint64(4) ], 'real32': [ pywbem.Real32(8), pywbem.Real32(2), pywbem.Real32(5), pywbem.Real32(6), pywbem.Real32(3), pywbem.Real32(9), pywbem.Real32(7), pywbem.Real32(1), pywbem.Real32(4) ], 'real64': [ pywbem.Real64(8), pywbem.Real64(2), pywbem.Real64(5), pywbem.Real64(6), pywbem.Real64(3), pywbem.Real64(9), pywbem.Real64(7), pywbem.Real64(1), pywbem.Real64(4) ] } def _dbgPrint(self, msg=''): if self._verbose: if len(msg): print('\t -- %s --' % msg) else: print('') def setUp(self): unittest.TestCase.setUp(self) wconn = wbem_connection.wbem_connection() self.conn = wconn._WBEMConnFromOptions(_g_opts) for iname in self.conn.EnumerateInstanceNames('TestMethod'): self.conn.DeleteInstance(iname) self._verbose = _g_opts.verbose self._dbgPrint() def tearDown(self): unittest.TestCase.tearDown(self) for iname in self.conn.EnumerateInstanceNames('TestMethod'): self.conn.DeleteInstance(iname) def _run_and_validate_getrand(self, type, methodName, min, max, expectedReturnValue=None, minReturnValue=None, maxReturnValue=None): isRealType = False if type.startswith('real'): isRealType = True if isRealType: self._dbgPrint('Testing %s invocation with min=%f, max=%f' % (methodName, min, max)) else: self._dbgPrint('Testing %s invocation with min=%d, max=%d' % (methodName, min, max)) (rv, oparams) = self.conn.InvokeMethod(methodName, 'TestMethod', min=min, max=max) if not oparams['success']: self.fail( '"Success" reported as false for invocation of method %s' % methodName) if expectedReturnValue is not None: if isRealType: self._dbgPrint( 'Verifying return value (%f) equal to expected return value %f...' % (rv, expectedReturnValue)) if abs(expectedReturnValue - rv) > real_tolerance: self.fail( 'Return value not as expected for invocation of method %s' % methodName) else: self._dbgPrint( 'Verifying return value (%d) equal to expected return value %d...' % (rv, expectedReturnValue)) if expectedReturnValue != rv: self.fail( 'Return value not as expected for invocation of method %s' % methodName) self._dbgPrint('Return value is as expected.') if minReturnValue is not None: if isRealType: self._dbgPrint('Verifying return value (%f) >= %f' % (rv, minReturnValue)) else: self._dbgPrint('Verifying return value (%d) >= %d' % (rv, minReturnValue)) if rv < minReturnValue: self.fail( 'Return value less than expected for invocation of method %s' % methodName) self._dbgPrint('Return value is as expected.') if maxReturnValue is not None: if isRealType: self._dbgPrint('Verifying return value (%f) <= %f' % (rv, maxReturnValue)) else: self._dbgPrint('Verifying return value (%d) <= %d' % (rv, maxReturnValue)) if rv > maxReturnValue: self.fail( 'Return value greater than expected for invocation of method %s' % methodName) self._dbgPrint('Return value is as expected.') def _run_and_validate_getrandlist(self, type, methodName, min, max, nelems): isRealType = False if type.startswith('real'): isRealType = True if isRealType: self._dbgPrint('Testing %s invocation with min=%f, max=%f' % (methodName, min, max)) else: self._dbgPrint('Testing %s invocation with min=%d, max=%d' % (methodName, min, max)) (rv, oparams) = self.conn.InvokeMethod(methodName, 'TestMethod', lo=min, hi=max, nelems=nelems) if not rv: self.fail('Invocation of %s returned false success value.' % methodName) self._dbgPrint('Invocation of %s returned successfully.' % methodName) if isRealType: self._dbgPrint('Validating lo (%f) and hi (%f) outparams...' % (min, max)) if abs(oparams['lo'] - min) > real_tolerance: self.fail( 'Returned low range value (%f) not equal to specified value (%f).' % (oparams['lo'], min)) if abs(oparams['hi'] - max) > real_tolerance: self.fail( 'Returned high range value (%f) not equal to specified value (%f).' % (oparams['hi'], max)) else: self._dbgPrint('Validating lo (%d) and hi (%d) outparams...' % (min, max)) if oparams['lo'] != min: self.fail( 'Returned low range value (%d) not equal to specified value (%d).' % (oparams['lo'], min)) if oparams['hi'] != max: self.fail( 'Returned high range value (%d) not equal to specified value (%d).' % (oparams['hi'], max)) self._dbgPrint('Lo and hi outparams validated successfully.') self._dbgPrint('Validating random list values...') if oparams['nlist'] is None: self.fail('Expected a list of values but got none.') if len(oparams['nlist']) != nelems: self.fail('Expected a list of %d items but got %d items instead.' % (nelems, len(oparams['nlist']))) minkey = '%s_min' % type maxkey = '%s_max' % type for num in oparams['nlist']: if num < TestMethods.limits[minkey] or \ num > TestMethods.limits[maxkey]: if isRealType: self.fail( 'List element %f not in expected range for type %s.' % (num, type)) else: self.fail( 'List element %d not in expected range for type %s.' % (num, type)) self._dbgPrint('Random list values validated successfully.') def _run_and_validate_minmedmax(self, type, methodName, numlist): self._dbgPrint('Testing %s invocation' % methodName) (rv, oparams) = self.conn.InvokeMethod(methodName, 'TestMethod', numlist=numlist) if not rv: self.fail('Invocation of %s returned false success value.' % methodName) self._dbgPrint('Invocation of %s returned successfully.' % methodName) self._dbgPrint('Validating min, median, and max outparams...') if oparams['min'] != 1: self.fail('Expected min of 1 but instead got %d' % oparams['min']) if oparams['max'] != 9: self.fail('Expected max of 9 but instead got %d' % oparams['max']) if oparams['med'] != 5: self.fail('Expected median of 5 but instead got %d' % oparams['med']) self._dbgPrint('Min, median, and max values validated successfully.') def _run_numeric_type_tests(self, typelist): gr = self._run_and_validate_getrand grl = self._run_and_validate_getrandlist mmm = self._run_and_validate_minmedmax for type in typelist: method = 'genRand_%s' % type minkey = '%s_min' % type maxkey = '%s_max' % type min = TestMethods.limits[minkey] max = TestMethods.limits[maxkey] gr(type, method, min, max, None, min, max) gr(type, method, min, min, min) gr(type, method, max, max, max) if min != 0: gr(type, method, TestMethods.zeros[type], TestMethods.zeros[type], TestMethods.zeros[type]) gr(type, method, TestMethods.tens[type], TestMethods.twenties[type], None, TestMethods.tens[type], TestMethods.twenties[type]) # the next two should cause exceptions; getting a TypeError exception is not an error in this case. try: gr(type, method, min - 1, min - 1, min - 1) except TypeError: pass try: gr(type, method, max + 1, max + 1, max + 1) except TypeError: pass method = 'genRandList_%s' % type nelems = _typed_randrange(TestMethods.tens[type], TestMethods.twenties[type], type) grl(type, method, min, max, nelems) grl(type, method, min, max, TestMethods.ones[type]) grl(type, method, min, max, TestMethods.zeros[type]) if min != 0: grl(type, method, TestMethods.zeros[type], max, nelems) else: grl(type, method, min, TestMethods.zeros[type], nelems) grl(type, method, TestMethods.tens[type], TestMethods.twenties[type], nelems) grl(type, method, TestMethods.tens[type], TestMethods.twenties[type], TestMethods.ones[type]) grl(type, method, TestMethods.tens[type], TestMethods.twenties[type], TestMethods.zeros[type]) method = 'minmedmax_%s' % type mmm(type, method, TestMethods.numlists[type]) def test_integer_types(self): self._run_numeric_type_tests(TestMethods.inttypes) def test_real_types(self): self._run_numeric_type_tests(TestMethods.realtypes) def test_refs(self): inst = pywbem.CIMInstance('TestMethod', properties={ 'id': 'one', 'p_str': 'One', 'p_sint32': pywbem.Sint32(1) }) self.conn.CreateInstance(inst) iname = pywbem.CIMInstanceName('TestMethod', namespace='root/cimv2', keybindings={'id': 'one'}) rv, outs = self.conn.InvokeMethod('getStrProp', iname) self.assertEquals(rv, 'One') rv, outs = self.conn.InvokeMethod('setStrProp', iname, value='won') self.assertFalse(outs) self.assertEquals(rv, 'One') rv, outs = self.conn.InvokeMethod('getStrProp', iname) self.assertEquals(rv, 'won') inst = self.conn.GetInstance(iname) self.assertEquals(inst['p_str'], 'won') rv, outs = self.conn.InvokeMethod('getIntProp', iname) self.assertEquals(rv, 1) self.assertTrue(isinstance(rv, pywbem.Sint32)) self.assertEquals(inst['p_sint32'], 1) rv, outs = self.conn.InvokeMethod('setIntProp', iname, value=pywbem.Sint32(2)) self.assertTrue(isinstance(rv, pywbem.Sint32)) self.assertEquals(rv, 1) self.assertFalse(outs) rv, outs = self.conn.InvokeMethod('getIntProp', iname) self.assertEquals(rv, 2) self.assertTrue(isinstance(rv, pywbem.Sint32)) inst = self.conn.GetInstance(iname) self.assertEquals(inst['p_sint32'], 2) rv, outs = self.conn.InvokeMethod('getObjectPath', 'TestMethod') self.assertTrue(isinstance(outs['path'], pywbem.CIMInstanceName)) self.assertEquals(outs['path']['id'], 'one') inst = pywbem.CIMInstance('TestMethod', properties={ 'id': 'two', 'p_str': 'Two', 'p_sint32': pywbem.Sint32(2) }) self.conn.CreateInstance(inst) rv, outs = self.conn.InvokeMethod('getObjectPaths', 'TestMethod') self.assertEquals(len(outs['paths']), 2) self.assertTrue(isinstance(outs['paths'][0], pywbem.CIMInstanceName)) to_delete = outs['paths'] inst = pywbem.CIMInstance('TestMethod', properties={ 'id': 'three', 'p_str': 'Three', 'p_sint32': pywbem.Sint32(3) }) self.conn.CreateInstance(inst) iname = pywbem.CIMInstanceName('TestMethod', namespace='root/cimv2', keybindings={'id': 'three'}) inames = self.conn.EnumerateInstanceNames('TestMethod') self.assertEquals(len(inames), 3) rv, outs = self.conn.InvokeMethod('delObject', 'TestMethod', path=iname) inames = self.conn.EnumerateInstanceNames('TestMethod') self.assertEquals(len(inames), 2) self.conn.CreateInstance(inst) ''' # OpenWBEM is broken! uncomment this for Pegasus. ''' rv, outs = self.conn.InvokeMethod('delObjects', 'TestMethod', paths=to_delete) inames = self.conn.EnumerateInstanceNames('TestMethod') self.assertEquals(len(inames), 1) self.assertEquals(inames[0]['id'], 'three') def test_mkUniStr_sint8(self): s = 'Scrum Rocks!' l = [pywbem.Sint8(ord(x)) for x in s] rv, outs = self.conn.InvokeMethod('mkUniStr_sint8', 'TestMethod', cArr=l) self.assertFalse(outs) self.assertEquals(rv, s) rv, outs = self.conn.InvokeMethod('mkUniStr_sint8', 'TestMethod', cArr=[]) self.assertEquals(rv, '') def test_strCat(self): ra = ['one', 'two', 'three', 'four'] rv, outs = self.conn.InvokeMethod('strCat', 'TestMethod', strs=ra, sep=',') self.assertEquals(rv, ','.join(ra)) self.assertFalse(outs) def test_strSplit(self): ra = 'one,two,three,four' rv, outs = self.conn.InvokeMethod('strSplit', 'TestMethod', str=ra, sep=',') self.assertEquals(outs['elems'], ra.split(',')) self.assertTrue(ra) def test_getDate(self): dt = pywbem.CIMDateTime.now() rv, outs = self.conn.InvokeMethod('getDate', 'TestMethod', datestr=str(dt)) self.assertFalse(outs) self.assertEquals(rv, dt) self.assertEquals(str(rv), str(dt)) self.assertTrue(isinstance(rv, pywbem.CIMDateTime)) def test_getDates(self): dt = pywbem.CIMDateTime.now() s1 = str(dt) ra = [s1] dt = pywbem.CIMDateTime(pywbem.datetime.now() + \ pywbem.timedelta(seconds=10)) s2 = str(dt) ra.append(s2) dt = pywbem.CIMDateTime(pywbem.datetime.now() + \ pywbem.timedelta(seconds=10)) s3 = str(dt) ra.append(s3) rv, outs = self.conn.InvokeMethod('getDates', 'TestMethod', datestrs=ra) self.assertTrue(rv) self.assertTrue(isinstance(rv, bool)) self.assertEquals(outs['nelems'], len(ra)) self.assertTrue(isinstance(outs['nelems'], pywbem.Sint32)) for i in range(0, len(ra)): self.assertTrue(isinstance(outs['elems'][i], pywbem.CIMDateTime)) self.assertEquals(str(outs['elems'][i]), ra[i]) def test_minmedmax(self): for tstr in [ 'Sint8', 'Uint8', 'Sint16', 'Uint16', 'Sint32', 'Uint32', 'Sint64', 'Uint64', 'Real32', 'Real64' ]: dt = getattr(pywbem, tstr) method = 'minmedmax_%s' % tstr numlist = [ dt(2), dt(5), dt(8), dt(1), dt(9), dt(6), dt(4), dt(7), dt(3), ] rv, outs = self.conn.InvokeMethod(method, 'TestMethod', numlist=numlist) self.assertTrue(rv) self.assertTrue(isinstance(rv, bool)) self.assertTrue(isinstance(outs['min'], dt)) self.assertTrue(isinstance(outs['med'], dt)) self.assertTrue(isinstance(outs['max'], dt)) self.assertEquals(outs['min'], 1) self.assertEquals(outs['max'], 9) self.assertEquals(outs['med'], 5)
# The ExecQuery operations executes a query against target namespace: # # ExecQuery <objec>.ExecQuery([IN] string QueryyLanguage, [IN]string Query) # # The QueryLanguage input parameter defines the query language in which the query parameter # is expressed. CIM and WBEM support a query mechanism that is used to select sets of # properties from CIM object instances. The CIM Server (CIMON) implements a Query Engine # to parse the query and evalute its results. The CIM Query Language used in the queries # is based on concepts of SQL-92, and W3C XML Query. # The CIM Query Language (CQL) is specified in "CIM Operations over HTTP Specification - DSP0200". # The support of queries with the semantics Select-From-Where is called WQL - WBEM Query Language. insts = cliconn.ExecQuery('WQL', 'select * from KC_Widget') # The invocation of CIM method (an extrinsic method) with the following method parameters: # # string Method_Name - The name of the method that will be invoked. # pywbem.CIMInstanceName Object_Name - A reference to a CIM instance. The InstanceName or # ClassName of the object on which the method is invoked. # ret = cliconn.InvokeMethod('Add', insts[0].classname, bc=insts[0].path, X=pywbem.Uint32(sys.argv[1]), Y=pywbem.Uint32(sys.argv[2])) print "result: %s" % ret[0] print "error: %s" % ret[1]
def _create_test_instance(ch, name_of_atom, number, time): """ Create a TestAtom instance. """ global _inst_paths new_instance = pywbem.CIMInstance('TestAtom') new_instance['Name'] = name_of_atom new_instance['boolProp'] = False #new_instance['char16Prop'] = #new_instance['char16Propa'] = Null new_instance['dateProp'] = time new_instance['real32Prop'] = pywbem.Real32(number) #new_instance['real32Propa'] = pywbem.CIMProperty('Real32Propa', \ type='Real32', is_array=True, value=None) new_instance['real32Propa'] = [pywbem.Real32(number), \ pywbem.Real32(number), \ pywbem.Real32(number)] new_instance['real64Prop'] = pywbem.Real64(number) new_instance['real64Propa'] = [pywbem.Real64(number), \ pywbem.Real64(number), \ pywbem.Real64(number)] new_instance['sint16Prop'] = pywbem.Sint16(number) new_instance['sint16Propa'] = [pywbem.Sint16(number), \ pywbem.Sint16(number), \ pywbem.Sint16(number)] new_instance['sint32Prop'] = pywbem.Sint32(number) new_instance['sint32Propa'] = [pywbem.Sint32(number), \ pywbem.Sint32(number), \ pywbem.Sint32(number)] new_instance['sint64Prop'] = pywbem.Sint64(number) new_instance['sint64Propa'] = [pywbem.Sint64(number), \ pywbem.Sint64(number), \ pywbem.Sint64(number)] new_instance['sint8prop'] = pywbem.Sint8(number) new_instance['sint8Propa'] = [pywbem.Sint8(number), \ pywbem.Sint8(number), \ pywbem.Sint8(number)] new_instance['stringProp'] = name_of_atom new_instance['stringPropa'] = ['proton', 'electron', 'neutron'] new_instance['uint16Prop'] = pywbem.Uint16(number) new_instance['uint16Propa'] = [pywbem.Uint16(number), \ pywbem.Uint16(number), \ pywbem.Uint16(number)] new_instance['uint32Prop'] = pywbem.Uint32(number) new_instance['uint32Propa'] = [pywbem.Uint32(number), \ pywbem.Uint32(number), \ pywbem.Uint32(number)] new_instance['uint64Prop'] = pywbem.Uint64(number) new_instance['uint64Propa'] = [pywbem.Uint64(number), \ pywbem.Uint64(number), \ pywbem.Uint64(number)] new_instance['uint8Prop'] = pywbem.Uint8(number) new_instance['uint8Propa'] = [pywbem.Uint8(number), \ pywbem.Uint8(number), \ pywbem.Uint8(number)] try: msg = '' cipath = ch.CreateInstance(new_instance) new_instance.path = cipath _inst_paths.append(cipath) except pywbem.CIMError, arg: raise
class RequestStateChange(object): Completed_with_No_Error = pywbem.Uint32(0) Not_Supported = pywbem.Uint32(1) Unknown_or_Unspecified_Error = pywbem.Uint32(2) Cannot_complete_within_Timeout_Period = pywbem.Uint32(3) Failed = pywbem.Uint32(4) Invalid_Parameter = pywbem.Uint32(5) In_Use = pywbem.Uint32(6) # DMTF_Reserved = .. Method_Parameters_Checked___Job_Started = pywbem.Uint32(4096) Invalid_State_Transition = pywbem.Uint32(4097) Use_of_Timeout_Parameter_Not_Supported = pywbem.Uint32(4098) Busy = pywbem.Uint32(4099) # Method_Reserved = 4100..32767 # Vendor_Specific = 32768..65535 class RequestedState(object): Enabled = pywbem.Uint16(2) Disabled = pywbem.Uint16(3) Shut_Down = pywbem.Uint16(4) Offline = pywbem.Uint16(6) Test = pywbem.Uint16(7) Defer = pywbem.Uint16(8) Quiesce = pywbem.Uint16(9) Reboot = pywbem.Uint16(10) Reset = pywbem.Uint16(11)