Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ovirt_host_networks: Fix removing the label #36783

Merged
merged 1 commit into from
Feb 28, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 10 additions & 6 deletions lib/ansible/modules/cloud/ovirt/ovirt_host_networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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),
)

Expand Down