From d63cdcacc3dc3997e08f715381c6ef05203e958b Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Mon, 26 Jun 2017 22:17:10 +0530 Subject: [PATCH] Make nic_name as optional parameter (#25990) Fix adds support for adding VMWare vSwitch without any physical NICs (uplinks). This makes nic_name as an optional parameter. Also, updated documentation and examples to reflect these changes. Fixes #25632 Signed-off-by: Abhijeet Kasurde --- .../modules/cloud/vmware/vmware_vswitch.py | 36 +++++++++++-------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/lib/ansible/modules/cloud/vmware/vmware_vswitch.py b/lib/ansible/modules/cloud/vmware/vmware_vswitch.py index e74cc1bca5e..74e0bdfa8de 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_vswitch.py +++ b/lib/ansible/modules/cloud/vmware/vmware_vswitch.py @@ -44,7 +44,7 @@ options: nic_name: description: - vmnic name to attach to vswitch - required: True + required: False number_of_ports: description: - Number of port to configure on vswitch @@ -66,17 +66,24 @@ extends_documentation_fragment: vmware.documentation ''' EXAMPLES = ''' -# Example from Ansible playbook - - - name: Add a VMware vSwitch - local_action: - module: vmware_vswitch - hostname: esxi_hostname - username: esxi_username - password: esxi_password - switch_name: vswitch_name - nic_name: vmnic_name - mtu: 9000 +- name: Add a VMware vSwitch + local_action: + module: vmware_vswitch + hostname: esxi_hostname + username: esxi_username + password: esxi_password + switch_name: vswitch_name + nic_name: vmnic_name + 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: @@ -138,7 +145,8 @@ class VMwareHostVirtualSwitch(object): vss_spec = vim.host.VirtualSwitch.Specification() vss_spec.numPorts = self.number_of_ports vss_spec.mtu = self.mtu - vss_spec.bridge = vim.host.VirtualSwitch.BondBridge(nicDevice=[self.nic_name]) + if 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.module.exit_json(changed=True) @@ -184,7 +192,7 @@ class VMwareHostVirtualSwitch(object): def main(): argument_spec = vmware_argument_spec() argument_spec.update(dict(switch_name=dict(required=True, type='str'), - nic_name=dict(required=True, type='str'), + nic_name=dict(required=False, type='str'), number_of_ports=dict(required=False, type='int', default=128), mtu=dict(required=False, type='int', default=1500), state=dict(default='present', choices=['present', 'absent'], type='str')))