-
Notifications
You must be signed in to change notification settings - Fork 23.8k
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
ovirt_vms: add ability to specify storage domain #24012
Conversation
The test
|
3e53401
to
542c5e8
Compare
The test
|
storage_domain: | ||
description: | ||
- "Name of the storage domain where all template disks should be copied." | ||
- "This parameter is considered only when template is provided." |
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.
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." |
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.
Please add
version_added: "2.4"
- "This parameter is considered only when template is provided." | ||
disk_format: | ||
description: | ||
- "COW or RAW; default: is COW" |
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.
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'), |
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.
Missing
disk_format=dict(default='COW', choices='COW, 'RAW'),
This makes me think that changing the disk_format may not have been tested...
542c5e8
to
31c6b1f
Compare
The test
The test
The test
The test
The test
|
31c6b1f
to
0f8b24c
Compare
@@ -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." |
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.
s/copied/created
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.
Please document if it's ideppotent or not.
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.
Done
version_added: "2.4" | ||
disk_format: | ||
description: | ||
- "This parameter is considered only when template and storage domain is provided." |
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.
please describe what the disk format is
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.
Please also use proper doc formatting like: "C(template) and C(storage_domain) parameters are provided"
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.
Also please say it's not idempotent.
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.
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') |
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.
you can use:
storage_domain = self.param('storage_domain')
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.
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'), |
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.
hmm, most of the things in other modules are in lower case, better to be consistent
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.
done
def build_entity(self): | ||
template = self.__get_template_with_version() | ||
|
||
disks_attachments = None |
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.
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()
...
)
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.
done
) | ||
) | ||
|
||
return storage_domain_obj, disks |
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.
not sure why it returns storage_domain_obj
?
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.
done
format=otypes.DiskFormat.COW, | ||
storage_domains=[ | ||
otypes.StorageDomain( | ||
id=storage_domain_obj.id |
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.
use here just get_id_by_name
the code above would not be needed then?
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.
done
otypes.DiskAttachment( | ||
disk=otypes.Disk( | ||
id=disk.id, | ||
format=otypes.DiskFormat.COW, |
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.
please use here otypes.DiskFormat(self.param('disk_format'))
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.
done
disks.append( | ||
otypes.DiskAttachment( | ||
disk=otypes.Disk( | ||
id=disk.id, |
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.
I think it's disk.disk.id
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.
done
btw they both work why?
else: | ||
format = otypes.DiskFormat.COW | ||
|
||
for disk in disk_attachments: |
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.
maybe rename disk to attachment
or att
to make it more clear?
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.
done
0f8b24c
to
8575add
Compare
The test
|
8575add
to
eafb648
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.
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. |
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.
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.
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.
done
version_added: "2.4" | ||
disk_format: | ||
description: | ||
- "File format for disk image files: I(cow) stands for copy on write, |
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.
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.
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.
done
cpu_sockets: 1 | ||
state: stopped | ||
clone: True | ||
timeout: 600 |
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.
Maybe I would remove the parameters which are not relevant to the example, to make it more clear?
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.
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: |
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.
if self._module.params.get('template') is None:
->
if self.param('template') is None:
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.
done
if self.param('storage_domain') is None: | ||
return None | ||
|
||
storage_domain = self.param('storage_domain') |
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.
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
?
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.
done
|
||
storage_domain = self.param('storage_domain') | ||
|
||
disk_attachments = ( |
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.
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.
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.
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, |
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.
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?
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.
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
eafb648
to
4410be9
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.
shipit
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.
shipit
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.
👍
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
COMPONENT NAME
ANSIBLE VERSION
ADDITIONAL INFORMATION