From a0db01545409bffe095b5dc1f9ebc92015003ffd Mon Sep 17 00:00:00 2001 From: Ondra Machacek Date: Wed, 28 Feb 2018 14:05:32 +0100 Subject: [PATCH] ovirt_host_networks: Fix removing the label (#36783) --- .../modules/cloud/ovirt/ovirt_host_networks.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/ansible/modules/cloud/ovirt/ovirt_host_networks.py b/lib/ansible/modules/cloud/ovirt/ovirt_host_networks.py index 0e40f693618..20652fa7fa1 100644 --- a/lib/ansible/modules/cloud/ovirt/ovirt_host_networks.py +++ b/lib/ansible/modules/cloud/ovirt/ovirt_host_networks.py @@ -347,15 +347,21 @@ def main(): ] if networks else None, ) elif state == 'absent' and nic: - attachments_service = nics_service.nic_service(nic.id).network_attachments_service() + nic_service = nics_service.nic_service(nic.id) + + attachments_service = nic_service.network_attachments_service() attachments = attachments_service.list() + attached_labels = set([str(lbl.id) for lbl in nic_service.network_labels_service().list()]) if networks: network_names = [network['name'] for network in networks] attachments = [ attachment for attachment in attachments if get_link_name(connection, attachment.network) in network_names ] - if labels or bond or attachments: + + # Need to check if there are any labels to be removed, as backend fail + # if we try to send remove non existing label, for bond and attachments it's OK: + if (labels and set(labels).intersection(attached_labels)) or bond or attachments: host_networks_module.action( entity=host, action='setup_networks', @@ -367,10 +373,8 @@ def main(): ), ] if bond else None, removed_labels=[ - otypes.NetworkLabel( - name=str(name), - ) for name in labels - ] if labels else None, + otypes.NetworkLabel(id=str(name)) for name in labels + ], removed_network_attachments=list(attachments), )