blob: 12a21b8eb2e776c66fe0204879a3c5c92f4a6361 [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):
7 client = OpenStackShell(username=auth['Username'],
Tony Mack488950a2013-04-07 20:35:50 -04008 password=auth['AuthMethod'],
Tony Mack0b2b8042013-04-07 19:55:27 -04009 tenant=auth['LoginBase'])
10 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