Fix a bunch of pep8 stuff
This commit is contained in:
@@ -85,8 +85,3 @@ class Controller(wsgi.Controller):
|
||||
except exception.NotFound:
|
||||
return faults.Fault(exc.HTTPNotFound())
|
||||
return exc.HTTPAccepted()
|
||||
|
||||
# def detail(self, req, id):
|
||||
# """ Returns a complete list of consoles for this instance"""
|
||||
# return _translate_detail_keys({})
|
||||
|
||||
|
||||
@@ -112,11 +112,9 @@ class ComputeManager(manager.Manager):
|
||||
FLAGS.network_topic,
|
||||
host)
|
||||
|
||||
|
||||
def get_console_pool_info(self, context, console_type):
|
||||
return self.driver.get_console_pool_info(console_type)
|
||||
|
||||
|
||||
@exception.wrap_exception
|
||||
def refresh_security_group(self, context, security_group_id, **_kwargs):
|
||||
"""This call passes stright through to the virtualization driver."""
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
"""
|
||||
:mod:`nova.console` -- Console Prxy to set up VM console access (i.e. with xvp)
|
||||
:mod:`nova.console` -- Console Prxy to set up VM console access (i.e. with xvp)
|
||||
=====================================================
|
||||
|
||||
.. automodule:: nova.console
|
||||
:platform: Unix
|
||||
:synopsis: Wrapper around console proxies such as xvp to set up multitenant VM console access
|
||||
.. moduleauthor:: Monsyne Dragon <mdragon@rackspace.com>
|
||||
:synopsis: Wrapper around console proxies such as xvp to set up
|
||||
multitenant VM console access
|
||||
.. moduleauthor:: Monsyne Dragon <mdragon@rackspace.com>
|
||||
"""
|
||||
|
||||
@@ -29,6 +29,7 @@ from nova import rpc
|
||||
|
||||
FLAGS = flags.FLAGS
|
||||
|
||||
|
||||
class ConsoleAPI(base.Base):
|
||||
"""API for spining up or down console proxy connections"""
|
||||
|
||||
@@ -70,7 +71,6 @@ class ConsoleAPI(base.Base):
|
||||
{"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,
|
||||
|
||||
@@ -43,7 +43,7 @@ class ConsoleProxy(object):
|
||||
|
||||
def generate_password(self, length=8):
|
||||
"""Returns random console password"""
|
||||
return os.urandom(length*2).encode('base64')[:length]
|
||||
return os.urandom(length * 2).encode('base64')[:length]
|
||||
|
||||
def get_port(self, context):
|
||||
"""get available port for consoles that need one"""
|
||||
@@ -56,4 +56,3 @@ class ConsoleProxy(object):
|
||||
def fix_console_password(self, password):
|
||||
"""Trim password to length, and any other massaging"""
|
||||
return password
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ Fake ConsoleProxy driver for tests.
|
||||
from nova import exception
|
||||
from nova.console import driver
|
||||
|
||||
|
||||
class FakeConsoleProxy(driver.ConsoleProxy):
|
||||
"""Fake ConsoleProxy driver."""
|
||||
|
||||
@@ -56,4 +57,3 @@ class FakeConsoleProxy(driver.ConsoleProxy):
|
||||
def fix_console_password(self, password):
|
||||
"""Trim password to length, and any other massaging"""
|
||||
return password
|
||||
|
||||
|
||||
@@ -35,9 +35,10 @@ flags.DEFINE_string('console_driver',
|
||||
flags.DEFINE_boolean('stub_compute', False,
|
||||
'Stub calls to compute worker for tests')
|
||||
|
||||
|
||||
class ConsoleProxyManager(manager.Manager):
|
||||
|
||||
""" Sets up and tears down any proxy connections needed for accessing
|
||||
""" Sets up and tears down any proxy connections needed for accessing
|
||||
instance consoles securely"""
|
||||
|
||||
def __init__(self, console_driver=None, *args, **kwargs):
|
||||
@@ -51,8 +52,8 @@ class ConsoleProxyManager(manager.Manager):
|
||||
self.driver.init_host()
|
||||
|
||||
@exception.wrap_exception
|
||||
def add_console(self, context, instance_id, password = None,
|
||||
port = None, **kwargs):
|
||||
def add_console(self, context, instance_id, password=None,
|
||||
port=None, **kwargs):
|
||||
instance = self.db.instance_get(context, instance_id)
|
||||
host = instance['host']
|
||||
name = instance['name']
|
||||
@@ -67,10 +68,10 @@ class ConsoleProxyManager(manager.Manager):
|
||||
password = self.driver.generate_password()
|
||||
if not port:
|
||||
port = self.driver.get_port(context)
|
||||
console_data = {'instance_name' : name,
|
||||
'instance_id' : instance_id,
|
||||
'password' : password,
|
||||
'pool_id' : pool['id']}
|
||||
console_data = {'instance_name': name,
|
||||
'instance_id': instance_id,
|
||||
'password': password,
|
||||
'pool_id': pool['id']}
|
||||
if port:
|
||||
console_data['port'] = port
|
||||
console = self.db.console_create(context, console_data)
|
||||
@@ -84,12 +85,11 @@ class ConsoleProxyManager(manager.Manager):
|
||||
except exception.NotFound:
|
||||
logging.debug(_('Tried to remove non-existant console '
|
||||
'%(console_id)s.') %
|
||||
{'console_id' : console_id})
|
||||
{'console_id': console_id})
|
||||
return
|
||||
self.db.console_delete(context, console_id)
|
||||
self.driver.teardown_console(context, console)
|
||||
|
||||
|
||||
def get_pool_for_instance_host(self, context, instance_host):
|
||||
context = context.elevated()
|
||||
console_type = self.driver.console_type
|
||||
@@ -103,9 +103,9 @@ class ConsoleProxyManager(manager.Manager):
|
||||
# compute worker's flagfile, at least for
|
||||
# xenserver. Thus we ned to ask.
|
||||
if FLAGS.stub_compute:
|
||||
pool_info = {'address' : '127.0.0.1',
|
||||
'username' : 'test',
|
||||
'password' : '1234pass'}
|
||||
pool_info = {'address': '127.0.0.1',
|
||||
'username': 'test',
|
||||
'password': '1234pass'}
|
||||
else:
|
||||
pool_info = rpc.call(context,
|
||||
self.db.queue_get_for(context,
|
||||
@@ -120,5 +120,3 @@ class ConsoleProxyManager(manager.Manager):
|
||||
pool_info['compute_host'] = instance_host
|
||||
pool = self.db.console_pool_create(context, pool_info)
|
||||
return pool
|
||||
|
||||
|
||||
|
||||
@@ -51,12 +51,13 @@ flags.DEFINE_integer('console_xvp_multiplex_port',
|
||||
"port for XVP to multiplex VNC connections on")
|
||||
FLAGS = flags.FLAGS
|
||||
|
||||
|
||||
class XVPConsoleProxy(driver.ConsoleProxy):
|
||||
"""Sets up XVP config, and manages xvp daemon"""
|
||||
|
||||
def __init__(self):
|
||||
self.xvpconf_template = open(FLAGS.console_xvp_conf_template).read()
|
||||
self.host = FLAGS.host #default, set by manager.
|
||||
self.host = FLAGS.host # default, set by manager.
|
||||
super(XVPConsoleProxy, self).__init__()
|
||||
|
||||
@property
|
||||
@@ -93,8 +94,8 @@ class XVPConsoleProxy(driver.ConsoleProxy):
|
||||
|
||||
def _rebuild_xvp_conf(self, context):
|
||||
logging.debug("Rebuilding xvp conf")
|
||||
pools = [ pool for pool in
|
||||
db.console_pool_get_all_by_host_type(context, self.host,
|
||||
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:
|
||||
@@ -103,7 +104,7 @@ class XVPConsoleProxy(driver.ConsoleProxy):
|
||||
return
|
||||
conf_data = {'multiplex_port': FLAGS.console_xvp_multiplex_port,
|
||||
'pools': pools,
|
||||
'pass_encode' : self.fix_console_password }
|
||||
'pass_encode': self.fix_console_password}
|
||||
config = str(Template(self.xvpconf_template, searchList=[conf_data]))
|
||||
self._write_conf(config)
|
||||
self._xvp_restart()
|
||||
@@ -119,7 +120,7 @@ class XVPConsoleProxy(driver.ConsoleProxy):
|
||||
if not pid:
|
||||
return
|
||||
try:
|
||||
os.kill(pid,signal.SIGTERM)
|
||||
os.kill(pid, signal.SIGTERM)
|
||||
except OSError:
|
||||
#if it's already not running, no problem.
|
||||
pass
|
||||
@@ -129,7 +130,7 @@ class XVPConsoleProxy(driver.ConsoleProxy):
|
||||
return
|
||||
logging.debug("Starting xvp")
|
||||
try:
|
||||
utils.execute('xvp -p %s -c %s -l %s' %
|
||||
utils.execute('xvp -p %s -c %s -l %s' %
|
||||
(FLAGS.console_xvp_pid,
|
||||
FLAGS.console_xvp_conf,
|
||||
FLAGS.console_xvp_log))
|
||||
@@ -160,7 +161,7 @@ class XVPConsoleProxy(driver.ConsoleProxy):
|
||||
if not pid:
|
||||
return False
|
||||
try:
|
||||
os.kill(pid,0)
|
||||
os.kill(pid, 0)
|
||||
except OSError:
|
||||
return False
|
||||
return True
|
||||
@@ -187,7 +188,4 @@ class XVPConsoleProxy(driver.ConsoleProxy):
|
||||
#xvp will blow up on passwords that are too long (mdragon)
|
||||
password = password[:maxlen]
|
||||
out, err = utils.execute('xvp %s' % flag, process_input=password)
|
||||
#p = subprocess.Popen(['xvp', flag], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||
#out,err = p.communicate(password)
|
||||
return out.strip()
|
||||
|
||||
|
||||
@@ -895,12 +895,15 @@ def host_get_networks(context, host):
|
||||
"""
|
||||
return IMPL.host_get_networks(context, host)
|
||||
|
||||
|
||||
##################
|
||||
|
||||
|
||||
def console_pool_create(context, values):
|
||||
"""Create console pool."""
|
||||
return IMPL.console_pool_create(context, values)
|
||||
|
||||
|
||||
def console_pool_get(context, pool_id):
|
||||
"""Get a console pool."""
|
||||
return IMPL.console_pool_get(context, pool_id)
|
||||
@@ -922,24 +925,26 @@ def console_pool_get_all_by_host_type(context, host, console_type):
|
||||
console_type)
|
||||
|
||||
|
||||
def console_create(context,values):
|
||||
def console_create(context, values):
|
||||
"""Create a console."""
|
||||
return IMPL.console_create(context, values)
|
||||
|
||||
|
||||
def console_delete(context, console_id):
|
||||
"""Delete a console."""
|
||||
return IMPL.console_delete(context, console_id)
|
||||
|
||||
|
||||
def console_get_by_pool_instance(context, pool_id, instance_id):
|
||||
"""Get console entry for a given instance and pool."""
|
||||
return IMPL.console_get_by_pool_instance(context, pool_id, instance_id)
|
||||
|
||||
|
||||
def console_get_all_by_instance(context, instance_id):
|
||||
"""Get consoles for a given instance."""
|
||||
return IMPL.console_get_all_by_instance(context, instance_id)
|
||||
|
||||
|
||||
def console_get(context, console_id, instance_id=None):
|
||||
"""Get a specific console (possibly on a given instance)."""
|
||||
return IMPL.console_get(context, console_id, instance_id)
|
||||
|
||||
|
||||
|
||||
@@ -1835,10 +1835,12 @@ def console_pool_get(context, pool_id):
|
||||
filter_by(id=pool_id).\
|
||||
first()
|
||||
if not result:
|
||||
raise exception.NotFound(_("No console pool with id %(pool_id)s") % {'pool_id': pool_id})
|
||||
raise exception.NotFound(_("No console pool with id %(pool_id)s") %
|
||||
{'pool_id': pool_id})
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def console_pool_get_by_host_type(context, compute_host, host,
|
||||
console_type):
|
||||
session = get_session()
|
||||
@@ -1853,9 +1855,9 @@ def console_pool_get_by_host_type(context, compute_host, host,
|
||||
raise exception.NotFound(_('No console pool of type %(type)s '
|
||||
'for compute host %(compute_host)s '
|
||||
'on proxy host %(host)s') %
|
||||
{'type' : console_type,
|
||||
'compute_host' : compute_host,
|
||||
'host' : host})
|
||||
{'type': console_type,
|
||||
'compute_host': compute_host,
|
||||
'host': host})
|
||||
return result
|
||||
|
||||
|
||||
@@ -1875,13 +1877,15 @@ def console_create(context, values):
|
||||
console.save()
|
||||
return console
|
||||
|
||||
|
||||
def console_delete(context, console_id):
|
||||
session = get_session()
|
||||
with session.begin():
|
||||
# consoles are meant to be transient. (mdragon)
|
||||
# consoles are meant to be transient. (mdragon)
|
||||
session.execute('delete from consoles '
|
||||
'where id=:id', {'id': console_id})
|
||||
|
||||
|
||||
def console_get_by_pool_instance(context, pool_id, instance_id):
|
||||
session = get_session()
|
||||
result = session.query(models.Console).\
|
||||
@@ -1891,11 +1895,12 @@ def console_get_by_pool_instance(context, pool_id, instance_id):
|
||||
first()
|
||||
if not result:
|
||||
raise exception.NotFound(_('No console for instance %(instance_id)s '
|
||||
'in pool %(pool_id)s') %
|
||||
'in pool %(pool_id)s') %
|
||||
{'instance_id': instance_id,
|
||||
'pool_id': pool_id})
|
||||
return result
|
||||
|
||||
|
||||
def console_get_all_by_instance(context, instance_id):
|
||||
session = get_session()
|
||||
results = session.query(models.Console).\
|
||||
@@ -1904,6 +1909,7 @@ def console_get_all_by_instance(context, instance_id):
|
||||
all()
|
||||
return results
|
||||
|
||||
|
||||
def console_get(context, console_id, instance_id=None):
|
||||
session = get_session()
|
||||
query = session.query(models.Console).\
|
||||
@@ -1914,7 +1920,5 @@ def console_get(context, console_id, instance_id=None):
|
||||
if not result:
|
||||
idesc = _(" on instance %(instance_id)s") if instance_id else ""
|
||||
raise exception.NotFound(_("No console with id %(instance)s") %
|
||||
{'instance' : idesc})
|
||||
{'instance': idesc})
|
||||
return result
|
||||
|
||||
|
||||
|
||||
@@ -537,6 +537,7 @@ class FloatingIp(BASE, NovaBase):
|
||||
project_id = Column(String(255))
|
||||
host = Column(String(255)) # , ForeignKey('hosts.id'))
|
||||
|
||||
|
||||
class ConsolePool(BASE, NovaBase):
|
||||
"""Represents pool of consoles on the same physical node."""
|
||||
__tablename__ = 'console_pools'
|
||||
@@ -548,6 +549,7 @@ class ConsolePool(BASE, NovaBase):
|
||||
host = Column(String(255))
|
||||
compute_host = Column(String(255))
|
||||
|
||||
|
||||
class Console(BASE, NovaBase):
|
||||
"""Represents a console session for an instance."""
|
||||
__tablename__ = 'consoles'
|
||||
@@ -555,10 +557,11 @@ class Console(BASE, NovaBase):
|
||||
instance_name = Column(String(255))
|
||||
instance_id = Column(Integer)
|
||||
password = Column(String(255))
|
||||
port = Column(Integer,nullable=True)
|
||||
port = Column(Integer, nullable=True)
|
||||
pool_id = Column(Integer, ForeignKey('console_pools.id'))
|
||||
pool = relationship(ConsolePool, backref=backref('consoles'))
|
||||
|
||||
|
||||
def register_models():
|
||||
"""Register Models and create metadata.
|
||||
|
||||
|
||||
@@ -218,7 +218,8 @@ DEFINE_integer('s3_port', 3333, 's3 port')
|
||||
DEFINE_string('s3_host', utils.get_my_ip(), 's3 host (for infrastructure)')
|
||||
DEFINE_string('s3_dmz', utils.get_my_ip(), 's3 dmz ip (for instances)')
|
||||
DEFINE_string('compute_topic', 'compute', 'the topic compute nodes listen on')
|
||||
DEFINE_string('console_topic', 'console', 'the topic console proxy nodes listen on')
|
||||
DEFINE_string('console_topic', 'console',
|
||||
'the topic console proxy nodes listen on')
|
||||
DEFINE_string('scheduler_topic', 'scheduler',
|
||||
'the topic scheduler nodes listen on')
|
||||
DEFINE_string('volume_topic', 'volume', 'the topic volume nodes listen on')
|
||||
|
||||
@@ -89,12 +89,12 @@ class ConsoleTestCase(test.TestCase):
|
||||
self.assertEqual(pool['id'], pool2['id'])
|
||||
|
||||
def test_get_pool_does_not_create_new_pool_if_exists(self):
|
||||
pool_info = {'address' : '127.0.0.1',
|
||||
'username' : 'test',
|
||||
'password' : '1234pass',
|
||||
'host' : self.console.host,
|
||||
'console_type' : self.console.driver.console_type,
|
||||
'compute_host' : 'sometesthostname' }
|
||||
pool_info = {'address': '127.0.0.1',
|
||||
'username': 'test',
|
||||
'password': '1234pass',
|
||||
'host': self.console.host,
|
||||
'console_type': self.console.driver.console_type,
|
||||
'compute_host': 'sometesthostname'}
|
||||
new_pool = db.console_pool_create(self.context, pool_info)
|
||||
pool = self.console.get_pool_for_instance_host(self.context,
|
||||
'sometesthostname')
|
||||
@@ -107,16 +107,16 @@ class ConsoleTestCase(test.TestCase):
|
||||
pool = db.console_pool_get_by_host_type(self.context,
|
||||
instance['host'],
|
||||
self.console.host,
|
||||
self.console.driver.console_type)
|
||||
self.console.driver.console_type)
|
||||
|
||||
console_instances = [con['instance_id'] for con in pool.consoles]
|
||||
console_instances = [con['instance_id'] for con in pool.consoles]
|
||||
self.assert_(instance_id in console_instances)
|
||||
|
||||
def test_add_console_does_not_duplicate(self):
|
||||
instance_id = self._create_instance()
|
||||
cons1 = self.console.add_console(self.context, instance_id)
|
||||
cons2 = self.console.add_console(self.context, instance_id)
|
||||
self.assertEqual(cons1,cons2)
|
||||
self.assertEqual(cons1, cons2)
|
||||
|
||||
def test_remove_console(self):
|
||||
instance_id = self._create_instance()
|
||||
@@ -127,4 +127,3 @@ class ConsoleTestCase(test.TestCase):
|
||||
db.console_get,
|
||||
self.context,
|
||||
console_id)
|
||||
|
||||
|
||||
@@ -290,9 +290,9 @@ class FakeConnection(object):
|
||||
return 'FAKE CONSOLE OUTPUT'
|
||||
|
||||
def get_console_pool_info(self, console_type):
|
||||
return {'address' : '127.0.0.1',
|
||||
'username' : 'fakeuser',
|
||||
'password' : 'fakepassword'}
|
||||
return {'address': '127.0.0.1',
|
||||
'username': 'fakeuser',
|
||||
'password': 'fakepassword'}
|
||||
|
||||
|
||||
class FakeInstance(object):
|
||||
|
||||
@@ -697,10 +697,10 @@ class LibvirtConnection(object):
|
||||
def get_console_pool_info(self, console_type):
|
||||
#TODO(mdragon): console proxy should be implemented for libvirt,
|
||||
# in case someone wants to use it with kvm or
|
||||
# such. For now return fake data.
|
||||
return {'address' : '127.0.0.1',
|
||||
'username' : 'fakeuser',
|
||||
'password' : 'fakepassword'}
|
||||
# such. For now return fake data.
|
||||
return {'address': '127.0.0.1',
|
||||
'username': 'fakeuser',
|
||||
'password': 'fakepassword'}
|
||||
|
||||
|
||||
class NWFilterFirewall(object):
|
||||
|
||||
@@ -189,9 +189,9 @@ class XenAPIConnection(object):
|
||||
|
||||
def get_console_pool_info(self, console_type):
|
||||
xs_url = urlparse.urlparse(FLAGS.xenapi_connection_url)
|
||||
return {'address' : xs_url.netloc,
|
||||
'username' : FLAGS.xenapi_connection_username,
|
||||
'password' : FLAGS.xenapi_connection_password}
|
||||
return {'address': xs_url.netloc,
|
||||
'username': FLAGS.xenapi_connection_username,
|
||||
'password': FLAGS.xenapi_connection_password}
|
||||
|
||||
|
||||
class XenAPISession(object):
|
||||
|
||||
Reference in New Issue
Block a user