@ -177,7 +177,7 @@ class VMwareHostVirtualSwitch(PyVmomi):
def process_state ( self ) :
"""
Function to m anage internal state of vSwitch
M anage internal state of vSwitch
"""
vswitch_states = {
' absent ' : {
@ -201,7 +201,7 @@ class VMwareHostVirtualSwitch(PyVmomi):
def state_create_vswitch ( self ) :
"""
Function to c reate a virtual switch
C reate a virtual switch
Source from
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 ) :
"""
Function to d eclare exit without unchanged
D eclare exit without unchanged
"""
self . module . exit_json ( changed = False )
def state_destroy_vswitch ( self ) :
"""
Function to r emove vSwitch from configuration
R emove vSwitch from configuration
"""
results = dict ( changed = False , result = " " )
@ -288,7 +288,7 @@ class VMwareHostVirtualSwitch(PyVmomi):
def state_update_vswitch ( self ) :
"""
Function to u pdate vSwitch
U pdate vSwitch
"""
results = dict ( changed = False , result = " No change in vSwitch ' %s ' " % self . switch )
@ -305,6 +305,16 @@ class VMwareHostVirtualSwitch(PyVmomi):
all_nics + = remain_pnic
diff = True
if vswitch_pnic_info [ ' mtu ' ] != self . mtu or \
vswitch_pnic_info [ ' num_ports ' ] != self . number_of_ports :
diff = True
if not all_nics :
diff = False
results [ ' result ' ] + = " as no NICs provided / found which are required while updating vSwitch. "
try :
if diff :
# vSwitch needs every parameter again while updating,
# even if we are updating any one of them
vss_spec = vim . host . VirtualSwitch . Specification ( )
@ -312,12 +322,6 @@ class VMwareHostVirtualSwitch(PyVmomi):
vss_spec . numPorts = self . number_of_ports
vss_spec . mtu = self . mtu
if vswitch_pnic_info [ ' mtu ' ] != self . mtu or \
vswitch_pnic_info [ ' num_ports ' ] != self . number_of_ports :
diff = True
try :
if diff :
network_mgr = self . host_system . configManager . networkSystem
if network_mgr :
network_mgr . UpdateVirtualSwitch ( vswitchName = self . switch ,
@ -361,7 +365,7 @@ class VMwareHostVirtualSwitch(PyVmomi):
def check_vswitch_configuration ( self ) :
"""
Function to c heck if vSwitch exists
C heck if vSwitch exists
Returns : ' present ' if vSwitch exists or ' absent ' if not
"""
@ -374,7 +378,7 @@ class VMwareHostVirtualSwitch(PyVmomi):
@staticmethod
def find_vswitch_by_name ( host , vswitch_name ) :
"""
F unction to f ind and return vSwitch managed object
F ind and return vSwitch managed object
Args :
host : Host system managed object
vswitch_name : Name of vSwitch to find