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 nic default vnic backport #58057

Merged
merged 2 commits into from Jun 19, 2019
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions changelogs/fragments/57936-ovirt-nic-default-vnic.yml
@@ -0,0 +1,2 @@
bugfixes:
- When nic has only one vnic profile use it as default or raise error (https://github.com/ansible/ansible/pull/57945)
32 changes: 26 additions & 6 deletions lib/ansible/modules/cloud/ovirt/ovirt_nic.py
Expand Up @@ -47,6 +47,7 @@
profile:
description:
- Virtual network interface profile to be attached to VM network interface.
- When not specified and network has only single profile it will be auto-selected, otherwise you must specify profile.
interface:
description:
- "Type of the network interface. For example e1000, pci_passthrough, rtl8139, rtl8139_virtio, spapr_vlan or virtio."
Expand Down Expand Up @@ -183,6 +184,15 @@ def update_check(self, entity):
)


def get_vnics(networks_service, network, connection):
resp = []
vnic_services = connection.system_service().vnic_profiles_service()
for vnic in vnic_services.list():
if vnic.network.id == network.id:
resp.append(vnic)
return resp


def main():
argument_spec = ovirt_full_argument_spec(
state=dict(type='str', default='present', choices=['absent', 'plugged', 'present', 'unplugged']),
Expand Down Expand Up @@ -234,8 +244,8 @@ def main():
)

# Find vNIC id of the network interface (if any):
profile = module.params.get('profile')
if profile and module.params['network']:
if module.params['network']:
profile = module.params.get('profile')
cluster_name = get_link_name(connection, cluster_id)
dcs_service = connection.system_service().data_centers_service()
dc = dcs_service.list(search='Clusters.name=%s' % cluster_name)[0]
Expand All @@ -252,10 +262,20 @@ def main():
dc.name
)
)
for vnic in connection.system_service().vnic_profiles_service().list():
if vnic.name == profile and vnic.network.id == network.id:
entitynics_module.vnic_id = vnic.id

if profile:
for vnic in connection.system_service().vnic_profiles_service().list():
if vnic.name == profile and vnic.network.id == network.id:
entitynics_module.vnic_id = vnic.id
else:
# When not specified which vnic use ovirtmgmt/ovirtmgmt
vnics = get_vnics(networks_service, network, connection)
if len(vnics) == 1:
entitynics_module.vnic_id = vnics[0].id
else:
raise Exception(
"You didn't specify any vnic profile. "
"Following vnic profiles are in system: '%s', please specify one of them" % ([vnic.name for vnic in vnics])
)
# Handle appropriate action:
state = module.params['state']
if state == 'present':
Expand Down