blob: 515576794b76ebfbbc2f241a11edbfb09111ace8 [file] [log] [blame]
Tony Mack0b2b8042013-04-07 19:55:27 -04001from plstackapi.openstack.client import OpenStackClient
2from plstackapi.openstack.driver import OpenStackDriver
Tony Mack62423942013-04-08 15:14:52 -04003from plstackapi.planetstack.api.auth import auth_check
Tony Macke87bffa2013-04-08 23:18:04 -04004from plstackapi.planetstack.models import Role
Tony Mack62423942013-04-08 15:14:52 -04005
Tony Mack0b2b8042013-04-07 19:55:27 -04006
7def add_role(auth, name):
Tony Mackb5f339f2013-04-08 16:29:38 -04008 driver = OpenStackDriver(client = auth_check(auth))
9 keystone_role = driver.create_role(name=name)
Tony Mack0b2b8042013-04-07 19:55:27 -040010 role = Role(role_type=name, role_id=keystone_role.id)
11 role.save()
12 return role
13
Tony Mackdcca4742013-04-08 21:54:57 -040014def delete_role(auth, filter={}):
Tony Mackb5f339f2013-04-08 16:29:38 -040015 driver = OpenStackDriver(client = auth_check(auth))
Tony Mack97850a22013-04-08 21:57:24 -040016 roles = Role.objects.filter(**filter)
17 for role in roles:
18 driver.delete_role({'id': role.role_id})
19 role.delete()
Tony Mack0b2b8042013-04-07 19:55:27 -040020 return 1
21
Tony Mack5271d6b2013-04-08 00:34:24 -040022def get_roles(auth, filter={}):
Tony Mack0b2b8042013-04-07 19:55:27 -040023 client = auth_check(auth)
24 roles = Role.objects.filter(**filter)
25 return roles
26
27
28