@ -44,7 +44,7 @@ options:
nic_name :
nic_name :
description :
description :
- vmnic name to attach to vswitch
- vmnic name to attach to vswitch
required : Tru e
required : Fals e
number_of_ports :
number_of_ports :
description :
description :
- Number of port to configure on vswitch
- Number of port to configure on vswitch
@ -66,8 +66,6 @@ extends_documentation_fragment: vmware.documentation
'''
'''
EXAMPLES = '''
EXAMPLES = '''
# Example from Ansible playbook
- name : Add a VMware vSwitch
- name : Add a VMware vSwitch
local_action :
local_action :
module : vmware_vswitch
module : vmware_vswitch
@ -77,6 +75,15 @@ EXAMPLES = '''
switch_name : vswitch_name
switch_name : vswitch_name
nic_name : vmnic_name
nic_name : vmnic_name
mtu : 9000
mtu : 9000
- name : Add a VMWare vSwitch without any physical NIC attached
vmware_vswitch :
hostname : 192.168 .10 .1
username : admin
password : password123
switch_name : vswitch_0001
mtu : 9000
'''
'''
try :
try :
@ -138,6 +145,7 @@ class VMwareHostVirtualSwitch(object):
vss_spec = vim . host . VirtualSwitch . Specification ( )
vss_spec = vim . host . VirtualSwitch . Specification ( )
vss_spec . numPorts = self . number_of_ports
vss_spec . numPorts = self . number_of_ports
vss_spec . mtu = self . mtu
vss_spec . mtu = self . mtu
if self . nic_name :
vss_spec . bridge = vim . host . VirtualSwitch . BondBridge ( nicDevice = [ self . nic_name ] )
vss_spec . bridge = vim . host . VirtualSwitch . BondBridge ( nicDevice = [ self . nic_name ] )
self . host_system . configManager . networkSystem . AddVirtualSwitch ( vswitchName = self . switch_name , spec = vss_spec )
self . host_system . configManager . networkSystem . AddVirtualSwitch ( vswitchName = self . switch_name , spec = vss_spec )
self . module . exit_json ( changed = True )
self . module . exit_json ( changed = True )
@ -184,7 +192,7 @@ class VMwareHostVirtualSwitch(object):
def main ( ) :
def main ( ) :
argument_spec = vmware_argument_spec ( )
argument_spec = vmware_argument_spec ( )
argument_spec . update ( dict ( switch_name = dict ( required = True , type = ' str ' ) ,
argument_spec . update ( dict ( switch_name = dict ( required = True , type = ' str ' ) ,
nic_name = dict ( required = Tru e, type = ' str ' ) ,
nic_name = dict ( required = Fals e, type = ' str ' ) ,
number_of_ports = dict ( required = False , type = ' int ' , default = 128 ) ,
number_of_ports = dict ( required = False , type = ' int ' , default = 128 ) ,
mtu = dict ( required = False , type = ' int ' , default = 1500 ) ,
mtu = dict ( required = False , type = ' int ' , default = 1500 ) ,
state = dict ( default = ' present ' , choices = [ ' present ' , ' absent ' ] , type = ' str ' ) ) )
state = dict ( default = ' present ' , choices = [ ' present ' , ' absent ' ] , type = ' str ' ) ) )