ovirt_vm update tempalte search by datacenter (#60461)

This commit is contained in:
Martin Nečas 2019-08-13 12:16:25 +02:00 committed by ansibot
parent 6110dcc789
commit 5972567ab6

View file

@ -831,11 +831,6 @@ options:
- "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.
@ -1270,14 +1265,12 @@ class VmsModule(BaseModule):
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')
clusters_service = self._connection.system_service().clusters_service()
cluster = search_by_name(clusters_service, self.param('cluster'))
data_center = self._connection.follow_link(cluster.data_center)
templates = templates_service.list(
search='name=%s and cluster=%s' % (self.param('template'), cluster)
search='name=%s and datacenter=%s' % (self.param('template'), data_center.name)
)
if not templates:
templates = templates_service.list(
search='name=%s' % self.param('template')
)
if self.param('template_version'):
templates = [
t for t in templates
@ -1285,10 +1278,10 @@ class VmsModule(BaseModule):
]
if not templates:
raise ValueError(
"Template with name '%s' and version '%s' in cluster '%s' was not found'" % (
"Template with name '%s' and version '%s' in data center '%s' was not found'" % (
self.param('template'),
self.param('template_version'),
cluster
data_center.name
)
)
template = sorted(templates, key=lambda t: t.version.version_number, reverse=True)[0]
@ -2308,7 +2301,6 @@ 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'),