Repository: ansible-collections/community.vmware

Issue:
vmware_guest_network: Remove deprecated parameter networks
##### SUMMARY
The `networks` parameter is deprecated and should be removed.

##### ISSUE TYPE
- Feature Idea

##### COMPONENT NAME
vmware_guest_network

##### ADDITIONAL INFORMATION
https://github.com/ansible-collections/community.vmware/blob/67b9506a306da2caec9a2eda60003fd54a9df71e/plugins/modules/vmware_guest_network.py#L865-L871


Discussion:

Resolving patch:
diff --git a/plugins/modules/vmware_guest_network.py b/plugins/modules/vmware_guest_network.py
--- a/plugins/modules/vmware_guest_network.py
+++ b/plugins/modules/vmware_guest_network.py
@@ -19,7 +19,7 @@
 author:
   - Diane Wang (@Tomorrow9) <dianew@vmware.com>
 notes:
-  - For backwards compatibility network_data is returned when using the gather_network_info and networks parameters
+  - For backwards compatibility network_data is returned when using the gather_network_info parameter
 options:
   name:
     description:
@@ -150,90 +150,6 @@
     description:
       - Return information about current guest network adapters.
     type: bool
-  networks:
-    type: list
-    elements: dict
-    description:
-      - This method will be deprecated, use loops in your playbook for multiple interfaces instead.
-      - A list of network adapters.
-      - C(mac) or C(label) or C(device_type) is required to reconfigure or remove an existing network adapter.
-      - 'If there are multiple network adapters with the same C(device_type), you should set C(label) or C(mac) to match
-         one of them, or will apply changes on all network adapters with the C(device_type) specified.'
-      - 'C(mac), C(label), C(device_type) is the order of precedence from greatest to least if all set.'
-    suboptions:
-      mac:
-        type: str
-        description:
-        - MAC address of the existing network adapter to be reconfigured or removed.
-      label:
-        type: str
-        description:
-        - Label of the existing network adapter to be reconfigured or removed, e.g., "Network adapter 1".
-      device_type:
-        type: str
-        description:
-        - 'Valid virtual network device types are C(e1000), C(e1000e), C(pcnet32), C(vmxnet2), C(vmxnet3) (default), C(sriov).'
-        - Used to add new network adapter, reconfigure or remove the existing network adapter with this type.
-        - If C(mac) and C(label) not specified or not find network adapter by C(mac) or C(label) will use this parameter.
-      name:
-        type: str
-        description:
-        - Name of the portgroup or distributed virtual portgroup for this interface.
-        - When specifying distributed virtual portgroup make sure given C(esxi_hostname) or C(cluster) is associated with it.
-      vlan:
-        type: int
-        description:
-        - VLAN number for this interface.
-      dvswitch_name:
-        type: str
-        description:
-        - Name of the distributed vSwitch.
-        - This value is required if multiple distributed portgroups exists with the same name.
-      state:
-        type: str
-        description:
-        - State of the network adapter.
-        - If set to C(present), then will do reconfiguration for the specified network adapter.
-        - If set to C(new), then will add the specified network adapter.
-        - If set to C(absent), then will remove this network adapter.
-      manual_mac:
-        type: str
-        description:
-        - Manual specified MAC address of the network adapter when creating, or reconfiguring.
-        - If not specified when creating new network adapter, mac address will be generated automatically.
-        - When reconfigure MAC address, VM should be in powered off state.
-        - There are restrictions on the MAC addresses you can set. Consult the documentation of your vSphere version as to allowed MAC addresses.
-      connected:
-        type: bool
-        description:
-        - Indicates that virtual network adapter connects to the associated virtual machine.
-      start_connected:
-        type: bool
-        description:
-        - Indicates that virtual network adapter starts with associated virtual machine powers on.
-      directpath_io:
-        type: bool
-        description:
-        - If set, Universal Pass-Through (UPT or DirectPath I/O) will be enabled on the network adapter.
-        - UPT is only compatible for Vmxnet3 adapter.
-      physical_function_backing:
-        version_added: '2.3.0'
-        type: str
-        description:
-        - If set, specifies the PCI ID of the physical function to use as backing for a SR-IOV network adapter.
-        - This option is only compatible for SR-IOV network adapters.
-      virtual_function_backing:
-        version_added: '2.3.0'
-        type: str
-        description:
-        - If set, specifies the PCI ID of the physical function to use as backing for a SR-IOV network adapter.
-        - This option is only compatible for SR-IOV network adapters.
-      allow_guest_os_mtu_change:
-        version_added: '2.3.0'
-        type: bool
-        description:
-        - Allows the guest OS to change the MTU on a SR-IOV network adapter.
-        - This option is only compatible for SR-IOV network adapters.
 extends_documentation_fragment:
 - community.vmware.vmware.documentation
 '''
@@ -323,7 +239,7 @@
     ]
 network_data:
   description: For backwards compatibility, metadata about the virtual machine network adapters
-  returned: when using gather_network_info or networks parameters
+  returned: when using gather_network_info parameter
   type: dict
   sample:
     "network_data": {
@@ -385,11 +301,10 @@ def __init__(self, module):
             sriov=vim.vm.device.VirtualSriovEthernetCard,
         )
 
-    def _get_network_object(self, vm_obj, network_params=None):
+    def _get_network_object(self, vm_obj):
         '''
         return network object matching given parameters
         :param vm_obj: vm object
-        :param network_params: dict containing parameters from deprecated networks list method
         :return: network object
         :rtype: object
         '''
@@ -399,14 +314,9 @@ def _get_network_object(self, vm_obj, network_params=None):
             compute_resource = self._get_compute_resource_by_name()
 
         pg_lookup = {}
-        if network_params:
-            vlan_id = network_params['vlan_id']
-            network_name = network_params['network_name']
-            switch_name = network_params['switch']
-        else:
-            vlan_id = self.params['vlan_id']
-            network_name = self.params['network_name']
-            switch_name = self.params['switch']
+        vlan_id = self.params['vlan_id']
+        network_name = self.params['network_name']
+        switch_name = self.params['switch']
 
         for pg in vm_obj.runtime.host.config.network.portgroup:
             pg_lookup[pg.spec.name] = {'switch': pg.spec.vswitchName, 'vlan_id': pg.spec.vlanId}
@@ -544,7 +454,7 @@ def _get_compute_resource_by_name(self, recurse=True):
         return None
 
     def _new_nic_spec(self, vm_obj, nic_obj=None, network_params=None):
-        network = self._get_network_object(vm_obj, network_params)
+        network = self._get_network_object(vm_obj)
 
         if network_params:
             connected = network_params['connected']
@@ -713,69 +623,21 @@ def _get_nic_info(self):
         rv['network_info'] = nic_info
         return rv
 
-    def _deprectated_list_config(self):
-        '''
-        this only exists to handle the old way of configuring interfaces, which
-        should be deprectated in favour of using loops in the playbook instead of
-        feeding lists directly into the module.
-        '''
-        diff = {'before': {}, 'after': {}}
-        changed = False
-        for i in self.params['networks']:
-            network_params = {}
-            network_params['mac_address'] = i.get('mac') or i.get('manual_mac')
-            network_params['network_name'] = i.get('name')
-            network_params['vlan_id'] = i.get('vlan')
-            network_params['switch'] = i.get('dvswitch_name')
-            network_params['guest_control'] = i.get('allow_guest_control', self.params['guest_control'])
-            network_params['physical_function_backing'] = i.get('physical_function_backing')
-            network_params['virtual_function_backing'] = i.get('virtual_function_backing')
-            network_params['allow_guest_os_mtu_change'] = i.get('allow_guest_os_mtu_change')
-
-            for k in ['connected', 'device_type', 'directpath_io', 'force', 'label', 'start_connected', 'state', 'wake_onlan']:
-                network_params[k] = i.get(k, self.params[k])
-
-            if network_params['state'] in ['new', 'present']:
-                n_diff, n_changed, network_info = self._nic_present(network_params)
-                diff['before'].update(n_diff['before'])
-                diff['after'] = n_diff['after']
-                if n_changed:
-                    changed = True
-
-            if network_params['state'] == 'absent':
-                n_diff, n_changed, network_info = self._nic_absent(network_params)
-                diff['before'].update(n_diff['before'])
-                diff['after'] = n_diff['after']
-                if n_changed:
-                    changed = True
-
-        return diff, changed, network_info
-
-    def _nic_present(self, network_params=None):
+    def _nic_present(self):
         changed = False
         diff = {'before': {}, 'after': {}}
-        # backwards compatibility, clean up when params['networks']
-        # has been removed
-        if network_params:
-            force = network_params['force']
-            label = network_params['label']
-            mac_address = network_params['mac_address']
-            network_name = network_params['network_name']
-            switch = network_params['switch']
-            vlan_id = network_params['vlan_id']
-        else:
-            force = self.params['force']
-            label = self.params['label']
-            mac_address = self.params['mac_address']
-            network_name = self.params['network_name']
-            switch = self.params['switch']
-            vlan_id = self.params['vlan_id']
+        force = self.params['force']
+        label = self.params['label']
+        mac_address = self.params['mac_address']
+        network_name = self.params['network_name']
+        switch = self.params['switch']
+        vlan_id = self.params['vlan_id']
 
         vm_obj = self.get_vm()
         if not vm_obj:
             self.module.fail_json(msg='could not find vm: {0}'.format(self.params['name']))
 
-        network_obj = self._get_network_object(vm_obj, network_params)
+        network_obj = self._get_network_object(vm_obj)
         nic_info, nic_obj_lst = self._get_nics_from_vm(vm_obj)
         label_lst = [d.get('label') for d in nic_info]
         mac_addr_lst = [d.get('mac_address') for d in nic_info]
@@ -805,7 +667,7 @@ def _nic_present(self, network_params=None):
         if (mac_address and mac_address in mac_addr_lst) or (label and label in label_lst):
             for nic_obj in nic_obj_lst:
                 if (mac_address and nic_obj.macAddress == mac_address) or (label and label == nic_obj.deviceInfo.label):
-                    device_spec = self._new_nic_spec(vm_obj, nic_obj, network_params)
+                    device_spec = self._new_nic_spec(vm_obj, nic_obj)
 
             # fabricate diff for check_mode
             if self.module.check_mode:
@@ -826,7 +688,7 @@ def _nic_present(self, network_params=None):
                         diff['after'].update({nic_mac: copy.deepcopy(nic)})
 
         if (not mac_address or mac_address not in mac_addr_lst) and (not label or label not in label_lst):
-            device_spec = self._new_nic_spec(vm_obj, None, network_params)
+            device_spec = self._new_nic_spec(vm_obj, None)
             device_spec.operation = vim.vm.device.VirtualDeviceSpec.Operation.add
             if self.module.check_mode:
                 # fabricate diff/returns for checkmode
@@ -902,7 +764,6 @@ def main():
         allow_guest_os_mtu_change=dict(type='bool', default=True),
         force=dict(type='bool', default=False),
         gather_network_info=dict(type='bool', default=False, aliases=['gather_network_facts']),
-        networks=dict(type='list', default=[], elements='dict'),
         guest_control=dict(type='bool', default=True),
         state=dict(type='str', default='present', choices=['absent', 'present'])
     )
@@ -931,23 +792,6 @@ def main():
 
         module.exit_json(network_info=nics.get('network_info'), network_data=network_data, changed=False)
 
-    if module.params['networks']:
-        network_data = {}
-        module.deprecate(
-            msg='The old way of configuring interfaces by supplying an arbitrary list will be removed, loops should be used to handle multiple interfaces',
-            version='3.0.0',
-            collection_name='community.vmware'
-        )
-        diff, changed, network_info = pyv._deprectated_list_config()
-        nd = copy.deepcopy(network_info)
-        nics_sorted = sorted(nd, key=lambda k: k['unit_number'])
-        for n, i in enumerate(nics_sorted):
-            key_name = '{0}'.format(n)
-            network_data[key_name] = i
-            network_data[key_name].update({'mac_addr': i['mac_address'], 'name': i['network_name']})
-
-        module.exit_json(changed=changed, network_info=network_info, network_data=network_data, diff=diff)
-
     if module.params['state'] == 'present':
         diff, changed, network_info = pyv._nic_present()
 


Test patch:
diff --git a/tests/integration/targets/vmware_guest_network/tasks/main.yml b/tests/integration/targets/vmware_guest_network/tasks/main.yml
--- a/tests/integration/targets/vmware_guest_network/tasks/main.yml
+++ b/tests/integration/targets/vmware_guest_network/tasks/main.yml
@@ -11,7 +11,7 @@
     setup_dvswitch: true
 
 - name: Create VMs
-  vmware_guest:
+  community.vmware.vmware_guest:
     hostname: "{{ vcenter_hostname }}"
     username: "{{ vcenter_username }}"
     password: "{{ vcenter_password }}"
@@ -36,7 +36,7 @@
     networks:
     - name: VM Network
 
-- vmware_guest_tools_wait:
+- community.vmware.vmware_guest_tools_wait:
     hostname: "{{ vcenter_hostname }}"
     username: "{{ vcenter_username }}"
     password: "{{ vcenter_password }}"
@@ -45,7 +45,7 @@
     name: test_vm1
 
 - name: gather network adapters' facts of the virtual machine
-  vmware_guest_network:
+  community.vmware.vmware_guest_network:
     validate_certs: false
     hostname: "{{ vcenter_hostname }}"
     username: "{{ vcenter_username }}"
@@ -56,48 +56,50 @@
 
 - debug: var=netadapter_info
 
-- name: get number of existing netowrk adapters
+- name: get number of existing network adapters
   set_fact:
     netadapter_num: "{{ netadapter_info.network_data | length }}"
 
 - name: add new network adapters to virtual machine
-  vmware_guest_network:
+  community.vmware.vmware_guest_network:
     validate_certs: false
     hostname: "{{ vcenter_hostname }}"
     username: "{{ vcenter_username }}"
     password: "{{ vcenter_password }}"
     name: test_vm1
-    networks:
-      - name: "VM Network"
-        state: new
-        device_type: e1000e
-        manual_mac: "aa:50:56:58:59:60"
-        connected: true
-      - name: "VM Network"
-        state: new
-        connected: true
-        device_type: vmxnet3
-        manual_mac: "aa:50:56:58:59:61"
+    network_name: "{{ item.network_name }}"
+    device_type: "{{ item.device_type }}"
+    mac_address: "{{ item.mac_address }}"
+    connected: "{{ item.connected }}"
+    state: present
+  loop:
+    - network_name: "VM Network"
+      device_type: e1000e
+      mac_address: "aa:50:56:58:59:60"
+      connected: true
+    - network_name: "VM Network"
+      device_type: vmxnet3
+      mac_address: "aa:50:56:58:59:61"
+      connected: true
   register: add_netadapter
 
 - debug: var=add_netadapter
 
-- name: assert the new netowrk adapters were added to VM
+- name: assert the new network adapters were added to VM
   assert:
     that:
       - add_netadapter is changed
-      - "{{ add_netadapter.network_data | length | int }} == {{ netadapter_num | int + 2 }}"
+      - "{{ add_netadapter.results[1].network_info | length | int }} == {{ netadapter_num | int + 2 }}"
 
 - name: delete one specified network adapter
-  vmware_guest_network:
+  community.vmware.vmware_guest_network:
     validate_certs: false
     hostname: "{{ vcenter_hostname }}"
     username: "{{ vcenter_username }}"
     password: "{{ vcenter_password }}"
     name: test_vm1
-    networks:
-      - state: absent
-        mac: "aa:50:56:58:59:60"
+    mac_address: "aa:50:56:58:59:60"
+    state: absent
   register: del_netadapter
 
 - debug: var=del_netadapter
@@ -106,10 +108,10 @@
   assert:
     that:
       - del_netadapter is changed
-      - "{{ del_netadapter.network_data | length | int }} == {{ netadapter_num | int + 1 }}"
+      - "{{ del_netadapter.network_info | length | int }} == {{ netadapter_num | int + 1 }}"
 
 - name: get instance uuid of virtual machines
-  vmware_guest_info:
+  community.vmware.vmware_guest_info:
     validate_certs: false
     hostname: "{{ vcenter_hostname }}"
     username: "{{ vcenter_username }}"
@@ -121,19 +123,17 @@
 - set_fact: vm1_instance_uuid="{{ guest_info['instance']['instance_uuid'] }}"
 
 - name: add new network adapters to virtual machine with instance uuid
-  vmware_guest_network:
+  community.vmware.vmware_guest_network:
     validate_certs: false
     hostname: "{{ vcenter_hostname }}"
     username: "{{ vcenter_username }}"
     password: "{{ vcenter_password }}"
     uuid: '{{ vm1_instance_uuid }}'
     use_instance_uuid: true
-    networks:
-      - name: "VM Network"
-        state: new
-        connected: true
-        device_type: e1000e
-        manual_mac: "bb:50:56:58:59:60"
+    network_name: "VM Network"
+    device_type: e1000e
+    mac_address: "bb:50:56:58:59:60"
+    connected: true
   register: add_netadapter_instanceuuid
 
 - debug: var=add_netadapter_instanceuuid
@@ -142,87 +142,82 @@
   assert:
     that:
       - add_netadapter_instanceuuid is changed
-      - "{{ add_netadapter_instanceuuid.network_data | length | int }} == {{ netadapter_num | int + 2 }}"
+      - "{{ add_netadapter_instanceuuid.network_info | length | int }} == {{ netadapter_num | int + 2 }}"
 
 - name: delete one specified network adapter
-  vmware_guest_network:
+  community.vmware.vmware_guest_network:
     validate_certs: false
     hostname: "{{ vcenter_hostname }}"
     username: "{{ vcenter_username }}"
     password: "{{ vcenter_password }}"
     name: test_vm1
-    networks:
-      - state: absent
-        mac: "bb:50:56:58:59:60"
+    mac_address: "bb:50:56:58:59:60"
+    state: absent
   register: del_netadapter
 
 - name: assert the network adapter was removed
   assert:
     that:
       - del_netadapter is changed
-      - "{{ del_netadapter.network_data | length | int }} == {{ netadapter_num | int + 1 }}"
+      - "{{ del_netadapter.network_info | length | int }} == {{ netadapter_num | int + 1 }}"
 
-- name: delete again one specified network adapter
-  vmware_guest_network:
+- name: delete again one specified network adapter (idempotency)
+  community.vmware.vmware_guest_network:
     validate_certs: false
     hostname: "{{ vcenter_hostname }}"
     username: "{{ vcenter_username }}"
     password: "{{ vcenter_password }}"
     name: test_vm1
-    networks:
-      - state: absent
-        mac: "bb:50:56:58:59:60"
+    mac_address: "bb:50:56:58:59:60"
+    state: absent
   register: del_again_netadapter
 
 - debug: var=del_again_netadapter
 
-- name: assert the network adapter was removed
+- name: assert no change (idempotency)
   assert:
     that:
       - not (del_again_netadapter is changed)
-      - "{{ del_again_netadapter.network_data | length | int }} == {{ netadapter_num | int + 1 }}"
+      - "{{ del_again_netadapter.network_info | length | int }} == {{ netadapter_num | int + 1 }}"
 
 - name: disable DirectPath I/O on a Vmxnet3 adapter
-  vmware_guest_network:
+  community.vmware.vmware_guest_network:
     validate_certs: false
     hostname: "{{ vcenter_hostname }}"
     username: "{{ vcenter_username }}"
     password: "{{ vcenter_password }}"
     name: "test_vm1"
-    networks:
-      - state: present
-        mac: "aa:50:56:58:59:61"
-        directpath_io: false
+    state: present
+    mac_address: "aa:50:56:58:59:61"
+    directpath_io: false
   register: disable_directpath_io
 
 - debug: var=disable_directpath_io
 
 - name: enable DirectPath I/O on a Vmxnet3 adapter
-  vmware_guest_network:
+  community.vmware.vmware_guest_network:
     validate_certs: false
     hostname: "{{ vcenter_hostname }}"
     username: "{{ vcenter_username }}"
     password: "{{ vcenter_password }}"
     name: "test_vm1"
-    networks:
-      - state: present
-        mac: "aa:50:56:58:59:61"
-        directpath_io: true
+    state: present
+    mac_address: "aa:50:56:58:59:61"
+    directpath_io: true
   register: enable_directpath_io
 
 - debug: var=enable_directpath_io
 
 - name: disconnect one specified network adapter
-  vmware_guest_network:
+  community.vmware.vmware_guest_network:
     validate_certs: false
     hostname: "{{ vcenter_hostname }}"
     username: "{{ vcenter_username }}"
     password: "{{ vcenter_password }}"
     name: test_vm1
-    networks:
-      - state: present
-        mac: "aa:50:56:58:59:61"
-        connected: false
+    state: present
+    mac_address: "aa:50:56:58:59:61"
+    connected: false
   register: disc_netadapter
 
 - debug: var=disc_netadapter
@@ -231,19 +226,18 @@
   assert:
     that:
       - disc_netadapter is changed
-      - "{{ disc_netadapter.network_data[netadapter_num]['connected'] }} == false"
+      - "{{ disc_netadapter.network_info[netadapter_num | int]['connected'] }} == false"
 
 - name: Check if network does not exists
-  vmware_guest_network:
+  community.vmware.vmware_guest_network:
     validate_certs: false
     hostname: "{{ vcenter_hostname }}"
     username: "{{ vcenter_username }}"
     password: "{{ vcenter_password }}"
     name: test_vm1
-    networks:
-      - name: non-existing-nw
-        manual_mac: "aa:50:56:11:22:33"
-        state: new
+    network_name: non-existing-nw
+    mac_address: "aa:50:56:11:22:33"
+    state: present
   register: no_nw_details
   ignore_errors: true
 
@@ -256,18 +250,17 @@
       - no_nw_details.failed
 
 - name: Change portgroup to dvPortgroup
-  vmware_guest_network:
+  community.vmware.vmware_guest_network:
     validate_certs: false
     hostname: "{{ vcenter_hostname }}"
     username: "{{ vcenter_username }}"
     password: "{{ vcenter_password }}"
     name: test_vm1
-    networks:
-      - name: "{{ dvpg1 }}"
-        label: "Network adapter 1"
-        connected: false
-        start_connected: true
-        state: present
+    network_name: "{{ dvpg1 }}"
+    label: "Network adapter 1"
+    connected: false
+    start_connected: true
+    state: present
   register: change_netaddr_dvp
 
 - debug: var=change_netaddr_dvp
@@ -278,18 +271,17 @@
       - change_netaddr_dvp.changed is sameas true
 
 - name: Change portgroup to dvPortgroup
-  vmware_guest_network:
+  community.vmware.vmware_guest_network:
     validate_certs: false
     hostname: "{{ vcenter_hostname }}"
     username: "{{ vcenter_username }}"
     password: "{{ vcenter_password }}"
     name: test_vm1
-    networks:
-      - name: "{{ dvpg1 }}"
-        label: "Network adapter 1"
-        connected: false
-        start_connected: true
-        state: present
+    network_name: "{{ dvpg1 }}"
+    label: "Network adapter 1"
+    connected: false
+    start_connected: true
+    state: present
   register: change_netaddr_dvp
 
 - debug: var=change_netaddr_dvp
@@ -300,18 +292,17 @@
       - change_netaddr_dvp.changed is sameas false
 
 - name: Change dvPortgroup to PortGroup
-  vmware_guest_network:
+  community.vmware.vmware_guest_network:
     validate_certs: false
     hostname: "{{ vcenter_hostname }}"
     username: "{{ vcenter_username }}"
     password: "{{ vcenter_password }}"
     name: test_vm1
-    networks:
-      - name: "VM Network"
-        label: "Network adapter 1"
-        connected: false
-        start_connected: true
-        state: present
+    network_name: "VM Network"
+    label: "Network adapter 1"
+    connected: false
+    start_connected: true
+    state: present
   register: change_netaddr_pg
 
 - debug: var=change_netaddr_pg
@@ -320,21 +311,20 @@
   assert:
     that:
       - change_netaddr_pg.changed is sameas true
-      - change_netaddr_pg.network_data['0'].name == "VM Network"
+      - change_netaddr_pg.network_info[0].network_name == "VM Network"
 
 - name: Change dvPortgroup to PortGroup
-  vmware_guest_network:
+  community.vmware.vmware_guest_network:
     validate_certs: false
     hostname: "{{ vcenter_hostname }}"
     username: "{{ vcenter_username }}"
     password: "{{ vcenter_password }}"
     name: test_vm1
-    networks:
-      - name: "VM Network"
-        label: "Network adapter 1"
-        connected: false
-        start_connected: true
-        state: present
+    network_name: "VM Network"
+    label: "Network adapter 1"
+    connected: false
+    start_connected: true
+    state: present
   register: change_netaddr_pg
 
 - debug: var=change_netaddr_pg
@@ -343,22 +333,21 @@
   assert:
     that:
       - change_netaddr_pg.changed is sameas false
-      - change_netaddr_pg.network_data['0'].name == "VM Network"
+      - change_netaddr_pg.network_info[0].network_name == "VM Network"
 
 # https://github.com/ansible/ansible/issues/65968
 - name: Create a network with dvPortgroup
-  vmware_guest_network:
+  community.vmware.vmware_guest_network:
     validate_certs: false
     hostname: "{{ vcenter_hostname }}"
     username: "{{ vcenter_username }}"
     password: "{{ vcenter_password }}"
     name: test_vm1
-    networks:
-      - name: "{{ dvpg1 }}"
-        label: "Network adapter 2"
-        connected: true
-        start_connected: true
-        state: new
+    network_name: "{{ dvpg1 }}"
+    label: "Network adapter 2"
+    connected: true
+    start_connected: true
+    state: present
   register: create_netaddr_pg
 
 - debug: var=create_netaddr_pg
@@ -369,7 +358,7 @@
       - create_netaddr_pg.changed is sameas true
 
 - name: gather network adapters' facts of the virtual machine
-  vmware_guest_network:
+  community.vmware.vmware_guest_network:
     validate_certs: false
     hostname: "{{ vcenter_hostname }}"
     username: "{{ vcenter_username }}"
@@ -384,7 +373,7 @@
       - nic_info.network_info is defined
 
 - name: Remove all network interfaces with loop
-  vmware_guest_network:
+  community.vmware.vmware_guest_network:
     validate_certs: false
     hostname: "{{ vcenter_hostname }}"
     username: "{{ vcenter_username }}"
@@ -395,7 +384,7 @@
   loop: "{{ nic_info.network_info }}"
 
 - name: gather network adapters' facts of the virtual machine
-  vmware_guest_network:
+  community.vmware.vmware_guest_network:
     validate_certs: false
     hostname: "{{ vcenter_hostname }}"
     username: "{{ vcenter_username }}"
@@ -410,7 +399,7 @@
       - "{{ nic_info2.network_info | length | int }} == 0"
 
 - name: add new adapter(s)
-  vmware_guest_network:
+  community.vmware.vmware_guest_network:
     validate_certs: false
     hostname: "{{ vcenter_hostname }}"
     username: "{{ vcenter_username }}"
@@ -429,7 +418,7 @@
 - name: "Change a dvpg with in same DVS(integration test for 204)"
   block:
     - name: "Prepare the integration test for 204"
-      vmware_dvs_portgroup:
+      community.vmware.vmware_dvs_portgroup:
         hostname: "{{ vcenter_hostname }}"
         username: "{{ vcenter_username }}"
         password: "{{ vcenter_password }}"
@@ -448,16 +437,15 @@
           - prepare_integration_test_204_result.changed is sameas true
 
     - name: "Change a port group to a dvport group"
-      vmware_guest_network:
+      community.vmware.vmware_guest_network:
         validate_certs: false
         hostname: "{{ vcenter_hostname }}"
         username: "{{ vcenter_username }}"
         password: "{{ vcenter_password }}"
         name: test_vm1
-        networks:
-          - name: "{{ dvpg1 }}"
-            label: Network adapter 1
-            state: present
+        network_name: "{{ dvpg1 }}"
+        label: "Network adapter 1"
+        state: present
       register: change_port_group_result
 
     - assert:
@@ -465,16 +453,15 @@
           - change_port_group_result.changed is sameas true
 
     - name: "Change a dvport group with in same DVS"
-      vmware_guest_network:
+      community.vmware.vmware_guest_network:
         validate_certs: false
         hostname: "{{ vcenter_hostname }}"
         username: "{{ vcenter_username }}"
         password: "{{ vcenter_password }}"
         name: test_vm1
-        networks:
-          - name: 204dvpg
-            label: Network adapter 1
-            state: present
+        network_name: 204dvpg
+        label: Network adapter 1
+        state: present
       register: change_dvport_group_result
 
     - assert:
@@ -482,16 +469,15 @@
           - change_dvport_group_result.changed is sameas true
 
     - name: "Revert a dvport group to port group"
-      vmware_guest_network:
+      community.vmware.vmware_guest_network:
         validate_certs: false
         hostname: "{{ vcenter_hostname }}"
         username: "{{ vcenter_username }}"
         password: "{{ vcenter_password }}"
         name: test_vm1
-        networks:
-          - name: VM Network
-            label: Network adapter 1
-            state: present
+        network_name: VM Network
+        label: "Network adapter 1"
+        state: present
       register: revert_dvport_group_result
 
     - assert:
@@ -499,7 +485,7 @@
           - revert_dvport_group_result.changed is sameas true
 
     - name: "Delete a dvport group for 204 integration test"
-      vmware_dvs_portgroup:
+      community.vmware.vmware_dvs_portgroup:
         hostname: "{{ vcenter_hostname }}"
         username: "{{ vcenter_username }}"
         password: "{{ vcenter_password }}"