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
add support for configuring host networks with vmware_guest #38647
Conversation
previously the vmware_guest module would only allow use of distributed networks, and not host-specific networks. This change makes it support both.
host = vm.summary.runtime.host | ||
elif self.params['esxi_hostname']: | ||
host = self.select_host() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about adding this -
diff --git a/lib/ansible/modules/cloud/vmware/vmware_guest.py b/lib/ansible/modules/cloud/vmware/vmware_guest.py
index 6985ca5497..f4fec7eec5 100644
--- a/lib/ansible/modules/cloud/vmware/vmware_guest.py
+++ b/lib/ansible/modules/cloud/vmware/vmware_guest.py
@@ -992,8 +992,24 @@ class PyVmomiHelper(PyVmomi):
self.module.fail_json(msg="Please specify at least a network name or"
" a VLAN name under VM network list.")
- if 'name' in network and find_obj(self.content, [vim.Network], network['name']) is None:
- self.module.fail_json(msg="Network '%(name)s' does not exist." % network)
+ if 'name' in network:
+ if find_obj(self.content, [vim.Network], network['name']) is None:
+ self.module.fail_json(msg="Network '%(name)s' does not exist." % network)
+ else:
+ if self.params.get('esxi_hostname', None):
+ esxi_hostname = self.select_host()
+ if network['name'] not in [nw.name for nw in esxi_hostname.network]:
+ self.module.fail_json(msg="Specified network '%s' is not associated "
+ "with the given ESXi hostname '%s'" % (network['name'],
+ self.params['esxi_hostname']))
+ elif self.params.get('cluster', None):
+ cluster = self.cache.get_cluster(self.params['cluster'])
+ if network['name'] not in [nw.name for nw in cluster.network]:
+ self.module.fail_json(msg="Specified network '%s' is not associated"
+ " with the given cluster '%s'" % (network['name'],
+ self.params['cluster']))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+ if find_obj(self.content, [vim.Network], network['name']) is None:
+ self.module.fail_json(msg="Network '%(name)s' does not exist." % network)
+ else:
^ The else
will get evaluated when the network is found, which is not what we're after. If the network is not found, we want to try searching the host for it instead.
+ if self.params.get('esxi_hostname', None):
+ esxi_hostname = self.select_host()
This will only handle the scenario where the user specifies an esxi_hostname. It won't handle the scenario where the user didn't specify one, but was automatically assigned one.
+ cluster = self.cache.get_cluster(self.params['cluster'])
+ if network['name'] not in [nw.name for nw in cluster.network]:
I don't follow this one. get_cluster
looks like it will only ever return vim.ClusterComputeResource
objects. This object does not have a network
attribute.
|
||
if host is not None: | ||
for hostnet in host.network: | ||
if hostnet.name == network['name']: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure if this will work because - if find_obj
is not able find this object that means it does not exists. If it finds then you will not hit this condition. Let me know if I am wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
find_obj
apparently only finds things that are cluster-wide. It does not find networks present on only a single host.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming @phemmer is right with host networks never being picked up (bit suspicious, can't imagine no-one ever tried with host networks itself, but no to time to test currently). This looks good.
SUMMARY
previously the vmware_guest module would only allow use of distributed networks, and not host-specific networks. This change makes it support both.
ISSUE TYPE
Classifying this as a bug because this isn't really new functionality. The functionality is there, it's just the validation that was incorrectly classifying the network as invalid.
COMPONENT NAME
vmware_guest
ANSIBLE VERSION
ADDITIONAL INFORMATION
Before:
After: