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: New module: vmware_guest_disk_facts #36026

Merged
merged 1 commit into from
Feb 16, 2018

Conversation

Akasurde
Copy link
Member

SUMMARY

Signed-off-by: Abhijeet Kasurde akasurde@redhat.com

ISSUE TYPE
  • New Module Pull Request
COMPONENT NAME

lib/ansible/modules/cloud/vmware/vmware_guest_disk_facts.py
test/integration/targets/vmware_guest_disk_facts/aliases
test/integration/targets/vmware_guest_disk_facts/tasks/main.yml

ANSIBLE VERSION
2.6devel

@ansibot
Copy link
Contributor

ansibot commented Feb 12, 2018

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

test/integration/targets/vmware_guest_disk_facts/tasks/main.yml:55:1: empty-lines too many blank lines (1 > 0)

click here for bot help

@ansibot
Copy link
Contributor

ansibot commented Feb 12, 2018

@ansibot ansibot added ci_verified Changes made in this PR are causing tests to fail. 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. 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. test This PR relates to tests. vmware VMware community labels Feb 12, 2018
@ansibot
Copy link
Contributor

ansibot commented Feb 12, 2018

@Akasurde @bedecarroll @chrrrles @dav1x @garbled1 @jjahns @kamsz @lrivallain @nafpliot-ibm @nerzhul @pdellaert @rhoop @ritzk @stravassac @tchernomax @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, 2018
@Akasurde Akasurde removed the needs_triage Needs a first human triage before being processed. label Feb 12, 2018
backing_disk_mode=disk.backing.diskMode,
backing_writethrough=disk.backing.writeThrough,
backing_thinprovisioned=disk.backing.thinProvisioned,
backing_eagerlyscrub=disk.backing.eagerlyScrub if disk.backing.eagerlyScrub else False,
Copy link
Contributor

Choose a reason for hiding this comment

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

backing_eagerlyscrub=bool(disk.backing.eagerlyScrub),
?

Copy link
Member Author

Choose a reason for hiding this comment

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

👍
This will happen when you overthink.


# VM already exists
if vm:
try:
Copy link
Contributor

Choose a reason for hiding this comment

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

+    # VM already exists
+    if vm:
+        …

+    if vm:
+        # VM exists
+        …

But that's a matter of taste.

Copy link
Member Author

@Akasurde Akasurde Feb 14, 2018

Choose a reason for hiding this comment

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

ok. You know just a copy-paste.

@tchernomax
Copy link
Contributor

ping @Akasurde

@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 14, 2018
Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
Copy link
Contributor

@tchernomax tchernomax left a comment

Choose a reason for hiding this comment

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

LGTM

@ansibot ansibot added shipit This PR is ready to be merged by Core and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Feb 15, 2018
@Akasurde Akasurde merged commit 55d1174 into ansible:devel Feb 16, 2018
@Akasurde Akasurde deleted the vmware_guest_disk_fact branch February 16, 2018 05:16
@Akasurde
Copy link
Member Author

@tchernomax Thanks for your valuable review comments. 👍

label=disk.deviceInfo.label,
summary=disk.deviceInfo.summary,
backing_filename=disk.backing.fileName,
backing_datastore=disk.backing.datastore.name,
Copy link
Contributor

Choose a reason for hiding this comment

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

datastore.name requires access to the datastore itself, and thus might throw a permission error. This value should be wrapped in a try/except.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK. I will added try/except for this.

Returns: A list of dict containing disks information

"""
disks_facts = dict()
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be a list, not a dictionary. The dictionary key is just an incrementing index value, which is what a list is for. Having it as a dictionary just makes it harder to use (having to deal with an index generator, and dictionaries don't guarantee order).

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, but I forgot the reason why I implemented dict instead of list for returning facts. If you feel that list is more appropriate than dict, then we can always refactor this code again. PR welcomed.

Copy link
Contributor

Choose a reason for hiding this comment

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

@phemmer , We've discussed this in the weekly Ansible VMware meeting.
In my opinion, having a dict is useful, IF the key is useful:

  • The reason to have facts is to use them in a task later on
  • With a list, to find the proper disk, it is harder to find the item you want to match on ( {{ (disks | selectattr('label', 'search', 'Hard disk 1') | list | first) }} for instance)
  • With a dict, if the key is useful, it doesn't require that. If you want to match on another criteria, the loop is still a possibility.

Proposal is to have the label as the dict key as it is what is visible in vCenter and is orderable, does that make sense to you? Any other criteria you might find easier? (disk.key is another possibility, but less 'visible' in vCenter)

@Akasurde
Copy link
Member Author

@phemmer @pdellaert With current implementation, I am able to add new disk to an existing virtual machine -

---
- name: Add a disk to already existing VM
  gather_facts: no
  vars_files:
    - vcenter_vars.yml
  hosts: localhost
  tasks:
    - set_fact:
        vm_name: "VM_2262"

    - name: "Getting information about VM {{ vm_name }}"
      vmware_guest_disk_facts:
        hostname: "{{ vcenter_server }}"
        username: "{{ vcenter_user }}"
        password: "{{ vcenter_pass }}"
        validate_certs: no
        datacenter: "{{ datacenter }}"
        name: "{{ vm_name }}"
      register: no_vm_result

    - set_fact:
        disk: "{{ disk | default([]) + [{ 'datastore' : item.value.backing_datastore, 'size_kb': item.value.capacity_in_kb }] }}"
      with_dict: "{{ no_vm_result.guest_disk_facts }}"

    - debug:
        var: disk

    - set_fact:
        new_disk: "{{ disk + [{ 'datastore': 'datastore2', 'size_kb': '21504'}] }}"

    - debug:
        var: new_disk

    - name: "Adding new disk to existing VM {{ vm_name }}"
      vmware_guest:
        hostname: "{{ vcenter_server }}"
        username: "{{ vcenter_user }}"
        password: "{{ vcenter_pass }}"
        validate_certs: no
        datacenter: "{{ datacenter }}"
        esxi_hostname: "{{ esxi_server }}"
        state: present
        folder: /Site2/DC2/vm
        name: "{{ vm_name }}"
        disk: "{{ new_disk }}"

@Akasurde
Copy link
Member Author

@ansible ansible locked and limited conversation to collaborators Apr 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cloud module This issue/PR relates to a module. new_module This PR includes a new module. new_plugin This PR includes a new plugin. shipit This PR is ready to be merged by Core support:community This issue/PR relates to code supported by the Ansible community. test This PR relates to tests. vmware VMware community
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants