Merge "Fixes cloudpipe extension to work with keystone"

This commit is contained in:
Jenkins
2012-02-28 09:17:18 +00:00
committed by Gerrit Code Review
2 changed files with 0 additions and 77 deletions

View File

@@ -92,7 +92,6 @@ from nova import version
from nova import vsa from nova import vsa
from nova.api.ec2 import ec2utils from nova.api.ec2 import ec2utils
from nova.auth import manager from nova.auth import manager
from nova.cloudpipe import pipelib
from nova.compute import instance_types from nova.compute import instance_types
from nova.compute import vm_states from nova.compute import vm_states
from nova.db import migration from nova.db import migration
@@ -132,65 +131,6 @@ class VpnCommands(object):
def __init__(self): def __init__(self):
self.manager = manager.AuthManager() self.manager = manager.AuthManager()
self.pipe = pipelib.CloudPipe()
@args('--project', dest="project", metavar='<Project name>',
help='Project name')
def list(self, project=None):
"""Print a listing of the VPN data for one or all projects."""
print "WARNING: This method only works with deprecated auth"
print "%-12s\t" % 'project',
print "%-20s\t" % 'ip:port',
print "%-20s\t" % 'private_ip',
print "%s" % 'state'
if project:
projects = [self.manager.get_project(project)]
else:
projects = self.manager.get_projects()
# NOTE(vish): This hits the database a lot. We could optimize
# by getting all networks in one query and all vpns
# in aother query, then doing lookups by project
for project in projects:
print "%-12s\t" % project.name,
ipport = "%s:%s" % (project.vpn_ip, project.vpn_port)
print "%-20s\t" % ipport,
ctxt = context.get_admin_context()
vpn = db.instance_get_project_vpn(ctxt, project.id)
if vpn:
address = None
state = 'down'
if vpn.get('fixed_ip', None):
address = vpn['fixed_ip']['address']
if project.vpn_ip and utils.vpn_ping(project.vpn_ip,
project.vpn_port):
state = 'up'
print address,
print vpn['host'],
print ec2utils.id_to_ec2_id(vpn['id']),
print vpn['vm_state'],
print state
else:
print None
def spawn(self):
"""Run all VPNs."""
print "WARNING: This method only works with deprecated auth"
ctxt = context.get_admin_context()
for p in reversed(self.manager.get_projects()):
if self._vpn_for(ctxt, p.id):
print 'spawning %s' % p.id
self.pipe.launch_vpn_instance(p.id, p.project_manager_id)
time.sleep(10)
@args('--project', dest="project_id", metavar='<Project name>',
help='Project name')
@args('--user', dest="user_id", metavar='<user name>', help='User name')
def run(self, project_id, user_id):
"""Start the VPN for a given project and user."""
if not user_id:
print "WARNING: This method only works with deprecated auth"
user_id = self.manager.get_project(project_id).project_manager_id
self.pipe.launch_vpn_instance(project_id, user_id)
@args('--project', dest="project_id", metavar='<Project name>', @args('--project', dest="project_id", metavar='<Project name>',
help='Project name') help='Project name')
@@ -213,13 +153,6 @@ class VpnCommands(object):
{'vpn_public_address': ip, {'vpn_public_address': ip,
'vpn_public_port': int(port)}) 'vpn_public_port': int(port)})
def _vpn_for(self, context, project_id):
"""Get the VPN instance for a project ID."""
for instance in db.instance_get_all_by_project(context, project_id):
if (instance['image_id'] == str(FLAGS.vpn_image_id)
and not instance['vm_state'] in [vm_states.DELETED]):
return instance
class ShellCommands(object): class ShellCommands(object):
def bpython(self): def bpython(self):

View File

@@ -58,16 +58,6 @@ class DbApiTestCase(test.TestCase):
self.project_id = 'fake' self.project_id = 'fake'
self.context = context.RequestContext(self.user_id, self.project_id) self.context = context.RequestContext(self.user_id, self.project_id)
def test_instance_get_project_vpn(self):
values = {'instance_type_id': FLAGS.default_instance_type,
'image_ref': FLAGS.vpn_image_id,
'project_id': self.project_id,
}
instance = db.instance_create(self.context, values)
result = db.instance_get_project_vpn(self.context.elevated(),
self.project_id)
self.assertEqual(instance['id'], result['id'])
def test_instance_get_all_by_filters(self): def test_instance_get_all_by_filters(self):
args = {'reservation_id': 'a', 'image_ref': 1, 'host': 'host1'} args = {'reservation_id': 'a', 'image_ref': 1, 'host': 'host1'}
inst1 = db.instance_create(self.context, args) inst1 = db.instance_create(self.context, args)