summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOndra Machacek <machacek.ondra@gmail.com>2017-01-18 16:44:02 +0100
committerRyan Brown <sb@ryansb.com>2017-01-18 10:44:02 -0500
commit5d00d4d85e86721896f43d69d62abd48d22193b2 (patch)
treea1dde3897e5e4c0975186173c3b57775020a5674
parentc6621aa0ae24b652e8eb5300d4481b39634d891e (diff)
downloadansible-5d00d4d85e86721896f43d69d62abd48d22193b2.tar.gz
cloud: ovirt_vms: Filter VNIC profile by cluster (#20246) (#20384)
This patch add additional filtering of VNIC profiles by the cluster parameter. It is a must, because there could be same names of the VNIC profiles in system, as every datacenter can have VNIC profile same name, which can be in other datacenter. This patch fixes issue #20246
-rw-r--r--lib/ansible/modules/cloud/ovirt/ovirt_vms.py33
1 files changed, 29 insertions, 4 deletions
diff --git a/lib/ansible/modules/cloud/ovirt/ovirt_vms.py b/lib/ansible/modules/cloud/ovirt/ovirt_vms.py
index ff139122e3..6e5e16f4a8 100644
--- a/lib/ansible/modules/cloud/ovirt/ovirt_vms.py
+++ b/lib/ansible/modules/cloud/ovirt/ovirt_vms.py
@@ -643,6 +643,34 @@ class VmsModule(BaseModule):
)
self.changed = True
+ def __get_vnic_profile_id(self, nic):
+ """
+ Return VNIC profile ID looked up by it's name, because there can be
+ more VNIC profiles with same name, other criteria of filter is cluster.
+ """
+ vnics_service = self._connection.system_service().vnic_profiles_service()
+ clusters_service = self._connection.system_service().clusters_service()
+ cluster = search_by_name(clusters_service, self.param('cluster'))
+ profiles = [
+ profile for profile in vnics_service.list()
+ if profile.name == nic.get('profile_name')
+ ]
+ cluster_networks = [
+ net.id for net in self._connection.follow_link(cluster.networks)
+ ]
+ try:
+ return next(
+ profile.id for profile in profiles
+ if profile.network.id in cluster_networks
+ )
+ except StopIteration:
+ raise Exception(
+ "Profile '%s' was not found in cluster '%s'" % (
+ nic.get('profile_name'),
+ self.param('cluster')
+ )
+ )
+
def __attach_nics(self, entity):
# Attach NICs to VM, if specified:
vnic_profiles_service = self._connection.system_service().vnic_profiles_service()
@@ -657,10 +685,7 @@ class VmsModule(BaseModule):
nic.get('interface', 'virtio')
),
vnic_profile=otypes.VnicProfile(
- id=search_by_name(
- vnic_profiles_service,
- nic.get('profile_name'),
- ).id
+ id=self.__get_vnic_profile_id(nic),
) if nic.get('profile_name') else None,
mac=otypes.Mac(
address=nic.get('mac_address')