cloudstack: cs_instance: fix template not found (#2005)

Let users decide which filter should be used to find the template.
This commit is contained in:
René Moser 2016-04-12 18:46:02 +02:00
parent 442c286b1c
commit 30a46ee542

View file

@ -87,6 +87,15 @@ options:
- Mutually exclusive with C(template) option. - Mutually exclusive with C(template) option.
required: false required: false
default: null default: null
template_filter:
description:
- Name of the filter used to search for the template or iso.
- Used for params C(iso) or C(template) on C(state=present).
required: false
default: 'executable'
choices: [ 'featured', 'self', 'selfexecutable', 'sharedexecutable', 'executable', 'community' ]
aliases: [ 'iso_filter' ]
version_added: '2.1'
hypervisor: hypervisor:
description: description:
- Name the hypervisor to be used for creating the new instance. - Name the hypervisor to be used for creating the new instance.
@ -450,7 +459,7 @@ class AnsibleCloudStackInstance(AnsibleCloudStack):
if self.template: if self.template:
return self._get_by_key(key, self.template) return self._get_by_key(key, self.template)
args['templatefilter'] = 'executable' args['templatefilter'] = self.module.params.get('template_filter')
templates = self.cs.listTemplates(**args) templates = self.cs.listTemplates(**args)
if templates: if templates:
for t in templates['template']: for t in templates['template']:
@ -462,7 +471,7 @@ class AnsibleCloudStackInstance(AnsibleCloudStack):
elif iso: elif iso:
if self.iso: if self.iso:
return self._get_by_key(key, self.iso) return self._get_by_key(key, self.iso)
args['isofilter'] = 'executable' args['isofilter'] = self.module.params.get('template_filter')
isos = self.cs.listIsos(**args) isos = self.cs.listIsos(**args)
if isos: if isos:
for i in isos['iso']: for i in isos['iso']:
@ -913,6 +922,7 @@ def main():
memory = dict(default=None, type='int'), memory = dict(default=None, type='int'),
template = dict(default=None), template = dict(default=None),
iso = dict(default=None), iso = dict(default=None),
template_filter = dict(default="executable", aliases=['iso_filter'], choices=['featured', 'self', 'selfexecutable', 'sharedexecutable', 'executable', 'community']),
networks = dict(type='list', aliases=[ 'network' ], default=None), networks = dict(type='list', aliases=[ 'network' ], default=None),
ip_to_networks = dict(type='list', aliases=['ip_to_network'], default=None), ip_to_networks = dict(type='list', aliases=['ip_to_network'], default=None),
ip_address = dict(defaul=None), ip_address = dict(defaul=None),