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

ovirt_vms: add ability to specify storage domain #24012

Merged
merged 1 commit into from
Jun 8, 2017

Conversation

tareqalayan
Copy link
Contributor

When creatinf a new VM from template, you can specify the storage domain
name and disk format where to copy all the template disks

For example if you want to create a VM from template into specific
storage domain you can do the following:

ovirt_vms:
name: vm_on_my_storage_domain
cluster: my_cluster
template: my_template
operating_system: other_linux
type: server
cpu_cores: 1
cpu_sockets: 1
state: stopped
clone: True
storage_domain: my_nfs_storage
format: COW

SUMMARY
ISSUE TYPE
  • Feature Pull Request
  • New Module Pull Request
  • Bugfix Pull Request
  • Docs Pull Request
COMPONENT NAME
ANSIBLE VERSION

ADDITIONAL INFORMATION

@ansibot
Copy link
Contributor

ansibot commented Apr 26, 2017

The test ansible-test sanity --test validate-modules failed with the following errors:

lib/ansible/modules/cloud/ovirt/ovirt_vms.py:0:0: E309 version_added for new option (disk_format) should be 2.4. Currently 0.0
lib/ansible/modules/cloud/ovirt/ovirt_vms.py:0:0: E309 version_added for new option (storage_domain) should be 2.4. Currently 0.0

click here for bot help

@ansibot
Copy link
Contributor

ansibot commented Apr 26, 2017

@ansibot ansibot added affects_2.4 This issue/PR affects Ansible v2.4 ci_verified Changes made in this PR are causing tests to fail. cloud feature_pull_request 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. virt Virt community (incl. QEMU, KVM, libvirt, ovirt, RHV and Proxmox) labels Apr 26, 2017
@tareqalayan tareqalayan force-pushed the vm-from-template-on-specific-sd branch from 3e53401 to 542c5e8 Compare April 26, 2017 13:06
@ansibot
Copy link
Contributor

ansibot commented Apr 26, 2017

The test ansible-test sanity --test validate-modules failed with the following errors:

lib/ansible/modules/cloud/ovirt/ovirt_vms.py:0:0: E309 version_added for new option (disk_format) should be 2.4. Currently 0.0
lib/ansible/modules/cloud/ovirt/ovirt_vms.py:0:0: E309 version_added for new option (storage_domain) should be 2.4. Currently 0.0

click here for bot help

storage_domain:
description:
- "Name of the storage domain where all template disks should be copied."
- "This parameter is considered only when template is provided."
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add
version_added: "2.4"

disk_format:
description:
- "COW or RAW; default: is COW"
- "This parameter is considered only when template and storage domain is provided."
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add
version_added: "2.4"

- "This parameter is considered only when template is provided."
disk_format:
description:
- "COW or RAW; default: is COW"
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove this line and replace with

choices: ['COW, 'RAW']
default: COW

See http://docs.ansible.com/ansible/dev_guide/developing_modules_documenting.html#documentation-block for more info

@@ -1004,6 +1060,7 @@ def main():
template=dict(default=None),
template_version=dict(default=None, type='int'),
use_latest_template_version=dict(default=None, type='bool'),
storage_domain=dict(default=None),
disks=dict(default=[], type='list'),
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing

disk_format=dict(default='COW', choices='COW, 'RAW'),

This makes me think that changing the disk_format may not have been tested...

@gundalow gundalow removed the needs_triage Needs a first human triage before being processed. label Apr 26, 2017
@tareqalayan tareqalayan force-pushed the vm-from-template-on-specific-sd branch from 542c5e8 to 31c6b1f Compare April 26, 2017 14:54
@tareqalayan
Copy link
Contributor Author

cc @machacekondra

@ansibot
Copy link
Contributor

ansibot commented Apr 26, 2017

The test ansible-test sanity --test ansible-doc --python 2.6 failed with the following error:

Command "ansible-doc ovirt_vms" returned exit status 1.
>>> Standard Error
[ERROR]: unable to parse /root/src/github.com/ansible/ansible/lib/ansible/modu
les/cloud/ovirt/ovirt_vms.py
ERROR! module ovirt_vms missing documentation (or could not parse documentation): Parsing produced an empty object.

The test ansible-test sanity --test ansible-doc --python 2.7 failed with the following error:

Command "ansible-doc ovirt_vms" returned exit status 1.
>>> Standard Error
[ERROR]: unable to parse /root/src/github.com/ansible/ansible/lib/ansible/modu
les/cloud/ovirt/ovirt_vms.py
ERROR! module ovirt_vms missing documentation (or could not parse documentation): Parsing produced an empty object.

The test ansible-test sanity --test ansible-doc --python 3.5 failed with the following error:

Command "ansible-doc ovirt_vms" returned exit status 1.
>>> Standard Error
[ERROR]: unable to parse /root/src/github.com/ansible/ansible/lib/ansible/modu
les/cloud/ovirt/ovirt_vms.py
ERROR! module ovirt_vms missing documentation (or could not parse documentation): Parsing produced an empty object.

The test ansible-test sanity --test ansible-doc --python 3.6 failed with the following error:

Command "ansible-doc ovirt_vms" returned exit status 1.
>>> Standard Error
[ERROR]: unable to parse /root/src/github.com/ansible/ansible/lib/ansible/modu
les/cloud/ovirt/ovirt_vms.py
ERROR! module ovirt_vms missing documentation (or could not parse documentation): Parsing produced an empty object.

The test ansible-test sanity --test validate-modules failed with the following error:

lib/ansible/modules/cloud/ovirt/ovirt_vms.py:0:0: E302 DOCUMENTATION is not valid YAML. Line 77 column 26

click here for bot help

@ansibot ansibot removed the ci_verified Changes made in this PR are causing tests to fail. label Apr 26, 2017
@tareqalayan tareqalayan force-pushed the vm-from-template-on-specific-sd branch from 31c6b1f to 0f8b24c Compare April 26, 2017 15:03
@@ -66,6 +66,17 @@
- "Specify if latest template version should be used, when running a stateless VM."
- "If this parameter is set to I(true) stateless VM is created."
version_added: "2.3"
storage_domain:
description:
- "Name of the storage domain where all template disks should be copied."
Copy link
Contributor

Choose a reason for hiding this comment

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

s/copied/created

Copy link
Contributor

Choose a reason for hiding this comment

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

Please document if it's ideppotent or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

version_added: "2.4"
disk_format:
description:
- "This parameter is considered only when template and storage domain is provided."
Copy link
Contributor

Choose a reason for hiding this comment

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

please describe what the disk format is

Copy link
Contributor

Choose a reason for hiding this comment

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

Please also use proper doc formatting like: "C(template) and C(storage_domain) parameters are provided"

Copy link
Contributor

Choose a reason for hiding this comment

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

Also please say it's not idempotent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -541,13 +552,61 @@ def __get_template_with_version(self):

return template

def __get_storage_domain_and_all_template_disks(self, template):

storage_domain = self._module.params.get('storage_domain')
Copy link
Contributor

Choose a reason for hiding this comment

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

you can use:

storage_domain = self.param('storage_domain')

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -1004,6 +1063,8 @@ def main():
template=dict(default=None),
template_version=dict(default=None, type='int'),
use_latest_template_version=dict(default=None, type='bool'),
storage_domain=dict(default=None),
disk_format=dict(choices=['COW','RAW'], default='COW'),
Copy link
Contributor

Choose a reason for hiding this comment

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

hmm, most of the things in other modules are in lower case, better to be consistent

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

def build_entity(self):
template = self.__get_template_with_version()

disks_attachments = None
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you move this logic to __get_storage_domain_and_all_template_disks and just call:

return otypes.Vm(
...
disk_attachments=self.__get_storage_domain_and_all_template_disks()
...
)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

)
)

return storage_domain_obj, disks
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure why it returns storage_domain_obj?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

format=otypes.DiskFormat.COW,
storage_domains=[
otypes.StorageDomain(
id=storage_domain_obj.id
Copy link
Contributor

Choose a reason for hiding this comment

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

use here just get_id_by_name the code above would not be needed then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

otypes.DiskAttachment(
disk=otypes.Disk(
id=disk.id,
format=otypes.DiskFormat.COW,
Copy link
Contributor

Choose a reason for hiding this comment

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

please use here otypes.DiskFormat(self.param('disk_format'))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

disks.append(
otypes.DiskAttachment(
disk=otypes.Disk(
id=disk.id,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's disk.disk.id

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done
btw they both work why?

else:
format = otypes.DiskFormat.COW

for disk in disk_attachments:
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe rename disk to attachment or att to make it more clear?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@tareqalayan tareqalayan force-pushed the vm-from-template-on-specific-sd branch from 0f8b24c to 8575add Compare April 26, 2017 16:47
@ansibot
Copy link
Contributor

ansibot commented Apr 26, 2017

The test ansible-test sanity --test validate-modules failed with the following error:

lib/ansible/modules/cloud/ovirt/ovirt_vms.py:0:0: E311 EXAMPLES is not valid YAML. Line 497 column 3

click here for bot help

@ansibot ansibot added the ci_verified Changes made in this PR are causing tests to fail. label Apr 26, 2017
@tareqalayan tareqalayan force-pushed the vm-from-template-on-specific-sd branch from 8575add to eafb648 Compare April 26, 2017 17:31
@ansibot ansibot removed the ci_verified Changes made in this PR are causing tests to fail. label Apr 26, 2017
Copy link
Contributor

@machacekondra machacekondra left a comment

Choose a reason for hiding this comment

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

Some minor comments.

- "Name of the storage domain where all template disks should be created."
- "This parameter is considered only when C(template) is provided."
- "C(**IMPORTANT**)"
- "This parameter is idempotent, template disks works as expected.
Copy link
Contributor

Choose a reason for hiding this comment

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

But won't be moved if the storage domain is changed, no? The note should be added only if the parameter is NOT idempotent. The default is meant to be idempotent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

version_added: "2.4"
disk_format:
description:
- "File format for disk image files: I(cow) stands for copy on write,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can copy paste what's already in ovirt_disks module:

- Specify format of the disk.
- If (cow) format is used, disk will by created as sparse, so space will be allocated for the volume as needed, also known as I(thin provision).
- If (raw) format is used, disk storage will be allocated right away, also known as I(preallocated).
- Note that this option isn't idempotent as it's not currently possible to change format of the disk via API.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

cpu_sockets: 1
state: stopped
clone: True
timeout: 600
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe I would remove the parameters which are not relevant to the example, to make it more clear?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -541,13 +574,52 @@ def __get_template_with_version(self):

return template

def __get_storage_domain_and_all_template_disks(self, template):

if self._module.params.get('template') is None:
Copy link
Contributor

Choose a reason for hiding this comment

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

if self._module.params.get('template') is None:
->
if self.param('template') is None:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

if self.param('storage_domain') is None:
return None

storage_domain = self.param('storage_domain')
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's not worth to create the temp var here, maybe just pass the self.param('storage_domain')
directly into the get_id_by_name ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


storage_domain = self.param('storage_domain')

disk_attachments = (
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's not worth to create the temp var here, maybe just pass the self._connection.follow_link(template.disk_attachments) directly in for, also it's not strict to use 80 chars/line and I think here the newline makes it less readable, so if you want to use temp var then I think it would be more readeble, to not use new line, but up to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done moved to be used directly in the for loop

return otypes.Vm(
name=self.param('name'),
cluster=otypes.Cluster(
name=self.param('cluster')
) if self.param('cluster') else None,
disk_attachments=disk_attachments if disk_attachments else None,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the if isn't needed here anymore as it's the job of __get_storage_domain_and_all_template_disks to handle it, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

When creatinf a new VM from template, you can specify the storage domain
name and disk format where to copy all the template disks

For example if you want to create a VM from template into specific
storage domain you can do the following:

  ovirt_vms:
    name: vm_on_my_storage_domain
    cluster: my_cluster
    template: my_template
    operating_system: other_linux
    type: server
    cpu_cores: 1
    cpu_sockets: 1
    state: stopped
    clone: True
    storage_domain: my_nfs_storage
    format: COW
@tareqalayan tareqalayan force-pushed the vm-from-template-on-specific-sd branch from eafb648 to 4410be9 Compare April 27, 2017 14:08
Copy link
Contributor

@machacekondra machacekondra left a comment

Choose a reason for hiding this comment

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

shipit

@ansibot ansibot added community_review In order to be merged, this PR must follow the community review workflow. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Apr 28, 2017
Copy link

@myakove myakove left a comment

Choose a reason for hiding this comment

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

shipit

@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label May 11, 2017
Copy link
Contributor

@mwperina mwperina left a comment

Choose a reason for hiding this comment

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

👍

@ryansb ryansb merged commit 013f759 into ansible:devel Jun 8, 2017
@ansibot ansibot added feature This issue/PR relates to a feature request. and removed feature_pull_request labels Mar 4, 2018
@dagwieers dagwieers added the ovirt oVirt and RHV community label Feb 20, 2019
@dagwieers dagwieers removed virt Virt community (incl. QEMU, KVM, libvirt, ovirt, RHV and Proxmox) labels Feb 28, 2019
@ansible ansible locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.4 This issue/PR affects Ansible v2.4 cloud community_review In order to be merged, this PR must follow the community review workflow. feature This issue/PR relates to a feature request. module This issue/PR relates to a module. ovirt oVirt and RHV community stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants