Skip to content

Commit

Permalink
ovirt_nic: Add network_filter_parameters
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Nečas <necas.marty@gmail.com>
  • Loading branch information
mnecas committed Nov 14, 2022
1 parent e8a7d91 commit 677b80b
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
bugfixes:
- ovirt_nic - Add network_filter_parameters (https://github.com/oVirt/ovirt-ansible-collection/pull/623).
58 changes: 57 additions & 1 deletion plugins/modules/ovirt_nic.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,19 @@
description:
- Defines if the NIC is linked to the virtual machine.
type: bool
network_filter_parameters:
description:
- "The list of network filter parameters."
elements: dict
type: list
version_added: 3.1.0
suboptions:
name:
description:
- "Name of the network filter parameter."
value:
description:
- "Value of the network filter parameter."
extends_documentation_fragment: @NAMESPACE@.@NAME@.ovirt
'''

Expand Down Expand Up @@ -122,6 +135,19 @@
id: 00000000-0000-0000-0000-000000000000
name: "new_nic_name"
vm: myvm
# Add NIC network filter parameters
- @NAMESPACE@.@NAME@.ovirt_nic:
state: present
name: mynic
vm: myvm
network_filter_parameters:
- name: GATEWAY_MAC
value: 01:02:03:ab:cd:ef
- name: GATEWAY_MAC
value: 01:02:03:ab:cd:eg
- name: GATEWAY_MAC
value: 01:02:03:ab:cd:eh
'''

RETURN = '''
Expand Down Expand Up @@ -170,6 +196,21 @@ def vnic_id(self):
def vnic_id(self, vnic_id):
self._vnic_id = vnic_id

def post_update(self, entity):
self._set_network_filter_parameters(entity.id)

def _set_network_filter_parameters(self, entity_id):
if self._module.params['network_filter_parameters'] is not None:
nfps_service = self._service.service(entity_id).network_filter_parameters_service()
nfp_list = nfps_service.list()
# Remove all previous network filter parameters
for nfp in nfp_list:
nfps_service.service(nfp.id).remove()

# Create all specified netwokr filters by user
for nfp in self._network_filter_parameters():
nfps_service.add(nfp)

def build_entity(self):
return otypes.Nic(
id=self._module.params.get('id'),
Expand All @@ -193,7 +234,8 @@ def update_check(self, entity):
equal(self._module.params.get('linked'), entity.linked) and
equal(self._module.params.get('name'), str(entity.name)) and
equal(self._module.params.get('profile'), get_link_name(self._connection, entity.vnic_profile)) and
equal(self._module.params.get('mac_address'), entity.mac.address)
equal(self._module.params.get('mac_address'), entity.mac.address) and
equal(self._network_filter_parameters(), entity.network_filter_parameters)
)
elif self._module.params.get('template'):
return (
Expand All @@ -203,6 +245,19 @@ def update_check(self, entity):
equal(self._module.params.get('profile'), get_link_name(self._connection, entity.vnic_profile))
)

def _network_filter_parameters(self):
if self._module.params['network_filter_parameters'] is None:
return []
networkFilterParameters = list()
for networkFilterParameter in self._module.params['network_filter_parameters']:
networkFilterParameters.append(
otypes.NetworkFilterParameter(
name=networkFilterParameter.get("name"),
value=networkFilterParameter.get("value")
)
)
return networkFilterParameters


def get_vnics(networks_service, network, connection):
resp = []
Expand All @@ -226,6 +281,7 @@ def main():
network=dict(type='str'),
mac_address=dict(type='str'),
linked=dict(type='bool'),
network_filter_parameters=dict(type='list', default=None, elements='dict'),
)
module = AnsibleModule(
argument_spec=argument_spec,
Expand Down

0 comments on commit 677b80b

Please sign in to comment.