-
Notifications
You must be signed in to change notification settings - Fork 339
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_vm_info: Add allocated Storage, CPU and Memory to output #1283
Merged
softwarefactory-project-zuul
merged 8 commits into
ansible-collections:main
from
Nina2244:patch-7
May 11, 2022
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b9a4cb5
Add allocated Storage, CPU and Memory to output
Nina2244 eeadfe0
Looks better like this
Nina2244 a130734
Create changelog file
Nina2244 3c012f6
Try to change the linter stuff
Nina2244 fb4f67f
Update vmware_vm_info.py
Nina2244 535ec55
Linter again
Nina2244 5afe37a
Linter again
Nina2244 d066995
Add version_added
mariolenz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
changelogs/fragments/1283-vmware_vm_info-allocaded_storag_cpu_memory_output.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
minor_changes: | ||
- vmware_vm_info - Add the feature to get the output of allocated storage, cpu und memory. | ||
(https://github.com/ansible-collections/community.vmware/pull/1283) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -184,7 +184,7 @@ | |
|
||
RETURN = r''' | ||
virtual_machines: | ||
description: list of dictionary of virtual machines and their information | ||
description: list of dictionary of virtual machines and their information. (allocated storage in byte and memory in MB) | ||
returned: success | ||
type: list | ||
sample: [ | ||
|
@@ -227,7 +227,12 @@ | |
"name": "tag_0001" | ||
} | ||
], | ||
"moid": "vm-24" | ||
"moid": "vm-24", | ||
"allocated": { | ||
"storage": 500000000, | ||
"cpu": 2, | ||
"memory": 16 | ||
}, | ||
} | ||
] | ||
''' | ||
|
@@ -238,10 +243,8 @@ | |
pass | ||
|
||
from ansible.module_utils.basic import AnsibleModule | ||
from ansible_collections.community.vmware.plugins.module_utils.vmware import ( | ||
PyVmomi, get_all_objs, | ||
vmware_argument_spec, _get_vm_prop, | ||
get_parent_datacenter, find_vm_by_name) | ||
from ansible_collections.community.vmware.plugins.module_utils.vmware import PyVmomi, \ | ||
get_all_objs, vmware_argument_spec, _get_vm_prop, get_parent_datacenter, find_vm_by_name | ||
from ansible_collections.community.vmware.plugins.module_utils.vmware_rest_client import VmwareRestClient | ||
|
||
|
||
|
@@ -326,6 +329,17 @@ def get_virtual_machines(self): | |
if self.module.params.get('show_tag'): | ||
vm_tags = self.get_tag_info(vm) | ||
|
||
storage_allocated = 0 | ||
for device in vm.config.hardware.device: | ||
if isinstance(device, vim.vm.device.VirtualDisk): | ||
storage_allocated += device.capacityInBytes | ||
|
||
allocated = { | ||
"storage": storage_allocated, | ||
"cpu": vm.config.hardware.numCPU, | ||
"memory": vm.config.hardware.memoryMB | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ERROR: plugins/modules/vmware_vm_info.py:340:17: E123: closing bracket does not match indentation of opening bracket's line |
||
|
||
vm_folder = PyVmomi.get_vm_path(content=self.content, vm_name=vm) | ||
datacenter = get_parent_datacenter(vm) | ||
datastore_url = list() | ||
|
@@ -349,6 +363,7 @@ def get_virtual_machines(self): | |
"folder": vm_folder, | ||
"moid": vm._moId, | ||
"datastore_url": datastore_url, | ||
"allocated": allocated | ||
} | ||
|
||
vm_type = self.module.params.get('vm_type') | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Add a flag to return these facts optionally (for example -
show_allocated
) rather than always returning facts.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.
Yes I will do this.