summaryrefslogtreecommitdiffstats
path: root/nova/console
diff options
context:
space:
mode:
authorRussell Bryant <rbryant@redhat.com>2012-05-16 16:31:39 -0400
committerRussell Bryant <rbryant@redhat.com>2012-05-23 07:11:03 -0400
commitf50ce35c9cf2e05d205485586da1cb6d5433ba56 (patch)
treed24d4c4900a63bbc695609056a7d45adf9b7ec32 /nova/console
parent82f38e44ae5504bc56e05446266912cb700a329e (diff)
downloadnova-f50ce35c9cf2e05d205485586da1cb6d5433ba56.tar.gz
nova-f50ce35c9cf2e05d205485586da1cb6d5433ba56.tar.xz
nova-f50ce35c9cf2e05d205485586da1cb6d5433ba56.zip
Add version to console rpc API.
Part of blueprint versioned-rpc-apis. Change-Id: I17d6e3094c56d8628688dabdc8d40b2f4f815af4
Diffstat (limited to 'nova/console')
-rw-r--r--nova/console/api.py23
-rw-r--r--nova/console/manager.py2
-rw-r--r--nova/console/rpcapi.py47
3 files changed, 58 insertions, 14 deletions
diff --git a/nova/console/api.py b/nova/console/api.py
index dd166052f..0feaae488 100644
--- a/nova/console/api.py
+++ b/nova/console/api.py
@@ -17,6 +17,7 @@
"""Handles ConsoleProxy API requests."""
+from nova.console import rpcapi as console_rpcapi
from nova.db import base
from nova import flags
from nova import rpc
@@ -42,16 +43,11 @@ class API(base.Base):
def delete_console(self, context, instance_id, console_id):
instance_id = self._translate_uuid_if_necessary(context, instance_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']}})
+ console = self.db.console_get(context, console_id, instance_id)
+ topic = self.db.queue_get_for(context, FLAGS.console_topic,
+ pool['host'])
+ rpcapi = console_rpcapi.ConsoleAPI(topic=topic)
+ rpcapi.remove_console(context, console['id'])
def create_console(self, context, instance_id):
#NOTE(mdragon): If we wanted to return this the console info
@@ -60,10 +56,9 @@ class API(base.Base):
# console info. I am not sure which is better
# here.
instance = self._get_instance(context, instance_id)
- rpc.cast(context,
- self._get_console_topic(context, instance['host']),
- {'method': 'add_console',
- 'args': {'instance_id': instance['id']}})
+ topic = self._get_console_topic(context, instance['host']),
+ rpcapi = console_rpcapi.ConsoleAPI(topic=topic)
+ rpcapi.add_console(context, instance['id'])
def _get_console_topic(self, context, instance_host):
topic = self.db.queue_get_for(context,
diff --git a/nova/console/manager.py b/nova/console/manager.py
index 335de3284..8a42b449a 100644
--- a/nova/console/manager.py
+++ b/nova/console/manager.py
@@ -53,6 +53,8 @@ class ConsoleProxyManager(manager.Manager):
"""
+ RPC_API_VERSION = '1.0'
+
def __init__(self, console_driver=None, *args, **kwargs):
if not console_driver:
console_driver = FLAGS.console_driver
diff --git a/nova/console/rpcapi.py b/nova/console/rpcapi.py
new file mode 100644
index 000000000..8f0c5b97f
--- /dev/null
+++ b/nova/console/rpcapi.py
@@ -0,0 +1,47 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2012, Red Hat, Inc.
+#
+# 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.
+
+"""
+Client side of the console RPC API.
+"""
+
+from nova import flags
+import nova.rpc.proxy
+
+
+FLAGS = flags.FLAGS
+
+
+class ConsoleAPI(nova.rpc.proxy.RpcProxy):
+ '''Client side of the console rpc API.
+
+ API version history:
+
+ 1.0 - Initial version.
+ '''
+
+ RPC_API_VERSION = '1.0'
+
+ def __init__(self, topic=None):
+ topic = topic if topic else FLAGS.console_topic
+ super(ConsoleAPI, self).__init__(topic=topic,
+ default_version=self.RPC_API_VERSION)
+
+ def add_console(self, ctxt, instance_id):
+ self.cast(ctxt, self.make_msg('add_console', instance_id=instance_id))
+
+ def remove_console(self, ctxt, console_id):
+ self.cast(ctxt, self.make_msg('remove_console', console_id=console_id))