4
'name_label': 'API_HVM',
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',
19
'actions_after_shutdown': 'destroy',
20
'actions_after_reboot': 'restart',
21
'actions_after_crash': 'destroy',
24
'PV_bootloader_args': '',
31
'platform_std_VGA': False,
32
'platform_serial': '',
33
'platform_localtime': False,
34
'platform_clock_offset': False,
35
'platform_enable_audio': False,
40
'name_label': 'gentoo.hvm',
41
'name_description': '',
48
'other_config': {'location': 'file:/root/gentoo.amd64.hvm.img'},
71
'other_config': {'vncunused': 1, 'vncpasswd': 'testing'},
78
from xapi import connect, execute
81
server, session = connect()
88
vm_list = execute(server, 'VM.get_all', (session,))
90
for vm_uuid in vm_list:
91
vm_record = execute(server, 'VM.get_record', (session, vm_uuid))
92
vm_names.append(vm_record['name_label'])
95
local_sr_list = execute(server, 'SR.get_by_name_label',
96
(session, local_vdi_cfg['SR_name']))
97
local_sr_uuid = local_sr_list[0]
100
net_list = execute(server, 'network.get_all', (session,))
101
net_uuid = net_list[0]
106
vm_uuid = execute(server, 'VM.create', (session, vm_cfg))
109
# Create a new VDI (Local)
110
local_vdi_cfg['SR'] = local_sr_uuid
111
local_vdi_uuid = execute(server, 'VDI.create',
112
(session, local_vdi_cfg))
115
# Create a new VBD (Local)
116
local_vbd_cfg['VM'] = vm_uuid
117
local_vbd_cfg['VDI'] = local_vdi_uuid
118
local_vbd_uuid = execute(server, 'VBD.create',
119
(session, local_vbd_cfg))
123
vif_cfg['network'] = net_uuid
124
vif_cfg['VM'] = vm_uuid
125
vif_uuid = execute(server, 'VIF.create', (session, vif_cfg))
128
console_cfg['VM'] = vm_uuid
129
console_uuid = execute(server, 'console.create',
130
(session, console_cfg))
134
execute(server, 'VM.start', (session, vm_uuid, False))
140
print 'Suspending VM..'
141
execute(server, 'VM.suspend', (session, vm_uuid))
142
print 'Suspended VM.'
144
print 'Resuming VM ...'
145
execute(server, 'VM.resume', (session, vm_uuid, False))
148
# Wait for user to say we're good to shut it down
150
destroy = raw_input('destroy VM? ')
151
if destroy[0] in ('y', 'Y'):
157
execute(server, 'VIF.destroy', (session, vif_uuid))
160
execute(server, 'VBD.destroy', (session, local_vbd_uuid))
162
execute(server, 'VDI.destroy', (session, local_vdi_uuid))
166
execute(server, 'VM.hard_shutdown', (session, vm_uuid))
171
execute(server, 'VM.destroy', (session, vm_uuid))
176
if __name__ == "__main__":