debuggers.hg

view tools/python/scripts/test_vm_create.py @ 13625:072ce22bcc91

[XENAPI] Update test scripts to move from VBD.image to creating VDI's
with the uri attribute.

Signed-off-by: Alastair Tse <atse@xensource.com>
author Alastair Tse <atse@xensource.com>
date Wed Jan 24 15:48:58 2007 +0000 (2007-01-24)
parents 9292da5e9a27
children 3cccf8e64296
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 import sys
97 import time
98 sys.path.append('/usr/lib/python')
100 from xapi import connect, execute
102 def test_vm_create():
103 server, session = connect()
104 vm_uuid = None
105 vdi_uuid = None
106 local_vdi_uuid = None
107 local_vbd_uuid = None
108 vbd_uuid = None
109 vif_uuid = None
111 # List all VMs
112 vm_list = execute(server, 'VM.get_all', (session,))
113 vm_names = []
114 for vm_uuid in vm_list:
115 vm_record = execute(server, 'VM.get_record', (session, vm_uuid))
116 vm_names.append(vm_record['name_label'])
118 # Get default SR
119 sr_list = execute(server, 'SR.get_by_name_label', (session,
120 vdi_cfg['SR_name']))
121 sr_uuid = sr_list[0]
123 local_sr_list = execute(server, 'SR.get_by_name_label',
124 (session, local_vdi_cfg['SR_name']))
125 local_sr_uuid = local_sr_list[0]
127 # Get default network
128 net_list = execute(server, 'network.get_all', (session,))
129 net_uuid = net_list[0]
131 try:
132 # Create a new VM
133 vm_uuid = execute(server, 'VM.create', (session, vm_cfg))
135 # Create a new VDI
136 vdi_cfg['SR'] = sr_uuid
137 vdi_uuid = execute(server, 'VDI.create', (session, vdi_cfg))
139 # Create a VDI backed VBD
140 vbd_cfg['VM'] = vm_uuid
141 vbd_cfg['VDI'] = vdi_uuid
142 vbd_uuid = execute(server, 'VBD.create', (session, vbd_cfg))
144 # Create a new VDI (Local)
145 local_vdi_cfg['SR'] = local_sr_uuid
146 local_vdi_uuid = execute(server, 'VDI.create',
147 (session, local_vdi_cfg))
149 # Create a new VBD (Local)
150 local_vbd_cfg['VM'] = vm_uuid
151 local_vbd_cfg['VDI'] = local_vdi_uuid
152 local_vbd_uuid = execute(server, 'VBD.create',
153 (session, local_vbd_cfg))
155 # Create a new VIF
156 vif_cfg['network'] = net_uuid
157 vif_cfg['VM'] = vm_uuid
158 vif_uuid = execute(server, 'VIF.create', (session, vif_cfg))
160 # Start the VM
161 execute(server, 'VM.start', (session, vm_uuid, False))
163 time.sleep(30)
165 test_suspend = True
166 if test_suspend:
167 print 'Suspending VM..'
168 execute(server, 'VM.suspend', (session, vm_uuid))
169 print 'Suspended VM.'
170 time.sleep(5)
171 print 'Resuming VM ...'
172 execute(server, 'VM.resume', (session, vm_uuid, False))
173 print 'Resumed VM.'
175 # Wait for user to say we're good to shut it down
176 while True:
177 destroy = raw_input('destroy VM? ')
178 if destroy[0] in ('y', 'Y'):
179 break
181 finally:
182 # Clean up
183 if vif_uuid:
184 execute(server, 'VIF.destroy', (session, vif_uuid))
186 if local_vbd_uuid:
187 execute(server, 'VBD.destroy', (session, local_vbd_uuid))
188 if local_vdi_uuid:
189 execute(server, 'VDI.destroy', (session, local_vdi_uuid))
191 if vbd_uuid:
192 execute(server, 'VBD.destroy', (session, vbd_uuid))
193 if vdi_uuid:
194 execute(server, 'VDI.destroy', (session, vdi_uuid))
196 if vm_uuid:
197 try:
198 execute(server, 'VM.hard_shutdown', (session, vm_uuid))
199 time.sleep(2)
200 except:
201 pass
203 execute(server, 'VM.destroy', (session, vm_uuid))
206 if __name__ == "__main__":
207 test_vm_create()