Merge "Add ability to set tags in network modules"

This commit is contained in:
Zuul
2026-05-19 22:09:35 +00:00
committed by Gerrit Code Review
6 changed files with 125 additions and 1 deletions

View File

@@ -83,6 +83,11 @@ options:
Network will use Openstack defaults if this option is
not provided.
type: str
tags:
description:
- A list of tags to set on the network
type: list
elements: str
extends_documentation_fragment:
- openstack.cloud.openstack
'''
@@ -208,7 +213,8 @@ class NetworkModule(OpenStackModule):
project=dict(),
port_security_enabled=dict(type='bool'),
mtu=dict(type='int', aliases=['mtu_size']),
dns_domain=dict()
dns_domain=dict(),
tags=dict(type='list', elements='str'),
)
def run(self):
@@ -224,6 +230,7 @@ class NetworkModule(OpenStackModule):
provider_network_type = self.params['provider_network_type']
provider_segmentation_id = self.params['provider_segmentation_id']
project = self.params['project']
tags = self.params['tags']
kwargs = {}
for arg in ('port_security_enabled', 'mtu', 'dns_domain'):
@@ -304,6 +311,12 @@ class NetworkModule(OpenStackModule):
)
changed = True
if tags is not None:
old_tags = self.conn.network.get_tags(net)
if set(old_tags) != set(tags):
self.conn.network.set_tags(net, tags)
changed = True
net = net.to_dict(computed=False)
self.exit(changed=changed, network=net, id=net['id'])
elif state == 'absent':

View File

@@ -112,6 +112,11 @@ options:
choices: ['present', 'absent']
default: present
type: str
tags:
description:
- A list of tags to set on the network
type: list
elements: str
extends_documentation_fragment:
- openstack.cloud.openstack
'''
@@ -326,6 +331,7 @@ class RouterModule(OpenStackModule):
network=dict(),
project=dict(),
state=dict(default='present', choices=['absent', 'present']),
tags=dict(type='list', elements='str'),
)
module_kwargs = dict(
@@ -603,6 +609,7 @@ class RouterModule(OpenStackModule):
name = self.params['name']
network_name_or_id = self._get_external_gateway_network_name()
project_name_or_id = self.params['project']
tags = self.params['tags']
if self.params['external_fixed_ips'] and not network_name_or_id:
self.fail(
@@ -686,6 +693,12 @@ class RouterModule(OpenStackModule):
self._update_ifaces(router, to_add, to_remove,
missing_internal_ports)
if tags is not None:
old_tags = self.conn.network.get_tags(router)
if set(old_tags) != set(tags):
self.conn.network.set_tags(router, tags)
changed = True
self.exit_json(changed=changed,
router=router.to_dict(computed=False))

View File

@@ -137,6 +137,11 @@ options:
- The subnet pool name or ID from which to obtain a CIDR
type: str
required: false
tags:
description:
- A list of tags to set on the network
type: list
elements: str
extends_documentation_fragment:
- openstack.cloud.openstack
'''
@@ -322,6 +327,7 @@ class SubnetModule(OpenStackModule):
state=dict(default='present',
choices=['absent', 'present']),
project=dict(),
tags=dict(type='list', elements='str'),
)
module_kwargs = dict(
@@ -429,6 +435,7 @@ class SubnetModule(OpenStackModule):
subnet_name = self.params['name']
gateway_ip = self.params['gateway_ip']
disable_gateway_ip = self.params['disable_gateway_ip']
tags = self.params['tags']
# fail early if incompatible options have been specified
if disable_gateway_ip and gateway_ip:
@@ -485,6 +492,12 @@ class SubnetModule(OpenStackModule):
self._validate_update(subnet, updates)
subnet = self.conn.network.update_subnet(subnet, **updates)
changed = True
if tags is not None:
old_tags = self.conn.network.get_tags(subnet)
if set(old_tags) != set(tags):
self.conn.network.set_tags(subnet, tags)
changed = True
self.exit_json(changed=changed, subnet=subnet, id=subnet.id)
elif state == 'absent' and subnet is not None:
self.conn.network.delete_subnet(subnet)