Skip to content

Commit

Permalink
ovirt add template cluster (ansible#59378)
Browse files Browse the repository at this point in the history
* ovirt add template cluster

* update doc

* add global search fallback

* update docs
  • Loading branch information
mnecas authored and ansibot committed Jul 23, 2019
1 parent f1dbf62 commit 8ee587a
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lib/ansible/modules/cloud/ovirt/ovirt_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,11 @@
- "VM should have snapshot specified by C(snapshot)."
- "If C(snapshot_name) specified C(snapshot_vm) is required."
version_added: "2.9"
template_cluster:
description:
- "Template cluster name. When not defined C(cluster) is used."
- "Allows you to create virtual machine in diffrent cluster than template cluster name."
version_added: "2.9"
notes:
- If VM is in I(UNASSIGNED) or I(UNKNOWN) state before any operation, the module will fail.
Expand Down Expand Up @@ -1265,9 +1270,14 @@ def __get_template_with_version(self):
template = None
templates_service = self._connection.system_service().templates_service()
if self.param('template'):
cluster = self.param('template_cluster') if self.param('template_cluster') else self.param('cluster')
templates = templates_service.list(
search='name=%s and cluster=%s' % (self.param('template'), self.param('cluster'))
search='name=%s and cluster=%s' % (self.param('template'), cluster)
)
if not templates:
templates = templates_service.list(
search='name=%s' % self.param('template')
)
if self.param('template_version'):
templates = [
t for t in templates
Expand All @@ -1278,7 +1288,7 @@ def __get_template_with_version(self):
"Template with name '%s' and version '%s' in cluster '%s' was not found'" % (
self.param('template'),
self.param('template_version'),
self.param('cluster')
cluster
)
)
template = sorted(templates, key=lambda t: t.version.version_number, reverse=True)[0]
Expand Down Expand Up @@ -2298,6 +2308,7 @@ def main():
cluster=dict(type='str'),
allow_partial_import=dict(type='bool'),
template=dict(type='str'),
template_cluster=dict(type='str'),
template_version=dict(type='int'),
use_latest_template_version=dict(type='bool'),
storage_domain=dict(type='str'),
Expand Down

0 comments on commit 8ee587a

Please sign in to comment.