ia64/xen-unstable

view tools/python/scripts/test_vm_create.py @ 13787:85e8d7b8360a

[XENAPI] Remove some deprecated fields from the Xen API test script.

Signed-off-by: Alastair Tse <atse@xensource.com>
author Alastair Tse <atse@xensource.com>
date Wed Jan 31 15:06:40 2007 +0000 (2007-01-31)
parents 3cccf8e64296
children 48d581be85ea
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,
19 'actions_after_shutdown': 'destroy',
20 'actions_after_reboot': 'restart',
21 'actions_after_crash': 'destroy',
23 'PV_bootloader': '',
24 'PV_bootloader_args': '',
26 'PV_kernel': '/boot/vmlinuz-2.6.18-xenU',
27 'PV_ramdisk': '',
28 'PV_args': 'root=/dev/sda1 ro',
30 #'HVM_boot': '',
31 'platform_std_VGA': False,
32 'platform_serial': '',
33 'platform_localtime': False,
34 'platform_clock_offset': False,
35 'platform_enable_audio': False,
36 'PCI_bus': ''
37 }
39 vdi_cfg = {
40 'name_label': 'API_VDI',
41 'name_description': '',
42 'virtual_size': 100 * 1024,
43 'sector_size': 1024,
44 'type': 'system',
45 'parent': '',
46 'SR_name': 'QCoW',
47 'sharable': False,
48 'read_only': False,
49 }
51 vbd_cfg = {
52 'VDI': '',
53 'VM': '',
54 'device': 'sda2',
55 'mode': 'RW',
56 'type': 'disk',
57 'driver': 'paravirtualised',
58 }
60 local_vdi_cfg = {
61 'name_label': 'gentoo.amd64.img',
62 'name_description': '',
63 'location': 'file:/root/gentoo.amd64.img',
64 'virtual_size': 0,
65 'sector_size': 0,
66 'type': 'system',
67 'parent': '',
68 'SR_name': 'Local',
69 'sharable': False,
70 'read_only': False,
71 }
73 local_vbd_cfg = {
74 'VDI': '',
75 'VM': '',
76 'device': 'sda1',
77 'mode': 'RW',
78 'type': 'disk',
79 'driver': 'paravirtualised',
80 }
82 vif_cfg = {
83 'name': 'API_VIF',
84 'type': 'paravirtualised',
85 'device': '',
86 'network': '',
87 'MAC': '',
88 'MTU': 1500,
89 }
91 console_cfg = {
92 'protocol': 'rfb',
93 'other_config': {'vncunused': 1, 'vncpasswd': 'testing'},
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 # Create a console
161 console_cfg['VM'] = vm_uuid
162 console_uuid = execute(server, 'console.create',
163 (session, console_cfg))
164 print console_uuid
166 # Start the VM
167 execute(server, 'VM.start', (session, vm_uuid, False))
169 time.sleep(30)
171 test_suspend = False
172 if test_suspend:
173 print 'Suspending VM..'
174 execute(server, 'VM.suspend', (session, vm_uuid))
175 print 'Suspended VM.'
176 time.sleep(5)
177 print 'Resuming VM ...'
178 execute(server, 'VM.resume', (session, vm_uuid, False))
179 print 'Resumed VM.'
181 finally:
182 # Wait for user to say we're good to shut it down
183 while True:
184 destroy = raw_input('destroy VM? ')
185 if destroy[0] in ('y', 'Y'):
186 break
188 # Clean up
189 if vif_uuid:
190 execute(server, 'VIF.destroy', (session, vif_uuid))
192 if local_vbd_uuid:
193 execute(server, 'VBD.destroy', (session, local_vbd_uuid))
194 if local_vdi_uuid:
195 execute(server, 'VDI.destroy', (session, local_vdi_uuid))
197 if vbd_uuid:
198 execute(server, 'VBD.destroy', (session, vbd_uuid))
199 if vdi_uuid:
200 execute(server, 'VDI.destroy', (session, vdi_uuid))
202 if vm_uuid:
203 try:
204 execute(server, 'VM.hard_shutdown', (session, vm_uuid))
205 time.sleep(2)
206 except:
207 pass
209 execute(server, 'VM.destroy', (session, vm_uuid))
212 if __name__ == "__main__":
213 test_vm_create()