2020-05-12 10:20:09 -05:00
|
|
|
#!/usr/bin/python
|
2022-07-28 09:19:14 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2020-05-12 10:20:09 -05:00
|
|
|
|
|
|
|
# Copyright (c) 2015 Hewlett-Packard Development Company, L.P.
|
|
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
|
|
|
|
DOCUMENTATION = '''
|
|
|
|
---
|
|
|
|
module: subnets_info
|
|
|
|
short_description: Retrieve information about one or more OpenStack subnets.
|
2020-06-17 12:35:09 -05:00
|
|
|
author: OpenStack Ansible SIG
|
2020-05-12 10:20:09 -05:00
|
|
|
description:
|
|
|
|
- Retrieve information about one or more subnets from OpenStack.
|
|
|
|
options:
|
|
|
|
name:
|
|
|
|
description:
|
|
|
|
- Name or ID of the subnet.
|
|
|
|
- Alias 'subnet' added in version 2.8.
|
|
|
|
required: false
|
|
|
|
aliases: ['subnet']
|
|
|
|
type: str
|
|
|
|
filters:
|
|
|
|
description:
|
|
|
|
- A dictionary of meta data to use for further filtering. Elements of
|
|
|
|
this dictionary may be additional dictionaries.
|
|
|
|
required: false
|
|
|
|
type: dict
|
|
|
|
extends_documentation_fragment:
|
|
|
|
- openstack.cloud.openstack
|
|
|
|
'''
|
|
|
|
|
|
|
|
EXAMPLES = '''
|
|
|
|
- name: Gather information about previously created subnets
|
|
|
|
openstack.cloud.subnets_info:
|
|
|
|
auth:
|
|
|
|
auth_url: https://identity.example.com
|
|
|
|
username: user
|
|
|
|
password: password
|
|
|
|
project_name: someproject
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: Show openstack subnets
|
|
|
|
debug:
|
2022-09-12 11:27:19 +00:00
|
|
|
msg: "{{ result.subnets }}"
|
2020-05-12 10:20:09 -05:00
|
|
|
|
|
|
|
- name: Gather information about a previously created subnet by name
|
|
|
|
openstack.cloud.subnets_info:
|
|
|
|
auth:
|
|
|
|
auth_url: https://identity.example.com
|
|
|
|
username: user
|
|
|
|
password: password
|
|
|
|
project_name: someproject
|
|
|
|
name: subnet1
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: Show openstack subnets
|
|
|
|
debug:
|
2022-09-12 11:27:19 +00:00
|
|
|
msg: "{{ result.subnets }}"
|
2020-05-12 10:20:09 -05:00
|
|
|
|
|
|
|
- name: Gather information about a previously created subnet with filter
|
|
|
|
# Note: name and filters parameters are not mutually exclusive
|
|
|
|
openstack.cloud.subnets_info:
|
|
|
|
auth:
|
|
|
|
auth_url: https://identity.example.com
|
|
|
|
username: user
|
|
|
|
password: password
|
|
|
|
project_name: someproject
|
|
|
|
filters:
|
2022-09-12 11:27:19 +00:00
|
|
|
project_id: 55e2ce24b2a245b09f181bf025724cbe
|
2020-05-12 10:20:09 -05:00
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: Show openstack subnets
|
|
|
|
debug:
|
2022-09-12 11:27:19 +00:00
|
|
|
msg: "{{ result.subnets }}"
|
2020-05-12 10:20:09 -05:00
|
|
|
'''
|
|
|
|
|
|
|
|
RETURN = '''
|
2022-09-12 11:27:19 +00:00
|
|
|
subnets:
|
2020-05-12 10:20:09 -05:00
|
|
|
description: has all the openstack information about the subnets
|
2022-09-12 11:27:19 +00:00
|
|
|
returned: always, but can be empty list
|
|
|
|
type: list
|
|
|
|
elements: dict
|
2020-05-12 10:20:09 -05:00
|
|
|
contains:
|
|
|
|
id:
|
2022-09-12 11:27:19 +00:00
|
|
|
description: The ID of the subnet.
|
2020-05-12 10:20:09 -05:00
|
|
|
type: str
|
|
|
|
name:
|
|
|
|
description: Name given to the subnet.
|
2022-09-12 11:27:19 +00:00
|
|
|
type: str
|
|
|
|
description:
|
|
|
|
description: Description of the subnet.
|
2020-05-12 10:20:09 -05:00
|
|
|
type: str
|
|
|
|
network_id:
|
|
|
|
description: Network ID this subnet belongs in.
|
|
|
|
type: str
|
|
|
|
cidr:
|
|
|
|
description: Subnet's CIDR.
|
|
|
|
type: str
|
|
|
|
gateway_ip:
|
|
|
|
description: Subnet's gateway ip.
|
|
|
|
type: str
|
2022-09-12 11:27:19 +00:00
|
|
|
is_dhcp_enabled:
|
|
|
|
description: Is DHCP enabled.
|
2020-05-12 10:20:09 -05:00
|
|
|
type: bool
|
|
|
|
ip_version:
|
|
|
|
description: IP version for this subnet.
|
|
|
|
type: int
|
|
|
|
dns_nameservers:
|
|
|
|
description: DNS name servers for this subnet.
|
|
|
|
type: list
|
|
|
|
elements: str
|
|
|
|
allocation_pools:
|
|
|
|
description: Allocation pools associated with this subnet.
|
|
|
|
type: list
|
|
|
|
elements: dict
|
2022-09-12 11:27:19 +00:00
|
|
|
created_at:
|
|
|
|
description: Date and time when the resource was created.
|
|
|
|
type: str
|
|
|
|
updated_at:
|
|
|
|
description: Date and time when the resource was updated.
|
|
|
|
type: str
|
|
|
|
dns_publish_fixed_ip:
|
|
|
|
description: Whether to publish DNS records for IPs from this subnet.
|
|
|
|
type: str
|
|
|
|
host_routes:
|
|
|
|
description: Additional routes for the subnet.
|
|
|
|
type: list
|
|
|
|
elements: dict
|
|
|
|
ipv6_address_mode:
|
|
|
|
description: The IPv6 address modes specifies mechanisms for assigning IP addresses.
|
|
|
|
type: str
|
|
|
|
ipv6_ra_mode:
|
|
|
|
description: The IPv6 router advertisement specifies whether the networking service should transmit ICMPv6 packets, for a subnet.
|
|
|
|
type: str
|
|
|
|
project_id:
|
|
|
|
description: The ID of the project.
|
|
|
|
type: str
|
|
|
|
revision_number:
|
|
|
|
description: The revision number of the resource.
|
|
|
|
type: str
|
|
|
|
segment_id:
|
|
|
|
description: The ID of a network segment the subnet is associated with.
|
|
|
|
type: str
|
|
|
|
service_types:
|
|
|
|
description: The service types associated with the subnet.
|
|
|
|
type: list
|
|
|
|
elements: str
|
|
|
|
subnet_pool_id:
|
|
|
|
description: The ID of the subnet pool associated with the subnet.
|
|
|
|
type: str
|
|
|
|
tags:
|
|
|
|
description: The list of tags on the resource.
|
|
|
|
type: list
|
|
|
|
elements: str
|
|
|
|
prefix_length:
|
|
|
|
description: The prefix length to use for subnet allocation from a subnet pool.
|
|
|
|
type: str
|
|
|
|
use_default_subnet_pool:
|
|
|
|
description: Whether to use the default subnet pool to obtain a CIDR.
|
|
|
|
type: bool
|
2020-05-12 10:20:09 -05:00
|
|
|
'''
|
|
|
|
|
2020-11-23 14:56:06 +01:00
|
|
|
from ansible_collections.openstack.cloud.plugins.module_utils.openstack import OpenStackModule
|
2020-05-12 10:20:09 -05:00
|
|
|
|
|
|
|
|
2020-11-23 14:56:06 +01:00
|
|
|
class SubnetInfoModule(OpenStackModule):
|
|
|
|
argument_spec = dict(
|
2022-07-27 12:39:44 +02:00
|
|
|
name=dict(aliases=['subnet']),
|
|
|
|
filters=dict(type='dict')
|
2020-05-12 10:20:09 -05:00
|
|
|
)
|
2021-08-16 13:21:27 +03:00
|
|
|
module_kwargs = dict(
|
|
|
|
supports_check_mode=True
|
|
|
|
)
|
2020-11-23 14:56:06 +01:00
|
|
|
|
|
|
|
def run(self):
|
2022-09-12 11:27:19 +00:00
|
|
|
kwargs = {}
|
|
|
|
subnets = []
|
2020-11-23 14:56:06 +01:00
|
|
|
if self.params['name']:
|
2022-09-12 11:27:19 +00:00
|
|
|
kwargs['name'] = self.params['name']
|
|
|
|
# Try to get subnet by ID
|
|
|
|
try:
|
|
|
|
raw = self.conn.network.get_subnet(self.params['name'])
|
|
|
|
raw = raw.to_dict(computed=False)
|
|
|
|
subnets.append(raw)
|
|
|
|
self.exit(changed=False, subnets=subnets)
|
|
|
|
except self.sdk.exceptions.ResourceNotFound:
|
|
|
|
pass
|
|
|
|
if self.params['filters']:
|
|
|
|
kwargs.update(self.params['filters'])
|
|
|
|
subnets = self.conn.network.subnets(**kwargs)
|
|
|
|
subnets = [i.to_dict(computed=False) for i in subnets]
|
|
|
|
self.exit(changed=False, subnets=subnets)
|
2020-11-23 14:56:06 +01:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
module = SubnetInfoModule()
|
|
|
|
module()
|
2020-05-12 10:20:09 -05:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|