@ -177,7 +177,7 @@ class VMwareHostVirtualSwitch(PyVmomi):
def process_state ( self ) :
def process_state ( self ) :
"""
"""
Function to m anage internal state of vSwitch
M anage 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 c reate a virtual switch
C reate 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 d eclare exit without unchanged
D eclare 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 r emove vSwitch from configuration
R emove 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 u pdate vSwitch
U pdate 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 c heck if vSwitch exists
C heck 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 ) :
"""
"""
F unction to f ind and return vSwitch managed object
F ind 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