diff --git a/.zuul.yaml b/.zuul.yaml index b2a816a5..171d17de 100644 --- a/.zuul.yaml +++ b/.zuul.yaml @@ -29,6 +29,7 @@ designate: https://opendev.org/openstack/designate devstack_services: designate: true + neutron-dns: true - job: name: ansible-collections-openstack-functional-devstack-octavia @@ -57,6 +58,7 @@ octavia: https://opendev.org/openstack/octavia devstack_services: designate: true + neutron-dns: true octavia: true o-api: true o-cw: true diff --git a/ci/roles/port/tasks/main.yml b/ci/roles/port/tasks/main.yml index 6bd47312..0396b1d8 100644 --- a/ci/roles/port/tasks/main.yml +++ b/ci/roles/port/tasks/main.yml @@ -60,6 +60,26 @@ state: absent 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) openstack.cloud.port: cloud: "{{ cloud }}" @@ -101,7 +121,7 @@ - name: Assert binding:profile exists in created port assert: - that: "port.port['binding:profile']" + that: "port.port['binding_profile']" - debug: var=port diff --git a/plugins/modules/port.py b/plugins/modules/port.py index e370b640..accef4fc 100644 --- a/plugins/modules/port.py +++ b/plugins/modules/port.py @@ -123,6 +123,14 @@ options: description: - Binding profile dict that the port should be created with. 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: - "python >= 3.6" - "openstacksdk" @@ -302,7 +310,9 @@ class NetworkPortModule(OpenStackModule): choices=['normal', 'direct', 'direct-physical', 'macvtap', 'baremetal', 'virtio-forwarder']), 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( @@ -312,6 +322,13 @@ class NetworkPortModule(OpenStackModule): 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): """Check for differences in the updatable values. @@ -324,10 +341,18 @@ class NetworkPortModule(OpenStackModule): 'binding:vnic_type', 'port_security_enabled', 'binding:profile'] + compare_dns = ['dns_name', 'dns_domain'] compare_list_dict = ['allowed_address_pairs', 'extra_dhcp_opts'] 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: if self.params[key] is not None and self.params[key] != port[key]: return True @@ -410,6 +435,11 @@ class NetworkPortModule(OpenStackModule): 'binding:vnic_type', 'port_security_enabled', '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: if self.params[optional_param] is not None: port_kwargs[optional_param] = self.params[optional_param] @@ -473,12 +503,14 @@ class NetworkPortModule(OpenStackModule): 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 else: if self._needs_update(port): 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 self.exit_json(changed=changed, id=port['id'], port=port)