/usr/share/pyshared/nova/console/api.py is in python-nova 2012.1-0ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | # 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.db import base
from nova import flags
from nova import rpc
from nova import utils
FLAGS = flags.FLAGS
class API(base.Base):
"""API for spinning up or down console proxy connections."""
def __init__(self, **kwargs):
super(API, self).__init__(**kwargs)
def get_consoles(self, context, instance_id):
instance_id = self._translate_uuid_if_necessary(context, instance_id)
return self.db.console_get_all_by_instance(context, instance_id)
def get_console(self, context, instance_id, console_id):
instance_id = self._translate_uuid_if_necessary(context, instance_id)
return self.db.console_get(context, console_id, instance_id)
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']}})
def create_console(self, context, instance_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.
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']}})
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}})
def _translate_uuid_if_necessary(self, context, instance_id):
if utils.is_uuid_like(instance_id):
instance = self.db.instance_get_by_uuid(context, instance_id)
instance_id = instance['id']
return instance_id
def _get_instance(self, context, instance_id):
if utils.is_uuid_like(instance_id):
instance = self.db.instance_get_by_uuid(context, instance_id)
else:
instance = self.db.instance_get(context, instance_id)
return instance
|