Commit e445a532 by Őry Máté

vm: make Instance.allocate_node smarter

parent bf6f89c8
......@@ -910,10 +910,16 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
delete_dump.apply_async(args=[self.mem_dump['path']],
queue=queue_name).get(timeout=timeout)
def allocate_node(self):
if self.node is None:
self.node = self.select_node()
def allocate_node(self, activity):
if self.node is not None:
return None
with activity.sub_activity(
'scheduling',
readable_name=ugettext_noop("schedule")) as sa:
sa.result = self.node = self.select_node()
self.save()
return self.node
def yield_node(self):
if self.node is not None:
......
......@@ -276,7 +276,7 @@ class DeployOperation(InstanceOperation):
def _operation(self, activity, timeout=15):
# Allocate VNC port and host node
self.instance.allocate_vnc_port()
self.instance.allocate_node()
self.instance.allocate_node(activity)
# Deploy virtual images
with activity.sub_activity(
......@@ -385,12 +385,7 @@ class MigrateOperation(InstanceOperation):
def _operation(self, activity, to_node=None, timeout=120):
if not to_node:
with activity.sub_activity('scheduling',
readable_name=ugettext_noop(
"schedule")) as sa:
to_node = self.instance.select_node()
sa.result = to_node
self.instance.allocate_node(activity)
try:
with activity.sub_activity(
'migrate_vm', readable_name=create_readable(
......@@ -744,7 +739,7 @@ class WakeUpOperation(InstanceOperation):
def _operation(self, activity, timeout=60):
# Schedule vm
self.instance.allocate_vnc_port()
self.instance.allocate_node()
self.instance.allocate_node(activity)
# Resume vm
with activity.sub_activity(
......@@ -758,13 +753,6 @@ class WakeUpOperation(InstanceOperation):
"deploy network")):
self.instance.deploy_net()
activity.result = create_readable(
"",
ugettext_noop(
"Scheduled to %(node)s" % {'node': self.instance.node.name}
)
)
try:
self.instance.renew(parent_activity=activity)
except:
......
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