blob: 0d07605fc15b2ffa51b860999bc509f01313d329 [file] [log] [blame]
Tony Mack7ab0db72013-04-08 23:19:32 -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 Site
Tony Mack7ab0db72013-04-08 23:19:32 -04005
6
Tony Mackb5478262013-04-08 23:51:47 -04007def add_site(auth, fields):
Tony Mack7ab0db72013-04-08 23:19:32 -04008 driver = OpenStackDriver(client = auth_check(auth))
9 site = Site(**fields)
Tony Mack3b113dc2013-04-08 23:54:26 -040010 nova_fields = {'tenant_name': site.login_base,
11 'description': site.name,
12 'enabled': site.enabled}
Tony Mack7ab0db72013-04-08 23:19:32 -040013 tenant = driver.create_tenant(**nova_fields)
14 site.tenant_id=tenant.id
15 site.save()
Tony Macka3d5ee62013-04-08 23:34:31 -040016 return site
Tony Mack7ab0db72013-04-08 23:19:32 -040017
Tony Mack1ae3cd12013-04-09 11:12:23 -040018def update_site(auth, id, **fields):
Tony Mack7ab0db72013-04-08 23:19:32 -040019 driver = OpenStackDriver(client = auth_check(auth))
Tony Mack1ae3cd12013-04-09 11:12:23 -040020 sites = Site.objects.filter(id=id)
Tony Mack7ab0db72013-04-08 23:19:32 -040021 if not sites:
22 return
23
24 site = Site[0]
25 nova_fields = {}
26 if 'description' in fields:
27 nova_fields['description'] = fields['name']
28 if 'enabled' in fields:
29 nova_fields['enabled'] = fields['enabled']
Tony Macka3d5ee62013-04-08 23:34:31 -040030 driver.update_tenant(site.tenant_id, **nova_fields)
31 site.update(**fields)
Tony Mack7ab0db72013-04-08 23:19:32 -040032 return site
33
34def delete_site(auth, filter={}):
35 driver = OpenStackDriver(client = auth_check(auth))
36 sites = Site.objects.filter(**filter)
37 for site in sites:
Tony Mackc96afa82013-04-09 01:18:54 -040038 driver.delete_tenant(id=site.tenant_id)
Tony Mack7ab0db72013-04-08 23:19:32 -040039 site.delete()
40 return 1
41
42def get_sites(auth, filter={}):
43 client = auth_check(auth)
44 sites = Site.objects.filter(**filter)
45 return sites
46
47
48