summaryrefslogtreecommitdiffstats
path: root/nova/compute
diff options
context:
space:
mode:
authorMonsyne Dragon <mdragon@rackspace.com>2011-01-05 19:02:24 -0600
committerMonsyne Dragon <mdragon@rackspace.com>2011-01-05 19:02:24 -0600
commit8e18c84b03c442bd5272000712a55a6b60d037ed (patch)
tree696ffd9b8cd871e77204debf2cf725cd1400cb16 /nova/compute
parentb437a98738c7a564205d1b27e36b844cd54445d1 (diff)
parentdd1e36b9690a2c2de18c565c496b25295a13d0aa (diff)
downloadnova-8e18c84b03c442bd5272000712a55a6b60d037ed.tar.gz
nova-8e18c84b03c442bd5272000712a55a6b60d037ed.tar.xz
nova-8e18c84b03c442bd5272000712a55a6b60d037ed.zip
pulled changes from trunk
added console api to openstack api
Diffstat (limited to 'nova/compute')
-rw-r--r--nova/compute/api.py27
-rw-r--r--nova/compute/manager.py44
2 files changed, 70 insertions, 1 deletions
diff --git a/nova/compute/api.py b/nova/compute/api.py
index a47703461..07c69bd31 100644
--- a/nova/compute/api.py
+++ b/nova/compute/api.py
@@ -74,6 +74,7 @@ class ComputeAPI(base.Base):
max_count=1, kernel_id=None, ramdisk_id=None,
display_name='', description='', key_name=None,
key_data=None, security_group='default',
+ availability_zone=None,
user_data=None,
generate_hostname=generate_default_hostname):
"""Create the number of instances requested if quote and
@@ -141,7 +142,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,
+ 'availability_zone': availability_zone}
elevated = context.elevated()
instances = []
@@ -257,6 +259,15 @@ class ComputeAPI(base.Base):
def get_instance(self, context, instance_id):
return self.db.instance_get_by_internal_id(context, instance_id)
+ def snapshot(self, context, instance_id, name):
+ """Snapshot the given instance."""
+ instance = self.db.instance_get_by_internal_id(context, instance_id)
+ host = instance['host']
+ rpc.cast(context,
+ self.db.queue_get_for(context, FLAGS.compute_topic, host),
+ {"method": "snapshot_instance",
+ "args": {"instance_id": instance['id'], "name": name}})
+
def reboot(self, context, instance_id):
"""Reboot the given instance."""
instance = self.db.instance_get_by_internal_id(context, instance_id)
@@ -284,6 +295,20 @@ class ComputeAPI(base.Base):
{"method": "unpause_instance",
"args": {"instance_id": instance['id']}})
+ def get_diagnostics(self, context, instance_id):
+ """Retrieve diagnostics for the given instance."""
+ instance = self.db.instance_get_by_internal_id(context, instance_id)
+ host = instance["host"]
+ return rpc.call(context,
+ self.db.queue_get_for(context, FLAGS.compute_topic, host),
+ {"method": "get_diagnostics",
+ "args": {"instance_id": instance["id"]}})
+
+ def get_actions(self, context, instance_id):
+ """Retrieve actions for the given instance."""
+ instance = self.db.instance_get_by_internal_id(context, instance_id)
+ return self.db.instance_get_actions(context, instance["id"])
+
def suspend(self, context, instance_id):
"""suspend the instance with instance_id"""
instance = self.db.instance_get_by_internal_id(context, instance_id)
diff --git a/nova/compute/manager.py b/nova/compute/manager.py
index 295e75eca..666854d2c 100644
--- a/nova/compute/manager.py
+++ b/nova/compute/manager.py
@@ -36,6 +36,7 @@ terminating it.
import datetime
import logging
+import socket
from nova import exception
from nova import flags
@@ -51,6 +52,9 @@ flags.DEFINE_string('compute_driver', 'nova.virt.connection.get_connection',
'Driver to use for controlling virtualization')
flags.DEFINE_string('stub_network', False,
'Stub network related code')
+flags.DEFINE_string('console_host', socket.gethostname(),
+ 'Console proxy host to use to connect to instances on'
+ 'this host.')
class ComputeManager(manager.Manager):
@@ -85,6 +89,15 @@ class ComputeManager(manager.Manager):
state = power_state.NOSTATE
self.db.instance_set_state(context, instance_id, state)
+ def get_console_topic(self, context, **_kwargs):
+ """Retrieves the console host for a project on this host
+ Currently this is just set in the flags for each compute
+ host."""
+ #TODO(mdragon): perhaps make this variable by console_type?
+ return self.db.queue_get_for(context,
+ FLAGS.console_topic,
+ FLAGS.console_host)
+
def get_network_topic(self, context, **_kwargs):
"""Retrieves the network host for a project on this host"""
# TODO(vish): This method should be memoized. This will make
@@ -230,6 +243,27 @@ class ComputeManager(manager.Manager):
self._update_state(context, instance_id)
@exception.wrap_exception
+ def snapshot_instance(self, context, instance_id, name):
+ """Snapshot an instance on this server."""
+ context = context.elevated()
+ instance_ref = self.db.instance_get(context, instance_id)
+
+ #NOTE(sirp): update_state currently only refreshes the state field
+ # if we add is_snapshotting, we will need this refreshed too,
+ # potentially?
+ self._update_state(context, instance_id)
+
+ logging.debug(_('instance %s: snapshotting'), instance_ref['name'])
+ if instance_ref['state'] != power_state.RUNNING:
+ logging.warn(_('trying to snapshot a non-running '
+ 'instance: %s (state: %s excepted: %s)'),
+ instance_ref['internal_id'],
+ instance_ref['state'],
+ power_state.RUNNING)
+
+ self.driver.snapshot(instance_ref, name)
+
+ @exception.wrap_exception
def rescue_instance(self, context, instance_id):
"""Rescue an instance on this server."""
context = context.elevated()
@@ -302,6 +336,16 @@ class ComputeManager(manager.Manager):
result))
@exception.wrap_exception
+ def get_diagnostics(self, context, instance_id):
+ """Retrieve diagnostics for an instance on this server."""
+ instance_ref = self.db.instance_get(context, instance_id)
+
+ if instance_ref["state"] == power_state.RUNNING:
+ logging.debug(_("instance %s: retrieving diagnostics"),
+ instance_ref["internal_id"])
+ return self.driver.get_diagnostics(instance_ref)
+
+ @exception.wrap_exception
def suspend_instance(self, context, instance_id):
"""suspend the instance with instance_id"""
context = context.elevated()