organized
diff --git a/plstackapi/core/api/__init__.py b/plstackapi/core/api/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/plstackapi/core/api/__init__.py
diff --git a/plstackapi/core/api/auth.py b/plstackapi/core/api/auth.py
new file mode 100644
index 0000000..4054da6
--- /dev/null
+++ b/plstackapi/core/api/auth.py
@@ -0,0 +1,8 @@
+from plstackapi.openstack.client import OpenStackClient
+
+def auth_check(auth):
+ client = OpenStackClient(username=auth['Username'],
+ password=auth['AuthString'],
+ tenant=auth['LoginBase'])
+ client.authenticate()
+ return client
diff --git a/plstackapi/core/api/deployment_networks.py b/plstackapi/core/api/deployment_networks.py
new file mode 100644
index 0000000..812ca15
--- /dev/null
+++ b/plstackapi/core/api/deployment_networks.py
@@ -0,0 +1,26 @@
+from plstackapi.openstack.client import OpenStackClient
+from plstackapi.openstack.driver import OpenStackDriver
+from plstackapi.core.api.auth import auth_check
+from plstackapi.core.models import DeploymentNetwork
+
+
+def add_deployment_network(auth, name):
+ auth_check(auth)
+ deployment = DeploymentNetwork(name=name)
+ deployment.save()
+ return deployment
+
+def delete_deployment_network(auth, filter={}):
+ auth_check(auth)
+ deployments = DeploymentNetwork.objects.filter(**filter)
+ for deployment in deployments:
+ deployment.delete()
+ return 1
+
+def get_deployment_networks(auth, filter={}):
+ auth_check(auth)
+ deployments = DeploymentNetwork.objects.filter(**filter)
+ return deployments
+
+
+
diff --git a/plstackapi/core/api/flavors.py b/plstackapi/core/api/flavors.py
new file mode 100644
index 0000000..a2d0b23
--- /dev/null
+++ b/plstackapi/core/api/flavors.py
@@ -0,0 +1,21 @@
+from plstackapi.openstack.client import OpenStackClient
+from plstackapi.openstack.driver import OpenStackDriver
+from plstackapi.core.api.auth import auth_check
+from plstackapi.core.models import Flavor
+
+
+def add_flavor(auth, fields={}):
+ """not implemented"""
+ return
+
+def delete_flavor(auth, filter={}):
+ """not implemented"""
+ return 1
+
+def get_flavors(auth, filter={}):
+ auth_check(auth)
+ flavors = Flavor.objects.filter(**filter)
+ return flavors
+
+
+
diff --git a/plstackapi/core/api/images.py b/plstackapi/core/api/images.py
new file mode 100644
index 0000000..b773b0b
--- /dev/null
+++ b/plstackapi/core/api/images.py
@@ -0,0 +1,21 @@
+from plstackapi.openstack.client import OpenStackClient
+from plstackapi.openstack.driver import OpenStackDriver
+from plstackapi.core.api.auth import auth_check
+from plstackapi.core.models import Image
+
+
+def add_image(auth, fields={}):
+ """not implemented"""
+ return
+
+def delete_image(auth, filter={}):
+ """not implemented"""
+ return 1
+
+def get_images(auth, filter={}):
+ auth_check(auth)
+ images = Image.objects.filter(**filter)
+ return images
+
+
+
diff --git a/plstackapi/core/api/keys.py b/plstackapi/core/api/keys.py
new file mode 100644
index 0000000..af21f41
--- /dev/null
+++ b/plstackapi/core/api/keys.py
@@ -0,0 +1,45 @@
+from plstackapi.openstack.client import OpenStackClient
+from plstackapi.openstack.driver import OpenStackDriver
+from plstackapi.core.api.auth import auth_check
+from plstackapi.core.models import Key, User
+
+def lookup_user(fields):
+ user = None
+ if 'user' in fields:
+ if isinstance(fields['user'], int):
+ users = User.objects.filter(id=fields['user'])
+ else:
+ users = User.objects.filter(email=fields['user'])
+ if users:
+ user = users[0]
+ return user
+
+def add_key(auth, fields):
+ driver = OpenStackDriver(client = auth_check(auth))
+ user = lookup_user(fields)
+ if user: fields['user'] = user
+ key = Key(**fields)
+ nova_fields = {'name': key.name,
+ 'key': key.key}
+ nova_key = driver.create_keypair(**nova_fields)
+ key.save()
+ return key
+
+def update_key(auth, id, **fields):
+ return
+
+def delete_key(auth, filter={}):
+ driver = OpenStackDriver(client = auth_check(auth))
+ keys = Key.objects.filter(**filter)
+ for key in keys:
+ driver.delete_keypair(name=key.name)
+ key.delete()
+ return 1
+
+def get_keys(auth, filter={}):
+ client = auth_check(auth)
+ keys = Key.objects.filter(**filter)
+ return keys
+
+
+
diff --git a/plstackapi/core/api/roles.py b/plstackapi/core/api/roles.py
new file mode 100644
index 0000000..844fb4f
--- /dev/null
+++ b/plstackapi/core/api/roles.py
@@ -0,0 +1,28 @@
+from plstackapi.openstack.client import OpenStackClient
+from plstackapi.openstack.driver import OpenStackDriver
+from plstackapi.core.api.auth import auth_check
+from plstackapi.core.models import Role
+
+
+def add_role(auth, name):
+ driver = OpenStackDriver(client = auth_check(auth))
+ keystone_role = driver.create_role(name=name)
+ role = Role(role_type=name, role_id=keystone_role.id)
+ role.save()
+ return role
+
+def delete_role(auth, filter={}):
+ driver = OpenStackDriver(client = auth_check(auth))
+ roles = Role.objects.filter(**filter)
+ for role in roles:
+ driver.delete_role({'id': role.role_id})
+ role.delete()
+ return 1
+
+def get_roles(auth, filter={}):
+ client = auth_check(auth)
+ roles = Role.objects.filter(**filter)
+ return roles
+
+
+
diff --git a/plstackapi/core/api/sites.py b/plstackapi/core/api/sites.py
new file mode 100644
index 0000000..0d07605
--- /dev/null
+++ b/plstackapi/core/api/sites.py
@@ -0,0 +1,48 @@
+from plstackapi.openstack.client import OpenStackClient
+from plstackapi.openstack.driver import OpenStackDriver
+from plstackapi.core.api.auth import auth_check
+from plstackapi.core.models import Site
+
+
+def add_site(auth, fields):
+ driver = OpenStackDriver(client = auth_check(auth))
+ site = Site(**fields)
+ nova_fields = {'tenant_name': site.login_base,
+ 'description': site.name,
+ 'enabled': site.enabled}
+ tenant = driver.create_tenant(**nova_fields)
+ site.tenant_id=tenant.id
+ site.save()
+ return site
+
+def update_site(auth, id, **fields):
+ driver = OpenStackDriver(client = auth_check(auth))
+ sites = Site.objects.filter(id=id)
+ if not sites:
+ return
+
+ site = Site[0]
+ nova_fields = {}
+ if 'description' in fields:
+ nova_fields['description'] = fields['name']
+ if 'enabled' in fields:
+ nova_fields['enabled'] = fields['enabled']
+ driver.update_tenant(site.tenant_id, **nova_fields)
+ site.update(**fields)
+ return site
+
+def delete_site(auth, filter={}):
+ driver = OpenStackDriver(client = auth_check(auth))
+ sites = Site.objects.filter(**filter)
+ for site in sites:
+ driver.delete_tenant(id=site.tenant_id)
+ site.delete()
+ return 1
+
+def get_sites(auth, filter={}):
+ client = auth_check(auth)
+ sites = Site.objects.filter(**filter)
+ return sites
+
+
+
diff --git a/plstackapi/core/api/users.py b/plstackapi/core/api/users.py
new file mode 100644
index 0000000..6862e30
--- /dev/null
+++ b/plstackapi/core/api/users.py
@@ -0,0 +1,67 @@
+from plstackapi.openstack.client import OpenStackClient
+from plstackapi.openstack.driver import OpenStackDriver
+from plstackapi.core.api.auth import auth_check
+from plstackapi.core.models import User, Site
+
+def lookup_site(fields):
+ site = None
+ if 'site' in fields:
+ if isinstance(fields['site'], int):
+ sites = Site.objects.filter(id=fields['site'])
+ else:
+ sites = Site.objects.filter(login_base=fields['site'])
+ if sites:
+ site = sites[0]
+ return site
+
+def add_user(auth, fields):
+ driver = OpenStackDriver(client = auth_check(auth))
+ site = lookup_site(fields)
+ if site: fields['site'] = site
+ user = User(**fields)
+ nova_fields = {'name': user.email[:user.email.find('@')],
+ 'email': user.email,
+ 'password': fields.get('password'),
+ 'enabled': user.enabled}
+ nova_user = driver.create_user(**nova_fields)
+ #driver.add_user_role(user.id, user.site.tenant_id, 'user')
+ user.user_id=nova_user.id
+ user.save()
+ return user
+
+def update_user(auth, id, **fields):
+ driver = OpenStackDriver(client = auth_check(auth))
+ users = User.objects.filter(id=id)
+ if not users:
+ return
+
+ user = users[0]
+ nova_fields = {}
+ if 'email' in fields:
+ nova_fields['name'] = fields['email'][:self.email.find('@')]
+ nova_fields['email'] = fields['email']
+ if 'password' in fields:
+ nova_fields['password'] = fields['password']
+ if 'enabled' in fields:
+ nova_fields['enabled'] = fields['enabled']
+ driver.update_user(user.user_id, **nova_fields)
+ site = lookup_site(fields)
+ if site: fields['site'] = site
+ user.update(**fields)
+ return user
+
+def delete_user(auth, filter={}):
+ driver = OpenStackDriver(client = auth_check(auth))
+ users = User.objects.filter(**filter)
+ for user in users:
+ driver.delete_user(id=user.user_id)
+ user.delete()
+ return 1
+
+def get_users(auth, filter={}):
+ client = auth_check(auth)
+ users = User.objects.filter(**filter)
+ return users
+
+
+