diff --git a/.zuul.yaml b/.zuul.yaml index 7c48010c7a580b78d298b4f9135407a68c6469e8..e4904ac89e5aead3f2f45820d96017054613a677 100644 --- a/.zuul.yaml +++ b/.zuul.yaml @@ -95,6 +95,7 @@ object object_container port + port_info project project_info recordset diff --git a/ci/roles/port_info/tasks/main.yml b/ci/roles/port_info/tasks/main.yml new file mode 100644 index 0000000000000000000000000000000000000000..496c7e08bc3f53f36dffe3a7d08e83b70dd5416c --- /dev/null +++ b/ci/roles/port_info/tasks/main.yml @@ -0,0 +1,72 @@ +--- +- name: List all ports + openstack.cloud.port_info: + cloud: "{{ cloud }}" + register: result_all + +- name: Assert fields + assert: + that: + - item in result_all.ports.0 + loop: + - allowed_address_pairs + - binding_host_id + - binding_profile + - binding_vif_details + - binding_vif_type + - binding_vnic_type + - created_at + - data_plane_status + - description + - device_id + - device_owner + - device_profile + - dns_assignment + - dns_domain + - dns_name + - extra_dhcp_opts + - fixed_ips + - id + - ip_allocation + - is_admin_state_up + - is_port_security_enabled + - mac_address + - name + - network_id + - numa_affinity_policy + - project_id + - propagate_uplink_status + - qos_network_policy_id + - qos_policy_id + - resource_request + - revision_number + - security_group_ids + - status + - tags + - tenant_id + - trunk_details + - updated_at + +- name: Get port by id + openstack.cloud.port_info: + cloud: "{{ cloud }}" + port: "{{ result_all.ports[0].id }}" + register: result_id + +- name: Assert results by id + assert: + that: + - item.id == result_all.ports[0].id + loop: "{{ result_id.ports }}" + +- name: List port with device_id filter + openstack.cloud.port_info: + cloud: "{{ cloud }}" + filters: + device_id: "{{ result_all.ports[0].device_id }}" + register: result_filter + +- name: Assert port was returned + assert: + that: + - result_filter.ports | length >= 1 diff --git a/ci/run-collection.yml b/ci/run-collection.yml index 3d5246f18f31a5f5c951d5e962ec11c5844ff4c3..b165177c7d86a32189d9e1f1f88a6712a59e82f8 100644 --- a/ci/run-collection.yml +++ b/ci/run-collection.yml @@ -52,6 +52,7 @@ when: sdk_version is version(0.44, '>=') - { role: object, tags: object } - { role: port, tags: port } + - { role: port_info, tags: port_info } - { role: project, tags: project } - { role: project_info, tags: project_info } - { role: recordset, tags: recordset } diff --git a/plugins/modules/port_info.py b/plugins/modules/port_info.py index 0ed3f0599a130f2bdde1521d21bd33ed1a37dc98..938dd4298ac7c13b63bc367cbfa3ba60938b0b6d 100644 --- a/plugins/modules/port_info.py +++ b/plugins/modules/port_info.py @@ -19,9 +19,8 @@ options: filters: description: - A dictionary of meta data to use for further filtering. Elements - of this dictionary will be matched against the returned port - dictionaries. Matching is currently limited to strings within - the port dictionary, or strings within nested dictionaries. + of this dictionary will be matched passed to the API as query + parameter filters. type: dict requirements: - "python >= 3.6" @@ -38,7 +37,7 @@ EXAMPLES = ''' register: result - debug: - msg: "{{ result.openstack_ports }}" + msg: "{{ result.ports}}" # Gather information about a single port - openstack.cloud.port_info: @@ -55,54 +54,60 @@ EXAMPLES = ''' ''' RETURN = ''' -openstack_ports: +ports: description: List of port dictionaries. A subset of the dictionary keys listed below may be returned, depending on your cloud provider. - returned: always, but can be null - type: complex + returned: always + type: list + elements: dict contains: - admin_state_up: - description: The administrative state of the router, which is - up (true) or down (false). - returned: success - type: bool - sample: true allowed_address_pairs: description: A set of zero or more allowed address pairs. An address pair consists of an IP address and MAC address. returned: success type: list sample: [] - "binding:host_id": + binding_host_id: description: The UUID of the host where the port is allocated. returned: success type: str sample: "b4bd682d-234a-4091-aa5b-4b025a6a7759" - "binding:profile": + binding_profile: description: A dictionary the enables the application running on the host to pass and receive VIF port-specific information to the plug-in. returned: success type: dict sample: {} - "binding:vif_details": + binding_vif_details: description: A dictionary that enables the application to pass information about functions that the Networking API provides. returned: success type: dict - sample: {"port_filter": true} - "binding:vif_type": + binding_vif_type: description: The VIF type for the port. returned: success type: dict - sample: "ovs" - "binding:vnic_type": + binding_vnic_type: description: The virtual network interface card (vNIC) type that is bound to the neutron port. returned: success type: str sample: "normal" + created_at: + description: Date the port was created + returned: success + type: str + sample: "2022-02-03T13:28:25Z" + data_plane_status: + description: Status of the underlying data plane of a port. + returned: success + type: str + description: + description: Description of a port + returned: success + type: str device_id: description: The UUID of the device that uses this port. returned: success @@ -113,15 +118,22 @@ openstack_ports: returned: success type: str sample: "network:router_interface" + device_profile: + description: Device profile + returned: success + type: str dns_assignment: description: DNS assignment information. returned: success type: list + dns_domain: + description: A valid DNS domain + returned: success + type: str dns_name: description: DNS name returned: success type: str - sample: "" extra_dhcp_opts: description: A set of zero or more extra DHCP option pairs. An option pair consists of an option value and name. @@ -138,11 +150,22 @@ openstack_ports: returned: success type: str sample: "3ec25c97-7052-4ab8-a8ba-92faf84148de" - ip_address: - description: The IP address. + ip_allocation: + description: Indicates when ports use either deferred, immediate + or no IP allocation (none). returned: success type: str - sample: "127.0.0.1" + is_admin_state_up: + description: The administrative state of the router, which is + up (true) or down (false). + returned: success + type: bool + sample: true + is_port_security_enabled: + description: The port security status. The status is enabled (true) or disabled (false). + returned: success + type: bool + sample: false mac_address: description: The MAC address. returned: success @@ -158,12 +181,46 @@ openstack_ports: returned: success type: str sample: "dd1ede4f-3952-4131-aab6-3b8902268c7d" - port_security_enabled: - description: The port security status. The status is enabled (true) or disabled (false). + numa_affinity_policy: + description: The port NUMA affinity policy requested during the + virtual machine scheduling. Values are None, required, + preferred or legacy. + returned: success + type: str + sample: "required" + project_id: + description: The ID of the project. + returned: success + type: str + sample: "aa1ede4f-3952-4131-aab6-3b8902268c7d" + propagate_uplink_status: + description: The uplink status propagation of the port. returned: success type: bool sample: false - security_groups: + qos_network_policy_id: + description: The ID of the QoS policy of the network where this + port is plugged. + returned: success + type: str + sample: "1e4f3958-c0c9-4dec-82fa-ed2dc1c5cb34" + qos_policy_id: + description: The ID of the QoS policy associated with the port. + returned: success + type: str + sample: "b20bb47f-5d6d-45a6-8fe7-2c1b44f0db73" + resource_request: + description: Expose Placement resources i.e. minimum-bandwidth + and traits i.e. vnic-type, physnet requested by a + port to Nova and Placement + returned: success + type: str + revision_number: + description: The revision number of the resource. + returned: success + type: int + sample: 0 + security_group_ids: description: The UUIDs of any attached security groups. returned: success type: list @@ -172,11 +229,26 @@ openstack_ports: returned: success type: str sample: "ACTIVE" + tags: + description: The list of tags on the resource. + returned: success + type: list + sample: [] tenant_id: - description: The UUID of the tenant who owns the network. + description: The UUID of the tenant who owns the network. Deprecated. returned: success type: str sample: "51fce036d7984ba6af4f6c849f65ef00" + trunk_details: + description: The details about the trunk. + returned: success + type: dict + updated_at: + description: Last port update + returned: success + type: str + sample: "2022-02-03T13:28:25Z" + ''' from ansible_collections.openstack.cloud.plugins.module_utils.openstack import OpenStackModule @@ -184,21 +256,22 @@ from ansible_collections.openstack.cloud.plugins.module_utils.openstack import O class NetworkPortInfoModule(OpenStackModule): argument_spec = dict( - port=dict(required=False), - filters=dict(type='dict', required=False), + port=dict(type='str', required=False), + filters=dict(type='dict', required=False, default={}), ) module_kwargs = dict( supports_check_mode=True ) - deprecated_names = ('openstack.cloud.port_facts') - def run(self): - port = self.params.get('port') - filters = self.params.get('filters') + port = self.params['port'] + filters = self.params['filters'] ports = self.conn.search_ports(port, filters) - self.exit_json(changed=False, openstack_ports=ports) + + ports = [p.to_dict(computed=False) for p in ports] + + self.exit_json(changed=False, ports=ports) def main():