ia64/xen-unstable

view tools/python/scripts/test_vm_create.py @ 13771:3cccf8e64296

[XEND] Merge VFB support for PV and HVM guests.

This patch merges the way VFB are represented inside Xend by making
HVM VNC consoles use the VFB as its configuration object.

It preserves the way options are specified through xm but will create
a new VFB device that is used by image.py to put vnc config into
qemu-dm's command line. The parsing is moved into image.py's
parseDeviceModel() rather than in configVNC().

Through the Xen API, you can create a 'console' of protocol 'rfb' and
end up with a VNC console, on both HVM and PV guests. The location of
the connecting port is stored in the location attribute of the console
object. This is updated on each XendDomainInfo.update() if it
changes.

Also fixes missing read of the vnclisten and HVM_boot from the
config when initialised via xm. Makes sure bootable attribute for VBD
is store as an int when making SXP config.

Signed-off-by: Alastair Tse <atse@xensource.com>
author Alastair Tse <atse@xensource.com>
date Wed Jan 31 13:20:36 2007 +0000 (2007-01-31)
parents 072ce22bcc91
children 85e8d7b8360a
line source
1 #!/usr/bin/python
3 vm_cfg = {
4 'name_label': 'APIVM',
5 'user_version': 1,
6 'is_a_template': False,
7 'auto_power_on': False, # TODO
9 'memory_static_min': 64,
10 'memory_static_max': 128,
11 #'memory_dynamic_min': 64,
12 #'memory_dynamic_max': 128,
15 'VCPUs_policy': 'credit',
16 'VCPUs_params': '',
17 'VCPUs_number': 2,
18 'VCPUs_features_required': '',
19 'VCPUs_features_can_use': '',
20 'VCPUs_features_force_on': '',
21 'VCPUs_features_force_off': '',
23 'actions_after_shutdown': 'destroy',
24 'actions_after_reboot': 'restart',
25 'actions_after_suspend': 'destroy',
26 'actions_after_crash': 'destroy',
28 'PV_bootloader': '',
29 'PV_bootloader_args': '',
31 'PV_kernel': '/boot/vmlinuz-2.6.18-xenU',
32 'PV_ramdisk': '',
33 'PV_args': 'root=/dev/sda1 ro',
35 #'HVM_boot': '',
36 'platform_std_VGA': False,
37 'platform_serial': '',
38 'platform_localtime': False,
39 'platform_clock_offset': False,
40 'platform_enable_audio': False,
41 'PCI_bus': ''
42 }
44 vdi_cfg = {
45 'name_label': 'API_VDI',
46 'name_description': '',
47 'virtual_size': 100 * 1024,
48 'sector_size': 1024,
49 'type': 'system',
50 'parent': '',
51 'SR_name': 'QCoW',
52 'sharable': False,
53 'read_only': False,
54 }
56 vbd_cfg = {
57 'VDI': '',
58 'VM': '',
59 'device': 'sda2',
60 'mode': 'RW',
61 'type': 'disk',
62 'driver': 'paravirtualised',
63 }
65 local_vdi_cfg = {
66 'name_label': 'gentoo.amd64.img',
67 'name_description': '',
68 'uri': 'file:/root/gentoo.amd64.img',
69 'virtual_size': 0,
70 'sector_size': 0,
71 'type': 'system',
72 'parent': '',
73 'SR_name': 'Local',
74 'sharable': False,
75 'read_only': False,
76 }
78 local_vbd_cfg = {
79 'VDI': '',
80 'VM': '',
81 'device': 'sda1',
82 'mode': 'RW',
83 'type': 'disk',
84 'driver': 'paravirtualised',
85 }
87 vif_cfg = {
88 'name': 'API_VIF',
89 'type': 'paravirtualised',
90 'device': '',
91 'network': '',
92 'MAC': '',
93 'MTU': 1500,
94 }
96 console_cfg = {
97 'protocol': 'rfb',
98 'other_config': {'vncunused': 1, 'vncpasswd': 'testing'},
99 }
101 import sys
102 import time
103 sys.path.append('/usr/lib/python')
105 from xapi import connect, execute
107 def test_vm_create():
108 server, session = connect()
109 vm_uuid = None
110 vdi_uuid = None
111 local_vdi_uuid = None
112 local_vbd_uuid = None
113 vbd_uuid = None
114 vif_uuid = None
116 # List all VMs
117 vm_list = execute(server, 'VM.get_all', (session,))
118 vm_names = []
119 for vm_uuid in vm_list:
120 vm_record = execute(server, 'VM.get_record', (session, vm_uuid))
121 vm_names.append(vm_record['name_label'])
123 # Get default SR
124 sr_list = execute(server, 'SR.get_by_name_label', (session,
125 vdi_cfg['SR_name']))
126 sr_uuid = sr_list[0]
128 local_sr_list = execute(server, 'SR.get_by_name_label',
129 (session, local_vdi_cfg['SR_name']))
130 local_sr_uuid = local_sr_list[0]
132 # Get default network
133 net_list = execute(server, 'network.get_all', (session,))
134 net_uuid = net_list[0]
136 try:
137 # Create a new VM
138 vm_uuid = execute(server, 'VM.create', (session, vm_cfg))
140 # Create a new VDI
141 vdi_cfg['SR'] = sr_uuid
142 vdi_uuid = execute(server, 'VDI.create', (session, vdi_cfg))
144 # Create a VDI backed VBD
145 vbd_cfg['VM'] = vm_uuid
146 vbd_cfg['VDI'] = vdi_uuid
147 vbd_uuid = execute(server, 'VBD.create', (session, vbd_cfg))
149 # Create a new VDI (Local)
150 local_vdi_cfg['SR'] = local_sr_uuid
151 local_vdi_uuid = execute(server, 'VDI.create',
152 (session, local_vdi_cfg))
154 # Create a new VBD (Local)
155 local_vbd_cfg['VM'] = vm_uuid
156 local_vbd_cfg['VDI'] = local_vdi_uuid
157 local_vbd_uuid = execute(server, 'VBD.create',
158 (session, local_vbd_cfg))
160 # Create a new VIF
161 vif_cfg['network'] = net_uuid
162 vif_cfg['VM'] = vm_uuid
163 vif_uuid = execute(server, 'VIF.create', (session, vif_cfg))
165 # Create a console
166 console_cfg['VM'] = vm_uuid
167 console_uuid = execute(server, 'console.create',
168 (session, console_cfg))
169 print console_uuid
171 # Start the VM
172 execute(server, 'VM.start', (session, vm_uuid, False))
174 time.sleep(30)
176 test_suspend = False
177 if test_suspend:
178 print 'Suspending VM..'
179 execute(server, 'VM.suspend', (session, vm_uuid))
180 print 'Suspended VM.'
181 time.sleep(5)
182 print 'Resuming VM ...'
183 execute(server, 'VM.resume', (session, vm_uuid, False))
184 print 'Resumed VM.'
186 # Wait for user to say we're good to shut it down
187 while True:
188 destroy = raw_input('destroy VM? ')
189 if destroy[0] in ('y', 'Y'):
190 break
192 finally:
193 # Clean up
194 if vif_uuid:
195 execute(server, 'VIF.destroy', (session, vif_uuid))
197 if local_vbd_uuid:
198 execute(server, 'VBD.destroy', (session, local_vbd_uuid))
199 if local_vdi_uuid:
200 execute(server, 'VDI.destroy', (session, local_vdi_uuid))
202 if vbd_uuid:
203 execute(server, 'VBD.destroy', (session, vbd_uuid))
204 if vdi_uuid:
205 execute(server, 'VDI.destroy', (session, vdi_uuid))
207 if vm_uuid:
208 try:
209 execute(server, 'VM.hard_shutdown', (session, vm_uuid))
210 time.sleep(2)
211 except:
212 pass
214 execute(server, 'VM.destroy', (session, vm_uuid))
217 if __name__ == "__main__":
218 test_vm_create()