Commit cbcf6f97 by Guba Sándor

implemented hot-attach functions

parent e5780f5a
...@@ -33,7 +33,7 @@ from .models import ( ...@@ -33,7 +33,7 @@ from .models import (
Instance, InstanceActivity, InstanceTemplate, Interface, Node, Instance, InstanceActivity, InstanceTemplate, Interface, Node,
NodeActivity, NodeActivity,
) )
from string import ascii_lowercase
logger = getLogger(__name__) logger = getLogger(__name__)
...@@ -98,6 +98,7 @@ class AddInterfaceOperation(InstanceOperation): ...@@ -98,6 +98,7 @@ class AddInterfaceOperation(InstanceOperation):
managed=managed, owner=user, vlan=vlan) managed=managed, owner=user, vlan=vlan)
if self.instance.is_running: if self.instance.is_running:
self.instance.attach_network(net)
net.deploy() net.deploy()
return net return net
...@@ -107,6 +108,7 @@ register_operation(AddInterfaceOperation) ...@@ -107,6 +108,7 @@ register_operation(AddInterfaceOperation)
class CreateDiskOperation(InstanceOperation): class CreateDiskOperation(InstanceOperation):
activity_code_suffix = 'create_disk' activity_code_suffix = 'create_disk'
id = 'create_disk' id = 'create_disk'
name = _("create disk") name = _("create disk")
...@@ -115,20 +117,28 @@ class CreateDiskOperation(InstanceOperation): ...@@ -115,20 +117,28 @@ class CreateDiskOperation(InstanceOperation):
def check_precond(self): def check_precond(self):
super(CreateDiskOperation, self).check_precond() super(CreateDiskOperation, self).check_precond()
# TODO remove check when hot-attach is implemented if self.instance.status not in ['STOPPED', 'PENDING', 'RUNNING']:
if self.instance.status not in ['STOPPED', 'PENDING']:
raise self.instance.WrongStateError(self.instance) raise self.instance.WrongStateError(self.instance)
def _operation(self, user, size, name=None): def _operation(self, user, size, activity, name=None):
# TODO implement with hot-attach when it'll be available
from storage.models import Disk from storage.models import Disk
if not name: if not name:
name = "new disk" name = "new disk"
disk = Disk.create(size=size, name=name, type="qcow2-norm") disk = Disk.create(size=size, name=name, type="qcow2-norm")
disk.full_clean() disk.full_clean()
devnums = list(ascii_lowercase)
for d in self.instance.disks.all():
devnums.remove(d.dev_num)
disk.dev_num = devnums.pop(0)
self.instance.disks.add(disk) self.instance.disks.add(disk)
if self.instance.is_running:
with activity.sub_activity('deploying_disk'):
disk.deploy()
with activity.sub_activity('attach_disk'):
self.instance.attach_disk(disk)
register_operation(CreateDiskOperation) register_operation(CreateDiskOperation)
...@@ -143,19 +153,26 @@ class DownloadDiskOperation(InstanceOperation): ...@@ -143,19 +153,26 @@ class DownloadDiskOperation(InstanceOperation):
def check_precond(self): def check_precond(self):
super(DownloadDiskOperation, self).check_precond() super(DownloadDiskOperation, self).check_precond()
# TODO remove check when hot-attach is implemented if self.instance.status not in ['STOPPED', 'PENDING', 'RUNNING']:
if self.instance.status not in ['STOPPED', 'PENDING']:
raise self.instance.WrongStateError(self.instance) raise self.instance.WrongStateError(self.instance)
def _operation(self, user, url, task, activity, name=None): def _operation(self, user, url, task, activity, name=None):
activity.result = url activity.result = url
# TODO implement with hot-attach when it'll be available
from storage.models import Disk from storage.models import Disk
disk = Disk.download(url=url, name=name, task=task) disk = Disk.download(url=url, name=name, task=task)
devnums = list(ascii_lowercase)
for d in self.instance.disks.all():
devnums.remove(d.dev_num)
disk.dev_num = devnums.pop(0)
disk.full_clean() disk.full_clean()
disk.save()
self.instance.disks.add(disk) self.instance.disks.add(disk)
if self.instance.is_running and disk.type not in ["iso"]:
with activity.sub_activity('attach_disk'):
self.instance.attach_disk(disk)
register_operation(DownloadDiskOperation) register_operation(DownloadDiskOperation)
...@@ -329,6 +346,7 @@ class RemoveInterfaceOperation(InstanceOperation): ...@@ -329,6 +346,7 @@ class RemoveInterfaceOperation(InstanceOperation):
def _operation(self, activity, user, system, interface): def _operation(self, activity, user, system, interface):
if self.instance.is_running: if self.instance.is_running:
self.instance.detach_network(interface)
interface.shutdown() interface.shutdown()
interface.destroy() interface.destroy()
...@@ -347,12 +365,13 @@ class RemoveDiskOperation(InstanceOperation): ...@@ -347,12 +365,13 @@ class RemoveDiskOperation(InstanceOperation):
def check_precond(self): def check_precond(self):
super(RemoveDiskOperation, self).check_precond() super(RemoveDiskOperation, self).check_precond()
# TODO remove check when hot-detach is implemented if self.instance.status not in ['STOPPED', 'RUNNING']:
if self.instance.status not in ['STOPPED']:
raise self.instance.WrongStateError(self.instance) raise self.instance.WrongStateError(self.instance)
def _operation(self, activity, user, system, disk): def _operation(self, activity, user, system, disk):
# TODO implement with hot-detach when it'll be available if self.instance.is_running and disk.type not in ["iso"]:
with activity.sub_activity('detach_disk'):
self.instance.detach_disk(disk)
return self.instance.disks.remove(disk) return self.instance.disks.remove(disk)
......
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 sign in to comment