diff --git a/ci/roles/quota/defaults/main.yml b/ci/roles/quota/defaults/main.yml index eafed1cd..fee1641e 100644 --- a/ci/roles/quota/defaults/main.yml +++ b/ci/roles/quota/defaults/main.yml @@ -28,3 +28,9 @@ test_compute_quota: ram: 5 server_group_members: 5 server_groups: 5 +test_loadbalancer_quota: + load_balancers: 5 + health_monitors: 5 + listeners: 5 + pools: 5 + members: 5 diff --git a/ci/roles/quota/tasks/main.yml b/ci/roles/quota/tasks/main.yml index 10475a93..3226c0da 100644 --- a/ci/roles/quota/tasks/main.yml +++ b/ci/roles/quota/tasks/main.yml @@ -79,6 +79,26 @@ openstack.cloud.quota: "{{ test_compute_quota }}" register: quotas + - name: Set load_balancer quotas + openstack.cloud.quotas: "{{ test_load_balancer_quota }}" + register: quotas + + - name: Assert changed + assert: + that: quotas is changed + + - name: Assert field values + assert: + that: quotas.quotas.load_balancer[item.key] == item.value + loop: "{{ test_load_balancer_quota | dict2items }}" + + - name: Set load_balancer quotas again + openstack.cloud.quota: "{{ test_load_balancer_quota }}" + + - name: Assert not changed + assert: + that: quotas is not changed + - name: Unset all quotas openstack.cloud.quota: state: absent @@ -90,7 +110,7 @@ - name: Set all quotas at once openstack.cloud.quota: - "{{ [test_network_quota, test_volume_quota, test_compute_quota] | combine }}" + "{{ [test_network_quota, test_volume_quota, test_compute_quota, test_load_balancer_quota] | combine }}" register: quotas - name: Assert changed @@ -112,9 +132,13 @@ that: quotas.quotas.compute[item.key] == item.value loop: "{{ test_compute_quota | dict2items }}" + - name: Assert load_balancer values + assert: + that: quotas.quotas.load_balancer[item.key] == item.value + - name: Set all quotas at once again openstack.cloud.quota: - "{{ [test_network_quota, test_volume_quota, test_compute_quota] | combine }}" + "{{ [test_network_quota, test_volume_quota, test_compute_quota, test_load_balancer_quota] | combine }}" register: quotas - name: Assert not changed diff --git a/plugins/modules/quota.py b/plugins/modules/quota.py index 572d1d7f..aa8f6cf2 100644 --- a/plugins/modules/quota.py +++ b/plugins/modules/quota.py @@ -20,6 +20,10 @@ backups: description: Maximum number of backups allowed. type: int + check_limit: + description: + - Flag to check the network quota usage before setting the new limit. + type: bool cores: description: Maximum number of CPU's per project. type: int @@ -38,6 +42,9 @@ groups: description: Number of groups that are allowed for the project type: int + health_monitors: + description: Maximum number of health monitors that can be created. + type: int injected_file_content_bytes: description: - Maximum file size in bytes. @@ -61,6 +68,12 @@ key_pairs: description: Number of key pairs to allow. type: int + l7_policies: + description: The maximum amount of L7 policies you can create. + type: int + listeners: + description: The maximum number of listeners you can create. + type: int load_balancers: description: The maximum amount of load balancers you can create type: int @@ -68,6 +81,9 @@ metadata_items: description: Number of metadata items allowed per instance. type: int + members: + description: Number of members allowed for loadbalancer. + type: int name: description: Name of the OpenStack Project to manage. required: true @@ -227,23 +243,43 @@ server_groups: description: Number of server groups to allow. type: int - network: - description: Network service quotas + load_balancer: + description: Load_balancer service quotas type: dict contains: - floating_ips: - description: Number of floating IP's to allow. + health_monitors: + description: Maximum number of health monitors that can be + created. + type: int + l7_policies: + description: The maximum amount of L7 policies you can + create. + type: int + listeners: + description: The maximum number of listeners you can create type: int load_balancers: description: The maximum amount of load balancers one can create type: int - networks: - description: Number of networks to allow. + members: + description: The maximum amount of members for + loadbalancer. type: int pools: description: The maximum amount of pools one can create. type: int + + network: + description: Network service quotas + type: dict + contains: + floating_ips: + description: Number of floating IP's to allow. + type: int + networks: + description: Number of networks to allow. + type: int ports: description: Number of Network ports to allow, this needs to be greater than the instances limit. @@ -312,9 +348,7 @@ server_groups: 10, network: floating_ips: 50, - load_balancers: 10, networks: 10, - pools: 10, ports: 160, rbac_policies: 10, routers: 10, @@ -330,6 +364,13 @@ per_volume_gigabytes: -1, snapshots: 10, volumes: 10, + load_balancer: + health_monitors: 10, + load_balancers: 10, + l7_policies: 10, + listeners: 10, + pools: 5, + members: 5, ''' from ansible_collections.openstack.cloud.plugins.module_utils.openstack import OpenStackModule @@ -337,12 +378,12 @@ class QuotaModule(OpenStackModule): - # TODO: Add missing network quota options 'check_limit', 'health_monitors', - # 'l7_policies', 'listeners' to argument_spec, DOCUMENTATION and - # RETURN docstrings + # TODO: Add missing network quota options 'check_limit', and 'l7_policies' + # to argument_spec, DOCUMENTATION and RETURN docstrings argument_spec = dict( backup_gigabytes=dict(type='int'), backups=dict(type='int'), + check_limit=dict(type='bool'), cores=dict(type='int'), fixed_ips=dict(type='int'), floating_ips=dict( @@ -350,6 +391,7 @@ class QuotaModule(OpenStackModule): 'network_floating_ips']), gigabytes=dict(type='int'), groups=dict(type='int'), + health_monitors=dict(type='int'), injected_file_content_bytes=dict(type='int', aliases=['injected_file_size']), injected_file_path_bytes=dict(type='int', @@ -357,8 +399,11 @@ class QuotaModule(OpenStackModule): injected_files=dict(type='int'), instances=dict(type='int'), key_pairs=dict(type='int', no_log=False), + l7_policies=dict(type='int'), + listeners=dict(type='int'), load_balancers=dict(type='int', aliases=['loadbalancer']), metadata_items=dict(type='int'), + members=dict(type='int'), name=dict(required=True), networks=dict(type='int', aliases=['network']), per_volume_gigabytes=dict(type='int'), @@ -397,7 +442,16 @@ class QuotaModule(OpenStackModule): # 'injected_file_path_bytes', # Nova API # 'injected_files', # version 2.56 }, - 'network': {'name'}, + 'load_balancer': {'name'}, + 'network': { + 'name', + 'l7_policies', # Advertised but non-functional + 'load_balancers', # Advertised but non-functional + 'loadbalancer', # Advertised but non-functional + 'health_monitors', # Available only via load_balancer + 'pools', # Available only via load_balancer + 'listeners', # Available only via load_balancer + }, 'volume': {'name'}, } @@ -409,12 +463,18 @@ def _get_quotas(self, project): self.warn('Block storage service aka volume service is not' ' supported by your cloud. Ignoring volume quotas.') + if self.conn.has_service('load-balancer'): + quota['load_balancer'] = self.conn.load_balancer.get_quota( + project.id) + else: + self.warn('Loadbalancer service is not supported by your' + ' cloud. Ignoring loadbalancer quotas.') + if self.conn.has_service('network'): quota['network'] = self.conn.network.get_quota(project.id) else: self.warn('Network service is not supported by your cloud.' ' Ignoring network quotas.') - quota['compute'] = self.conn.compute.get_quota_set(project.id) return quota @@ -452,7 +512,6 @@ def run(self): # Get current quota values quotas = self._get_quotas(project) - changed = False if self.ansible.check_mode: @@ -468,6 +527,8 @@ def run(self): self.conn.network.delete_quota(project.id) if 'volume' in quotas: self.conn.block_storage.revert_quota_set(project) + if 'load_balancer' in quotas: + self.conn.load_balancer.delete_quota(project.id) # Necessary since we can't tell what the default quotas are quotas = self._get_quotas(project) @@ -485,6 +546,10 @@ def run(self): if 'network' in changes: quotas['network'] = self.conn.network.update_quota( project.id, **changes['network']) + if 'load_balancer' in changes: + quotas['load_balancer'] = \ + self.conn.load_balancer.update_quota( + project.id, **changes['load_balancer']) changed = True quotas = {k: v.to_dict(computed=False) for k, v in quotas.items()}