mirror of
https://opendev.org/openstack/ansible-collections-openstack.git
synced 2026-07-29 03:04:29 +00:00
Add binding profile to port module
Neutron port is able to configure binding profile during creation. Add support of the binding profile to module Change-Id: I7a36fb05065cbd559cd7a00842070f97e7afbc13
This commit is contained in:
@@ -4,3 +4,6 @@ subnet_name: ansible_port_subnet
|
|||||||
port_name: ansible_port
|
port_name: ansible_port
|
||||||
secgroup_name: ansible_port_secgroup
|
secgroup_name: ansible_port_secgroup
|
||||||
no_security_groups: True
|
no_security_groups: True
|
||||||
|
binding_profile:
|
||||||
|
"pci_slot": "0000:03:11.1"
|
||||||
|
"physical_network": "provider"
|
||||||
|
|||||||
@@ -88,6 +88,30 @@
|
|||||||
state: absent
|
state: absent
|
||||||
name: "{{ secgroup_name }}"
|
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
|
- name: Delete subnet
|
||||||
openstack.cloud.subnet:
|
openstack.cloud.subnet:
|
||||||
cloud: "{{ cloud }}"
|
cloud: "{{ cloud }}"
|
||||||
|
|||||||
@@ -119,6 +119,10 @@ options:
|
|||||||
description:
|
description:
|
||||||
- Whether to enable or disable the port security on the network.
|
- Whether to enable or disable the port security on the network.
|
||||||
type: bool
|
type: bool
|
||||||
|
binding_profile:
|
||||||
|
description:
|
||||||
|
- Binding profile dict that the port should be created with.
|
||||||
|
type: dict
|
||||||
requirements:
|
requirements:
|
||||||
- "python >= 3.6"
|
- "python >= 3.6"
|
||||||
- "openstacksdk"
|
- "openstacksdk"
|
||||||
@@ -199,6 +203,20 @@ EXAMPLES = '''
|
|||||||
name: port1
|
name: port1
|
||||||
network: foo
|
network: foo
|
||||||
vnic_type: direct
|
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 = '''
|
RETURN = '''
|
||||||
@@ -246,6 +264,10 @@ port_security_enabled:
|
|||||||
description: Port security state on the network.
|
description: Port security state on the network.
|
||||||
returned: success
|
returned: success
|
||||||
type: bool
|
type: bool
|
||||||
|
binding:profile:
|
||||||
|
description: Port binded profile
|
||||||
|
returned: success
|
||||||
|
type: dict
|
||||||
'''
|
'''
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
||||||
@@ -274,7 +296,8 @@ def _needs_update(module, port, cloud):
|
|||||||
'device_owner',
|
'device_owner',
|
||||||
'device_id',
|
'device_id',
|
||||||
'binding:vnic_type',
|
'binding:vnic_type',
|
||||||
'port_security_enabled']
|
'port_security_enabled',
|
||||||
|
'binding:profile']
|
||||||
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']
|
||||||
@@ -357,7 +380,8 @@ def _compose_port_args(module, cloud):
|
|||||||
'device_owner',
|
'device_owner',
|
||||||
'device_id',
|
'device_id',
|
||||||
'binding:vnic_type',
|
'binding:vnic_type',
|
||||||
'port_security_enabled']
|
'port_security_enabled',
|
||||||
|
'binding:profile']
|
||||||
for optional_param in optional_parameters:
|
for optional_param in optional_parameters:
|
||||||
if module.params[optional_param] is not None:
|
if module.params[optional_param] is not None:
|
||||||
port_kwargs[optional_param] = module.params[optional_param]
|
port_kwargs[optional_param] = module.params[optional_param]
|
||||||
@@ -393,7 +417,8 @@ def main():
|
|||||||
vnic_type=dict(default=None,
|
vnic_type=dict(default=None,
|
||||||
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')
|
||||||
)
|
)
|
||||||
|
|
||||||
module_kwargs = openstack_module_kwargs(
|
module_kwargs = openstack_module_kwargs(
|
||||||
@@ -424,6 +449,9 @@ def main():
|
|||||||
# Neutron API accept 'binding:vnic_type' as an argument
|
# Neutron API accept 'binding:vnic_type' as an argument
|
||||||
# for the port type.
|
# for the port type.
|
||||||
module.params['binding:vnic_type'] = module.params.pop('vnic_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
|
port = None
|
||||||
network_id = None
|
network_id = None
|
||||||
|
|||||||
Reference in New Issue
Block a user