Repository: ansible/ansible-modules-extras

Issue:
vmware_dvs_portgroup destroy fails
<!--- Verify first that your issue/request is not already reported in GitHub -->
##### ISSUE TYPE

<!--- Pick one below and delete the rest: -->
- Bug Report
##### COMPONENT NAME

<!--- Name of the plugin/module/task -->

cloud/vmware/vmware_dvs_portgroup.py
##### ANSIBLE VERSION

<!--- Paste verbatim output from “ansible --version” between quotes below -->

```
ansible 2.1.1.0 (detached HEAD 780c363482) last updated 2016/08/19 17:46:34 (GMT -400)
  lib/ansible/modules/core: (detached HEAD 91a839f1e3) last updated 2016/08/19 17:46:11 (GMT -400)
  lib/ansible/modules/extras: (detached HEAD 1aeb9f8a8c) last updated 2016/08/19 17:46:13 (GMT -400)
  config file =
  configured module search path = Default w/o overrides

```
##### CONFIGURATION

<!---
Mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).
-->
##### OS / ENVIRONMENT

<!---
Mention the OS you are running Ansible from, and the OS you are
managing, or say “N/A” for anything that is not platform-specific.
-->

N/A
##### SUMMARY

<!--- Explain the problem briefly -->

The function definition for state_destroy_dvspg(self) contains the line
            task = dvs_portgroup.Destroy_Task()

This should be 
            task = self.dvs_portgroup.Destroy_Task()
##### STEPS TO REPRODUCE

<!---
For bugs, show exactly how to reproduce the problem.
For new features, show how the feature would be used.
-->

Issue a playbook task to remove a vSphere portgroup by setting the state property to absent.

<!--- Paste example playbooks or commands between quotes below -->

```
  - name: Remove vSphere Portgroups
    vmware_dvs_portgroup:
      hostname: "{{ VSPHERE_HOST }}"
      username: "{{ VSPHERE_LOGIN }}"
      password: "{{ VSPHERE_PASSWORD }}"
      portgroup_name: "{{ TESTBED_NAME }}_{{ item }}"
      switch_name: "{{ VDS }}"
      vlan_id: "{{ item }}"
      num_ports: 10
      portgroup_type: earlyBinding
      state: absent
      validate_certs: False
    with_items: "{{ test_vlans }}"

```

<!--- You can also paste gist.github.com links for larger files -->
##### EXPECTED RESULTS

<!--- What did you expect to happen when running the steps above? -->

Expected portgroup entry to be removed from vSphere networking.
##### ACTUAL RESULTS

<!--- What actually happened? If possible run with high verbosity (-vvvv) -->

Task fails with an error that 'dvs_portgroup' is not defined.

<!--- Paste verbatim command output between quotes below -->

```
TASK [teardown : Remove vSphere Portgroup] *************************************
task path: /var/jenkins/workspace/Build_CVP_Testbed/lab-automation/roles/teardown/tasks/main.yml:46
<10.81.110.96> ESTABLISH SSH CONNECTION FOR USER: root
<10.81.110.96> SSH: EXEC sshpass -d12 ssh -C -q -o ControlMaster=auto -o ControlPersist=60s -o User=root -o ConnectTimeout=10 -o ControlPath=/users/builder/.ansible/cp/ansible-ssh-%h-%p-%r 10.81.110.96 '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1471642781.59-166008742553082 `" && echo ansible-tmp-1471642781.59-166008742553082="` echo $HOME/.ansible/tmp/ansible-tmp-1471642781.59-166008742553082 `" ) && sleep 0'"'"''
<10.81.110.96> PUT /tmp/tmpzAGbLy TO /root/.ansible/tmp/ansible-tmp-1471642781.59-166008742553082/vmware_dvs_portgroup
<10.81.110.96> SSH: EXEC sshpass -d12 sftp -o BatchMode=no -b - -C -o ControlMaster=auto -o ControlPersist=60s -o User=root -o ConnectTimeout=10 -o ControlPath=/users/builder/.ansible/cp/ansible-ssh-%h-%p-%r '[10.81.110.96]'
<10.81.110.96> ESTABLISH SSH CONNECTION FOR USER: root
<10.81.110.96> SSH: EXEC sshpass -d12 ssh -C -q -o ControlMaster=auto -o ControlPersist=60s -o User=root -o ConnectTimeout=10 -o ControlPath=/users/builder/.ansible/cp/ansible-ssh-%h-%p-%r -tt 10.81.110.96 '/bin/sh -c '"'"'LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /usr/bin/python /root/.ansible/tmp/ansible-tmp-1471642781.59-166008742553082/vmware_dvs_portgroup; rm -rf "/root/.ansible/tmp/ansible-tmp-1471642781.59-166008742553082/" > /dev/null 2>&1 && sleep 0'"'"''
failed: [10.81.110.96] (item=502) => {"failed": true, "invocation": {"module_args": {"hostname": "10.81.110.87", "num_ports": 10, "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "portgroup_name": "garaaa_502", "portgroup_type": "earlyBinding", "state": "absent", "switch_name": "EOS+vDS", "username": "jenkins@vsphere.local", "validate_certs": false, "vlan_id": 502}, "module_name": "vmware_dvs_portgroup"}, "item": 502, "msg": "global name 'dvs_portgroup' is not defined"}
```



Discussion:
<!-- @grybak-arista: Thanks for filing this bug report! -->

@chrrrles ping, this issue is waiting for your response.
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)

<!--- boilerplate: issue_bug_new --->


Resolving patch:
diff --git a/cloud/vmware/vmware_dvs_portgroup.py b/cloud/vmware/vmware_dvs_portgroup.py
--- a/cloud/vmware/vmware_dvs_portgroup.py
+++ b/cloud/vmware/vmware_dvs_portgroup.py
@@ -68,7 +68,7 @@
         password: vcenter_password
         portgroup_name: Management
         switch_name: dvSwitch
-        vlan_id: 123 
+        vlan_id: 123
         num_ports: 120
         portgroup_type: earlyBinding
         state: present
@@ -93,7 +93,7 @@ def __init__(self, module):
         self.dv_switch = None
         self.state = self.module.params['state']
         self.content = connect_to_api(module)
-        
+
     def process_state(self):
         try:
             dvspg_states = {
@@ -143,7 +143,7 @@ def state_destroy_dvspg(self):
         result = None
 
         if not self.module.check_mode:
-            task = dvs_portgroup.Destroy_Task()
+            task = self.dvs_portgroup.Destroy_Task()
             changed, result = wait_for_task(task)
         self.module.exit_json(changed=changed, result=str(result))
 


Test patch: