ovirt_vm: dont try to update template when already created from clone (#65317)

This commit is contained in:
Martin Nečas 2019-12-09 11:09:33 +01:00 committed by ansibot
parent 5c9539903e
commit 9c79de2e1e

View file

@ -1301,30 +1301,31 @@ class VmsModule(BaseModule):
""" """
template = None template = None
templates_service = self._connection.system_service().templates_service() templates_service = self._connection.system_service().templates_service()
if self.param('template'): if self._is_new:
clusters_service = self._connection.system_service().clusters_service() if self.param('template'):
cluster = search_by_name(clusters_service, self.param('cluster')) clusters_service = self._connection.system_service().clusters_service()
data_center = self._connection.follow_link(cluster.data_center) cluster = search_by_name(clusters_service, self.param('cluster'))
templates = templates_service.list( data_center = self._connection.follow_link(cluster.data_center)
search='name=%s and datacenter=%s' % (self.param('template'), data_center.name) templates = templates_service.list(
) search='name=%s and datacenter=%s' % (self.param('template'), data_center.name)
if self.param('template_version'):
templates = [
t for t in templates
if t.version.version_number == self.param('template_version')
]
if not templates:
raise ValueError(
"Template with name '%s' and version '%s' in data center '%s' was not found'" % (
self.param('template'),
self.param('template_version'),
data_center.name
)
) )
template = sorted(templates, key=lambda t: t.version.version_number, reverse=True)[0] if self.param('template_version'):
elif self._is_new: templates = [
# If template isn't specified and VM is about to be created specify default template: t for t in templates
template = templates_service.template_service('00000000-0000-0000-0000-000000000000').get() if t.version.version_number == self.param('template_version')
]
if not templates:
raise ValueError(
"Template with name '%s' and version '%s' in data center '%s' was not found'" % (
self.param('template'),
self.param('template_version'),
data_center.name
)
)
template = sorted(templates, key=lambda t: t.version.version_number, reverse=True)[0]
else:
# If template isn't specified and VM is about to be created specify default template:
template = templates_service.template_service('00000000-0000-0000-0000-000000000000').get()
return template return template