Commit 6e3194a9 authored by Antoine Millet's avatar Antoine Millet

Implemented vm_attach_disk and vm_detach_disk VM handlers

parent 9aa3244a
......@@ -115,6 +115,10 @@ class NodeConfigParser(object):
self.rescue_script = config.get('node', 'rescue_script', default_rescue_script)
default_vlan_script = 'hkvm-vlan'
self.vlan_script = config.get('node', 'vlan_script', default_vlan_script)
default_attach_script = 'hkvm-attach'
self.attach_script = config.get('node', 'attach_script', default_attach_script)
default_detach_script = 'hkvm-detach'
self.detach_script = config.get('node', 'detach_script', default_detach_script)
# RPC handler ACLs
acl_section_name = 'node_handler'
......
......@@ -274,6 +274,36 @@ class Handler(HostHandler):
logger.error(msg)
raise UndefinedDomain(msg)
@libvirt_handler
def vm_attach_disk(self, name, pool, volume, driver='virtio', bps=0, iops=0):
logger.debug('VM attach disk %s/%s -> %s ', pool, volume, name)
self.hypervisor.storage.update()
if name in self.hypervisor.domains:
rcode, output = execute(self.main, [self.main.config.attach_script,
'--driver', driver,
'--bps', str(bps),
'--iops', str(iops),
name, pool, volume])
if rcode != 0:
raise RuntimeError(output.strip().split('\n')[-1].strip())
else:
msg = 'Cannot attach disk on VM %s because it is not defined' % name
logger.error(msg)
raise UndefinedDomain(msg)
@libvirt_handler
def vm_detach_disk(self, name, pool, volume):
logger.debug('VM detach disk %s/%s <- %s ', pool, volume, name)
if name in self.hypervisor.domains:
rcode, output = execute(self.main, [self.main.config.detach_script,
name, pool, volume])
if rcode != 0:
raise RuntimeError(output.strip().split('\n')[-1].strip())
else:
msg = 'Cannot detach disk from VM %s because it is not defined' % name
logger.error(msg)
raise UndefinedDomain(msg)
@libvirt_handler
def vm_stop(self, name):
logger.debug('VM stop %s', name)
......
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