summaryrefslogtreecommitdiffstats
path: root/nova/compute
diff options
context:
space:
mode:
authorTrey Morris <trey.morris@rackspace.com>2010-12-28 23:55:58 -0600
committerTrey Morris <trey.morris@rackspace.com>2010-12-28 23:55:58 -0600
commit8aea573bd2e44e152fb4ef1627640bab1818dede (patch)
tree87c51a14f8e17f570aa0e473cf3200877df81ea9 /nova/compute
parent675ca7c5f38af0fa1150936e881482aa20fdaa45 (diff)
initial lock functionality commit
Diffstat (limited to 'nova/compute')
-rw-r--r--nova/compute/api.py35
-rw-r--r--nova/compute/manager.py24
2 files changed, 58 insertions, 1 deletions
diff --git a/nova/compute/api.py b/nova/compute/api.py
index a47703461..361ab9914 100644
--- a/nova/compute/api.py
+++ b/nova/compute/api.py
@@ -141,7 +141,8 @@ class ComputeAPI(base.Base):
'display_description': description,
'user_data': user_data or '',
'key_name': key_name,
- 'key_data': key_data}
+ 'key_data': key_data,
+ 'locked': False}
elevated = context.elevated()
instances = []
@@ -319,3 +320,35 @@ class ComputeAPI(base.Base):
self.db.queue_get_for(context, FLAGS.compute_topic, host),
{"method": "unrescue_instance",
"args": {"instance_id": instance['id']}})
+
+ def lock(self, context, instance_id):
+ """
+ lock the instance with instance_id
+
+ """
+ instance = self.get_instance(context, instance_id)
+ host = instance['host']
+ rpc.cast(context,
+ self.db.queue_get_for(context, FLAGS.compute_topic, host),
+ {"method": "lock_instance",
+ "args": {"instance_id": instance['id']}})
+
+ def unlock(self, context, instance_id):
+ """
+ unlock the instance with instance_id
+
+ """
+ instance = self.get_instance(context, instance_id)
+ host = instance['host']
+ rpc.cast(context,
+ self.db.queue_get_for(context, FLAGS.compute_topic, host),
+ {"method": "unlock_instance",
+ "args": {"instance_id": instance['id']}})
+
+ def get_lock(self, context, instance_id):
+ """
+ return the boolean state of (instance with instance_id)'s lock
+
+ """
+ instance = self.get_instance(context, instance_id)
+ return instance['locked']
diff --git a/nova/compute/manager.py b/nova/compute/manager.py
index 70b175e7c..05f1e44a2 100644
--- a/nova/compute/manager.py
+++ b/nova/compute/manager.py
@@ -330,6 +330,30 @@ class ComputeManager(manager.Manager):
result))
@exception.wrap_exception
+ def lock_instance(self, context, instance_id):
+ """
+ lock the instance with instance_id
+
+ """
+ context = context.elevated()
+ instance_ref = self.db.instance_get(context, instance_id)
+
+ logging.debug(_('instance %s: locking'), instance_ref['internal_id'])
+ self.db.instance_set_lock(context, instance_id, True)
+
+ @exception.wrap_exception
+ def unlock_instance(self, context, instance_id):
+ """
+ unlock the instance with instance_id
+
+ """
+ context = context.elevated()
+ instance_ref = self.db.instance_get(context, instance_id)
+
+ logging.debug(_('instance %s: unlocking'), instance_ref['internal_id'])
+ self.db.instance_set_lock(context, instance_id, False)
+
+ @exception.wrap_exception
def get_console_output(self, context, instance_id):
"""Send the console output for an instance."""
context = context.elevated()