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
This commit is contained in:
parent
c6621aa0ae
commit
5d00d4d85e
1 changed files with 29 additions and 4 deletions
|
@ -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')
|
||||
|
|
Loading…
Reference in a new issue