VMware: provide appropriate error if NICs missing (#43414)

While creating/reconfiguring vSwitch without NICs check if nics details
are gathered or not.

Fixes: #42619

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
pull/43384/head
Abhijeet Kasurde 6 years ago committed by ansibot
parent d1c0b7a597
commit 80369cf034

@ -177,7 +177,7 @@ class VMwareHostVirtualSwitch(PyVmomi):
def process_state(self): def process_state(self):
""" """
Function to manage internal state of vSwitch Manage internal state of vSwitch
""" """
vswitch_states = { vswitch_states = {
'absent': { 'absent': {
@ -201,7 +201,7 @@ class VMwareHostVirtualSwitch(PyVmomi):
def state_create_vswitch(self): def state_create_vswitch(self):
""" """
Function to create a virtual switch Create a virtual switch
Source from Source from
https://github.com/rreubenur/pyvmomi-community-samples/blob/patch-1/samples/create_vswitch.py https://github.com/rreubenur/pyvmomi-community-samples/blob/patch-1/samples/create_vswitch.py
@ -252,13 +252,13 @@ class VMwareHostVirtualSwitch(PyVmomi):
def state_exit_unchanged(self): def state_exit_unchanged(self):
""" """
Function to declare exit without unchanged Declare exit without unchanged
""" """
self.module.exit_json(changed=False) self.module.exit_json(changed=False)
def state_destroy_vswitch(self): def state_destroy_vswitch(self):
""" """
Function to remove vSwitch from configuration Remove vSwitch from configuration
""" """
results = dict(changed=False, result="") results = dict(changed=False, result="")
@ -288,7 +288,7 @@ class VMwareHostVirtualSwitch(PyVmomi):
def state_update_vswitch(self): def state_update_vswitch(self):
""" """
Function to update vSwitch Update vSwitch
""" """
results = dict(changed=False, result="No change in vSwitch '%s'" % self.switch) results = dict(changed=False, result="No change in vSwitch '%s'" % self.switch)
@ -305,19 +305,23 @@ class VMwareHostVirtualSwitch(PyVmomi):
all_nics += remain_pnic all_nics += remain_pnic
diff = True diff = True
# vSwitch needs every parameter again while updating,
# even if we are updating any one of them
vss_spec = vim.host.VirtualSwitch.Specification()
vss_spec.bridge = vim.host.VirtualSwitch.BondBridge(nicDevice=all_nics)
vss_spec.numPorts = self.number_of_ports
vss_spec.mtu = self.mtu
if vswitch_pnic_info['mtu'] != self.mtu or \ if vswitch_pnic_info['mtu'] != self.mtu or \
vswitch_pnic_info['num_ports'] != self.number_of_ports: vswitch_pnic_info['num_ports'] != self.number_of_ports:
diff = True diff = True
if not all_nics:
diff = False
results['result'] += " as no NICs provided / found which are required while updating vSwitch."
try: try:
if diff: if diff:
# vSwitch needs every parameter again while updating,
# even if we are updating any one of them
vss_spec = vim.host.VirtualSwitch.Specification()
vss_spec.bridge = vim.host.VirtualSwitch.BondBridge(nicDevice=all_nics)
vss_spec.numPorts = self.number_of_ports
vss_spec.mtu = self.mtu
network_mgr = self.host_system.configManager.networkSystem network_mgr = self.host_system.configManager.networkSystem
if network_mgr: if network_mgr:
network_mgr.UpdateVirtualSwitch(vswitchName=self.switch, network_mgr.UpdateVirtualSwitch(vswitchName=self.switch,
@ -361,7 +365,7 @@ class VMwareHostVirtualSwitch(PyVmomi):
def check_vswitch_configuration(self): def check_vswitch_configuration(self):
""" """
Function to check if vSwitch exists Check if vSwitch exists
Returns: 'present' if vSwitch exists or 'absent' if not Returns: 'present' if vSwitch exists or 'absent' if not
""" """
@ -374,7 +378,7 @@ class VMwareHostVirtualSwitch(PyVmomi):
@staticmethod @staticmethod
def find_vswitch_by_name(host, vswitch_name): def find_vswitch_by_name(host, vswitch_name):
""" """
Function to find and return vSwitch managed object Find and return vSwitch managed object
Args: Args:
host: Host system managed object host: Host system managed object
vswitch_name: Name of vSwitch to find vswitch_name: Name of vSwitch to find

Loading…
Cancel
Save