mirror of
https://opendev.org/openstack/ansible-collections-openstack.git
synced 2026-03-27 14:03:03 +00:00
Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1ce7dd8b5f | ||
|
|
438bbea34b | ||
|
|
e065818024 | ||
|
|
0764e671a9 | ||
|
|
5f4db3583e | ||
|
|
6262474c94 | ||
|
|
f9fcd35018 | ||
|
|
5dbf47cb49 | ||
|
|
57c63e7918 | ||
|
|
ed5829d462 | ||
|
|
b025e7c356 | ||
|
|
782340833e | ||
|
|
73aab9e80c | ||
|
|
ae7e8260a3 | ||
|
|
c5d0d3ec82 |
@@ -5,6 +5,67 @@ Ansible OpenStack Collection Release Notes
|
||||
.. contents:: Topics
|
||||
|
||||
|
||||
v2.4.1
|
||||
======
|
||||
|
||||
Release Summary
|
||||
---------------
|
||||
|
||||
Bugfixes and minor changes
|
||||
|
||||
Minor Changes
|
||||
-------------
|
||||
|
||||
- Update tags when changing server
|
||||
|
||||
Bugfixes
|
||||
--------
|
||||
|
||||
- Fix missed client_cert in OpenStackModule
|
||||
|
||||
v2.4.0
|
||||
======
|
||||
|
||||
Release Summary
|
||||
---------------
|
||||
|
||||
New trait module and minor changes
|
||||
|
||||
Major Changes
|
||||
-------------
|
||||
|
||||
- Add trait module
|
||||
|
||||
Minor Changes
|
||||
-------------
|
||||
|
||||
- Add loadbalancer quota options
|
||||
- Allow create instance with tags
|
||||
|
||||
New Modules
|
||||
-----------
|
||||
|
||||
- openstack.cloud.trait - Add or Delete a trait from OpenStack
|
||||
|
||||
v2.3.3
|
||||
======
|
||||
|
||||
Release Summary
|
||||
---------------
|
||||
|
||||
Bugfixes and minor changes
|
||||
|
||||
Minor Changes
|
||||
-------------
|
||||
|
||||
- Add test to only_ipv4 in inventory
|
||||
- add an option to use only IPv4 only for ansible_host and ansible_ssh_host
|
||||
|
||||
Bugfixes
|
||||
--------
|
||||
|
||||
- CI - Fix deprecated ANSIBLE_COLLECTIONS_PATHS variable
|
||||
|
||||
v2.3.2
|
||||
======
|
||||
|
||||
|
||||
@@ -586,3 +586,33 @@ releases:
|
||||
- Drop compat implementations for tests
|
||||
release_summary: Bugfixes and minor changes
|
||||
release_date: '2024-12-20'
|
||||
2.3.3:
|
||||
changes:
|
||||
bugfixes:
|
||||
- CI - Fix deprecated ANSIBLE_COLLECTIONS_PATHS variable
|
||||
minor_changes:
|
||||
- Add test to only_ipv4 in inventory
|
||||
- add an option to use only IPv4 only for ansible_host and ansible_ssh_host
|
||||
release_summary: Bugfixes and minor changes
|
||||
release_date: '2024-12-22'
|
||||
2.4.0:
|
||||
changes:
|
||||
major_changes:
|
||||
- Add trait module
|
||||
minor_changes:
|
||||
- Add loadbalancer quota options
|
||||
- Allow create instance with tags
|
||||
release_summary: New trait module and minor changes
|
||||
modules:
|
||||
- description: Add or Delete a trait from OpenStack
|
||||
name: trait
|
||||
namespace: ''
|
||||
release_date: '2025-01-15'
|
||||
2.4.1:
|
||||
changes:
|
||||
bugfixes:
|
||||
- Fix missed client_cert in OpenStackModule
|
||||
minor_changes:
|
||||
- Update tags when changing server
|
||||
release_summary: Bugfixes and minor changes
|
||||
release_date: '2024-01-20'
|
||||
|
||||
@@ -303,6 +303,25 @@
|
||||
that:
|
||||
- inventory.all.children.RegionOne.hosts.keys() | sort == ['ansible_server1', 'ansible_server2'] | sort
|
||||
|
||||
- name: List servers with inventory plugin with IPv4 only
|
||||
ansible.builtin.command:
|
||||
cmd: ansible-inventory --list --yaml --extra-vars only_ipv4=true --inventory-file openstack.yaml
|
||||
chdir: "{{ tmp_dir.path }}"
|
||||
environment:
|
||||
ANSIBLE_INVENTORY_CACHE: "True"
|
||||
ANSIBLE_INVENTORY_CACHE_PLUGIN: "jsonfile"
|
||||
ANSIBLE_CACHE_PLUGIN_CONNECTION: "{{ tmp_dir.path }}/.cache/"
|
||||
register: inventory
|
||||
|
||||
- name: Read YAML output from inventory plugin again
|
||||
ansible.builtin.set_fact:
|
||||
inventory: "{{ inventory.stdout | from_yaml }}"
|
||||
|
||||
- name: Check YAML output from inventory plugin again
|
||||
assert:
|
||||
that:
|
||||
- inventory.all.children.RegionOne.hosts.keys() | sort == ['ansible_server1', 'ansible_server2'] | sort
|
||||
|
||||
- name: Delete server 2
|
||||
openstack.cloud.resource:
|
||||
service: compute
|
||||
|
||||
@@ -28,3 +28,9 @@ test_compute_quota:
|
||||
ram: 5
|
||||
server_group_members: 5
|
||||
server_groups: 5
|
||||
test_load_balancer_quota:
|
||||
load_balancers: 5
|
||||
health_monitors: 5
|
||||
listeners: 5
|
||||
pools: 5
|
||||
members: 5
|
||||
|
||||
158
ci/roles/quota/tasks/loadbalancer.yml
Normal file
158
ci/roles/quota/tasks/loadbalancer.yml
Normal file
@@ -0,0 +1,158 @@
|
||||
---
|
||||
- module_defaults:
|
||||
group/openstack.cloud.openstack:
|
||||
cloud: "{{ cloud }}"
|
||||
name: "{{ test_project }}"
|
||||
# Backward compatibility with Ansible 2.9
|
||||
openstack.cloud.project:
|
||||
cloud: "{{ cloud }}"
|
||||
name: "{{ test_project }}"
|
||||
openstack.cloud.quota:
|
||||
cloud: "{{ cloud }}"
|
||||
name: "{{ test_project }}"
|
||||
block:
|
||||
- name: Create test project
|
||||
openstack.cloud.project:
|
||||
state: present
|
||||
|
||||
- name: Clear quotas before tests
|
||||
openstack.cloud.quota:
|
||||
state: absent
|
||||
register: default_quotas
|
||||
|
||||
- name: Set network quota
|
||||
openstack.cloud.quota: "{{ test_network_quota }}"
|
||||
register: quotas
|
||||
|
||||
- name: Assert changed
|
||||
assert:
|
||||
that: quotas is changed
|
||||
|
||||
- name: Assert field values
|
||||
assert:
|
||||
that: quotas.quotas.network[item.key] == item.value
|
||||
loop: "{{ test_network_quota | dict2items }}"
|
||||
|
||||
- name: Set network quota again
|
||||
openstack.cloud.quota: "{{ test_network_quota }}"
|
||||
register: quotas
|
||||
|
||||
- name: Assert not changed
|
||||
assert:
|
||||
that: quotas is not changed
|
||||
|
||||
- name: Set volume quotas
|
||||
openstack.cloud.quota: "{{ test_volume_quota }}"
|
||||
register: quotas
|
||||
|
||||
- name: Assert changed
|
||||
assert:
|
||||
that: quotas is changed
|
||||
|
||||
- name: Assert field values
|
||||
assert:
|
||||
that: quotas.quotas.volume[item.key] == item.value
|
||||
loop: "{{ test_volume_quota | dict2items }}"
|
||||
|
||||
- name: Set volume quotas again
|
||||
openstack.cloud.quota: "{{ test_volume_quota }}"
|
||||
register: quotas
|
||||
|
||||
- name: Assert not changed
|
||||
assert:
|
||||
that: quotas is not changed
|
||||
|
||||
- name: Set compute quotas
|
||||
openstack.cloud.quota: "{{ test_compute_quota }}"
|
||||
register: quotas
|
||||
|
||||
- name: Assert changed
|
||||
assert:
|
||||
that: quotas is changed
|
||||
|
||||
- name: Assert field values
|
||||
assert:
|
||||
that: quotas.quotas.compute[item.key] == item.value
|
||||
loop: "{{ test_compute_quota | dict2items }}"
|
||||
|
||||
- name: Set compute quotas again
|
||||
openstack.cloud.quota: "{{ test_compute_quota }}"
|
||||
register: quotas
|
||||
|
||||
- name: Set load_balancer quotas
|
||||
openstack.cloud.quota: "{{ 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 }}"
|
||||
register: quotas
|
||||
|
||||
- name: Assert not changed
|
||||
assert:
|
||||
that: quotas is not changed
|
||||
|
||||
- name: Unset all quotas
|
||||
openstack.cloud.quota:
|
||||
state: absent
|
||||
register: quotas
|
||||
|
||||
- name: Assert defaults restore
|
||||
assert:
|
||||
that: quotas.quotas == default_quotas.quotas
|
||||
|
||||
- name: Set all quotas at once
|
||||
openstack.cloud.quota:
|
||||
"{{ [test_network_quota, test_volume_quota, test_compute_quota, test_load_balancer_quota] | combine }}"
|
||||
register: quotas
|
||||
|
||||
- name: Assert changed
|
||||
assert:
|
||||
that: quotas is changed
|
||||
|
||||
- name: Assert volume values
|
||||
assert:
|
||||
that: quotas.quotas.volume[item.key] == item.value
|
||||
loop: "{{ test_volume_quota | dict2items }}"
|
||||
|
||||
- name: Assert network values
|
||||
assert:
|
||||
that: quotas.quotas.network[item.key] == item.value
|
||||
loop: "{{ test_network_quota | dict2items }}"
|
||||
|
||||
- name: Assert compute values
|
||||
assert:
|
||||
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
|
||||
loop: "{{ test_load_balancer_quota | dict2items }}"
|
||||
|
||||
- name: Set all quotas at once again
|
||||
openstack.cloud.quota:
|
||||
"{{ [test_network_quota, test_volume_quota, test_compute_quota, test_load_balancer_quota] | combine }}"
|
||||
register: quotas
|
||||
|
||||
- name: Assert not changed
|
||||
assert:
|
||||
that: quotas is not changed
|
||||
|
||||
- name: Unset all quotas
|
||||
openstack.cloud.quota:
|
||||
state: absent
|
||||
register: quotas
|
||||
|
||||
- name: Delete test project
|
||||
openstack.cloud.project:
|
||||
state: absent
|
||||
|
||||
@@ -128,4 +128,9 @@
|
||||
|
||||
- name: Delete test project
|
||||
openstack.cloud.project:
|
||||
state: absent
|
||||
state: absent
|
||||
|
||||
- import_tasks: loadbalancer.yml
|
||||
tags:
|
||||
- loadbalancer
|
||||
|
||||
|
||||
@@ -399,6 +399,9 @@
|
||||
- port-id: "{{ port.port.id }}"
|
||||
reuse_ips: false
|
||||
state: present
|
||||
tags:
|
||||
- first
|
||||
- second
|
||||
wait: true
|
||||
register: server
|
||||
|
||||
@@ -413,6 +416,7 @@
|
||||
|selectattr('OS-EXT-IPS:type', 'equalto', 'floating')
|
||||
|map(attribute='addr')
|
||||
|list|length == 0
|
||||
- server.server.tags == ["first", "second"]
|
||||
|
||||
- name: Find all floating ips for debugging
|
||||
openstack.cloud.floating_ip_info:
|
||||
@@ -454,6 +458,8 @@
|
||||
- '{{ server_security_group }}'
|
||||
- '{{ server_alt_security_group }}'
|
||||
state: present
|
||||
tags:
|
||||
- yellow
|
||||
wait: true
|
||||
register: server_updated
|
||||
|
||||
@@ -475,6 +481,7 @@
|
||||
- server_updated.server.addresses[server_network]|length == 2
|
||||
- port.port.fixed_ips[0].ip_address in
|
||||
server_updated.server.addresses[server_network]|map(attribute='addr')
|
||||
- server_updated.server.tags == ['yellow']
|
||||
# TODO: Verify networks once openstacksdk's issue #2010352 has been solved
|
||||
# Ref.: https://storyboard.openstack.org/#!/story/2010352
|
||||
#- server_updated.server.addresses.public|length > 0
|
||||
@@ -509,6 +516,8 @@
|
||||
- '{{ server_security_group }}'
|
||||
- '{{ server_alt_security_group }}'
|
||||
state: present
|
||||
tags:
|
||||
- yellow
|
||||
wait: true
|
||||
register: server_updated_again
|
||||
|
||||
@@ -517,6 +526,7 @@
|
||||
that:
|
||||
- server.server.id == server_updated_again.server.id
|
||||
- server_updated_again is not changed
|
||||
- server_updated_again.server.tags == ['yellow']
|
||||
|
||||
# TODO: Drop failure test once openstacksdk's issue #2010352 has been solved
|
||||
# Ref.: https://storyboard.openstack.org/#!/story/2010352
|
||||
|
||||
1
ci/roles/trait/defaults/main.yml
Normal file
1
ci/roles/trait/defaults/main.yml
Normal file
@@ -0,0 +1 @@
|
||||
trait_name: CUSTOM_ANSIBLE_TRAIT
|
||||
23
ci/roles/trait/tasks/main.yml
Normal file
23
ci/roles/trait/tasks/main.yml
Normal file
@@ -0,0 +1,23 @@
|
||||
---
|
||||
- openstack.cloud.trait:
|
||||
cloud: "{{ cloud }}"
|
||||
state: present
|
||||
id: "{{ trait_name }}"
|
||||
delegate_to: localhost
|
||||
register: item
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "'name' in item.trait"
|
||||
- "item.trait.id == trait_name"
|
||||
|
||||
- openstack.cloud.trait:
|
||||
cloud: "{{ cloud }}"
|
||||
state: absent
|
||||
id: "{{ trait_name }}"
|
||||
delegate_to: localhost
|
||||
register: item
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "'trait' not in item"
|
||||
@@ -75,10 +75,10 @@ ansible-galaxy collection install --requirements-file ci/requirements.yml
|
||||
if [ -z "$PIP_INSTALL" ]; then
|
||||
tox -ebuild
|
||||
ansible-galaxy collection install "$(find build_artifact/ -maxdepth 1 -name 'openstack-cloud-*')" --force
|
||||
TEST_COLLECTIONS_PATHS=${HOME}/.ansible/collections:$ANSIBLE_COLLECTIONS_PATHS
|
||||
TEST_COLLECTIONS_PATHS=${HOME}/.ansible/collections:$ANSIBLE_COLLECTIONS_PATH
|
||||
else
|
||||
pip freeze | grep ansible-collections-openstack
|
||||
TEST_COLLECTIONS_PATHS=$VIRTUAL_ENV/share/ansible/collections:$ANSIBLE_COLLECTIONS_PATHS
|
||||
TEST_COLLECTIONS_PATHS=$VIRTUAL_ENV/share/ansible/collections:$ANSIBLE_COLLECTIONS_PATH
|
||||
fi
|
||||
|
||||
# We need to source the current tox environment so that Ansible will
|
||||
@@ -129,7 +129,7 @@ cd ci/
|
||||
# Run tests
|
||||
set -o pipefail
|
||||
# shellcheck disable=SC2086
|
||||
ANSIBLE_COLLECTIONS_PATHS=$TEST_COLLECTIONS_PATHS ansible-playbook \
|
||||
ANSIBLE_COLLECTIONS_PATH=$TEST_COLLECTIONS_PATHS ansible-playbook \
|
||||
-vvv ./run-collection.yml \
|
||||
-e "sdk_version=${SDK_VER} cloud=${CLOUD} cloud_alt=${CLOUD_ALT} ${ANSIBLE_VARS}" \
|
||||
${tag_opt} 2>&1 | sudo tee /opt/stack/logs/test_output.log
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
- { role: object, tags: object }
|
||||
- { role: object_container, tags: object_container }
|
||||
- { role: port, tags: port }
|
||||
- { role: trait, tags: trait }
|
||||
- { role: trunk, tags: trunk }
|
||||
- { role: project, tags: project }
|
||||
- { role: quota, tags: quota }
|
||||
|
||||
@@ -32,4 +32,4 @@ build_ignore:
|
||||
- .vscode
|
||||
- ansible_collections_openstack.egg-info
|
||||
- changelogs
|
||||
version: 2.3.2
|
||||
version: 2.4.1
|
||||
|
||||
@@ -96,6 +96,12 @@ options:
|
||||
only.
|
||||
type: bool
|
||||
default: false
|
||||
only_ipv4:
|
||||
description:
|
||||
- Use only ipv4 addresses for ansible_host and ansible_ssh_host.
|
||||
- Using I(only_ipv4) helps when running Ansible in a ipv4 only setup.
|
||||
type: bool
|
||||
default: false
|
||||
show_all:
|
||||
description:
|
||||
- Whether all servers should be listed or not.
|
||||
@@ -384,10 +390,17 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
|
||||
if address['OS-EXT-IPS:type'] == 'floating'),
|
||||
None)
|
||||
|
||||
fixed_ip = next(
|
||||
(address['addr'] for address in addresses
|
||||
if address['OS-EXT-IPS:type'] == 'fixed'),
|
||||
None)
|
||||
if self.get_option('only_ipv4'):
|
||||
fixed_ip = next(
|
||||
(address['addr'] for address in addresses
|
||||
if (address['OS-EXT-IPS:type'] == 'fixed' and address['version'] == 4)),
|
||||
None)
|
||||
|
||||
else:
|
||||
fixed_ip = next(
|
||||
(address['addr'] for address in addresses
|
||||
if address['OS-EXT-IPS:type'] == 'fixed'),
|
||||
None)
|
||||
|
||||
ip = floating_ip if floating_ip is not None and not self.get_option('private') else fixed_ip
|
||||
|
||||
|
||||
@@ -374,6 +374,7 @@ class OpenStackModule:
|
||||
verify=self.params['validate_certs'],
|
||||
cacert=self.params['ca_cert'],
|
||||
key=self.params['client_key'],
|
||||
cert=self.params['client_cert'],
|
||||
api_timeout=self.params['api_timeout'],
|
||||
interface=self.params['interface'],
|
||||
)
|
||||
|
||||
@@ -38,6 +38,9 @@ options:
|
||||
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 +64,12 @@ options:
|
||||
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 +77,9 @@ options:
|
||||
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,6 +239,33 @@ quotas:
|
||||
server_groups:
|
||||
description: Number of server groups to allow.
|
||||
type: int
|
||||
load_balancer:
|
||||
description: Load_balancer service quotas
|
||||
type: dict
|
||||
contains:
|
||||
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
|
||||
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
|
||||
@@ -234,16 +273,9 @@ quotas:
|
||||
floating_ips:
|
||||
description: Number of floating IP's to allow.
|
||||
type: int
|
||||
load_balancers:
|
||||
description: The maximum amount of load balancers one can
|
||||
create
|
||||
type: int
|
||||
networks:
|
||||
description: Number of networks to allow.
|
||||
type: int
|
||||
pools:
|
||||
description: The maximum amount of pools one can create.
|
||||
type: int
|
||||
ports:
|
||||
description: Number of Network ports to allow, this needs
|
||||
to be greater than the instances limit.
|
||||
@@ -312,9 +344,7 @@ quotas:
|
||||
server_groups: 10,
|
||||
network:
|
||||
floating_ips: 50,
|
||||
load_balancers: 10,
|
||||
networks: 10,
|
||||
pools: 10,
|
||||
ports: 160,
|
||||
rbac_policies: 10,
|
||||
routers: 10,
|
||||
@@ -330,6 +360,13 @@ quotas:
|
||||
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,9 +374,8 @@ 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'
|
||||
# to argument_spec, DOCUMENTATION and RETURN docstrings
|
||||
argument_spec = dict(
|
||||
backup_gigabytes=dict(type='int'),
|
||||
backups=dict(type='int'),
|
||||
@@ -350,6 +386,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 +394,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'),
|
||||
@@ -382,9 +422,9 @@ class QuotaModule(OpenStackModule):
|
||||
supports_check_mode=True
|
||||
)
|
||||
|
||||
# Some attributes in quota resources don't exist in the api anymore, mostly
|
||||
# compute quotas that were simply network proxies. This map allows marking
|
||||
# them to be skipped.
|
||||
# Some attributes in quota resources don't exist in the api anymore, e.g.
|
||||
# compute quotas that were simply network proxies, and pre-Octavia network
|
||||
# quotas. This map allows marking them to be skipped.
|
||||
exclusion_map = {
|
||||
'compute': {
|
||||
# 'fixed_ips', # Available until Nova API version 2.35
|
||||
@@ -397,7 +437,16 @@ class QuotaModule(OpenStackModule):
|
||||
# 'injected_file_path_bytes', # Nova API
|
||||
# 'injected_files', # version 2.56
|
||||
},
|
||||
'network': {'name'},
|
||||
'load_balancer': {'name'},
|
||||
'network': {
|
||||
'name',
|
||||
'l7_policies',
|
||||
'load_balancers',
|
||||
'loadbalancer',
|
||||
'health_monitors',
|
||||
'pools',
|
||||
'listeners',
|
||||
},
|
||||
'volume': {'name'},
|
||||
}
|
||||
|
||||
@@ -409,12 +458,18 @@ class QuotaModule(OpenStackModule):
|
||||
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 +507,6 @@ class QuotaModule(OpenStackModule):
|
||||
|
||||
# Get current quota values
|
||||
quotas = self._get_quotas(project)
|
||||
|
||||
changed = False
|
||||
|
||||
if self.ansible.check_mode:
|
||||
@@ -468,6 +522,8 @@ class QuotaModule(OpenStackModule):
|
||||
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 +541,10 @@ class QuotaModule(OpenStackModule):
|
||||
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()}
|
||||
|
||||
@@ -205,6 +205,12 @@ options:
|
||||
choices: [present, absent]
|
||||
default: present
|
||||
type: str
|
||||
tags:
|
||||
description:
|
||||
- A list of tags should be added to instance
|
||||
type: list
|
||||
elements: str
|
||||
default: []
|
||||
terminate_volume:
|
||||
description:
|
||||
- If C(true), delete volume when deleting the instance and if it has
|
||||
@@ -756,6 +762,7 @@ server:
|
||||
description: A list of associated tags.
|
||||
returned: success
|
||||
type: list
|
||||
elements: str
|
||||
task_state:
|
||||
description: The task state of this server.
|
||||
returned: success
|
||||
@@ -825,6 +832,7 @@ class ServerModule(OpenStackModule):
|
||||
scheduler_hints=dict(type='dict'),
|
||||
security_groups=dict(default=[], type='list', elements='str'),
|
||||
state=dict(default='present', choices=['absent', 'present']),
|
||||
tags=dict(type='list', default=[], elements='str'),
|
||||
terminate_volume=dict(default=False, type='bool'),
|
||||
userdata=dict(),
|
||||
volume_size=dict(type='int'),
|
||||
@@ -890,7 +898,8 @@ class ServerModule(OpenStackModule):
|
||||
return {
|
||||
**self._build_update_ips(server),
|
||||
**self._build_update_security_groups(server),
|
||||
**self._build_update_server(server)}
|
||||
**self._build_update_server(server),
|
||||
**self._build_update_tags(server)}
|
||||
|
||||
def _build_update_ips(self, server):
|
||||
auto_ip = self.params['auto_ip']
|
||||
@@ -1030,6 +1039,13 @@ class ServerModule(OpenStackModule):
|
||||
|
||||
return update
|
||||
|
||||
def _build_update_tags(self, server):
|
||||
required_tags = self.params.get('tags')
|
||||
if set(server["tags"]) == set(required_tags):
|
||||
return {}
|
||||
update = dict(tags=required_tags)
|
||||
return update
|
||||
|
||||
def _create(self):
|
||||
for k in ['auto_ip', 'floating_ips', 'floating_ip_pools']:
|
||||
if self.params[k] \
|
||||
@@ -1072,7 +1088,7 @@ class ServerModule(OpenStackModule):
|
||||
for k in ['auto_ip', 'availability_zone', 'boot_from_volume',
|
||||
'boot_volume', 'config_drive', 'description', 'key_name',
|
||||
'name', 'network', 'reuse_ips', 'scheduler_hints',
|
||||
'security_groups', 'terminate_volume', 'timeout',
|
||||
'security_groups', 'tags', 'terminate_volume', 'timeout',
|
||||
'userdata', 'volume_size', 'volumes', 'wait']:
|
||||
if self.params[k] is not None:
|
||||
args[k] = self.params[k]
|
||||
@@ -1104,6 +1120,7 @@ class ServerModule(OpenStackModule):
|
||||
def _update(self, server, update):
|
||||
server = self._update_ips(server, update)
|
||||
server = self._update_security_groups(server, update)
|
||||
server = self._update_tags(server, update)
|
||||
server = self._update_server(server, update)
|
||||
# Refresh server attributes after security groups etc. have changed
|
||||
#
|
||||
@@ -1176,6 +1193,16 @@ class ServerModule(OpenStackModule):
|
||||
# be postponed until all updates have been applied.
|
||||
return server
|
||||
|
||||
def _update_tags(self, server, update):
|
||||
tags = update.get('tags')
|
||||
|
||||
self.conn.compute.put(
|
||||
"/servers/{server_id}/tags".format(server_id=server['id']),
|
||||
json={"tags": tags},
|
||||
microversion="2.26"
|
||||
)
|
||||
return server
|
||||
|
||||
def _parse_metadata(self, metadata):
|
||||
if not metadata:
|
||||
return {}
|
||||
|
||||
110
plugins/modules/trait.py
Normal file
110
plugins/modules/trait.py
Normal file
@@ -0,0 +1,110 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (c) 2025, ScaleUp Technologies GmbH & Co. KG
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
DOCUMENTATION = '''
|
||||
---
|
||||
module: trait
|
||||
short_description: Add/Delete a trait from OpenStack
|
||||
author: OpenStack Ansible SIG
|
||||
description:
|
||||
- Add or Delete a trait from OpenStack
|
||||
options:
|
||||
id:
|
||||
description:
|
||||
- ID/Name of this trait
|
||||
required: true
|
||||
type: str
|
||||
state:
|
||||
description:
|
||||
- Should the resource be present or absent.
|
||||
choices: [present, absent]
|
||||
default: present
|
||||
type: str
|
||||
extends_documentation_fragment:
|
||||
- openstack.cloud.openstack
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
# Creates a trait with the ID CUSTOM_WINDOWS_SPLA
|
||||
- openstack.cloud.trait:
|
||||
cloud: openstack
|
||||
state: present
|
||||
id: CUSTOM_WINDOWS_SPLA
|
||||
'''
|
||||
|
||||
RETURN = '''
|
||||
trait:
|
||||
description: Dictionary describing the trait.
|
||||
returned: On success when I(state) is 'present'
|
||||
type: dict
|
||||
contains:
|
||||
id:
|
||||
description: ID of the trait.
|
||||
returned: success
|
||||
type: str
|
||||
'''
|
||||
|
||||
from ansible_collections.openstack.cloud.plugins.module_utils.openstack import (
|
||||
OpenStackModule)
|
||||
|
||||
|
||||
class TraitModule(OpenStackModule):
|
||||
|
||||
argument_spec = dict(
|
||||
id=dict(required=True),
|
||||
state=dict(default='present',
|
||||
choices=['absent', 'present']),
|
||||
)
|
||||
|
||||
module_kwargs = dict(
|
||||
supports_check_mode=True,
|
||||
)
|
||||
|
||||
def _system_state_change(self, trait):
|
||||
state = self.params['state']
|
||||
if state == 'present' and not trait:
|
||||
return True
|
||||
if state == 'absent' and trait:
|
||||
return True
|
||||
return False
|
||||
|
||||
def run(self):
|
||||
|
||||
state = self.params['state']
|
||||
id = self.params['id']
|
||||
|
||||
try:
|
||||
trait = self.conn.placement.get_trait(id)
|
||||
except self.sdk.exceptions.NotFoundException:
|
||||
trait = None
|
||||
|
||||
if self.ansible.check_mode:
|
||||
self.exit_json(changed=self._system_state_change(trait), trait=trait)
|
||||
|
||||
changed = False
|
||||
if state == 'present':
|
||||
if not trait:
|
||||
trait = self.conn.placement.create_trait(id)
|
||||
changed = True
|
||||
|
||||
self.exit_json(
|
||||
changed=changed, trait=trait.to_dict(computed=False))
|
||||
|
||||
elif state == 'absent':
|
||||
if trait:
|
||||
self.conn.placement.delete_trait(id, ignore_missing=False)
|
||||
self.exit_json(changed=True)
|
||||
|
||||
self.exit_json(changed=False)
|
||||
|
||||
|
||||
def main():
|
||||
module = TraitModule()
|
||||
module()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user