-
Notifications
You must be signed in to change notification settings - Fork 23.7k
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
Conversation
The test
|
b4e8483
to
9733eb0
Compare
@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 |
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, |
There was a problem hiding this comment.
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),
?
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
ping @Akasurde |
Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
9733eb0
to
f2eb236
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
@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 }}" |
SUMMARY
Signed-off-by: Abhijeet Kasurde akasurde@redhat.com
ISSUE TYPE
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