Example #1
0
    def run(self):
        log = self.env.get_logger()
        log.log_debug('##### IndicationThread.run entered...')
        self.shuttingdown = False
        ch = self.env.get_cimom_handle()
        while not self.shuttingdown:
            # Acquire the lock on the condition variable before we wait on it
            self._cond.acquire()
            # We'll wait on the condition for 5 seconds. Then we'll
            # wake up and generate an indication
            l = self._cond.wait(5.0)
            self._cond.release()
            # If we're shutting down, just break out of this loop
            if self.shuttingdown:
                break

            # Modify 'Key2' of _PyFooInsts and generate a CIM_InstModification
            # life cycle indication

            k = 'Key2'
            v = _PyFooInsts[k]
            cipath = pywbem.CIMInstanceName('PyIndFoo', {'TheKey': k},
                                            namespace='root/cimv2')
            pci = pywbem.CIMInstance('PyIndFoo', {
                'TheKey': k,
                'TheValue': pywbem.Sint32(v)
            },
                                     path=cipath)
            v += 1
            _PyFooInsts[k] = v
            sci = pywbem.CIMInstance('PyIndFoo', {
                'TheKey': k,
                'TheValue': pywbem.Sint32(v)
            },
                                     path=cipath)

            self.count += 1

            ci = pywbem.CIMInstance('CIM_InstModification')
            ci['PreviousInstance'] = pci
            ci['SourceInstance'] = sci
            ci['SourceInstanceModelPath'] = cipath
            ci['IndicationIdentifier'] = 'PyTestInd:%s' % self.count
            ci['IndicationTime'] = pywbem.CIMDateTime.now()
            ci['PerceivedSeverity'] = pywbem.Uint16(2)
            ch.export_indication(ci, 'root/cimv2')

        log.log_debug('##### IndicationThread.run returning')
Example #2
0
    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
Example #3
0
def _createFilter(query,
                  ns,
                  querylang='WQL',
                  src_ns='root/cimv2',
                  in_name=None):
    name = in_name or 'cimfilter%s' % time.time()
    filterinst = pywbem.CIMInstance('CIM_IndicationFilter')
    filterinst['CreationClassName'] = 'CIM_IndicationFilter'
    filterinst['SystemCreationClassName'] = 'CIM_ComputerSystem'
    filterinst['SystemName'] = getfqdn()
    filterinst['Name'] = name
    filterinst['Query'] = query
    filterinst['QueryLanguage'] = querylang
    filterinst['SourceNamespace'] = src_ns
    cop = pywbem.CIMInstanceName('CIM_IndicationFilter')
    cop.keybindings = {
        'CreationClassName': 'CIM_IndicationFilter',
        'SystemClassName': 'CIM_ComputerSystem',
        'SystemName': getfqdn(),
        'Name': name
    }
    cop.namespace = ns
    filterinst.path = cop
    filtercop = conn.CreateInstance(filterinst)
    return filtercop
Example #4
0
    def cim_method_send_indication(self, env, object_name, method):
        """
        Method to test the upcalls to the cimom handle for export_indications.
        """
        global _indication_names, _indication_count
        cimtime = pywbem.CIMDateTime.now()
        ch = env.get_cimom_handle()
        ch.set_default_namespace("root/cimv2")
        logger = env.get_logger()

        for name in _indication_names:
            alert_ind = pywbem.CIMInstance("UpcallAtom_Indication")
            alert_ind['AlertType'] = pywbem.Uint16(2)
            alert_ind['Description'] = name
            alert_ind['PerceivedSeverity'] = pywbem.Uint16(1)
            alert_ind['PorbablyCause'] = pywbem.Uint16(1)
            alert_ind['IndicationTime'] = cimtime
            alert_ind['SystemName'] = socket.getfqdn()

            try:
                print '### Exporting indication. pid:', os.getpid()
                ch.export_indication(alert_ind)
                print '### Done exporting indication'
            except pywbem.CIMError, arg:
                print '### Caught exception exporting indication'
                raise
Example #5
0
def _createSubscription(ns, handler, indfilter):
    subinst = pywbem.CIMInstance('CIM_IndicationSubscription')
    subinst['Filter'] = indfilter
    subinst['Handler'] = indhandler
    cop = pywbem.CIMInstanceName('CIM_IndicationSubscription')
    cop.keybindings = {'Filter': indfilter, 'Handler': indhandler}
    cop.namespace = ns
    subinst.path = cop
    subcop = conn.CreateInstance(subinst)
    return subcop
Example #6
0
 def _enum(self, ns, classname, keys_only=True):
     if (ns, classname) not in self.instances:
         raise Exception("Mock me! %s" % classname)
     for className, keybindings, props in self.instances[(ns, classname)]:
         op = pywbem.CIMInstanceName(className,
                                     keybindings=keybindings,
                                     namespace=ns)
         if keys_only:
             yield op
         else:
             inst = pywbem.CIMInstance(className, properties=props, path=op)
             inst.update(keybindings)
             yield inst
Example #7
0
    def set_instance(self, env, instance, previous_instance, cim_class):
        """Return a newly created or modified instance.

        Keyword arguments:
        env -- Provider Environment (pycimmb.ProviderEnvironment)
        instance -- The new pywbem.CIMInstance.  If modifying an existing 
            instance, the properties on this instance have been filtered by 
            the PropertyList from the request.
        previous_instance -- The previous pywbem.CIMInstance if modifying 
            an existing instance.  None if creating a new instance. 
        cim_class -- The pywbem.CIMClass

        Return the new instance.  The keys must be set on the new instance. 

        Possible Errors:
        CIM_ERR_ACCESS_DENIED
        CIM_ERR_NOT_SUPPORTED
        CIM_ERR_INVALID_PARAMETER (including missing, duplicate, unrecognized 
            or otherwise incorrect parameters)
        CIM_ERR_ALREADY_EXISTS (the CIM Instance already exists -- only 
            valid if previous_instance is None, indicating that the operation
            was CreateInstance)
        CIM_ERR_NOT_FOUND (the CIM Instance does not exist -- only valid 
            if previous_instance is not None, indicating that the operation
            was ModifyInstance)
        CIM_ERR_FAILED (some other unspecified error occurred)

        """

        logger = env.get_logger()
        logger.log_debug('Entering %s.set_instance()' \
                % self.__class__.__name__)

        if previous_instance is None:
            _PyFooInsts[model['TheKey']] = instance['TheValue']
        else:
            if 'TheValue' in instance:
                try:
                    _PyFooInsts[instance['TheKey']] = instance['TheValue']
                except KeyError:
                    raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND)
                ci = pywbem.CIMInstance('CIM_InstModification')
                ci['PreviousInstance'] = previous_instance
                ci['SourceInstance'] = instance
                ci['SourceInstanceModelPath'] = instance.path
                ci['IndicationIdentifier'] = 'PyTestInd:%s' % 'one'
                ci['IndicationTime'] = pywbem.CIMDateTime.now()
                ci['PerceivedSeverity'] = pywbem.Uint16(2)
                ch = env.get_cimom_handle()
                ch.export_indication(ci, 'root/cimv2')
        return instance
Example #8
0
def add_vm_resources (conn, vsms, vm_ref):
    try:
        print '*** Adding processor and CD resources to VM %s ' % vm_ref['Name']
        # AddResourceSettings requires the Xen_ComputerSystemSettingData reference, find it
        # We'll use the association class for that
        association_class = 'CIM_SettingsDefineState'      # association to traverse via Xen_ComputerSystem
        result_class      = 'CIM_VirtualSystemSettingData' # result class we are looking for
        in_params         = {'ResultClass': result_class, 'AssocClass': association_class }
        affected_config_arr  = conn.AssociatorNames(vm_ref, **in_params)
        affected_config = affected_config_arr[0]

        cd_drive = pywbem.CIMInstance('Xen_DiskSettingData')
        cd_drive['Elementname']       = 'my_cd_drive'
        cd_drive['ResourceType']      = pywbem.Uint16(15)
        cd_drive['VirtualQuantity']   = pywbem.Uint64(1)
        cd_drive['AllocationUnits']   = "count"
        cd_drive['Access']            = pywbem.Uint8(1)
        cd_drive['Bootable']          = True

        more_mem = pywbem.CIMInstance('CIM_ResourceAllocationSettingData')
        more_mem['ResourceType']    = pywbem.Uint16(4)
        more_mem['VirtualQuantity'] = pywbem.Uint64(512)
        more_mem['AllocationUnits'] = 'byte*2^20'

        rasds = [cd_drive, more_mem]
        in_params = {'ResourceSettings': rasds, 'AffectedConfiguration':affected_config}
        [rval, out_params] = conn.InvokeMethod('AddResourceSettings', vsms, **in_params)
        if rval != 4096:
            sys.stderr.write('%s returned error: %s\n' % (sys._getframe(0).f_code.co_name, rval))
            return 0
        job_ref = out_params['Job']
        job = wait_for_job_to_complete(conn, job_ref)
        conn.DeleteInstance(job_ref)
    except Exception, e:
        sys.stderr.write('Exception caught in %s: %s\n' % (sys._getframe(0).f_code.co_name, e))
        return 0
Example #9
0
 def createDest(self,
                 destination,
                 ns,
                 in_name=None):
     name = in_name or 'cimlistener%d'%time.time()
     destinst=pywbem.CIMInstance('CIM_ListenerDestinationCIMXML')
     destinst['CreationClassName']='CIM_ListenerDestinationCIMXML'
     destinst['SystemCreationClassName']='CIM_ComputerSystem'
     destinst['SystemName']=getfqdn()
     destinst['Name']=name
     destinst['Destination']=destination
     cop = pywbem.CIMInstanceName('CIM_ListenerDestinationCIMXML')
     cop.keybindings = { 'CreationClassName':'CIM_ListenerDestinationCIMXML',
                         'SystemCreationClassName':'CIM_ComputerSystem',
                         'SystemName':getfqdn(),
                         'Name':name }
     cop.namespace=ns
     destinst.path = cop
     destcop = self._conn.CreateInstance(destinst)
     return destcop
Example #10
0
 def createFilter(self,
                   query,
                   ns,
                   in_name=None):
     name = in_name or 'cimfilter%d'%time.time()
     filterinst=pywbem.CIMInstance('CIM_IndicationFilter')
     filterinst['CreationClassName']='CIM_IndicationFilter'
     filterinst['SystemCreationClassName']='CIM_ComputerSystem'
     filterinst['SystemName']=getfqdn()
     filterinst['Name']=name
     filterinst['Query']=query
     filterinst['QueryLanguage']='WQL'
     cop = pywbem.CIMInstanceName('CIM_IndicationFilter')
     cop.keybindings = { 'CreationClassName':'CIM_IndicationFilter',
                         'SystemCreationClassName':'CIM_ComputerSystem',
                         'SystemName':getfqdn(),
                         'Name':name }
     cop.namespace=ns
     filterinst.path = cop
     filtercop = self._conn.CreateInstance(filterinst)
     return filtercop
Example #11
0
    def run(self):
        log = self.env.get_logger()
        log.log_debug('##### IndicationThread.run entered...')
        self.shuttingdown = False
        ch = self.env.get_cimom_handle()
        while not self.shuttingdown:
            # Acquire the lock on the condition variable before we wait on it
            self._cond.acquire()
            # We'll wait on the condition for 5 seconds. Then we'll
            # wake up and generate an indication
            l = self._cond.wait(5.0)
            self._cond.release()
            # If we're shutting down, just break out of this loop
            if self.shuttingdown:
                break

            self.count += 1

            ci = pywbem.CIMInstance('Py_TestAlert')
            ci['SystemName'] = self.sysname
            ci['MessageID'] = 'PyTestInd:%s' % self.count
            ci['Message'] = 'Hello. This is a python alert indication'
            ci['SystemCreationClassName'] = 'OMC_UnitaryComputerSystem'
            ci['EventID'] = str(self.count)
            ci['EventTime'] = pywbem.CIMDateTime.now()
            ci['AlertType'] = pywbem.Uint16(1)
            ci['Description'] = 'This is a test indication from the provider interface'
            ci['ProviderName'] = 'AlertIndication.py'
            ci['PerceivedSeverity'] = pywbem.Uint16(2)
            ci['OwningEntity'] = 'mine. mine. all mine'
            ci['RecommendedActions'] = ['Have fun', 'Ignore crap like this']
            ci['IndicationTime'] = pywbem.CIMDateTime.now()
            ci['IndicationIdentifier'] = 'Little redundant'
            log.log_debug('##### IndicationThread.run exporting indication')

            ch.export_indication(ci, 'root/cimv2')

        log.log_debug('##### IndicationThread.run returning')
Example #12
0
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]
Example #13
0
    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')
Example #14
0
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
Example #15
0
    def cim_method_methodtest(self, env, object_name, method, param_paths,
                              param_embedded, param_nullparam,
                              param_uint8array, param_s, param_embedded_a,
                              param_io16):
        """Implements Py_LotsOfDataTypes.MethodTest()

        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_paths --  The input parameter paths (type REF CIM_System (CIMInstanceName)[]) 
        param_embedded --  The input parameter embedded (type string) 
        param_nullparam --  The input parameter nullParam (type datetime) 
        param_uint8array --  The input parameter uint8array (type uint8[]) 
        param_s --  The input parameter s (type string) (Required)
        param_embedded_a --  The input parameter embedded_a (type string[]) 
        param_io16 --  The input parameter io16 (type sint16) 

        Returns a two-tuple containing the return value (type string)
        and a dictionary with the out-parameters

        Output parameters:
        paths -- (type REF CIM_System (CIMInstanceName)[]) 
        b -- (type boolean) 
        embedded -- (type string) 
        nullParam -- (type datetime) 
        embedded_a -- (type string[]) 
        io16 -- (type sint16) 
        r64 -- (type real64) 
        msg -- (type string) 

        """

        # TODO do something
        insts = [
            pywbem.CIMInstance(classname='PyFoo',
                               properties={
                                   'FooValue': pywbem.Sint32(3),
                                   'FooKey': 'Key3'
                               },
                               path=pywbem.CIMInstanceName(
                                   classname='PyFoo', namespace='root/cimv2')),
            pywbem.CIMInstance(classname='PyFoo',
                               properties={
                                   'FooValue': pywbem.Sint32(2),
                                   'FooKey': 'Key2'
                               },
                               path=pywbem.CIMInstanceName(
                                   classname='PyFoo', namespace='root/cimv2'))
        ]

        out_params = {}
        out_params['paths'] = param_paths
        out_params['b'] = True
        if param_embedded is not None:
            out_params['embedded'] = param_embedded
        else:
            out_params['embedded'] = insts[0]
        out_params['nullparam'] = None
        if param_embedded_a is not None:
            out_params['embedded_a'] = param_embedded_a
        else:
            out_params['embedded_a'] = insts
        out_params['io16'] = pywbem.Sint16(16)
        out_params['r64'] = pywbem.Real64(3.14159)
        out_params['msg'] = 'A message'
        rval = 'Return' + ` out_params `
        return (rval, out_params)