X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;ds=sidebyside;f=planetstack%2Fopenstack%2Fmanager.py;h=131b8fbc82501eb0148b7271764a4f63a27237c9;hb=6795fbebdf1c348f1539dbd32e255f50e9ff4e12;hp=3c779527eb0f247a32c364a235f16fa058b26e25;hpb=b0d9742e1a7746ea0d8cbf78d85cab38883a8edc;p=plstackapi.git diff --git a/planetstack/openstack/manager.py b/planetstack/openstack/manager.py index 3c77952..131b8fb 100644 --- a/planetstack/openstack/manager.py +++ b/planetstack/openstack/manager.py @@ -2,6 +2,7 @@ import os #os.environ.setdefault("DJANGO_SETTINGS_MODULE", "planetstack.settings") import string import random +import md5 from netaddr import IPAddress, IPNetwork from planetstack import settings @@ -54,15 +55,18 @@ class OpenStackManager: self.init_admin() @require_enabled - def init_user(self, auth, caller): + def init_caller(self, caller, tenant): + auth = {'username': caller.email, + 'password': md5.new(caller.password).hexdigest()[:6], + 'tenant': tenant} self.client = OpenStackClient(**auth) self.driver = OpenStackDriver(client=self.client) self.caller = caller @require_enabled - def init_admin(self): + def init_admin(self, tenant=None): # use the admin credentials - self.client = OpenStackClient() + self.client = OpenStackClient(tenant=tenant) self.driver = OpenStackDriver(client=self.client) self.caller = self.driver.admin_user self.caller.kuser_id = self.caller.id @@ -91,17 +95,16 @@ class OpenStackManager: @require_enabled def save_user(self, user): + name = user.email[:user.email.find('@')] + user_fields = {'name': name, + 'email': user.email, + 'password': md5.new(user.password).hexdigest()[:6], + 'enabled': True} if not user.kuser_id: - name = user.email[:user.email.find('@')] - user_fields = {'name': name, - 'email': user.email, - 'password': user.password, - 'enabled': True} keystone_user = self.driver.create_user(**user_fields) user.kuser_id = keystone_user.id - - if user.public_key: - self.save_key(user.public_key, user.keyname) + else: + self.driver.update_user(user.kuser_id, user_fields) if user.site: self.driver.add_user_role(user.kuser_id, user.site.tenant_id, 'user') @@ -110,6 +113,11 @@ class OpenStackManager: else: # may have admin role so attempt to remove it self.driver.delete_user_role(user.kuser_id, user.site.tenant_id, 'admin') + + if user.public_key: + self.init_caller(user, user.site.login_base) + self.save_key(user.public_key, user.keyname) + self.init_admin() @require_enabled def delete_user(self, user): @@ -203,8 +211,8 @@ class OpenStackManager: if subnet: self.driver.delete_external_route(subnet) - + @require_enabled def get_next_subnet(self): # limit ourself to 10.0.x.x for now valid_subnet = lambda net: net.startswith('10.0')