ia64/xen-unstable

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