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 |
Tony Mack | e87bffa | 2013-04-08 23:18:04 -0400 | [diff] [blame] | 4 | from plstackapi.planetstack.models import Role |
Tony Mack | 6242394 | 2013-04-08 15:14:52 -0400 | [diff] [blame] | 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 | dcca474 | 2013-04-08 21:54:57 -0400 | [diff] [blame] | 14 | def delete_role(auth, filter={}): |
Tony Mack | b5f339f | 2013-04-08 16:29:38 -0400 | [diff] [blame] | 15 | driver = OpenStackDriver(client = auth_check(auth)) |
Tony Mack | 97850a2 | 2013-04-08 21:57:24 -0400 | [diff] [blame] | 16 | roles = Role.objects.filter(**filter) |
| 17 | for role in roles: |
| 18 | driver.delete_role({'id': role.role_id}) |
| 19 | role.delete() |
Tony Mack | 0b2b804 | 2013-04-07 19:55:27 -0400 | [diff] [blame] | 20 | return 1 |
| 21 | |
Tony Mack | 5271d6b | 2013-04-08 00:34:24 -0400 | [diff] [blame] | 22 | def get_roles(auth, filter={}): |
Tony Mack | 0b2b804 | 2013-04-07 19:55:27 -0400 | [diff] [blame] | 23 | client = auth_check(auth) |
| 24 | roles = Role.objects.filter(**filter) |
| 25 | return roles |
| 26 | |
| 27 | |
| 28 | |