Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VMware: add new module vmware_guest_network #52075

Merged
merged 5 commits into from Jul 8, 2019

Conversation

Tomorrow9
Copy link
Contributor

@Tomorrow9 Tomorrow9 commented Feb 12, 2019

SUMMARY

Fixes #51066

ISSUE TYPE
  • New Module Pull Request
COMPONENT NAME

vmware_guest_network

ADDITIONAL INFORMATION

This module is used to add, reconfigure, remove network adapters for virtual machine.

- name: Change network adapter settings of virtual machine
  vmware_guest_network:
    hostname: "{{ vcenter_hostname }}"
    username: "{{ vcenter_username }}"
    password: "{{ vcenter_password }}"
    datacenter: "{{ datacenter_name }}"
    validate_certs: no
    name: test-vm
    gather_network_facts: false
    networks:
      - name: "VM Network"
        state: new
        mac: "00:50:56:11:22:33"
      - state: present
        device_type: e1000e
        mac: "00:50:56:44:55:66"
      - state: present
        label: "Network adapter 3"
        connected: false
      - state: absent
        label: "Network adapter 4"
  delegate_to: localhost

@ansibot
Copy link
Contributor

ansibot commented Feb 12, 2019

@ansibot
Copy link
Contributor

ansibot commented Feb 12, 2019

@Tomorrow9, just so you are aware we have a dedicated Working Group for vmware.
You can find other people interested in this in #ansible-vmware on Freenode IRC
For more information about communities, meetings and agendas see https://github.com/ansible/community

click here for bot help

@ansibot ansibot added affects_2.8 This issue/PR affects Ansible v2.8 cloud community_review In order to be merged, this PR must follow the community review workflow. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. new_module This PR includes a new module. new_plugin This PR includes a new plugin. support:community This issue/PR relates to code supported by the Ansible community. vmware VMware community labels Feb 12, 2019
@ansibot
Copy link
Contributor

ansibot commented Feb 12, 2019

The test ansible-test sanity --test pylint [explain] failed with 1 error:

lib/ansible/modules/cloud/vmware/vmware_guest_network.py:453:0: missing-final-newline Final newline missing

The test ansible-test sanity --test pep8 [explain] failed with 5 errors:

lib/ansible/modules/cloud/vmware/vmware_guest_network.py:78:100: W291 trailing whitespace
lib/ansible/modules/cloud/vmware/vmware_guest_network.py:324:41: E131 continuation line unaligned for hanging indent
lib/ansible/modules/cloud/vmware/vmware_guest_network.py:328:41: E127 continuation line over-indented for visual indent
lib/ansible/modules/cloud/vmware/vmware_guest_network.py:329:41: E127 continuation line over-indented for visual indent
lib/ansible/modules/cloud/vmware/vmware_guest_network.py:453:11: W292 no newline at end of file

click here for bot help

@ansibot ansibot added ci_verified Changes made in this PR are causing tests to fail. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed community_review In order to be merged, this PR must follow the community review workflow. labels Feb 12, 2019
@ansibot
Copy link
Contributor

ansibot commented Feb 12, 2019

@MikeKlebolt @Akasurde @bedecarroll @CastawayEGR @chrrrles @dav1x @garbled1 @GyorgyPeter @imjoseangel @jjahns @kamsz @karstenjakobsen @kryptsi @lrivallain @nafpliot-ibm @nerzhul @oboukili @rhoop @ritzk @rmin @stravassac @tchernomax @warthog9 @woshihaoren

As a maintainer of a module in the same namespace this new module has been submitted to, your vote counts for shipits. Please review this module and add shipit if you would like to see it merged.

click here for bot help

@ansibot ansibot added community_review In order to be merged, this PR must follow the community review workflow. and removed ci_verified Changes made in this PR are causing tests to fail. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Feb 12, 2019
@Tomorrow9
Copy link
Contributor Author

I also hit this issue #50656 in this module. On vSphere 6.5, it works well, on vSphere 6.7, there is error "VM network does not exist" and "Hot plug failed". I'll take a look at that. Thanks.

@ansibot
Copy link
Contributor

ansibot commented Feb 15, 2019

@Tomorrow9
Copy link
Contributor Author

Tomorrow9 commented Feb 15, 2019

I also hit this issue #50656 in this module. On vSphere 6.5, it works well, on vSphere 6.7, there is error "VM network does not exist" and "Hot plug failed". I'll take a look at that. Thanks.

Sorry, my mistake, configured the wrong "datacenter" parameter. :(

Copy link
Contributor

@xenlo xenlo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Edited… see next Review

Copy link
Contributor

@xenlo xenlo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tested this new module. Here is my feedback on what I tested, what works, what doesn't.

Adding NICs on an existing VM

  networks:
    - name: "vlan{{ vlan.id }}"
      mac: "{{ 'aa:bb:cc:dd:%02d:%02d' | format((vlan.id |int), (host.id |int)) }}"
      state: new

It works!

That really eases what was theoretically possible to do with vmware_guest module but to hard in practice. So that's a huge improvement for me.

Removing NICs on an existing VM

  networks:
    - name: "vlan{{ vlan.id }}"
      mac: "{{ 'aa:bb:cc:dd:%02d:%02d' | format((vlan.id |int), (host.id |int)) }}"
      state: new

Well here I have 2 issues:

     - 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 will use the first matched network adapter.'
  • In our use case, we don't work with the label but with the mac. I assume that it would be possible to delete or edit a NIC identified by its mac address. Am I wrong?
  • It sounds strange to me to be able to delete a NIC just based on its device_type. I can imagine use case where you have to change something on all NICs of a defined type, … but not on just the first one found.

lib/ansible/modules/cloud/vmware/vmware_guest_network.py Outdated Show resolved Hide resolved
lib/ansible/modules/cloud/vmware/vmware_guest_network.py Outdated Show resolved Hide resolved
@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed community_review In order to be merged, this PR must follow the community review workflow. labels Feb 17, 2019
@Tomorrow9
Copy link
Contributor Author

@xenlo thanks for your reviewing and feedback.
So the first question is: use mac address as one parameter to delete or reconfigure the matched network adapter. Right, that's reasonable. I'm not using this scenario but you do, so I'll add this.
The second one is: for multiple network adapters, what I wanted to do is if we do not get network adapter label, just know their device type and want to configure one of them, we can use it. But specify the "device_type" to reconfigure/remove all of them with that type, this also make sense. I'll make some changes.
Also, if there are any more scenarios not covered in this module, please let me know. Thank you very much.

Tomorrow9 and others added 2 commits June 28, 2019 05:58
Co-Authored-By: Abhijeet Kasurde <akasurde@redhat.com>
Co-Authored-By: Abhijeet Kasurde <akasurde@redhat.com>
@ansibot
Copy link
Contributor

ansibot commented Jun 28, 2019

The test ansible-test sanity --test validate-modules [explain] failed with 7 errors:

lib/ansible/modules/cloud/vmware/vmware_guest_network.py:0:0: E337 Argument 'cluster' in argument_spec defines type as 'str' but documentation doesn't define type
lib/ansible/modules/cloud/vmware/vmware_guest_network.py:0:0: E337 Argument 'datacenter' in argument_spec defines type as 'str' but documentation doesn't define type
lib/ansible/modules/cloud/vmware/vmware_guest_network.py:0:0: E337 Argument 'esxi_hostname' in argument_spec defines type as 'str' but documentation doesn't define type
lib/ansible/modules/cloud/vmware/vmware_guest_network.py:0:0: E337 Argument 'folder' in argument_spec defines type as 'str' but documentation doesn't define type
lib/ansible/modules/cloud/vmware/vmware_guest_network.py:0:0: E337 Argument 'name' in argument_spec defines type as 'str' but documentation doesn't define type
lib/ansible/modules/cloud/vmware/vmware_guest_network.py:0:0: E337 Argument 'networks' in argument_spec defines type as <class 'list'> but documentation doesn't define type
lib/ansible/modules/cloud/vmware/vmware_guest_network.py:0:0: E337 Argument 'uuid' in argument_spec defines type as 'str' but documentation doesn't define type

click here for bot help

@ansibot ansibot added ci_verified Changes made in this PR are causing tests to fail. and removed stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. labels Jun 28, 2019
@Akasurde
Copy link
Member

Akasurde commented Jul 2, 2019

@Tomorrow9 Could you please merge Tomorrow9#2 which addresses my review comments ? Thanks.

@ansibot
Copy link
Contributor

ansibot commented Jul 3, 2019

@Tomorrow9 this PR contains the following merge commits:

Please rebase your branch to remove these commits.

click here for bot help

@ansibot ansibot added merge_commit This PR contains at least one merge commit. Please resolve! needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html solaris Solaris community support:core This issue/PR relates to code supported by the Ansible Engineering Team. test This PR relates to tests. and removed ci_verified Changes made in this PR are causing tests to fail. labels Jul 3, 2019
@Tomorrow9 Tomorrow9 force-pushed the fix_pr51066 branch 2 times, most recently from a2b1771 to 13637cf Compare July 3, 2019 06:46
@ansibot ansibot removed merge_commit This PR contains at least one merge commit. Please resolve! needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html labels Jul 3, 2019
@ansibot
Copy link
Contributor

ansibot commented Jul 3, 2019

The test ansible-test sanity --test pylint [explain] failed with 1 error:

lib/ansible/modules/cloud/vmware/vmware_guest_network.py:209:20: undefined-variable Undefined variable 'nic_devices'

The test ansible-test sanity --test validate-modules [explain] failed with 1 error:

lib/ansible/modules/cloud/vmware/vmware_guest_network.py:0:0: E325 Argument 'networks' in argument_spec defines type as <class 'list'> but documentation defines type as 'list'

click here for bot help

* Added is_mac API

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
@Tomorrow9 Tomorrow9 force-pushed the fix_pr51066 branch 3 times, most recently from 1ac77d3 to e3564ae Compare July 4, 2019 10:21
@ansibot ansibot added needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI. stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. and removed needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI. stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. labels Jul 4, 2019
@Akasurde Akasurde merged commit 9c140d2 into ansible:devel Jul 8, 2019
@ansible ansible locked and limited conversation to collaborators Aug 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.8 This issue/PR affects Ansible v2.8 cloud module This issue/PR relates to a module. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. new_module This PR includes a new module. new_plugin This PR includes a new plugin. solaris Solaris community support:community This issue/PR relates to code supported by the Ansible community. support:core This issue/PR relates to code supported by the Ansible Engineering Team. test This PR relates to tests. vmware VMware community
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing module vmware_guest_network to manage NICs
8 participants