docstring cleanup, console
This commit is contained in:
@@ -15,23 +15,19 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
"""
|
||||
Handles ConsoleProxy API requests
|
||||
"""
|
||||
"""Handles ConsoleProxy API requests."""
|
||||
|
||||
from nova import exception
|
||||
from nova.db import base
|
||||
|
||||
|
||||
from nova import flags
|
||||
from nova import rpc
|
||||
from nova.db import base
|
||||
|
||||
|
||||
FLAGS = flags.FLAGS
|
||||
|
||||
|
||||
class API(base.Base):
|
||||
"""API for spining up or down console proxy connections"""
|
||||
"""API for spinning up or down console proxy connections."""
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(API, self).__init__(**kwargs)
|
||||
@@ -51,8 +47,8 @@ class API(base.Base):
|
||||
self.db.queue_get_for(context,
|
||||
FLAGS.console_topic,
|
||||
pool['host']),
|
||||
{"method": "remove_console",
|
||||
"args": {"console_id": console['id']}})
|
||||
{'method': 'remove_console',
|
||||
'args': {'console_id': console['id']}})
|
||||
|
||||
def create_console(self, context, instance_id):
|
||||
instance = self.db.instance_get(context, instance_id)
|
||||
@@ -63,13 +59,12 @@ class API(base.Base):
|
||||
# here.
|
||||
rpc.cast(context,
|
||||
self._get_console_topic(context, instance['host']),
|
||||
{"method": "add_console",
|
||||
"args": {"instance_id": instance_id}})
|
||||
{'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}})
|
||||
return rpc.call(context, topic, {'method': 'get_console_topic',
|
||||
'args': {'fake': 1}})
|
||||
|
||||
@@ -15,9 +15,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
"""
|
||||
Fake ConsoleProxy driver for tests.
|
||||
"""
|
||||
"""Fake ConsoleProxy driver for tests."""
|
||||
|
||||
from nova import exception
|
||||
|
||||
@@ -27,32 +25,32 @@ class FakeConsoleProxy(object):
|
||||
|
||||
@property
|
||||
def console_type(self):
|
||||
return "fake"
|
||||
return 'fake'
|
||||
|
||||
def setup_console(self, context, console):
|
||||
"""Sets up actual proxies"""
|
||||
"""Sets up actual proxies."""
|
||||
pass
|
||||
|
||||
def teardown_console(self, context, console):
|
||||
"""Tears down actual proxies"""
|
||||
"""Tears down actual proxies."""
|
||||
pass
|
||||
|
||||
def init_host(self):
|
||||
"""Start up any config'ed consoles on start"""
|
||||
"""Start up any config'ed consoles on start."""
|
||||
pass
|
||||
|
||||
def generate_password(self, length=8):
|
||||
"""Returns random console password"""
|
||||
return "fakepass"
|
||||
"""Returns random console password."""
|
||||
return 'fakepass'
|
||||
|
||||
def get_port(self, context):
|
||||
"""get available port for consoles that need one"""
|
||||
"""Get available port for consoles that need one."""
|
||||
return 5999
|
||||
|
||||
def fix_pool_password(self, password):
|
||||
"""Trim password to length, and any other massaging"""
|
||||
"""Trim password to length, and any other massaging."""
|
||||
return password
|
||||
|
||||
def fix_console_password(self, password):
|
||||
"""Trim password to length, and any other massaging"""
|
||||
"""Trim password to length, and any other massaging."""
|
||||
return password
|
||||
|
||||
@@ -15,9 +15,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
"""
|
||||
Console Proxy Service
|
||||
"""
|
||||
"""Console Proxy Service."""
|
||||
|
||||
import functools
|
||||
import socket
|
||||
@@ -29,6 +27,7 @@ from nova import manager
|
||||
from nova import rpc
|
||||
from nova import utils
|
||||
|
||||
|
||||
FLAGS = flags.FLAGS
|
||||
flags.DEFINE_string('console_driver',
|
||||
'nova.console.xvp.XVPConsoleProxy',
|
||||
@@ -41,9 +40,11 @@ flags.DEFINE_string('console_public_hostname',
|
||||
|
||||
|
||||
class ConsoleProxyManager(manager.Manager):
|
||||
"""Sets up and tears down any console proxy connections.
|
||||
|
||||
""" Sets up and tears down any proxy connections needed for accessing
|
||||
instance consoles securely"""
|
||||
Needed for accessing instance consoles securely.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, console_driver=None, *args, **kwargs):
|
||||
if not console_driver:
|
||||
@@ -67,7 +68,7 @@ class ConsoleProxyManager(manager.Manager):
|
||||
pool['id'],
|
||||
instance_id)
|
||||
except exception.NotFound:
|
||||
logging.debug(_("Adding console"))
|
||||
logging.debug(_('Adding console'))
|
||||
if not password:
|
||||
password = utils.generate_password(8)
|
||||
if not port:
|
||||
@@ -115,8 +116,8 @@ class ConsoleProxyManager(manager.Manager):
|
||||
self.db.queue_get_for(context,
|
||||
FLAGS.compute_topic,
|
||||
instance_host),
|
||||
{"method": "get_console_pool_info",
|
||||
"args": {"console_type": console_type}})
|
||||
{'method': 'get_console_pool_info',
|
||||
'args': {'console_type': console_type}})
|
||||
pool_info['password'] = self.driver.fix_pool_password(
|
||||
pool_info['password'])
|
||||
pool_info['host'] = self.host
|
||||
|
||||
@@ -15,9 +15,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
"""
|
||||
VMRC console drivers.
|
||||
"""
|
||||
"""VMRC console drivers."""
|
||||
|
||||
import base64
|
||||
import json
|
||||
@@ -27,6 +25,8 @@ from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.virt.vmwareapi import vim_util
|
||||
|
||||
|
||||
FLAGS = flags.FLAGS
|
||||
flags.DEFINE_integer('console_vmrc_port',
|
||||
443,
|
||||
"port for VMware VMRC connections")
|
||||
@@ -34,8 +34,6 @@ flags.DEFINE_integer('console_vmrc_error_retries',
|
||||
10,
|
||||
"number of retries for retrieving VMRC information")
|
||||
|
||||
FLAGS = flags.FLAGS
|
||||
|
||||
|
||||
class VMRCConsole(object):
|
||||
"""VMRC console driver with ESX credentials."""
|
||||
@@ -69,34 +67,34 @@ class VMRCConsole(object):
|
||||
return password
|
||||
|
||||
def generate_password(self, vim_session, pool, instance_name):
|
||||
"""
|
||||
Returns VMRC Connection credentials.
|
||||
"""Returns VMRC Connection credentials.
|
||||
|
||||
Return string is of the form '<VM PATH>:<ESX Username>@<ESX Password>'.
|
||||
|
||||
"""
|
||||
username, password = pool['username'], pool['password']
|
||||
vms = vim_session._call_method(vim_util, "get_objects",
|
||||
"VirtualMachine", ["name", "config.files.vmPathName"])
|
||||
vms = vim_session._call_method(vim_util, 'get_objects',
|
||||
'VirtualMachine', ['name', 'config.files.vmPathName'])
|
||||
vm_ds_path_name = None
|
||||
vm_ref = None
|
||||
for vm in vms:
|
||||
vm_name = None
|
||||
ds_path_name = None
|
||||
for prop in vm.propSet:
|
||||
if prop.name == "name":
|
||||
if prop.name == 'name':
|
||||
vm_name = prop.val
|
||||
elif prop.name == "config.files.vmPathName":
|
||||
elif prop.name == 'config.files.vmPathName':
|
||||
ds_path_name = prop.val
|
||||
if vm_name == instance_name:
|
||||
vm_ref = vm.obj
|
||||
vm_ds_path_name = ds_path_name
|
||||
break
|
||||
if vm_ref is None:
|
||||
raise exception.NotFound(_("instance - %s not present") %
|
||||
raise exception.NotFound(_('instance - %s not present') %
|
||||
instance_name)
|
||||
json_data = json.dumps({"vm_id": vm_ds_path_name,
|
||||
"username": username,
|
||||
"password": password})
|
||||
json_data = json.dumps({'vm_id': vm_ds_path_name,
|
||||
'username': username,
|
||||
'password': password})
|
||||
return base64.b64encode(json_data)
|
||||
|
||||
def is_otp(self):
|
||||
@@ -115,28 +113,28 @@ class VMRCSessionConsole(VMRCConsole):
|
||||
return 'vmrc+session'
|
||||
|
||||
def generate_password(self, vim_session, pool, instance_name):
|
||||
"""
|
||||
Returns a VMRC Session.
|
||||
"""Returns a VMRC Session.
|
||||
|
||||
Return string is of the form '<VM MOID>:<VMRC Ticket>'.
|
||||
|
||||
"""
|
||||
vms = vim_session._call_method(vim_util, "get_objects",
|
||||
"VirtualMachine", ["name"])
|
||||
vm_ref = None
|
||||
vms = vim_session._call_method(vim_util, 'get_objects',
|
||||
'VirtualMachine', ['name'])
|
||||
vm_ref = NoneV
|
||||
for vm in vms:
|
||||
if vm.propSet[0].val == instance_name:
|
||||
vm_ref = vm.obj
|
||||
if vm_ref is None:
|
||||
raise exception.NotFound(_("instance - %s not present") %
|
||||
raise exception.NotFound(_('instance - %s not present') %
|
||||
instance_name)
|
||||
virtual_machine_ticket = \
|
||||
vim_session._call_method(
|
||||
vim_session._get_vim(),
|
||||
"AcquireCloneTicket",
|
||||
'AcquireCloneTicket',
|
||||
vim_session._get_vim().get_service_content().sessionManager)
|
||||
json_data = json.dumps({"vm_id": str(vm_ref.value),
|
||||
"username": virtual_machine_ticket,
|
||||
"password": virtual_machine_ticket})
|
||||
json_data = json.dumps({'vm_id': str(vm_ref.value),
|
||||
'username': virtual_machine_ticket,
|
||||
'password': virtual_machine_ticket})
|
||||
return base64.b64encode(json_data)
|
||||
|
||||
def is_otp(self):
|
||||
|
||||
@@ -15,9 +15,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
"""
|
||||
VMRC Console Manager.
|
||||
"""
|
||||
"""VMRC Console Manager."""
|
||||
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
@@ -25,24 +23,21 @@ from nova import log as logging
|
||||
from nova import manager
|
||||
from nova import rpc
|
||||
from nova import utils
|
||||
from nova.virt.vmwareapi_conn import VMWareAPISession
|
||||
from nova.virt import vmwareapi_conn
|
||||
|
||||
|
||||
LOG = logging.getLogger("nova.console.vmrc_manager")
|
||||
|
||||
|
||||
FLAGS = flags.FLAGS
|
||||
flags.DEFINE_string('console_public_hostname',
|
||||
'',
|
||||
flags.DEFINE_string('console_public_hostname', '',
|
||||
'Publicly visible name for this console host')
|
||||
flags.DEFINE_string('console_driver',
|
||||
'nova.console.vmrc.VMRCConsole',
|
||||
flags.DEFINE_string('console_driver', 'nova.console.vmrc.VMRCConsole',
|
||||
'Driver to use for the console')
|
||||
|
||||
|
||||
class ConsoleVMRCManager(manager.Manager):
|
||||
|
||||
"""
|
||||
Manager to handle VMRC connections needed for accessing instance consoles.
|
||||
"""
|
||||
"""Manager to handle VMRC connections for accessing instance consoles."""
|
||||
|
||||
def __init__(self, console_driver=None, *args, **kwargs):
|
||||
self.driver = utils.import_object(FLAGS.console_driver)
|
||||
@@ -56,7 +51,7 @@ class ConsoleVMRCManager(manager.Manager):
|
||||
"""Get VIM session for the pool specified."""
|
||||
vim_session = None
|
||||
if pool['id'] not in self.sessions.keys():
|
||||
vim_session = VMWareAPISession(pool['address'],
|
||||
vim_session = vmwareapi_conn.VMWareAPISession(pool['address'],
|
||||
pool['username'],
|
||||
pool['password'],
|
||||
FLAGS.console_vmrc_error_retries)
|
||||
@@ -65,7 +60,7 @@ class ConsoleVMRCManager(manager.Manager):
|
||||
|
||||
def _generate_console(self, context, pool, name, instance_id, instance):
|
||||
"""Sets up console for the instance."""
|
||||
LOG.debug(_("Adding console"))
|
||||
LOG.debug(_('Adding console'))
|
||||
|
||||
password = self.driver.generate_password(
|
||||
self._get_vim_session(pool),
|
||||
@@ -84,9 +79,10 @@ class ConsoleVMRCManager(manager.Manager):
|
||||
@exception.wrap_exception
|
||||
def add_console(self, context, instance_id, password=None,
|
||||
port=None, **kwargs):
|
||||
"""
|
||||
Adds a console for the instance. If it is one time password, then we
|
||||
generate new console credentials.
|
||||
"""Adds a console for the instance.
|
||||
|
||||
If it is one time password, then we generate new console credentials.
|
||||
|
||||
"""
|
||||
instance = self.db.instance_get(context, instance_id)
|
||||
host = instance['host']
|
||||
@@ -97,19 +93,17 @@ class ConsoleVMRCManager(manager.Manager):
|
||||
pool['id'],
|
||||
instance_id)
|
||||
if self.driver.is_otp():
|
||||
console = self._generate_console(
|
||||
context,
|
||||
pool,
|
||||
name,
|
||||
instance_id,
|
||||
instance)
|
||||
console = self._generate_console(context,
|
||||
pool,
|
||||
name,
|
||||
instance_id,
|
||||
instance)
|
||||
except exception.NotFound:
|
||||
console = self._generate_console(
|
||||
context,
|
||||
pool,
|
||||
name,
|
||||
instance_id,
|
||||
instance)
|
||||
console = self._generate_console(context,
|
||||
pool,
|
||||
name,
|
||||
instance_id,
|
||||
instance)
|
||||
return console['id']
|
||||
|
||||
@exception.wrap_exception
|
||||
@@ -118,13 +112,11 @@ class ConsoleVMRCManager(manager.Manager):
|
||||
try:
|
||||
console = self.db.console_get(context, console_id)
|
||||
except exception.NotFound:
|
||||
LOG.debug(_("Tried to remove non-existent console "
|
||||
"%(console_id)s.") %
|
||||
{'console_id': console_id})
|
||||
LOG.debug(_('Tried to remove non-existent console '
|
||||
'%(console_id)s.') % {'console_id': console_id})
|
||||
return
|
||||
LOG.debug(_("Removing console "
|
||||
"%(console_id)s.") %
|
||||
{'console_id': console_id})
|
||||
LOG.debug(_('Removing console '
|
||||
'%(console_id)s.') % {'console_id': console_id})
|
||||
self.db.console_delete(context, console_id)
|
||||
self.driver.teardown_console(context, console)
|
||||
|
||||
@@ -139,11 +131,11 @@ class ConsoleVMRCManager(manager.Manager):
|
||||
console_type)
|
||||
except exception.NotFound:
|
||||
pool_info = rpc.call(context,
|
||||
self.db.queue_get_for(context,
|
||||
FLAGS.compute_topic,
|
||||
instance_host),
|
||||
{"method": "get_console_pool_info",
|
||||
"args": {"console_type": console_type}})
|
||||
self.db.queue_get_for(context,
|
||||
FLAGS.compute_topic,
|
||||
instance_host),
|
||||
{'method': 'get_console_pool_info',
|
||||
'args': {'console_type': console_type}})
|
||||
pool_info['password'] = self.driver.fix_pool_password(
|
||||
pool_info['password'])
|
||||
pool_info['host'] = self.host
|
||||
|
||||
@@ -15,16 +15,14 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
"""
|
||||
XVP (Xenserver VNC Proxy) driver.
|
||||
"""
|
||||
"""XVP (Xenserver VNC Proxy) driver."""
|
||||
|
||||
import fcntl
|
||||
import os
|
||||
import signal
|
||||
import subprocess
|
||||
|
||||
from Cheetah.Template import Template
|
||||
from Cheetah import Template
|
||||
|
||||
from nova import context
|
||||
from nova import db
|
||||
@@ -33,6 +31,8 @@ from nova import flags
|
||||
from nova import log as logging
|
||||
from nova import utils
|
||||
|
||||
|
||||
FLAGS = flags.FLAGS
|
||||
flags.DEFINE_string('console_xvp_conf_template',
|
||||
utils.abspath('console/xvp.conf.template'),
|
||||
'XVP conf template')
|
||||
@@ -47,12 +47,11 @@ flags.DEFINE_string('console_xvp_log',
|
||||
'XVP log file')
|
||||
flags.DEFINE_integer('console_xvp_multiplex_port',
|
||||
5900,
|
||||
"port for XVP to multiplex VNC connections on")
|
||||
FLAGS = flags.FLAGS
|
||||
'port for XVP to multiplex VNC connections on')
|
||||
|
||||
|
||||
class XVPConsoleProxy(object):
|
||||
"""Sets up XVP config, and manages xvp daemon"""
|
||||
"""Sets up XVP config, and manages XVP daemon."""
|
||||
|
||||
def __init__(self):
|
||||
self.xvpconf_template = open(FLAGS.console_xvp_conf_template).read()
|
||||
@@ -61,50 +60,51 @@ class XVPConsoleProxy(object):
|
||||
|
||||
@property
|
||||
def console_type(self):
|
||||
return "vnc+xvp"
|
||||
return 'vnc+xvp'
|
||||
|
||||
def get_port(self, context):
|
||||
"""get available port for consoles that need one"""
|
||||
"""Get available port for consoles that need one."""
|
||||
#TODO(mdragon): implement port selection for non multiplex ports,
|
||||
# we are not using that, but someone else may want
|
||||
# it.
|
||||
return FLAGS.console_xvp_multiplex_port
|
||||
|
||||
def setup_console(self, context, console):
|
||||
"""Sets up actual proxies"""
|
||||
"""Sets up actual proxies."""
|
||||
self._rebuild_xvp_conf(context.elevated())
|
||||
|
||||
def teardown_console(self, context, console):
|
||||
"""Tears down actual proxies"""
|
||||
"""Tears down actual proxies."""
|
||||
self._rebuild_xvp_conf(context.elevated())
|
||||
|
||||
def init_host(self):
|
||||
"""Start up any config'ed consoles on start"""
|
||||
"""Start up any config'ed consoles on start."""
|
||||
ctxt = context.get_admin_context()
|
||||
self._rebuild_xvp_conf(ctxt)
|
||||
|
||||
def fix_pool_password(self, password):
|
||||
"""Trim password to length, and encode"""
|
||||
"""Trim password to length, and encode."""
|
||||
return self._xvp_encrypt(password, is_pool_password=True)
|
||||
|
||||
def fix_console_password(self, password):
|
||||
"""Trim password to length, and encode"""
|
||||
"""Trim password to length, and encode."""
|
||||
return self._xvp_encrypt(password)
|
||||
|
||||
def _rebuild_xvp_conf(self, context):
|
||||
logging.debug(_("Rebuilding xvp conf"))
|
||||
logging.debug(_('Rebuilding xvp conf'))
|
||||
pools = [pool for pool in
|
||||
db.console_pool_get_all_by_host_type(context, self.host,
|
||||
self.console_type)
|
||||
if pool['consoles']]
|
||||
if not pools:
|
||||
logging.debug("No console pools!")
|
||||
logging.debug('No console pools!')
|
||||
self._xvp_stop()
|
||||
return
|
||||
conf_data = {'multiplex_port': FLAGS.console_xvp_multiplex_port,
|
||||
'pools': pools,
|
||||
'pass_encode': self.fix_console_password}
|
||||
config = str(Template(self.xvpconf_template, searchList=[conf_data]))
|
||||
config = str(Template.Template(self.xvpconf_template,
|
||||
searchList=[conf_data]))
|
||||
self._write_conf(config)
|
||||
self._xvp_restart()
|
||||
|
||||
@@ -114,7 +114,7 @@ class XVPConsoleProxy(object):
|
||||
cfile.write(config)
|
||||
|
||||
def _xvp_stop(self):
|
||||
logging.debug(_("Stopping xvp"))
|
||||
logging.debug(_('Stopping xvp'))
|
||||
pid = self._xvp_pid()
|
||||
if not pid:
|
||||
return
|
||||
@@ -127,19 +127,19 @@ class XVPConsoleProxy(object):
|
||||
def _xvp_start(self):
|
||||
if self._xvp_check_running():
|
||||
return
|
||||
logging.debug(_("Starting xvp"))
|
||||
logging.debug(_('Starting xvp'))
|
||||
try:
|
||||
utils.execute('xvp',
|
||||
'-p', FLAGS.console_xvp_pid,
|
||||
'-c', FLAGS.console_xvp_conf,
|
||||
'-l', FLAGS.console_xvp_log)
|
||||
except exception.ProcessExecutionError, err:
|
||||
logging.error(_("Error starting xvp: %s") % err)
|
||||
logging.error(_('Error starting xvp: %s') % err)
|
||||
|
||||
def _xvp_restart(self):
|
||||
logging.debug(_("Restarting xvp"))
|
||||
logging.debug(_('Restarting xvp'))
|
||||
if not self._xvp_check_running():
|
||||
logging.debug(_("xvp not running..."))
|
||||
logging.debug(_('xvp not running...'))
|
||||
self._xvp_start()
|
||||
else:
|
||||
pid = self._xvp_pid()
|
||||
@@ -178,7 +178,9 @@ class XVPConsoleProxy(object):
|
||||
|
||||
Note that xvp's obfuscation should not be considered 'real' encryption.
|
||||
It simply DES encrypts the passwords with static keys plainly viewable
|
||||
in the xvp source code."""
|
||||
in the xvp source code.
|
||||
|
||||
"""
|
||||
maxlen = 8
|
||||
flag = '-e'
|
||||
if is_pool_password:
|
||||
|
||||
Reference in New Issue
Block a user