mirror of
https://opendev.org/openstack/ansible-collections-openstack.git
synced 2026-05-07 22:03:09 +00:00
Change subnets_info module to work with new SDK
Change-Id: Ie23604c34ed9fb17eeb15bf73db9019ca9ebc7d8
This commit is contained in:
committed by
Jakob Meng
parent
c13fac3796
commit
97fa59bf6f
@@ -5,6 +5,7 @@ expected_fields:
|
|||||||
- created_at
|
- created_at
|
||||||
- description
|
- description
|
||||||
- dns_nameservers
|
- dns_nameservers
|
||||||
|
- dns_publish_fixed_ip
|
||||||
- gateway_ip
|
- gateway_ip
|
||||||
- host_routes
|
- host_routes
|
||||||
- id
|
- id
|
||||||
|
|||||||
@@ -62,6 +62,49 @@
|
|||||||
assert:
|
assert:
|
||||||
that: subnet is not changed
|
that: subnet is not changed
|
||||||
|
|
||||||
|
- name: Get Subnet Info with name
|
||||||
|
openstack.cloud.subnets_info:
|
||||||
|
cloud: "{{ cloud }}"
|
||||||
|
name: "{{ subnet_name }}"
|
||||||
|
register: subnet
|
||||||
|
|
||||||
|
- name: assert subnet fields
|
||||||
|
assert:
|
||||||
|
that: item in subnet.subnets[0]
|
||||||
|
loop: "{{ expected_fields }}"
|
||||||
|
|
||||||
|
- name: Get Subnet Info with filters
|
||||||
|
openstack.cloud.subnets_info:
|
||||||
|
cloud: "{{ cloud }}"
|
||||||
|
filters:
|
||||||
|
enable_dhcp: "{{ enable_subnet_dhcp }}"
|
||||||
|
gateway_ip: 192.168.0.1
|
||||||
|
cidr: 192.168.0.0/24
|
||||||
|
register: subnet
|
||||||
|
|
||||||
|
- name: Verify Subnet info result
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- subnet is not changed
|
||||||
|
- subnet.subnets is defined
|
||||||
|
- subnet.subnets | length > 0
|
||||||
|
|
||||||
|
- name: Get Subnet Info with name and improper filter values
|
||||||
|
openstack.cloud.subnets_info:
|
||||||
|
cloud: "{{ cloud }}"
|
||||||
|
name: "{{ subnet_name }}"
|
||||||
|
filters:
|
||||||
|
gateway_ip: 192.168.16.1
|
||||||
|
cidr: 192.168.16.0/24
|
||||||
|
register: subnet
|
||||||
|
|
||||||
|
- name: Verify Subnet info result
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- subnet is not changed
|
||||||
|
- subnet.subnets is defined
|
||||||
|
- subnet.subnets | length == 0
|
||||||
|
|
||||||
- name: Update subnet
|
- name: Update subnet
|
||||||
openstack.cloud.subnet:
|
openstack.cloud.subnet:
|
||||||
cloud: "{{ cloud }}"
|
cloud: "{{ cloud }}"
|
||||||
|
|||||||
@@ -51,16 +51,16 @@
|
|||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- idem1 is not changed
|
- idem1 is not changed
|
||||||
- subnet_result.openstack_subnets is defined
|
- subnet_result.subnets is defined
|
||||||
- subnet_result.openstack_subnets | length == 1
|
- subnet_result.subnets | length == 1
|
||||||
- subnet_result.openstack_subnets[0].allocation_pools is defined
|
- subnet_result.subnets[0].allocation_pools is defined
|
||||||
- subnet_result.openstack_subnets[0].allocation_pools | length == 1
|
- subnet_result.subnets[0].allocation_pools | length == 1
|
||||||
|
|
||||||
- name: Verify Subnet Allocation Pools
|
- name: Verify Subnet Allocation Pools
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- subnet_result.openstack_subnets[0].allocation_pools.0.start == '192.168.0.2'
|
- subnet_result.subnets[0].allocation_pools.0.start == '192.168.0.2'
|
||||||
- subnet_result.openstack_subnets[0].allocation_pools.0.end == '192.168.0.8'
|
- subnet_result.subnets[0].allocation_pools.0.end == '192.168.0.8'
|
||||||
|
|
||||||
- name: Delete subnet {{ subnet_name }}
|
- name: Delete subnet {{ subnet_name }}
|
||||||
openstack.cloud.subnet:
|
openstack.cloud.subnet:
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ EXAMPLES = '''
|
|||||||
|
|
||||||
- name: Show openstack subnets
|
- name: Show openstack subnets
|
||||||
debug:
|
debug:
|
||||||
msg: "{{ result.openstack_subnets }}"
|
msg: "{{ result.subnets }}"
|
||||||
|
|
||||||
- name: Gather information about a previously created subnet by name
|
- name: Gather information about a previously created subnet by name
|
||||||
openstack.cloud.subnets_info:
|
openstack.cloud.subnets_info:
|
||||||
@@ -59,7 +59,7 @@ EXAMPLES = '''
|
|||||||
|
|
||||||
- name: Show openstack subnets
|
- name: Show openstack subnets
|
||||||
debug:
|
debug:
|
||||||
msg: "{{ result.openstack_subnets }}"
|
msg: "{{ result.subnets }}"
|
||||||
|
|
||||||
- name: Gather information about a previously created subnet with filter
|
- name: Gather information about a previously created subnet with filter
|
||||||
# Note: name and filters parameters are not mutually exclusive
|
# Note: name and filters parameters are not mutually exclusive
|
||||||
@@ -70,62 +70,98 @@ EXAMPLES = '''
|
|||||||
password: password
|
password: password
|
||||||
project_name: someproject
|
project_name: someproject
|
||||||
filters:
|
filters:
|
||||||
tenant_id: 55e2ce24b2a245b09f181bf025724cbe
|
project_id: 55e2ce24b2a245b09f181bf025724cbe
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- name: Show openstack subnets
|
- name: Show openstack subnets
|
||||||
debug:
|
debug:
|
||||||
msg: "{{ result.openstack_subnets }}"
|
msg: "{{ result.subnets }}"
|
||||||
'''
|
'''
|
||||||
|
|
||||||
RETURN = '''
|
RETURN = '''
|
||||||
openstack_subnets:
|
subnets:
|
||||||
description: has all the openstack information about the subnets
|
description: has all the openstack information about the subnets
|
||||||
returned: always, but can be null
|
returned: always, but can be empty list
|
||||||
type: complex
|
type: list
|
||||||
|
elements: dict
|
||||||
contains:
|
contains:
|
||||||
id:
|
id:
|
||||||
description: Unique UUID.
|
description: The ID of the subnet.
|
||||||
returned: success
|
|
||||||
type: str
|
type: str
|
||||||
name:
|
name:
|
||||||
description: Name given to the subnet.
|
description: Name given to the subnet.
|
||||||
returned: success
|
type: str
|
||||||
|
description:
|
||||||
|
description: Description of the subnet.
|
||||||
type: str
|
type: str
|
||||||
network_id:
|
network_id:
|
||||||
description: Network ID this subnet belongs in.
|
description: Network ID this subnet belongs in.
|
||||||
returned: success
|
|
||||||
type: str
|
type: str
|
||||||
cidr:
|
cidr:
|
||||||
description: Subnet's CIDR.
|
description: Subnet's CIDR.
|
||||||
returned: success
|
|
||||||
type: str
|
type: str
|
||||||
gateway_ip:
|
gateway_ip:
|
||||||
description: Subnet's gateway ip.
|
description: Subnet's gateway ip.
|
||||||
returned: success
|
|
||||||
type: str
|
type: str
|
||||||
enable_dhcp:
|
is_dhcp_enabled:
|
||||||
description: DHCP enable flag for this subnet.
|
description: Is DHCP enabled.
|
||||||
returned: success
|
|
||||||
type: bool
|
type: bool
|
||||||
ip_version:
|
ip_version:
|
||||||
description: IP version for this subnet.
|
description: IP version for this subnet.
|
||||||
returned: success
|
|
||||||
type: int
|
type: int
|
||||||
tenant_id:
|
|
||||||
description: Tenant id associated with this subnet.
|
|
||||||
returned: success
|
|
||||||
type: str
|
|
||||||
dns_nameservers:
|
dns_nameservers:
|
||||||
description: DNS name servers for this subnet.
|
description: DNS name servers for this subnet.
|
||||||
returned: success
|
|
||||||
type: list
|
type: list
|
||||||
elements: str
|
elements: str
|
||||||
allocation_pools:
|
allocation_pools:
|
||||||
description: Allocation pools associated with this subnet.
|
description: Allocation pools associated with this subnet.
|
||||||
returned: success
|
|
||||||
type: list
|
type: list
|
||||||
elements: dict
|
elements: dict
|
||||||
|
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
|
||||||
'''
|
'''
|
||||||
|
|
||||||
from ansible_collections.openstack.cloud.plugins.module_utils.openstack import OpenStackModule
|
from ansible_collections.openstack.cloud.plugins.module_utils.openstack import OpenStackModule
|
||||||
@@ -141,14 +177,23 @@ class SubnetInfoModule(OpenStackModule):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
kwargs = self.check_versioned(
|
kwargs = {}
|
||||||
filters=self.params['filters']
|
subnets = []
|
||||||
)
|
|
||||||
if self.params['name']:
|
if self.params['name']:
|
||||||
kwargs['name_or_id'] = self.params['name']
|
kwargs['name'] = self.params['name']
|
||||||
subnets = self.conn.search_subnets(**kwargs)
|
# Try to get subnet by ID
|
||||||
|
try:
|
||||||
self.exit(changed=False, openstack_subnets=subnets)
|
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)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|||||||
Reference in New Issue
Block a user