blob: 5d1bfaf7ce4eb3e18f8d55d917e081541f757b11 [file] [log] [blame]
Tony Mack0b2b8042013-04-07 19:55:27 -04001from plstackapi.openstack.client import OpenStackClient
2from plstackapi.openstack.driver import OpenStackDriver
3from plstackapi.planetstack.models import *
4
5
6def auth_check(auth):
Tony Mack198027c2013-04-08 00:35:50 -04007 client = OpenStackDriver(username=auth['Username'],
8 password=auth['AuthMethod'],
9 tenant=auth['LoginBase'])
Tony Mack0b2b8042013-04-07 19:55:27 -040010 client.authenticate()
11 return client
12
13
14def 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
21def 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
Tony Mack5271d6b2013-04-08 00:34:24 -040028def get_roles(auth, filter={}):
Tony Mack0b2b8042013-04-07 19:55:27 -040029 client = auth_check(auth)
30 roles = Role.objects.filter(**filter)
31 return roles
32
33
34