summaryrefslogtreecommitdiffstats
path: root/snaps/openstack/create_project.py
diff options
context:
space:
mode:
Diffstat (limited to 'snaps/openstack/create_project.py')
-rw-r--r--snaps/openstack/create_project.py83
1 files changed, 64 insertions, 19 deletions
diff --git a/snaps/openstack/create_project.py b/snaps/openstack/create_project.py
index 0349890..ed7e9cd 100644
--- a/snaps/openstack/create_project.py
+++ b/snaps/openstack/create_project.py
@@ -74,6 +74,29 @@ class OpenStackProject(OpenStackIdentityObject):
logger.warn('Unable to associate user %s due to %s',
user.name, e)
+ if self.project_settings.quotas:
+ quota_dict = self.project_settings.quotas
+ nova = nova_utils.nova_client(self._os_creds, self._os_session)
+ quotas = nova_utils.get_compute_quotas(nova, self.__project.id)
+ if quotas:
+ if 'cores' in quota_dict:
+ quotas.cores = quota_dict['cores']
+ if 'instances' in quota_dict:
+ quotas.instances = quota_dict['instances']
+ if 'injected_files' in quota_dict:
+ quotas.injected_files = quota_dict['injected_files']
+ if 'injected_file_content_bytes' in quota_dict:
+ quotas.injected_file_content_bytes = \
+ quota_dict['injected_file_content_bytes']
+ if 'ram' in quota_dict:
+ quotas.ram = quota_dict['ram']
+ if 'fixed_ips' in quota_dict:
+ quotas.fixed_ips = quota_dict['fixed_ips']
+ if 'key_pairs' in quota_dict:
+ quotas.key_pairs = quota_dict['key_pairs']
+
+ nova_utils.update_quotas(nova, self.__project.id, quotas)
+
return self.__project
def clean(self):
@@ -83,16 +106,20 @@ class OpenStackProject(OpenStackIdentityObject):
"""
if self.__project:
# Delete security group 'default' if exists
- neutron = neutron_utils.neutron_client(self._os_creds)
- default_sec_grp = neutron_utils.get_security_group(
- neutron, sec_grp_name='default',
- project_id=self.__project.id)
- if default_sec_grp:
- try:
- neutron_utils.delete_security_group(
- neutron, default_sec_grp)
- except:
- pass
+ neutron = neutron_utils.neutron_client(
+ self._os_creds, self._os_session)
+ try:
+ default_sec_grp = neutron_utils.get_security_group(
+ neutron, self._keystone, sec_grp_name='default',
+ project_name=self.__project.name)
+ if default_sec_grp:
+ try:
+ neutron_utils.delete_security_group(
+ neutron, default_sec_grp)
+ except:
+ pass
+ finally:
+ neutron.httpclient.session.session.close()
# Delete Project
try:
@@ -114,6 +141,8 @@ class OpenStackProject(OpenStackIdentityObject):
if role:
keystone_utils.delete_role(self._keystone, role)
+ super(self.__class__, self).clean()
+
def get_project(self):
"""
Returns the OpenStack project object populated on create()
@@ -142,32 +171,48 @@ class OpenStackProject(OpenStackIdentityObject):
Returns the compute quotas as an instance of the ComputeQuotas class
:return:
"""
- nova = nova_utils.nova_client(self._os_creds)
- return nova_utils.get_compute_quotas(nova, self.__project.id)
+ nova = nova_utils.nova_client(self._os_creds, self._os_session)
+
+ try:
+ return nova_utils.get_compute_quotas(nova, self.__project.id)
+ finally:
+ nova.client.session.session.close()
def get_network_quotas(self):
"""
Returns the network quotas as an instance of the NetworkQuotas class
:return:
"""
- neutron = neutron_utils.neutron_client(self._os_creds)
- return neutron_utils.get_network_quotas(neutron, self.__project.id)
+ neutron = neutron_utils.neutron_client(
+ self._os_creds, self._os_session)
+ try:
+ return neutron_utils.get_network_quotas(neutron, self.__project.id)
+ finally:
+ neutron.httpclient.session.session.close()
def update_compute_quotas(self, compute_quotas):
"""
Updates the compute quotas for this project
:param compute_quotas: a ComputeQuotas object.
"""
- nova = nova_utils.nova_client(self._os_creds)
- nova_utils.update_quotas(nova, self.__project.id, compute_quotas)
+ nova = nova_utils.nova_client(self._os_creds, self._os_session)
+ try:
+ nova_utils.update_quotas(nova, self.__project.id, compute_quotas)
+ finally:
+ nova.client.session.session.close()
def update_network_quotas(self, network_quotas):
"""
Updates the network quotas for this project
:param network_quotas: a NetworkQuotas object.
"""
- neutron = neutron_utils.neutron_client(self._os_creds)
- neutron_utils.update_quotas(neutron, self.__project.id, network_quotas)
+ neutron = neutron_utils.neutron_client(
+ self._os_creds, self._os_session)
+ try:
+ neutron_utils.update_quotas(
+ neutron, self.__project.id, network_quotas)
+ finally:
+ neutron.httpclient.session.session.close()
class ProjectSettings(ProjectConfig):
@@ -181,4 +226,4 @@ class ProjectSettings(ProjectConfig):
from warnings import warn
warn('Use snaps.config.project.ProjectConfig instead',
DeprecationWarning)
- super(self.__class__, self).__init__(**kwargs) \ No newline at end of file
+ super(self.__class__, self).__init__(**kwargs)