Commit 2654f523 by Guba Sándor

instance: docstrings

parent 24872266
...@@ -265,6 +265,8 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, ...@@ -265,6 +265,8 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel,
@property @property
def is_running(self): def is_running(self):
"""Check if VM is in running state.
"""
return self.status == 'RUNNING' return self.status == 'RUNNING'
@property @property
...@@ -306,6 +308,8 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, ...@@ -306,6 +308,8 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel,
@classmethod @classmethod
def create(cls, params, disks, networks, req_traits, tags): def create(cls, params, disks, networks, req_traits, tags):
""" Create new Instance object.
"""
# create instance and do additional setup # create instance and do additional setup
inst = cls(**params) inst = cls(**params)
...@@ -397,7 +401,11 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, ...@@ -397,7 +401,11 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel,
self._do_renew(which='delete') self._do_renew(which='delete')
super(Instance, self).clean(*args, **kwargs) super(Instance, self).clean(*args, **kwargs)
def manual_state_change(self, new_state, reason=None, user=None): def manual_state_change(self, new_state="NOSTATE", reason=None, user=None):
""" Manually change state of an Instance.
Can be used to recover VM after administrator fixed problems.
"""
# TODO cancel concurrent activity (if exists) # TODO cancel concurrent activity (if exists)
act = InstanceActivity.create(code_suffix='manual_state_change', act = InstanceActivity.create(code_suffix='manual_state_change',
instance=self, user=user) instance=self, user=user)
...@@ -535,6 +543,8 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, ...@@ -535,6 +543,8 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel,
proto=proto) proto=proto)
def get_connect_command(self, use_ipv6=False): def get_connect_command(self, use_ipv6=False):
"""Returns a formatted connect string.
"""
try: try:
port = self.get_connect_port(use_ipv6=use_ipv6) port = self.get_connect_port(use_ipv6=use_ipv6)
host = self.get_connect_host(use_ipv6=use_ipv6) host = self.get_connect_host(use_ipv6=use_ipv6)
...@@ -567,6 +577,8 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, ...@@ -567,6 +577,8 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel,
return return
def get_vm_desc(self): def get_vm_desc(self):
"""Serialize Instance object to vmdriver.
"""
return { return {
'name': self.vm_name, 'name': self.vm_name,
'vcpu': self.num_cores, 'vcpu': self.num_cores,
...@@ -988,6 +1000,10 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, ...@@ -988,6 +1000,10 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel,
queue="localhost.man") queue="localhost.man")
def wake_up(self, user=None, task_uuid=None, timeout=60): def wake_up(self, user=None, task_uuid=None, timeout=60):
""" Wake up Virtual Machine from SUSPENDED state.
Power on Virtual Machine and load its memory from dump.
"""
if self.status not in ['SUSPENDED']: if self.status not in ['SUSPENDED']:
raise self.WrongStateError(self) raise self.WrongStateError(self)
...@@ -1119,11 +1135,18 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, ...@@ -1119,11 +1135,18 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel,
net.deploy() net.deploy()
def save_as_template_async(self, name, user=None, **kwargs): def save_as_template_async(self, name, user=None, **kwargs):
""" Save as template asynchronusly.
"""
return local_tasks.save_as_template.apply_async( return local_tasks.save_as_template.apply_async(
args=[self, name, user, kwargs], queue="localhost.man") args=[self, name, user, kwargs], queue="localhost.man")
def save_as_template(self, name, task_uuid=None, user=None, def save_as_template(self, name, task_uuid=None, user=None,
timeout=300, **kwargs): timeout=300, **kwargs):
""" Save Virtual Machine as a Template.
Template can be shared with groups and users.
Users can instantiate Virtual Machines from Templates.
"""
with instance_activity(code_suffix="save_as_template", instance=self, with instance_activity(code_suffix="save_as_template", instance=self,
task_uuid=task_uuid, user=user) as act: task_uuid=task_uuid, user=user) as act:
# prepare parameters # prepare parameters
......
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