Tony Mack | 7ab0db7 | 2013-04-08 23:19:32 -0400 | [diff] [blame^] | 1 | from plstackapi.openstack.client import OpenStackClient |
| 2 | from plstackapi.openstack.driver import OpenStackDriver |
| 3 | from plstackapi.planetstack.api.auth import auth_check |
| 4 | from plstackapi.planetstack.models import Site |
| 5 | |
| 6 | |
| 7 | def add_site(auth, **fields): |
| 8 | driver = OpenStackDriver(client = auth_check(auth)) |
| 9 | site = Site(**fields) |
| 10 | nova_fields = {'tenant_name': fields['login_base'], |
| 11 | 'description': fields['name', |
| 12 | 'enabled': fields['enabled']} |
| 13 | tenant = driver.create_tenant(**nova_fields) |
| 14 | site.tenant_id=tenant.id |
| 15 | site.save() |
| 16 | return role |
| 17 | |
| 18 | def update_site(auth, tenant_id, **fields): |
| 19 | driver = OpenStackDriver(client = auth_check(auth)) |
| 20 | sites = Site.objects.filter(tenant_id=tenant_id) |
| 21 | 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'] |
| 30 | |
| 31 | site.updtae(**fields) |
| 32 | return site |
| 33 | |
| 34 | def 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 | |
| 42 | def get_sites(auth, filter={}): |
| 43 | client = auth_check(auth) |
| 44 | sites = Site.objects.filter(**filter) |
| 45 | return sites |
| 46 | |
| 47 | |
| 48 | |