mirror of
https://opendev.org/openstack/ansible-collections-openstack.git
synced 2026-05-06 13:23:06 +00:00
Merge "Add dns_[name,domain] to the port module"
This commit is contained in:
@@ -29,6 +29,7 @@
|
|||||||
designate: https://opendev.org/openstack/designate
|
designate: https://opendev.org/openstack/designate
|
||||||
devstack_services:
|
devstack_services:
|
||||||
designate: true
|
designate: true
|
||||||
|
neutron-dns: true
|
||||||
|
|
||||||
- job:
|
- job:
|
||||||
name: ansible-collections-openstack-functional-devstack-octavia
|
name: ansible-collections-openstack-functional-devstack-octavia
|
||||||
@@ -57,6 +58,7 @@
|
|||||||
octavia: https://opendev.org/openstack/octavia
|
octavia: https://opendev.org/openstack/octavia
|
||||||
devstack_services:
|
devstack_services:
|
||||||
designate: true
|
designate: true
|
||||||
|
neutron-dns: true
|
||||||
octavia: true
|
octavia: true
|
||||||
o-api: true
|
o-api: true
|
||||||
o-cw: true
|
o-cw: true
|
||||||
|
|||||||
@@ -60,6 +60,26 @@
|
|||||||
state: absent
|
state: absent
|
||||||
name: "{{ port_name }}"
|
name: "{{ port_name }}"
|
||||||
|
|
||||||
|
- name: Create port (with dns_name, dns_domain)
|
||||||
|
openstack.cloud.port:
|
||||||
|
cloud: "{{ cloud }}"
|
||||||
|
state: present
|
||||||
|
name: "{{ port_name }}"
|
||||||
|
network: "{{ network_name }}"
|
||||||
|
fixed_ips:
|
||||||
|
- ip_address: 10.5.5.69
|
||||||
|
dns_name: "dns-port-name"
|
||||||
|
dns_domain: "example.com."
|
||||||
|
register: port
|
||||||
|
|
||||||
|
- debug: var=port
|
||||||
|
|
||||||
|
- name: Delete port (with dns name,domain)
|
||||||
|
openstack.cloud.port:
|
||||||
|
cloud: "{{ cloud }}"
|
||||||
|
state: absent
|
||||||
|
name: "{{ port_name }}"
|
||||||
|
|
||||||
- name: Create port (with allowed_address_pairs and extra_dhcp_opts)
|
- name: Create port (with allowed_address_pairs and extra_dhcp_opts)
|
||||||
openstack.cloud.port:
|
openstack.cloud.port:
|
||||||
cloud: "{{ cloud }}"
|
cloud: "{{ cloud }}"
|
||||||
@@ -101,7 +121,7 @@
|
|||||||
|
|
||||||
- name: Assert binding:profile exists in created port
|
- name: Assert binding:profile exists in created port
|
||||||
assert:
|
assert:
|
||||||
that: "port.port['binding:profile']"
|
that: "port.port['binding_profile']"
|
||||||
|
|
||||||
- debug: var=port
|
- debug: var=port
|
||||||
|
|
||||||
|
|||||||
@@ -123,6 +123,14 @@ options:
|
|||||||
description:
|
description:
|
||||||
- Binding profile dict that the port should be created with.
|
- Binding profile dict that the port should be created with.
|
||||||
type: dict
|
type: dict
|
||||||
|
dns_name:
|
||||||
|
description:
|
||||||
|
- The dns name of the port ( only with dns-integration enabled )
|
||||||
|
type: str
|
||||||
|
dns_domain:
|
||||||
|
description:
|
||||||
|
- The dns domain of the port ( only with dns-integration enabled )
|
||||||
|
type: str
|
||||||
requirements:
|
requirements:
|
||||||
- "python >= 3.6"
|
- "python >= 3.6"
|
||||||
- "openstacksdk"
|
- "openstacksdk"
|
||||||
@@ -302,7 +310,9 @@ class NetworkPortModule(OpenStackModule):
|
|||||||
choices=['normal', 'direct', 'direct-physical',
|
choices=['normal', 'direct', 'direct-physical',
|
||||||
'macvtap', 'baremetal', 'virtio-forwarder']),
|
'macvtap', 'baremetal', 'virtio-forwarder']),
|
||||||
port_security_enabled=dict(default=None, type='bool'),
|
port_security_enabled=dict(default=None, type='bool'),
|
||||||
binding_profile=dict(default=None, type='dict')
|
binding_profile=dict(default=None, type='dict'),
|
||||||
|
dns_name=dict(type='str', default=None),
|
||||||
|
dns_domain=dict(type='str', default=None)
|
||||||
)
|
)
|
||||||
|
|
||||||
module_kwargs = dict(
|
module_kwargs = dict(
|
||||||
@@ -312,6 +322,13 @@ class NetworkPortModule(OpenStackModule):
|
|||||||
supports_check_mode=True
|
supports_check_mode=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def _is_dns_integration_enabled(self):
|
||||||
|
""" Check if dns-integraton is enabled """
|
||||||
|
for ext in self.conn.network.extensions():
|
||||||
|
if ext.alias == 'dns-integration':
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def _needs_update(self, port):
|
def _needs_update(self, port):
|
||||||
"""Check for differences in the updatable values.
|
"""Check for differences in the updatable values.
|
||||||
|
|
||||||
@@ -324,10 +341,18 @@ class NetworkPortModule(OpenStackModule):
|
|||||||
'binding:vnic_type',
|
'binding:vnic_type',
|
||||||
'port_security_enabled',
|
'port_security_enabled',
|
||||||
'binding:profile']
|
'binding:profile']
|
||||||
|
compare_dns = ['dns_name', 'dns_domain']
|
||||||
compare_list_dict = ['allowed_address_pairs',
|
compare_list_dict = ['allowed_address_pairs',
|
||||||
'extra_dhcp_opts']
|
'extra_dhcp_opts']
|
||||||
compare_list = ['security_groups']
|
compare_list = ['security_groups']
|
||||||
|
|
||||||
|
if self.conn.has_service('dns') and \
|
||||||
|
self._is_dns_integration_enabled():
|
||||||
|
for key in compare_dns:
|
||||||
|
if self.params[key] is not None and \
|
||||||
|
self.params[key] != port[key]:
|
||||||
|
return True
|
||||||
|
|
||||||
for key in compare_simple:
|
for key in compare_simple:
|
||||||
if self.params[key] is not None and self.params[key] != port[key]:
|
if self.params[key] is not None and self.params[key] != port[key]:
|
||||||
return True
|
return True
|
||||||
@@ -410,6 +435,11 @@ class NetworkPortModule(OpenStackModule):
|
|||||||
'binding:vnic_type',
|
'binding:vnic_type',
|
||||||
'port_security_enabled',
|
'port_security_enabled',
|
||||||
'binding:profile']
|
'binding:profile']
|
||||||
|
|
||||||
|
if self.conn.has_service('dns') and \
|
||||||
|
self._is_dns_integration_enabled():
|
||||||
|
optional_parameters.extend(['dns_name', 'dns_domain'])
|
||||||
|
|
||||||
for optional_param in optional_parameters:
|
for optional_param in optional_parameters:
|
||||||
if self.params[optional_param] is not None:
|
if self.params[optional_param] is not None:
|
||||||
port_kwargs[optional_param] = self.params[optional_param]
|
port_kwargs[optional_param] = self.params[optional_param]
|
||||||
@@ -473,12 +503,14 @@ class NetworkPortModule(OpenStackModule):
|
|||||||
msg="Specified network was not found."
|
msg="Specified network was not found."
|
||||||
)
|
)
|
||||||
|
|
||||||
port = self.conn.create_port(network_id, **port_kwargs)
|
port_kwargs['network_id'] = network_id
|
||||||
|
port = self.conn.network.create_port(**port_kwargs)
|
||||||
changed = True
|
changed = True
|
||||||
else:
|
else:
|
||||||
if self._needs_update(port):
|
if self._needs_update(port):
|
||||||
port_kwargs = self._compose_port_args()
|
port_kwargs = self._compose_port_args()
|
||||||
port = self.conn.update_port(port['id'], **port_kwargs)
|
port = self.conn.network.update_port(port['id'],
|
||||||
|
**port_kwargs)
|
||||||
changed = True
|
changed = True
|
||||||
self.exit_json(changed=changed, id=port['id'], port=port)
|
self.exit_json(changed=changed, id=port['id'], port=port)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user