Fix bugs
diff --git a/plstackapi/core/models/site.py b/plstackapi/core/models/site.py
index ef7db95..b15e35b 100644
--- a/plstackapi/core/models/site.py
+++ b/plstackapi/core/models/site.py
@@ -29,7 +29,6 @@
# update the record
if self.id:
self.driver.update_tenant(self.tenant_id,
- name=self.login_base,
description=self.name,
enabled=self.enabled)
diff --git a/plstackapi/core/models/slice.py b/plstackapi/core/models/slice.py
index dda6553..027ba10 100644
--- a/plstackapi/core/models/slice.py
+++ b/plstackapi/core/models/slice.py
@@ -39,6 +39,11 @@
router = self.driver.create_router(self.name)
self.router_id = router['id']
+ if self.id:
+ self.driver.update_tenant(self.tenant_id,
+ description=self.description,
+ enabled=self.enabled)
+
super(Slice, self).save(*args, **kwds)
def delete(self, *args, **kwds):
diff --git a/plstackapi/openstack/driver.py b/plstackapi/openstack/driver.py
index 940be6c..3522b8c 100644
--- a/plstackapi/openstack/driver.py
+++ b/plstackapi/openstack/driver.py
@@ -67,14 +67,32 @@
def add_user_role(self, user_id, tenant_id, role_name):
user = self.shell.keystone.users.find(id=user_id)
tenant = self.shell.keystone.tenants.find(id=tenant_id)
- role = self.shell.keystone.roles.find(role_name)
- return tenant.add_user(user, role)
+ role = self.shell.keystone.roles.find(name=role_name)
+
+ role_found = False
+ user_roles = user.list_roles(tenant.id)
+ for user_role in user_roles:
+ if user_role.name == role.name:
+ role_found = True
+ if not role_found:
+ tenant.add_user(user, role)
+
+ return 1
def delete_user_role(self, user_id, tenant_id, role_name):
user = self.shell.keystone.users.find(id=user_id)
tenant = self.shell.keystone.tenants.find(id=tenant_id)
- role = self.shell.keystone.roles.find(role_name)
- return tenant.delete_user(user, role)
+ role = self.shell.keystone.roles.find(name=role_name)
+
+ role_found = False
+ user_roles = user.list_roles(tenant.id)
+ for user_role in user_roles:
+ if user_role.name == role.name:
+ role_found = True
+ if role_found:
+ tenant.remove_user(user, role)
+
+ return 1
def update_user(self, id, **kwds):
return self.shell.keystone.users.update(id, **kwds)