43
44
VMHelper.late_import()
45
46
def list_instances(self):
46
""" List VM instances """
47
return [self._session.get_xenapi().VM.get_name_label(vm) \
48
for vm in self._session.get_xenapi().VM.get_all()]
47
"""List VM instances"""
49
for vm in self._session.get_xenapi().VM.get_all():
50
rec = self._session.get_xenapi().VM.get_record(vm)
51
if not rec["is_a_template"] and not rec["is_control_domain"]:
52
vms.append(rec["name_label"])
50
55
def spawn(self, instance):
51
""" Create VM instance """
56
"""Create VM instance"""
52
57
vm = VMHelper.lookup(self._session, instance.name)
54
59
raise Exception('Attempted to create non-unique name %s' %
82
87
def reboot(self, instance):
83
""" Reboot VM instance """
88
"""Reboot VM instance"""
84
89
instance_name = instance.name
85
90
vm = VMHelper.lookup(self._session, instance_name)
87
92
raise Exception('instance not present %s' % instance_name)
88
93
task = self._session.call_xenapi('Async.VM.clean_reboot', vm)
89
self._session.wait_for_task(task)
94
self._session.wait_for_task(instance.id, task)
91
96
def destroy(self, instance):
92
""" Destroy VM instance """
97
"""Destroy VM instance"""
93
98
vm = VMHelper.lookup(self._session, instance.name)
95
100
# Don't complain, just return. This lets us clean up instances
101
106
task = self._session.call_xenapi('Async.VM.hard_shutdown',
103
self._session.wait_for_task(task)
108
self._session.wait_for_task(instance.id, task)
104
109
except XenAPI.Failure, exc:
105
110
logging.warn(exc)
110
115
task = self._session.call_xenapi('Async.VDI.destroy', vdi)
111
self._session.wait_for_task(task)
116
self._session.wait_for_task(instance.id, task)
112
117
except XenAPI.Failure, exc:
113
118
logging.warn(exc)
115
120
task = self._session.call_xenapi('Async.VM.destroy', vm)
116
self._session.wait_for_task(task)
117
except XenAPI.Failure, exc:
121
self._session.wait_for_task(instance.id, task)
122
except XenAPI.Failure, exc:
125
def _wait_with_callback(self, instance_id, task, callback):
128
ret = self._session.wait_for_task(instance_id, task)
129
except XenAPI.Failure, exc:
133
def pause(self, instance, callback):
134
"""Pause VM instance"""
135
instance_name = instance.name
136
vm = VMHelper.lookup(self._session, instance_name)
138
raise Exception('instance not present %s' % instance_name)
139
task = self._session.call_xenapi('Async.VM.pause', vm)
140
self._wait_with_callback(instance.id, task, callback)
142
def unpause(self, instance, callback):
143
"""Unpause VM instance"""
144
instance_name = instance.name
145
vm = VMHelper.lookup(self._session, instance_name)
147
raise Exception('instance not present %s' % instance_name)
148
task = self._session.call_xenapi('Async.VM.unpause', vm)
149
self._wait_with_callback(instance.id, task, callback)
120
151
def get_info(self, instance_id):
121
""" Return data about VM instance """
152
"""Return data about VM instance"""
122
153
vm = VMHelper.lookup_blocking(self._session, instance_id)
124
155
raise Exception('instance not present %s' % instance_id)
134
165
return VMHelper.compile_diagnostics(self._session, rec)
136
167
def get_console_output(self, instance):
137
""" Return snapshot of console """
168
"""Return snapshot of console"""
138
169
# TODO: implement this to fix pylint!
139
170
return 'FAKE CONSOLE OUTPUT of instance'