[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-cim] Re: Pywbem script



Subrahmanian, Raj wrote:
> Jim
> Could you shoot over the latest script you are using to create vms? 
> There is this strange null pointer exception I am trying to hunt down.
> Thanks
>   

Some example python script attached.  Very minimal.  Would be nice to
expand on it and add to repo.  Pywbem documentation: 
http://pywbem.sourceforge.net/documentation.shtml

For DefineSystem, I have a collection of "cimxml conf files'.  I've
attached example PV and HVM one I'm currently using.  Tweak them as
necessary and use the fakeclient program I sent invoke DefineSystem on
target node.

Jim

> Raj
>   
#!/usr/bin/python

import sys
import pywbem


# Connect to cimom
conn = pywbem.WBEMConnection('http://localhost', ('root', 'novell'))

# Enumerate instances of Xen_ComputerSystem
print 'Enumerating instances of Xen_ComputerSystem:'
inst_names = conn.EnumerateInstanceNames('Xen_ComputerSystem')
for n in inst_names:
    inst = conn.GetInstance(n)

    for key, value in inst.items():
        if key in ('Name', 'RequestedState'):
            print '    %s = %s' % (key, value)

# Get instance of Virtual System Management Service
print 'Looking for Virtual System Management Service...'
vsms = conn.EnumerateInstanceNames("Xen_VirtualSystemManagementService")
print 'Got Virtual System Management Service: %s' % str(vsms[0])


# Create virtual system settings for new VM
vssd = '''
instance of Xen_ComputerSystemSettingData {
VirtualSystemIdentifier = "vm1";
VirtualSystemType = "Xen Paravirtual";
Bootloader = "/usr/lib/xen/boot/domUloader.py";
BootloaderOptions = "--entry=hda2:/boot/vmlinux-xen,/boot/initrd-xen";
Root = "/dev/hda2";
KernelOptions = "Term=xterm";
};
'''

# Create resource settings for the new VM
proc_rasd = '''
instance of Xen_ProcessorSettingData {
ResourceType = 3;
VirtualQuantity = 1;
AllocationUnits = "Cores";
};
'''

mem_rasd = '''
instance of Xen_MemorySettingData {
ResourceType = 4;
VirtualQuantity = 256;
AllocationUnits = "MegaBytes";
};
'''

disk_rasd = '''
instance of Xen_DiskSettingData {
ResourceType = 19;
DiskConfigInfo =  "file:/var/lib/xen/images/vm1/hda,hda,w";
};
'''

nic_rasd = '''
instance of Xen_NetworkPortSettingData {
 ResourceType = 10;
 NICConfigInfo = "mac=00:16:3e:9d:9e:ad";
};
'''

rasds = [proc_rasd, mem_rasd, disk_rasd, nic_rasd]

in_params = {'SystemSettings': vssd, 'ResourceSettings': rasds}


# Invoke DefineSystem on Virtual System Management Serive to define a new VM,
# providing the new VM settings and its resource settings.
try:
    print 'Calling DefineSystem to create a new VM ...'
    (rval, out_params) = conn.InvokeMethod('DefineSystem', vsms[0], **in_params)
    print 'Return Value of DefineSystem: %s' % rval
    print 'Output = %s' % out_params

except pywbem.CIMError, arg:
    print 'Caught exception when calling InvokeMethod'
    if arg[0] != pywbem.CIM_ERR_NOT_SUPPORTED:
        print 'InvokeMethod(instancename): %s' % arg[1]
        sys.exit(1)

except ValueError, e:
    pass


# Get instance of newly created vm
print 'Enumerating instances of Xen_ComputerSystem:'
inst_names = conn.EnumerateInstanceNames('Xen_ComputerSystem')
for n in inst_names:
    inst = conn.GetInstance(n)

    for key, value in inst.items():
        if key in ('Name', 'RequestedState'):
            print '    %s = %s' % (key, value)


# Invoke RequestStateChange to activate new vm
inst_names = conn.EnumerateInstanceNames('Xen_ComputerSystem')
for n in inst_names:
    inst = conn.GetInstance(n)


# Get instance of newly activated vm
<?xml version="1.0" encoding="UTF-8"?>
<CIM CIMVERSION="2.0" DTDVERSION="2.0">
<MESSAGE ID="5" PROTOCOLVERSION="1.0">
<SIMPLEREQ>
<METHODCALL NAME="DefineSystem">
<LOCALINSTANCEPATH>
 <LOCALNAMESPACEPATH>
  <NAMESPACE NAME="root"/><NAMESPACE NAME="cimv2"/>
 </LOCALNAMESPACEPATH>
 <INSTANCENAME CLASSNAME="Xen_VirtualSystemManagementService">
  <KEYBINDING NAME="CreationClassName">
   <KEYVALUE VALUETYPE="string">Xen_VirtualSystemManagementService</KEYVALUE>
  </KEYBINDING>
  <KEYBINDING NAME="Name">
   <KEYVALUE VALUETYPE="string">Xen Hypervisor</KEYVALUE>
  </KEYBINDING>
  <KEYBINDING NAME="SystemCreationClassName">
   <KEYVALUE VALUETYPE="string">CIM_ComputerSystem</KEYVALUE>
  </KEYBINDING>
  <KEYBINDING NAME="SystemName">
   <KEYVALUE VALUETYPE="string">xen81</KEYVALUE>
  </KEYBINDING>
 </INSTANCENAME>
</LOCALINSTANCEPATH>
<PARAMVALUE NAME="SystemSettings" PARAMTYPE="string">
 <VALUE>
instance of Xen_ComputerSystemSettingData {
 VirtualSystemIdentifier = "sles10_pv";
 VirtualSystemType = "Xen Paravirtual";
 Bootloader = "/usr/lib/xen/boot/domUloader.py";
 BootloaderOptions = "--entry=xvda2:/boot/vmlinuz-xenpae,/boot/initrd-xenpae";
 KernelOptions = "3";
 UUID = "1f54006c-1b7e-b1b4-3f9a-f9fe49a65e02";
 localtime = False;
 OnPoweroff = 0;
 OnReboot = 1;
 OnCrash = 2;
};
</VALUE>
</PARAMVALUE>

<PARAMVALUE NAME="ResourceSettings" PARAMTYPE="string">
 <VALUE.ARRAY>
  <VALUE>
instance of Xen_ProcessorSettingData {
 ResourceType = 3;
 VirtualQuantity = 1;
 AllocationUnits = "Cores";
};
  </VALUE>
  <VALUE>
instance of Xen_MemorySettingData {
 ResourceType = 4;
 VirtualQuantity = 512;
 AllocationUnits = "MegaBytes";
};
  </VALUE>
  <VALUE>
instance of Xen_DiskSettingData {
 ResourceType = 19;
 DiskConfigInfo = "file:/var/lib/xen/images/sles10_pv/disk0,xvda,w";
};
  </VALUE>
  <VALUE>
instance of Xen_NetworkPortSettingData {
 ResourceType = 10;
 NICConfigInfo = "mac=00:16:3e:4b:25:aa";
};
  </VALUE>
  <VALUE>
instance of Xen_ConsoleSettingData {
 ResourceType = 24;
 Protocol = 1;
 ConsoleConfigInfo = "vncunused=1";
};
  </VALUE>
 </VALUE.ARRAY>
</PARAMVALUE>
</METHODCALL>
</SIMPLEREQ>
</MESSAGE>
</CIM>
<?xml version="1.0" encoding="UTF-8"?>
<CIM CIMVERSION="2.0" DTDVERSION="2.0">
<MESSAGE ID="5" PROTOCOLVERSION="1.0">
<SIMPLEREQ>
<METHODCALL NAME="DefineSystem">
<LOCALINSTANCEPATH>
 <LOCALNAMESPACEPATH>
  <NAMESPACE NAME="root"/><NAMESPACE NAME="cimv2"/>
 </LOCALNAMESPACEPATH>
 <INSTANCENAME CLASSNAME="Xen_VirtualSystemManagementService">
  <KEYBINDING NAME="CreationClassName">
   <KEYVALUE VALUETYPE="string">Xen_VirtualSystemManagementService</KEYVALUE>
  </KEYBINDING>
  <KEYBINDING NAME="Name">
   <KEYVALUE VALUETYPE="string">Xen Hypervisor</KEYVALUE>
  </KEYBINDING>
  <KEYBINDING NAME="SystemCreationClassName">
   <KEYVALUE VALUETYPE="string">CIM_ComputerSystem</KEYVALUE>
  </KEYBINDING>
  <KEYBINDING NAME="SystemName">
   <KEYVALUE VALUETYPE="string">xen81</KEYVALUE>
  </KEYBINDING>
 </INSTANCENAME>
</LOCALINSTANCEPATH>
<PARAMVALUE NAME="SystemSettings" PARAMTYPE="string">
 <VALUE>
instance of Xen_ComputerSystemSettingData {
 VirtualSystemIdentifier = "winxp_provider";
 VirtualSystemType = "Xen HVM";
 BootOrder = "c";
 localtime = True;
 OnPoweroff = 0;
 OnReboot = 1;
 OnCrash = 5;
};
</VALUE>
</PARAMVALUE>

<PARAMVALUE NAME="ResourceSettings" PARAMTYPE="string">
 <VALUE.ARRAY>
  <VALUE>
instance of Xen_ProcessorSettingData {
 ResourceType = 3;
 VirtualQuantity = 1;
 AllocationUnits = "Cores";
};
  </VALUE>
  <VALUE>
instance of Xen_MemorySettingData {
 ResourceType = 4;
 VirtualQuantity = 512;
 AllocationUnits = "Bytes";
};
  </VALUE>
  <VALUE>
instance of Xen_DiskSettingData {
 ResourceType = 20;
 DiskConfigInfo = "file:/tests/demo/disks/winxp-32-unmod.img,ioemu:hda,w";
};
  </VALUE>
  <VALUE>
instance of Xen_NetworkPortSettingData {
 ResourceType = 10;
 NICConfigInfo = "type=ioemu,mac=00:16:3e:8a:a9:48";
};
  </VALUE>
  <VALUE>
instance of Xen_ConsoleSettingData {
 ResourceType = 24;
 Protocol = 1;
};
  </VALUE>
 </VALUE.ARRAY>
</PARAMVALUE>
</METHODCALL>
</SIMPLEREQ>
</MESSAGE>
</CIM>
_______________________________________________
Xen-cim mailing list
Xen-cim@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-cim

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.