1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

ovirt_host_networks: Fix removing the label (#36783)

This commit is contained in:
Ondra Machacek 2018-02-28 14:05:32 +01:00 committed by ansibot
parent d1214484e6
commit a0db015454

View file

@ -347,15 +347,21 @@ def main():
] if networks else None, ] if networks else None,
) )
elif state == 'absent' and nic: 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() attachments = attachments_service.list()
attached_labels = set([str(lbl.id) for lbl in nic_service.network_labels_service().list()])
if networks: if networks:
network_names = [network['name'] for network in networks] network_names = [network['name'] for network in networks]
attachments = [ attachments = [
attachment for attachment in attachments attachment for attachment in attachments
if get_link_name(connection, attachment.network) in network_names 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( host_networks_module.action(
entity=host, entity=host,
action='setup_networks', action='setup_networks',
@ -367,10 +373,8 @@ def main():
), ),
] if bond else None, ] if bond else None,
removed_labels=[ removed_labels=[
otypes.NetworkLabel( otypes.NetworkLabel(id=str(name)) for name in labels
name=str(name), ],
) for name in labels
] if labels else None,
removed_network_attachments=list(attachments), removed_network_attachments=list(attachments),
) )