summaryrefslogtreecommitdiffstats
path: root/nova/console
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/console
parentb437a98738c7a564205d1b27e36b844cd54445d1 (diff)
parentdd1e36b9690a2c2de18c565c496b25295a13d0aa (diff)
pulled changes from trunk
added console api to openstack api
Diffstat (limited to 'nova/console')
-rw-r--r--nova/console/api.py80
-rw-r--r--nova/console/manager.py18
2 files changed, 86 insertions, 12 deletions
diff --git a/nova/console/api.py b/nova/console/api.py
new file mode 100644
index 000000000..78bfe636b
--- /dev/null
+++ b/nova/console/api.py
@@ -0,0 +1,80 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright (c) 2010 Openstack, LLC.
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+"""
+Handles ConsoleProxy API requests
+"""
+
+from nova import exception
+from nova.db import base
+
+
+from nova import flags
+from nova import rpc
+
+
+FLAGS = flags.FLAGS
+
+class ConsoleAPI(base.Base):
+ """API for spining up or down console proxy connections"""
+
+ def __init__(self, **kwargs):
+ super(ConsoleAPI, self).__init__(**kwargs)
+
+ def get_consoles(self, context, instance_internal_id):
+ instance = self.db.instance_get_by_internal_id(context,
+ instance_internal_id)
+ return self.db.console_get_all_by_instance(context, instance['id'])
+
+ def get_console(self, context, instance_internal_id, console_id):
+ return self.db.console_get(context, console_id, instance_internal_id)
+
+ def delete_console(self, context, instance_internal_id, console_id):
+ instance = self.db.instance_get_by_internal_id(context,
+ instance_internal_id)
+ console = self.db.console_get(context,
+ console_id,
+ instance['id'])
+ pool = console['pool']
+ rpc.cast(context,
+ self.db.queue_get_for(context,
+ FLAGS.console_topic,
+ pool['host']),
+ {"method": "remove_console",
+ "args": {"console_id": console['id']}})
+
+ def create_console(self, context, instance_internal_id):
+ instance = self.db.instance_get_by_internal_id(context,
+ instance_internal_id)
+ #NOTE(mdragon): If we wanted to return this the console info
+ # here, as we would need to do a call.
+ # They can just do an index later to fetch
+ # console info. I am not sure which is better
+ # here.
+ rpc.cast(context,
+ self._get_console_topic(context, instance['host']),
+ {"method": "add_console",
+ "args": {"instance_id": instance['id']}})
+
+
+ def _get_console_topic(self, context, instance_host):
+ topic = self.db.queue_get_for(context,
+ FLAGS.compute_topic,
+ instance_host)
+ return rpc.call(context,
+ topic,
+ {"method": "get_console_topic", "args": {'fake': 1}})
diff --git a/nova/console/manager.py b/nova/console/manager.py
index 93c6fabce..e3cbdae0e 100644
--- a/nova/console/manager.py
+++ b/nova/console/manager.py
@@ -78,21 +78,15 @@ class ConsoleProxyManager(manager.Manager):
return console['id']
@exception.wrap_exception
- def remove_console(self, context, instance_id, **_kwargs):
- instance = self.db.instance_get(context, instance_id)
- host = instance['host']
- pool = self.get_pool_for_instance_host(context, host)
+ def remove_console(self, context, console_id, **_kwargs):
try:
- console = self.db.console_get_by_pool_instance(context,
- pool['id'],
- instance_id)
+ console = self.db.console_get(context, console_id)
except exception.NotFound:
- logging.debug(_('Tried to remove non-existant console in pool '
- '%(pool_id)s for instance %(instance_id)s.' %
- {'instance_id' : instance_id,
- 'pool_id' : pool['id']}))
+ logging.debug(_('Tried to remove non-existant console '
+ '%(console_id)s.') %
+ {'console_id' : console_id})
return
- self.db.console_delete(context, console['id'])
+ self.db.console_delete(context, console_id)
self.driver.teardown_console(context, console)