Tony Mack | 0b2b804 | 2013-04-07 19:55:27 -0400 | [diff] [blame^] | 1 | from plstackapi.openstack.client import OpenStackClient |
| 2 | from plstackapi.openstack.driver import OpenStackDriver |
| 3 | from plstackapi.planetstack.models import * |
| 4 | |
| 5 | |
| 6 | def auth_check(auth): |
| 7 | client = OpenStackShell(username=auth['Username'], |
| 8 | password=auth['AuthMethod', |
| 9 | tenant=auth['LoginBase']) |
| 10 | client.authenticate() |
| 11 | return client |
| 12 | |
| 13 | |
| 14 | def add_role(auth, name): |
| 15 | client = auth_check(auth) |
| 16 | keystone_role = client.keystone.roles.create(name) |
| 17 | role = Role(role_type=name, role_id=keystone_role.id) |
| 18 | role.save() |
| 19 | return role |
| 20 | |
| 21 | def delete_role(auth, name): |
| 22 | client = auth_check(auth) |
| 23 | role = Role.objects.filter(role_type=name) |
| 24 | client.keystone.roles.delete(role.role_id) |
| 25 | role.delete() |
| 26 | return 1 |
| 27 | |
| 28 | def get_roles(auth, filter): |
| 29 | client = auth_check(auth) |
| 30 | roles = Role.objects.filter(**filter) |
| 31 | return roles |
| 32 | |
| 33 | |
| 34 | |