| from plstackapi.openstack.client import OpenStackClient |
| from plstackapi.openstack.driver import OpenStackDriver |
| from plstackapi.planetstack.models import * |
| |
| |
| def auth_check(auth): |
| client = OpenStackShell(username=auth['Username'], |
| password=auth['AuthMethod', |
| tenant=auth['LoginBase']) |
| client.authenticate() |
| return client |
| |
| |
| def add_role(auth, name): |
| client = auth_check(auth) |
| keystone_role = client.keystone.roles.create(name) |
| role = Role(role_type=name, role_id=keystone_role.id) |
| role.save() |
| return role |
| |
| def delete_role(auth, name): |
| client = auth_check(auth) |
| role = Role.objects.filter(role_type=name) |
| client.keystone.roles.delete(role.role_id) |
| role.delete() |
| return 1 |
| |
| def get_roles(auth, filter): |
| client = auth_check(auth) |
| roles = Role.objects.filter(**filter) |
| return roles |
| |
| |
| |