1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

ovirt: Use id instead of name of Blank template (#38948)

Since Blank template could be renamed we must use it's ID to be sure we
are using the Blank template.
This commit is contained in:
Ondra Machacek 2018-04-18 20:17:11 +02:00 committed by ansibot
parent dc09ddfbd5
commit aeaf0e358f

View file

@ -854,6 +854,7 @@ class VmsModule(BaseModule):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(VmsModule, self).__init__(*args, **kwargs) super(VmsModule, self).__init__(*args, **kwargs)
self._initialization = None self._initialization = None
self._is_new = False
def __get_template_with_version(self): def __get_template_with_version(self):
""" """
@ -862,8 +863,8 @@ class VmsModule(BaseModule):
through it's version until we find the version we look for. through it's version until we find the version we look for.
""" """
template = None template = None
templates_service = self._connection.system_service().templates_service()
if self.param('template'): if self.param('template'):
templates_service = self._connection.system_service().templates_service()
templates = templates_service.list(search='name=%s' % self.param('template')) templates = templates_service.list(search='name=%s' % self.param('template'))
if self.param('template_version'): if self.param('template_version'):
templates = [ templates = [
@ -878,6 +879,9 @@ class VmsModule(BaseModule):
) )
) )
template = sorted(templates, key=lambda t: t.version.version_number, reverse=True)[0] template = sorted(templates, key=lambda t: t.version.version_number, reverse=True)[0]
elif self._is_new:
# 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
@ -1117,10 +1121,9 @@ class VmsModule(BaseModule):
) )
def pre_create(self, entity): def pre_create(self, entity):
# If VM don't exists, and template is not specified, set it to Blank: # Mark if entity exists before touching it:
if entity is None: if entity is None:
if self.param('template') is None: self._is_new = True
self._module.params['template'] = 'Blank'
def post_update(self, entity): def post_update(self, entity):
self.post_present(entity.id) self.post_present(entity.id)