Commit 992883f9 authored by Antoine Millet's avatar Antoine Millet

Added undefine method handler.

parent 38300207
......@@ -242,6 +242,45 @@ class CliHandler(OnlineCCHandler):
self._check(conn, 'resume', query)
return self._vm_action(query, 'vm_resume')
@listed
def undefine(self, conn, query, delete_storage=True):
'''
Undefine selected virtual machines.
:param query: the tql query to select objects.
:param delete_storage: delete storage of vm.
:return: a dict where key is the id of a selected object, and the value
a tuple (errcode, message) where errcode is (success|error|warn) and
message an error message or the output of the command in case of
success.
'''
self._check(conn, 'undefine', query)
#FIXME: When tag globbing will be implemented, the list of tags to
# show will be: r, p, h, disk*
# I ask "all tags" pending implementation.
objects = self._server.list(query, show=set(('*',)))
errs = Reporter()
for obj in objects:
if obj['r'] != 'vm':
errs.error(obj['id'], 'bad role')
continue
try:
hvcon = self._server.get_connection(obj['p'])
except KeyError:
errs.error(obj['id'], 'hypervisor not connected')
else:
if delete_storage:
for disk in obj.get('disk', '').split():
pool = obj.get('disk%s_pool' % disk)
name = obj.get('disk%s_vol' % disk)
hvcon.proxy.vol_delete(pool, name)
hvcon.proxy.vm_undefine(obj['h'])
errs.success(obj['id'], 'vm undefined')
return errs.get_dict()
@listed
def passwd(self, conn, query, password, method='ssha'):
'''
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment