diff --git a/ci/roles/port/defaults/main.yml b/ci/roles/port/defaults/main.yml index de022001..948a315d 100644 --- a/ci/roles/port/defaults/main.yml +++ b/ci/roles/port/defaults/main.yml @@ -4,3 +4,6 @@ subnet_name: ansible_port_subnet port_name: ansible_port secgroup_name: ansible_port_secgroup no_security_groups: True +binding_profile: + "pci_slot": "0000:03:11.1" + "physical_network": "provider" diff --git a/ci/roles/port/tasks/main.yml b/ci/roles/port/tasks/main.yml index b36d344b..6bd47312 100644 --- a/ci/roles/port/tasks/main.yml +++ b/ci/roles/port/tasks/main.yml @@ -88,6 +88,30 @@ state: absent name: "{{ secgroup_name }}" +- name: Test port binding config (runs from train release sdk > 0.28) + block: + - name: Create port (with binding profile) + openstack.cloud.port: + cloud: "{{ cloud }}" + state: present + name: "{{ port_name }}" + network: "{{ network_name }}" + binding_profile: "{{ binding_profile }}" + register: port + + - name: Assert binding:profile exists in created port + assert: + that: "port.port['binding:profile']" + + - debug: var=port + + - name: Delete port (with binding profile) + openstack.cloud.port: + cloud: "{{ cloud }}" + state: absent + name: "{{ port_name }}" + when: sdk_version is version(0.28, '>') + - name: Delete subnet openstack.cloud.subnet: cloud: "{{ cloud }}" diff --git a/plugins/modules/port.py b/plugins/modules/port.py index 9e9efeaf..549a1984 100644 --- a/plugins/modules/port.py +++ b/plugins/modules/port.py @@ -119,6 +119,10 @@ options: description: - Whether to enable or disable the port security on the network. type: bool + binding_profile: + description: + - Binding profile dict that the port should be created with. + type: dict requirements: - "python >= 3.6" - "openstacksdk" @@ -199,6 +203,20 @@ EXAMPLES = ''' name: port1 network: foo vnic_type: direct + +# Create a port with binding profile +- openstack.cloud.port: + state: present + auth: + auth_url: https://identity.example.com + username: admin + password: admin + project_name: admin + name: port1 + network: foo + binding_profile: + "pci_slot": "0000:03:11.1" + "physical_network": "provider" ''' RETURN = ''' @@ -246,6 +264,10 @@ port_security_enabled: description: Port security state on the network. returned: success type: bool +binding:profile: + description: Port binded profile + returned: success + type: dict ''' from ansible.module_utils.basic import AnsibleModule, missing_required_lib @@ -274,7 +296,8 @@ def _needs_update(module, port, cloud): 'device_owner', 'device_id', 'binding:vnic_type', - 'port_security_enabled'] + 'port_security_enabled', + 'binding:profile'] compare_list_dict = ['allowed_address_pairs', 'extra_dhcp_opts'] compare_list = ['security_groups'] @@ -357,7 +380,8 @@ def _compose_port_args(module, cloud): 'device_owner', 'device_id', 'binding:vnic_type', - 'port_security_enabled'] + 'port_security_enabled', + 'binding:profile'] for optional_param in optional_parameters: if module.params[optional_param] is not None: port_kwargs[optional_param] = module.params[optional_param] @@ -393,7 +417,8 @@ def main(): vnic_type=dict(default=None, choices=['normal', 'direct', 'direct-physical', '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') ) module_kwargs = openstack_module_kwargs( @@ -424,6 +449,9 @@ def main(): # Neutron API accept 'binding:vnic_type' as an argument # for the port type. module.params['binding:vnic_type'] = module.params.pop('vnic_type') + # Neutron API accept 'binding:profile' as an argument + # for the port binding profile type. + module.params['binding:profile'] = module.params.pop('binding_profile') port = None network_id = None