blob: 844fb4fd8d15993a336d570607a03b9d88bf43a5 [file] [log] [blame]
Tony Mack0b2b8042013-04-07 19:55:27 -04001from plstackapi.openstack.client import OpenStackClient
2from plstackapi.openstack.driver import OpenStackDriver
Tony Mackf1c12242013-04-09 16:08:43 -04003from plstackapi.core.api.auth import auth_check
4from plstackapi.core.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