summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVishvananda Ishaya <vishvananda@gmail.com>2010-08-04 18:37:00 -0700
committerVishvananda Ishaya <vishvananda@gmail.com>2010-08-04 18:37:00 -0700
commitd1709793045de2f77f4a1fb06f63d27cbcf640d1 (patch)
treed57bb1e8ee52e5e6986c9f6625f41cca5767834b
parentcc64a872c685b931bf76e2323986b427cad777c3 (diff)
downloadnova-d1709793045de2f77f4a1fb06f63d27cbcf640d1.tar.gz
nova-d1709793045de2f77f4a1fb06f63d27cbcf640d1.tar.xz
nova-d1709793045de2f77f4a1fb06f63d27cbcf640d1.zip
clean up nova-manage. If vpn data isn't set for user it skips it
-rwxr-xr-xbin/nova-manage23
-rw-r--r--nova/auth/manager.py39
2 files changed, 37 insertions, 25 deletions
diff --git a/bin/nova-manage b/bin/nova-manage
index b0f0029ed..7835c7a77 100755
--- a/bin/nova-manage
+++ b/bin/nova-manage
@@ -29,16 +29,12 @@ from nova import flags
from nova import utils
from nova.auth import manager
from nova.compute import model
-from nova.compute import network
from nova.cloudpipe import pipelib
from nova.endpoint import cloud
FLAGS = flags.FLAGS
-class NetworkCommands(object):
- def restart(self):
- network.restart_nets()
class VpnCommands(object):
def __init__(self):
@@ -170,6 +166,13 @@ class ProjectCommands(object):
arguments: name"""
self.manager.delete_project(name)
+ def environment(self, project_id, user_id, filename='novarc'):
+ """exports environment variables to an sourcable file
+ arguments: project_id user_id [filename='novarc]"""
+ rc = self.manager.get_environment_rc(project_id, user_id)
+ with open(filename, 'w') as f:
+ f.write(rc)
+
def list(self):
"""lists all projects
arguments: <none>"""
@@ -182,14 +185,11 @@ class ProjectCommands(object):
self.manager.remove_from_project(user, project)
def zip(self, project_id, user_id, filename='nova.zip'):
- """exports credentials for user to a zip file
+ """exports credentials for project to a zip file
arguments: project_id user_id [filename='nova.zip]"""
- project = self.manager.get_project(project_id)
- if project:
- with open(filename, 'w') as f:
- f.write(project.get_credentials(user_id))
- else:
- print "Project %s doesn't exist" % project
+ zip = self.manager.get_credentials(project_id, user_id)
+ with open(filename, 'w') as f:
+ f.write(zip)
def usage(script_name):
@@ -197,7 +197,6 @@ def usage(script_name):
categories = [
- ('network', NetworkCommands),
('user', UserCommands),
('project', ProjectCommands),
('role', RoleCommands),
diff --git a/nova/auth/manager.py b/nova/auth/manager.py
index 463cfdf4a..312b569aa 100644
--- a/nova/auth/manager.py
+++ b/nova/auth/manager.py
@@ -58,6 +58,8 @@ flags.DEFINE_string('credentials_template',
flags.DEFINE_string('vpn_client_template',
utils.abspath('cloudpipe/client.ovpn.template'),
'Template for creating users vpn file')
+flags.DEFINE_string('credential_vpn_file', 'nova-vpn.conf',
+ 'Filename of certificate in credentials zip')
flags.DEFINE_string('credential_key_file', 'pk.pem',
'Filename of private key in credentials zip')
flags.DEFINE_string('credential_cert_file', 'cert.pem',
@@ -663,25 +665,27 @@ class AuthManager(object):
rc = self.__generate_rc(user.access, user.secret, pid)
private_key, signed_cert = self._generate_x509_cert(user.id, pid)
- vpn = Vpn.lookup(pid)
- if not vpn:
- raise exception.Error("No vpn data allocated for project %s" %
- project.name)
- configfile = open(FLAGS.vpn_client_template,"r")
- s = string.Template(configfile.read())
- configfile.close()
- config = s.substitute(keyfile=FLAGS.credential_key_file,
- certfile=FLAGS.credential_cert_file,
- ip=vpn.ip,
- port=vpn.port)
-
tmpdir = tempfile.mkdtemp()
zf = os.path.join(tmpdir, "temp.zip")
zippy = zipfile.ZipFile(zf, 'w')
zippy.writestr(FLAGS.credential_rc_file, rc)
zippy.writestr(FLAGS.credential_key_file, private_key)
zippy.writestr(FLAGS.credential_cert_file, signed_cert)
- zippy.writestr("nebula-client.conf", config)
+
+ network_data = networkdata.NetworkData.lookup(pid)
+ if network_data:
+ configfile = open(FLAGS.vpn_client_template,"r")
+ s = string.Template(configfile.read())
+ configfile.close()
+ config = s.substitute(keyfile=FLAGS.credential_key_file,
+ certfile=FLAGS.credential_cert_file,
+ ip=network_data.ip,
+ port=network_data.port)
+ zippy.writestr(FLAGS.credential_vpn_file, config)
+ else:
+ logging.warn("No vpn data for project %s" %
+ pid)
+
zippy.writestr(FLAGS.ca_file, crypto.fetch_ca(user.id))
zippy.close()
with open(zf, 'rb') as f:
@@ -690,6 +694,15 @@ class AuthManager(object):
shutil.rmtree(tmpdir)
return buffer
+ def get_environment_rc(self, user, project=None):
+ """Get credential zip for user in project"""
+ if not isinstance(user, User):
+ user = self.get_user(user)
+ if project is None:
+ project = user.id
+ pid = Project.safe_id(project)
+ return self.__generate_rc(user.access, user.secret, pid)
+
def __generate_rc(self, access, secret, pid):
"""Generate rc file for user"""
rc = open(FLAGS.credentials_template).read()