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 |
Tony Mack | 6242394 | 2013-04-08 15:14:52 -0400 | [diff] [blame] | 3 | from plstackapi.planetstack.api.auth import auth_check |
| 4 | from plstackapi.planetstack.models import * |
| 5 | |
Tony Mack | 0b2b804 | 2013-04-07 19:55:27 -0400 | [diff] [blame] | 6 | |
| 7 | def add_role(auth, name): |
Tony Mack | b5f339f | 2013-04-08 16:29:38 -0400 | [diff] [blame] | 8 | driver = OpenStackDriver(client = auth_check(auth)) |
| 9 | keystone_role = driver.create_role(name=name) |
Tony Mack | 0b2b804 | 2013-04-07 19:55:27 -0400 | [diff] [blame] | 10 | role = Role(role_type=name, role_id=keystone_role.id) |
| 11 | role.save() |
| 12 | return role |
| 13 | |
Tony Mack | 0856d56 | 2013-04-08 21:41:31 -0400 | [diff] [blame] | 14 | def delete_role(auth, role_id): |
Tony Mack | b5f339f | 2013-04-08 16:29:38 -0400 | [diff] [blame] | 15 | driver = OpenStackDriver(client = auth_check(auth)) |
Tony Mack | 414e690 | 2013-04-08 21:44:07 -0400 | [diff] [blame^] | 16 | role = Role.objects.filter(role_id=role_id) |
Tony Mack | b5f339f | 2013-04-08 16:29:38 -0400 | [diff] [blame] | 17 | driver.delete_role(name) |
Tony Mack | 0b2b804 | 2013-04-07 19:55:27 -0400 | [diff] [blame] | 18 | role.delete() |
| 19 | return 1 |
| 20 | |
Tony Mack | 5271d6b | 2013-04-08 00:34:24 -0400 | [diff] [blame] | 21 | def get_roles(auth, filter={}): |
Tony Mack | 0b2b804 | 2013-04-07 19:55:27 -0400 | [diff] [blame] | 22 | client = auth_check(auth) |
| 23 | roles = Role.objects.filter(**filter) |
| 24 | return roles |
| 25 | |
| 26 | |
| 27 | |