blob: 18a896a6bfc9edf5052b227fd4bb54228d3a6aee [file] [log] [blame]
Tony Mack7ab0db72013-04-08 23:19:32 -04001from plstackapi.openstack.client import OpenStackClient
2from plstackapi.openstack.driver import OpenStackDriver
3from plstackapi.planetstack.api.auth import auth_check
4from plstackapi.planetstack.models import Site
5
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 Macka3d5ee62013-04-08 23:34:31 -040018def update_site(auth, login_base, **fields):
Tony Mack7ab0db72013-04-08 23:19:32 -040019 driver = OpenStackDriver(client = auth_check(auth))
Tony Macka3d5ee62013-04-08 23:34:31 -040020 sites = Site.objects.filter(login_base=login_base)
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:
38 driver.delete_tenant({'id': site.tenant_id})
39 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