Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions ci/roles/quota/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
28 changes: 26 additions & 2 deletions ci/roles/quota/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
93 changes: 79 additions & 14 deletions plugins/modules/quota.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -61,13 +68,22 @@
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
aliases: [loadbalancer]
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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand All @@ -330,35 +364,46 @@
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
from collections import defaultdict


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(
type='int', aliases=['floatingip', 'compute_floating_ips',
'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',
aliases=['injected_path_size']),
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'),
Expand Down Expand Up @@ -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'},
}

Expand All @@ -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
Expand Down Expand Up @@ -452,7 +512,6 @@ def run(self):

# Get current quota values
quotas = self._get_quotas(project)

changed = False

if self.ansible.check_mode:
Expand All @@ -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)
Expand All @@ -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()}
Expand Down