ia64/xen-unstable

view tools/python/scripts/test_hvm_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 2adbc1d22fe7
line source
1 #!/usr/bin/python
3 vm_cfg = {
4 'name_label': 'API_HVM',
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': '',
27 'PV_ramdisk': '',
28 'PV_args': '',
30 'HVM_boot': 'cda',
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 local_vdi_cfg = {
40 'name_label': 'gentoo.hvm',
41 'name_description': '',
42 'location': 'file:/root/gentoo.amd64.hvm.img',
43 'virtual_size': 0,
44 'sector_size': 0,
45 'type': 'system',
46 'parent': '',
47 'SR_name': 'Local',
48 'sharable': False,
49 'read_only': False,
50 }
52 local_vbd_cfg = {
53 'VDI': '',
54 'VM': '',
55 'device': 'hda',
56 'mode': 'RW',
57 'type': 'disk',
58 'driver': 'ioemu',
59 }
61 vif_cfg = {
62 'name': 'API_VIF',
63 'type': 'ioemu',
64 'device': '',
65 'network': '',
66 'MAC': '',
67 'MTU': 1500,
68 }
70 console_cfg = {
71 'protocol': 'rfb',
72 'other_config': {'vncunused': 1, 'vncpasswd': 'testing'},
73 }
76 import sys
77 import time
78 sys.path.append('/usr/lib/python')
80 from xapi import connect, execute
82 def test_vm_create():
83 server, session = connect()
84 vm_uuid = None
85 local_vdi_uuid = None
86 local_vbd_uuid = None
87 vif_uuid = None
89 # List all VMs
90 vm_list = execute(server, 'VM.get_all', (session,))
91 vm_names = []
92 for vm_uuid in vm_list:
93 vm_record = execute(server, 'VM.get_record', (session, vm_uuid))
94 vm_names.append(vm_record['name_label'])
96 # Get default SR
97 local_sr_list = execute(server, 'SR.get_by_name_label',
98 (session, local_vdi_cfg['SR_name']))
99 local_sr_uuid = local_sr_list[0]
101 # Get default network
102 net_list = execute(server, 'network.get_all', (session,))
103 net_uuid = net_list[0]
105 try:
106 # Create a new VM
107 print 'Create VM'
108 vm_uuid = execute(server, 'VM.create', (session, vm_cfg))
110 print 'Create VDI'
111 # Create a new VDI (Local)
112 local_vdi_cfg['SR'] = local_sr_uuid
113 local_vdi_uuid = execute(server, 'VDI.create',
114 (session, local_vdi_cfg))
116 print 'Create VBD'
117 # Create a new VBD (Local)
118 local_vbd_cfg['VM'] = vm_uuid
119 local_vbd_cfg['VDI'] = local_vdi_uuid
120 local_vbd_uuid = execute(server, 'VBD.create',
121 (session, local_vbd_cfg))
123 print 'Craete VIF'
124 # Create a new VIF
125 vif_cfg['network'] = net_uuid
126 vif_cfg['VM'] = vm_uuid
127 vif_uuid = execute(server, 'VIF.create', (session, vif_cfg))
129 # Create a console
130 console_cfg['VM'] = vm_uuid
131 console_uuid = execute(server, 'console.create',
132 (session, console_cfg))
133 print console_uuid
135 # Start the VM
136 execute(server, 'VM.start', (session, vm_uuid, False))
138 time.sleep(30)
140 test_suspend = False
141 if test_suspend:
142 print 'Suspending VM..'
143 execute(server, 'VM.suspend', (session, vm_uuid))
144 print 'Suspended VM.'
145 time.sleep(5)
146 print 'Resuming VM ...'
147 execute(server, 'VM.resume', (session, vm_uuid, False))
148 print 'Resumed VM.'
150 # Wait for user to say we're good to shut it down
151 while True:
152 destroy = raw_input('destroy VM? ')
153 if destroy[0] in ('y', 'Y'):
154 break
156 finally:
157 # Clean up
158 if vif_uuid:
159 execute(server, 'VIF.destroy', (session, vif_uuid))
161 if local_vbd_uuid:
162 execute(server, 'VBD.destroy', (session, local_vbd_uuid))
163 if local_vdi_uuid:
164 execute(server, 'VDI.destroy', (session, local_vdi_uuid))
166 if vm_uuid:
167 try:
168 execute(server, 'VM.hard_shutdown', (session, vm_uuid))
169 time.sleep(2)
170 except:
171 pass
172 try:
173 execute(server, 'VM.destroy', (session, vm_uuid))
174 except:
175 pass
178 if __name__ == "__main__":
179 test_vm_create()