mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
cs_template: implement update and revamp (#37015)
This commit is contained in:
parent
7f990cfc11
commit
dd953dbe96
8 changed files with 584 additions and 130 deletions
|
@ -1,22 +1,8 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
#
|
#
|
||||||
# (c) 2015, René Moser <mail@renemoser.net>
|
# Copyright (c) 2015, René Moser <mail@renemoser.net>
|
||||||
#
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
# This file is part of Ansible
|
|
||||||
#
|
|
||||||
# Ansible is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# Ansible is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||||
'status': ['stableinterface'],
|
'status': ['stableinterface'],
|
||||||
|
@ -28,7 +14,9 @@ DOCUMENTATION = '''
|
||||||
module: cs_template
|
module: cs_template
|
||||||
short_description: Manages templates on Apache CloudStack based clouds.
|
short_description: Manages templates on Apache CloudStack based clouds.
|
||||||
description:
|
description:
|
||||||
- Register a template from URL, create a template from a ROOT volume of a stopped VM or its snapshot, extract and delete templates.
|
- Register templates from an URL.
|
||||||
|
- Create templates from a ROOT volume of a stopped VM or its snapshot.
|
||||||
|
- Update (since version 2.7), extract and delete templates.
|
||||||
version_added: '2.0'
|
version_added: '2.0'
|
||||||
author: "René Moser (@resmo)"
|
author: "René Moser (@resmo)"
|
||||||
options:
|
options:
|
||||||
|
@ -38,8 +26,8 @@ options:
|
||||||
required: true
|
required: true
|
||||||
url:
|
url:
|
||||||
description:
|
description:
|
||||||
- URL of where the template is hosted on C(state=present).
|
- URL of where the template is hosted on I(state=present).
|
||||||
- URL to which the template would be extracted on C(state=extracted).
|
- URL to which the template would be extracted on I(state=extracted).
|
||||||
- Mutually exclusive with C(vm).
|
- Mutually exclusive with C(vm).
|
||||||
vm:
|
vm:
|
||||||
description:
|
description:
|
||||||
|
@ -57,38 +45,36 @@ options:
|
||||||
description:
|
description:
|
||||||
- The MD5 checksum value of this template.
|
- The MD5 checksum value of this template.
|
||||||
- If set, we search by checksum instead of name.
|
- If set, we search by checksum instead of name.
|
||||||
default: false
|
|
||||||
is_ready:
|
is_ready:
|
||||||
description:
|
description:
|
||||||
- This flag is used for searching existing templates.
|
- "Note: this flag was not implemented and therefore marked as deprecated."
|
||||||
- If set to C(true), it will only list template ready for deployment e.g. successfully downloaded and installed.
|
- Deprecated, will be removed in version 2.11.
|
||||||
- Recommended to set it to C(false).
|
type: bool
|
||||||
default: false
|
|
||||||
is_public:
|
is_public:
|
||||||
description:
|
description:
|
||||||
- Register the template to be publicly available to all users.
|
- Register the template to be publicly available to all users.
|
||||||
- Only used if C(state) is present.
|
- Only used if C(state) is present.
|
||||||
default: false
|
type: bool
|
||||||
is_featured:
|
is_featured:
|
||||||
description:
|
description:
|
||||||
- Register the template to be featured.
|
- Register the template to be featured.
|
||||||
- Only used if C(state) is present.
|
- Only used if C(state) is present.
|
||||||
default: false
|
type: bool
|
||||||
is_dynamically_scalable:
|
is_dynamically_scalable:
|
||||||
description:
|
description:
|
||||||
- Register the template having XS/VMWare tools installed in order to support dynamic scaling of VM CPU/memory.
|
- Register the template having XS/VMWare tools installed in order to support dynamic scaling of VM CPU/memory.
|
||||||
- Only used if C(state) is present.
|
- Only used if C(state) is present.
|
||||||
default: false
|
type: bool
|
||||||
cross_zones:
|
cross_zones:
|
||||||
description:
|
description:
|
||||||
- Whether the template should be synced or removed across zones.
|
- Whether the template should be synced or removed across zones.
|
||||||
- Only used if C(state) is present or absent.
|
- Only used if C(state) is present or absent.
|
||||||
default: false
|
default: no
|
||||||
|
type: bool
|
||||||
mode:
|
mode:
|
||||||
description:
|
description:
|
||||||
- Mode for the template extraction.
|
- Mode for the template extraction.
|
||||||
- Only used if C(state=extracted).
|
- Only used if I(state=extracted).
|
||||||
required: false
|
|
||||||
default: http_download
|
default: http_download
|
||||||
choices: [ http_download, ftp_upload ]
|
choices: [ http_download, ftp_upload ]
|
||||||
domain:
|
domain:
|
||||||
|
@ -107,63 +93,92 @@ options:
|
||||||
template_filter:
|
template_filter:
|
||||||
description:
|
description:
|
||||||
- Name of the filter used to search for the template.
|
- Name of the filter used to search for the template.
|
||||||
required: false
|
- The filter C(all) was added in 2.7.
|
||||||
default: self
|
default: self
|
||||||
choices: [ featured, self, selfexecutable, sharedexecutable, executable, community ]
|
choices: [ all, featured, self, selfexecutable, sharedexecutable, executable, community ]
|
||||||
|
template_find_options:
|
||||||
|
description:
|
||||||
|
- Options to find a template uniquely.
|
||||||
|
- More than one allowed.
|
||||||
|
choices: [ display_text, checksum, cross_zones ]
|
||||||
|
version_added: 2.7
|
||||||
|
aliases: [ template_find_option ]
|
||||||
|
default: []
|
||||||
hypervisor:
|
hypervisor:
|
||||||
description:
|
description:
|
||||||
- Name the hypervisor to be used for creating the new template.
|
- Name the hypervisor to be used for creating the new template.
|
||||||
- Relevant when using C(state=present).
|
- Relevant when using I(state=present).
|
||||||
choices: [ KVM, VMware, BareMetal, XenServer, LXC, HyperV, UCS, OVM, Simulator ]
|
choices:
|
||||||
|
- KVM
|
||||||
|
- kvm
|
||||||
|
- VMware
|
||||||
|
- vmware
|
||||||
|
- BareMetal
|
||||||
|
- baremetal
|
||||||
|
- XenServer
|
||||||
|
- xenserver
|
||||||
|
- LXC
|
||||||
|
- lxc
|
||||||
|
- HyperV
|
||||||
|
- hyperv
|
||||||
|
- UCS
|
||||||
|
- ucs
|
||||||
|
- OVM
|
||||||
|
- ovm
|
||||||
|
- Simulator
|
||||||
|
- simulator
|
||||||
requires_hvm:
|
requires_hvm:
|
||||||
description:
|
description:
|
||||||
- true if this template requires HVM.
|
- Whether the template requires HVM or not.
|
||||||
default: false
|
- Only considered while creating the template.
|
||||||
|
type: bool
|
||||||
password_enabled:
|
password_enabled:
|
||||||
description:
|
description:
|
||||||
- True if the template supports the password reset feature.
|
- Enable template password reset support.
|
||||||
default: false
|
type: bool
|
||||||
template_tag:
|
template_tag:
|
||||||
description:
|
description:
|
||||||
- the tag for this template.
|
- The tag for this template.
|
||||||
sshkey_enabled:
|
sshkey_enabled:
|
||||||
description:
|
description:
|
||||||
- True if the template supports the sshkey upload feature.
|
- True if the template supports the sshkey upload feature.
|
||||||
default: false
|
- Only considered if C(url) is used (API limitation).
|
||||||
|
type: bool
|
||||||
is_routing:
|
is_routing:
|
||||||
description:
|
description:
|
||||||
- True if the template type is routing i.e., if template is used to deploy router.
|
- Sets the template type to routing, i.e. if template is used to deploy routers.
|
||||||
- Only considered if C(url) is used.
|
- Only considered if C(url) is used.
|
||||||
|
type: bool
|
||||||
format:
|
format:
|
||||||
description:
|
description:
|
||||||
- The format for the template.
|
- The format for the template.
|
||||||
- Relevant when using C(state=present).
|
- Only considered if I(state=present).
|
||||||
choices: [ QCOW2, RAW, VHD, OVA ]
|
choices: [ QCOW2, RAW, VHD, OVA ]
|
||||||
is_extractable:
|
is_extractable:
|
||||||
description:
|
description:
|
||||||
- True if the template or its derivatives are extractable.
|
- Allows the template or its derivatives to be extractable.
|
||||||
default: false
|
type: bool
|
||||||
details:
|
details:
|
||||||
description:
|
description:
|
||||||
- Template details in key/value pairs.
|
- Template details in key/value pairs.
|
||||||
bits:
|
bits:
|
||||||
description:
|
description:
|
||||||
- 32 or 64 bits support.
|
- 32 or 64 bits support.
|
||||||
required: false
|
|
||||||
default: 64
|
default: 64
|
||||||
|
choices: [ 32, 64 ]
|
||||||
display_text:
|
display_text:
|
||||||
description:
|
description:
|
||||||
- Display text of the template.
|
- Display text of the template.
|
||||||
state:
|
state:
|
||||||
description:
|
description:
|
||||||
- State of the template.
|
- State of the template.
|
||||||
required: false
|
|
||||||
default: present
|
default: present
|
||||||
choices: [ present, absent, extracted ]
|
choices: [ present, absent, extracted ]
|
||||||
poll_async:
|
poll_async:
|
||||||
description:
|
description:
|
||||||
- Poll async jobs until job has finished.
|
- Poll async jobs until job has finished.
|
||||||
default: true
|
default: yes
|
||||||
|
type: bool
|
||||||
tags:
|
tags:
|
||||||
description:
|
description:
|
||||||
- List of tags. Tags are a list of dictionaries having keys C(key) and C(value).
|
- List of tags. Tags are a list of dictionaries having keys C(key) and C(value).
|
||||||
|
@ -184,12 +199,25 @@ EXAMPLES = '''
|
||||||
cross_zones: yes
|
cross_zones: yes
|
||||||
os_type: Debian GNU/Linux 7(64-bit)
|
os_type: Debian GNU/Linux 7(64-bit)
|
||||||
|
|
||||||
- name: create a template from a stopped virtual machine's volume
|
- name: Create a template from a stopped virtual machine's volume
|
||||||
local_action:
|
local_action:
|
||||||
module: cs_template
|
module: cs_template
|
||||||
name: debian-base-template
|
name: Debian 9 (64-bit) 20GB ({{ ansible_date_time.date }})
|
||||||
vm: debian-base-vm
|
vm: debian-9-base-vm
|
||||||
os_type: Debian GNU/Linux 7(64-bit)
|
os_type: Debian GNU/Linux 9 (64-bit)
|
||||||
|
zone: tokio-ix
|
||||||
|
password_enabled: yes
|
||||||
|
is_public: yes
|
||||||
|
|
||||||
|
# Note: Use template_find_option(s) when a template name is not unique
|
||||||
|
- name: Create a template from a stopped virtual machine's volume
|
||||||
|
local_action:
|
||||||
|
module: cs_template
|
||||||
|
name: Debian 9 (64-bit)
|
||||||
|
display_text: Debian 9 (64-bit) 20GB ({{ ansible_date_time.date }})
|
||||||
|
template_find_option: display_text
|
||||||
|
vm: debian-9-base-vm
|
||||||
|
os_type: Debian GNU/Linux 9 (64-bit)
|
||||||
zone: tokio-ix
|
zone: tokio-ix
|
||||||
password_enabled: yes
|
password_enabled: yes
|
||||||
is_public: yes
|
is_public: yes
|
||||||
|
@ -197,10 +225,9 @@ EXAMPLES = '''
|
||||||
- name: create a template from a virtual machine's root volume snapshot
|
- name: create a template from a virtual machine's root volume snapshot
|
||||||
local_action:
|
local_action:
|
||||||
module: cs_template
|
module: cs_template
|
||||||
name: debian-base-template
|
name: Debian 9 (64-bit) Snapshot ROOT-233_2015061509114
|
||||||
vm: debian-base-vm
|
|
||||||
snapshot: ROOT-233_2015061509114
|
snapshot: ROOT-233_2015061509114
|
||||||
os_type: Debian GNU/Linux 7(64-bit)
|
os_type: Debian GNU/Linux 9 (64-bit)
|
||||||
zone: tokio-ix
|
zone: tokio-ix
|
||||||
password_enabled: yes
|
password_enabled: yes
|
||||||
is_public: yes
|
is_public: yes
|
||||||
|
@ -370,9 +397,6 @@ class AnsibleCloudStackTemplate(AnsibleCloudStack):
|
||||||
'tempaltetype': 'template_type',
|
'tempaltetype': 'template_type',
|
||||||
'ostypename': 'os_type',
|
'ostypename': 'os_type',
|
||||||
'crossZones': 'cross_zones',
|
'crossZones': 'cross_zones',
|
||||||
'isextractable': 'is_extractable',
|
|
||||||
'isfeatured': 'is_featured',
|
|
||||||
'ispublic': 'is_public',
|
|
||||||
'format': 'format',
|
'format': 'format',
|
||||||
'hypervisor': 'hypervisor',
|
'hypervisor': 'hypervisor',
|
||||||
'url': 'url',
|
'url': 'url',
|
||||||
|
@ -432,9 +456,20 @@ class AnsibleCloudStackTemplate(AnsibleCloudStack):
|
||||||
return self._get_by_key(key, s)
|
return self._get_by_key(key, s)
|
||||||
self.module.fail_json(msg="Snapshot '%s' not found" % snapshot)
|
self.module.fail_json(msg="Snapshot '%s' not found" % snapshot)
|
||||||
|
|
||||||
def create_template(self):
|
def present_template(self):
|
||||||
template = self.get_template()
|
template = self.get_template()
|
||||||
if not template:
|
if template:
|
||||||
|
template = self.update_template(template)
|
||||||
|
elif self.module.params.get('url'):
|
||||||
|
template = self.register_template()
|
||||||
|
elif self.module.params.get('vm'):
|
||||||
|
template = self.create_template()
|
||||||
|
else:
|
||||||
|
self.fail_json(msg="one of the following is required on state=present: url, vm")
|
||||||
|
return template
|
||||||
|
|
||||||
|
def create_template(self):
|
||||||
|
template = None
|
||||||
self.result['changed'] = True
|
self.result['changed'] = True
|
||||||
|
|
||||||
args = self._get_args()
|
args = self._get_args()
|
||||||
|
@ -450,6 +485,7 @@ class AnsibleCloudStackTemplate(AnsibleCloudStack):
|
||||||
poll_async = self.module.params.get('poll_async')
|
poll_async = self.module.params.get('poll_async')
|
||||||
if poll_async:
|
if poll_async:
|
||||||
template = self.poll_job(template, 'template')
|
template = self.poll_job(template, 'template')
|
||||||
|
|
||||||
if template:
|
if template:
|
||||||
template = self.ensure_tags(resource=template, resource_type='Template')
|
template = self.ensure_tags(resource=template, resource_type='Template')
|
||||||
|
|
||||||
|
@ -462,8 +498,7 @@ class AnsibleCloudStackTemplate(AnsibleCloudStack):
|
||||||
'hypervisor',
|
'hypervisor',
|
||||||
]
|
]
|
||||||
self.module.fail_on_missing_params(required_params=required_params)
|
self.module.fail_on_missing_params(required_params=required_params)
|
||||||
template = self.get_template()
|
template = None
|
||||||
if not template:
|
|
||||||
self.result['changed'] = True
|
self.result['changed'] = True
|
||||||
args = self._get_args()
|
args = self._get_args()
|
||||||
args.update({
|
args.update({
|
||||||
|
@ -485,36 +520,106 @@ class AnsibleCloudStackTemplate(AnsibleCloudStack):
|
||||||
args['zoneid'] = -1
|
args['zoneid'] = -1
|
||||||
|
|
||||||
if not self.module.check_mode:
|
if not self.module.check_mode:
|
||||||
res = self.query_api('registerTemplate', **args)
|
self.query_api('registerTemplate', **args)
|
||||||
template = res['template']
|
template = self.get_template()
|
||||||
return template
|
return template
|
||||||
|
|
||||||
|
def update_template(self, template):
|
||||||
|
args = {
|
||||||
|
'id': template['id'],
|
||||||
|
'displaytext': self.get_or_fallback('display_text', 'name'),
|
||||||
|
'format': self.module.params.get('format'),
|
||||||
|
'isdynamicallyscalable': self.module.params.get('is_dynamically_scalable'),
|
||||||
|
'isrouting': self.module.params.get('is_routing'),
|
||||||
|
'ostypeid': self.get_os_type(key='id'),
|
||||||
|
'passwordenabled': self.module.params.get('password_enabled'),
|
||||||
|
}
|
||||||
|
if self.has_changed(args, template):
|
||||||
|
self.result['changed'] = True
|
||||||
|
if not self.module.check_mode:
|
||||||
|
self.query_api('updateTemplate', **args)
|
||||||
|
template = self.get_template()
|
||||||
|
|
||||||
|
args = {
|
||||||
|
'id': template['id'],
|
||||||
|
'isextractable': self.module.params.get('is_extractable'),
|
||||||
|
'isfeatured': self.module.params.get('is_featured'),
|
||||||
|
'ispublic': self.module.params.get('is_public'),
|
||||||
|
}
|
||||||
|
if self.has_changed(args, template):
|
||||||
|
self.result['changed'] = True
|
||||||
|
if not self.module.check_mode:
|
||||||
|
self.query_api('updateTemplatePermissions', **args)
|
||||||
|
# Refresh
|
||||||
|
template = self.get_template()
|
||||||
|
|
||||||
|
if template:
|
||||||
|
template = self.ensure_tags(resource=template, resource_type='Template')
|
||||||
|
|
||||||
|
return template
|
||||||
|
|
||||||
|
def _is_find_option(self, param_name):
|
||||||
|
return param_name in self.module.params.get('template_find_options')
|
||||||
|
|
||||||
|
def _find_option_match(self, template, param_name, internal_name=None):
|
||||||
|
if not internal_name:
|
||||||
|
internal_name = param_name
|
||||||
|
|
||||||
|
if param_name in self.module.params.get('template_find_options'):
|
||||||
|
param_value = self.module.params.get(param_name)
|
||||||
|
|
||||||
|
if not param_value:
|
||||||
|
self.fail_json(msg="The param template_find_options has %s but param was not provided." % param_name)
|
||||||
|
|
||||||
|
if template[internal_name] == param_value:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def get_template(self):
|
def get_template(self):
|
||||||
args = {
|
args = {
|
||||||
'isready': self.module.params.get('is_ready'),
|
'name': self.module.params.get('name'),
|
||||||
'templatefilter': self.module.params.get('template_filter'),
|
'templatefilter': self.module.params.get('template_filter'),
|
||||||
'domainid': self.get_domain(key='id'),
|
'domainid': self.get_domain(key='id'),
|
||||||
'account': self.get_account(key='name'),
|
'account': self.get_account(key='name'),
|
||||||
'projectid': self.get_project(key='id')
|
'projectid': self.get_project(key='id')
|
||||||
}
|
}
|
||||||
if not self.module.params.get('cross_zones'):
|
|
||||||
|
cross_zones = self.module.params.get('cross_zones')
|
||||||
|
if not cross_zones:
|
||||||
args['zoneid'] = self.get_zone(key='id')
|
args['zoneid'] = self.get_zone(key='id')
|
||||||
|
|
||||||
# if checksum is set, we only look on that.
|
template_found = None
|
||||||
checksum = self.module.params.get('checksum')
|
|
||||||
if not checksum:
|
|
||||||
args['name'] = self.module.params.get('name')
|
|
||||||
|
|
||||||
templates = self.query_api('listTemplates', **args)
|
templates = self.query_api('listTemplates', **args)
|
||||||
if templates:
|
if templates:
|
||||||
# if checksum is set, we only look on that.
|
for tmpl in templates['template']:
|
||||||
if not checksum:
|
|
||||||
return templates['template'][0]
|
if self._is_find_option('cross_zones') and not self._find_option_match(
|
||||||
|
template=tmpl,
|
||||||
|
param_name='cross_zones',
|
||||||
|
internal_name='crossZones'):
|
||||||
|
continue
|
||||||
|
|
||||||
|
if self._is_find_option('checksum') and not self._find_option_match(
|
||||||
|
template=tmpl,
|
||||||
|
param_name='checksum'):
|
||||||
|
continue
|
||||||
|
|
||||||
|
if self._is_find_option('display_text') and not self._find_option_match(
|
||||||
|
template=tmpl,
|
||||||
|
param_name='display_text',
|
||||||
|
internal_name='displaytext'):
|
||||||
|
continue
|
||||||
|
|
||||||
|
if not template_found:
|
||||||
|
template_found = tmpl
|
||||||
|
# A cross zones template has one entry per zone but the same id
|
||||||
|
elif tmpl['id'] == template_found['id']:
|
||||||
|
continue
|
||||||
else:
|
else:
|
||||||
for i in templates['template']:
|
self.fail_json(msg="Multiple templates found matching provided params. Please use template_find_options.")
|
||||||
if 'checksum' in i and i['checksum'] == checksum:
|
|
||||||
return i
|
return template_found
|
||||||
return None
|
|
||||||
|
|
||||||
def extract_template(self):
|
def extract_template(self):
|
||||||
template = self.get_template()
|
template = self.get_template()
|
||||||
|
@ -556,6 +661,14 @@ class AnsibleCloudStackTemplate(AnsibleCloudStack):
|
||||||
res = self.poll_job(res, 'template')
|
res = self.poll_job(res, 'template')
|
||||||
return template
|
return template
|
||||||
|
|
||||||
|
def get_result(self, template):
|
||||||
|
super(AnsibleCloudStackTemplate, self).get_result(template)
|
||||||
|
if template:
|
||||||
|
self.result['is_extractable'] = True if template['isextractable'] else False
|
||||||
|
self.result['is_featured'] = True if template['isfeatured'] else False
|
||||||
|
self.result['is_public'] = True if template['ispublic'] else False
|
||||||
|
return self.result
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
argument_spec = cs_argument_spec()
|
argument_spec = cs_argument_spec()
|
||||||
|
@ -566,20 +679,21 @@ def main():
|
||||||
vm=dict(),
|
vm=dict(),
|
||||||
snapshot=dict(),
|
snapshot=dict(),
|
||||||
os_type=dict(),
|
os_type=dict(),
|
||||||
is_ready=dict(type='bool', default=False),
|
is_ready=dict(type='bool', removed_in_version='2.11'),
|
||||||
is_public=dict(type='bool', default=True),
|
is_public=dict(type='bool'),
|
||||||
is_featured=dict(type='bool', default=False),
|
is_featured=dict(type='bool'),
|
||||||
is_dynamically_scalable=dict(type='bool', default=False),
|
is_dynamically_scalable=dict(type='bool'),
|
||||||
is_extractable=dict(type='bool', default=False),
|
is_extractable=dict(type='bool'),
|
||||||
is_routing=dict(type='bool'),
|
is_routing=dict(type='bool'),
|
||||||
checksum=dict(),
|
checksum=dict(),
|
||||||
template_filter=dict(default='self', choices=['featured', 'self', 'selfexecutable', 'sharedexecutable', 'executable', 'community']),
|
template_filter=dict(default='self', choices=['all', 'featured', 'self', 'selfexecutable', 'sharedexecutable', 'executable', 'community']),
|
||||||
|
template_find_options=dict(type='list', choices=['display_text', 'checksum', 'cross_zones'], aliases=['template_find_option'], default=[]),
|
||||||
hypervisor=dict(choices=CS_HYPERVISORS),
|
hypervisor=dict(choices=CS_HYPERVISORS),
|
||||||
requires_hvm=dict(type='bool', default=False),
|
requires_hvm=dict(type='bool'),
|
||||||
password_enabled=dict(type='bool', default=False),
|
password_enabled=dict(type='bool'),
|
||||||
template_tag=dict(),
|
template_tag=dict(),
|
||||||
sshkey_enabled=dict(type='bool', default=False),
|
sshkey_enabled=dict(type='bool'),
|
||||||
format=dict(choices=['QCOW2', 'RAW', 'VHD', 'OVA'], ),
|
format=dict(choices=['QCOW2', 'RAW', 'VHD', 'OVA']),
|
||||||
details=dict(),
|
details=dict(),
|
||||||
bits=dict(type='int', choices=[32, 64], default=64),
|
bits=dict(type='int', choices=[32, 64], default=64),
|
||||||
state=dict(choices=['present', 'absent', 'extracted'], default='present'),
|
state=dict(choices=['present', 'absent', 'extracted'], default='present'),
|
||||||
|
@ -606,19 +720,13 @@ def main():
|
||||||
acs_tpl = AnsibleCloudStackTemplate(module)
|
acs_tpl = AnsibleCloudStackTemplate(module)
|
||||||
|
|
||||||
state = module.params.get('state')
|
state = module.params.get('state')
|
||||||
if state in ['absent']:
|
if state == 'absent':
|
||||||
tpl = acs_tpl.remove_template()
|
tpl = acs_tpl.remove_template()
|
||||||
|
|
||||||
elif state in ['extracted']:
|
elif state == 'extracted':
|
||||||
tpl = acs_tpl.extract_template()
|
tpl = acs_tpl.extract_template()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if module.params.get('url'):
|
tpl = acs_tpl.present_template()
|
||||||
tpl = acs_tpl.register_template()
|
|
||||||
elif module.params.get('vm'):
|
|
||||||
tpl = acs_tpl.create_template()
|
|
||||||
else:
|
|
||||||
module.fail_json(msg="one of the following is required on state=present: url,vm")
|
|
||||||
|
|
||||||
result = acs_tpl.get_result(tpl)
|
result = acs_tpl.get_result(tpl)
|
||||||
|
|
||||||
|
|
2
test/integration/targets/cs_template/aliases
Normal file
2
test/integration/targets/cs_template/aliases
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
cloud/cs
|
||||||
|
shippable/cs/group1
|
5
test/integration/targets/cs_template/defaults/main.yml
Normal file
5
test/integration/targets/cs_template/defaults/main.yml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
cs_template_hypervisor: Simulator
|
||||||
|
cs_template_os_type: Other Linux (64-bit)
|
||||||
|
cs_template_url: http://dl.openvm.eu/cloudstack/macchinina/x86_64/macchinina-vmware.ova
|
||||||
|
cs_template_format: OVA
|
3
test/integration/targets/cs_template/meta/main.yml
Normal file
3
test/integration/targets/cs_template/meta/main.yml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
---
|
||||||
|
dependencies:
|
||||||
|
- cs_common
|
3
test/integration/targets/cs_template/tasks/main.yml
Normal file
3
test/integration/targets/cs_template/tasks/main.yml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
---
|
||||||
|
- import_tasks: test1.yml
|
||||||
|
- import_tasks: test2.yml
|
160
test/integration/targets/cs_template/tasks/test1.yml
Normal file
160
test/integration/targets/cs_template/tasks/test1.yml
Normal file
|
@ -0,0 +1,160 @@
|
||||||
|
---
|
||||||
|
- name: setup template
|
||||||
|
cs_template:
|
||||||
|
name: "ansible-template-test1"
|
||||||
|
state: absent
|
||||||
|
register: template
|
||||||
|
- name: verify setup template
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- template is successful
|
||||||
|
|
||||||
|
- name: test download template in check mode
|
||||||
|
cs_template:
|
||||||
|
name: "ansible-template-test1"
|
||||||
|
url: "{{ cs_template_url }}"
|
||||||
|
format: "{{ cs_template_format }}"
|
||||||
|
hypervisor: "{{ cs_template_hypervisor }}"
|
||||||
|
os_type: "{{ cs_template_os_type }}"
|
||||||
|
cross_zones: yes
|
||||||
|
register: template
|
||||||
|
check_mode: yes
|
||||||
|
- name: verify test download template in check mode
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- template is changed
|
||||||
|
|
||||||
|
- name: test download template
|
||||||
|
cs_template:
|
||||||
|
name: "ansible-template-test1"
|
||||||
|
url: "{{ cs_template_url }}"
|
||||||
|
format: "{{ cs_template_format }}"
|
||||||
|
hypervisor: "{{ cs_template_hypervisor }}"
|
||||||
|
os_type: "{{ cs_template_os_type }}"
|
||||||
|
cross_zones: yes
|
||||||
|
register: template
|
||||||
|
- name: verify test download template
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- template is changed
|
||||||
|
- template.name == "ansible-template-test1"
|
||||||
|
- template.display_text == "ansible-template-test1"
|
||||||
|
- template.cross_zones == true
|
||||||
|
|
||||||
|
- name: test download template idempotence
|
||||||
|
cs_template:
|
||||||
|
name: "ansible-template-test1"
|
||||||
|
url: "{{ cs_template_url }}"
|
||||||
|
format: "{{ cs_template_format }}"
|
||||||
|
hypervisor: "{{ cs_template_hypervisor }}"
|
||||||
|
os_type: "{{ cs_template_os_type }}"
|
||||||
|
cross_zones: yes
|
||||||
|
register: template
|
||||||
|
- name: verify test download template idempotence
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- template is not changed
|
||||||
|
- template.name == "ansible-template-test1"
|
||||||
|
- template.display_text == "ansible-template-test1"
|
||||||
|
- template.cross_zones == true
|
||||||
|
|
||||||
|
- name: test update template in check mode
|
||||||
|
cs_template:
|
||||||
|
name: "ansible-template-test1"
|
||||||
|
display_text: "{{ cs_resource_prefix }}-template display_text"
|
||||||
|
url: "{{ cs_template_url }}"
|
||||||
|
format: "{{ cs_template_format }}"
|
||||||
|
hypervisor: "{{ cs_template_hypervisor }}"
|
||||||
|
os_type: "{{ cs_template_os_type }}"
|
||||||
|
is_featured: yes
|
||||||
|
cross_zones: yes
|
||||||
|
register: template
|
||||||
|
check_mode: yes
|
||||||
|
- name: verify test update template in check mode
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- template is changed
|
||||||
|
- template.name == "ansible-template-test1"
|
||||||
|
- template.display_text == "ansible-template-test1"
|
||||||
|
- template.cross_zones == true
|
||||||
|
- template.is_featured == false
|
||||||
|
|
||||||
|
- name: test update template
|
||||||
|
cs_template:
|
||||||
|
name: "ansible-template-test1"
|
||||||
|
display_text: "{{ cs_resource_prefix }}-template display_text"
|
||||||
|
url: "{{ cs_template_url }}"
|
||||||
|
format: "{{ cs_template_format }}"
|
||||||
|
hypervisor: "{{ cs_template_hypervisor }}"
|
||||||
|
os_type: "{{ cs_template_os_type }}"
|
||||||
|
is_featured: yes
|
||||||
|
cross_zones: yes
|
||||||
|
register: template
|
||||||
|
- name: verify test update template
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- template is changed
|
||||||
|
- template.name == "ansible-template-test1"
|
||||||
|
- template.display_text == "{{ cs_resource_prefix }}-template display_text"
|
||||||
|
- template.cross_zones == true
|
||||||
|
- template.is_featured == true
|
||||||
|
|
||||||
|
- name: test update template idempotence
|
||||||
|
cs_template:
|
||||||
|
name: "ansible-template-test1"
|
||||||
|
display_text: "{{ cs_resource_prefix }}-template display_text"
|
||||||
|
url: "{{ cs_template_url }}"
|
||||||
|
format: "{{ cs_template_format }}"
|
||||||
|
hypervisor: "{{ cs_template_hypervisor }}"
|
||||||
|
os_type: "{{ cs_template_os_type }}"
|
||||||
|
is_featured: yes
|
||||||
|
cross_zones: yes
|
||||||
|
register: template
|
||||||
|
- name: verify test update template idempotence
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- template is not changed
|
||||||
|
- template.name == "ansible-template-test1"
|
||||||
|
- template.display_text == "{{ cs_resource_prefix }}-template display_text"
|
||||||
|
- template.cross_zones == true
|
||||||
|
- template.is_featured == true
|
||||||
|
|
||||||
|
- name: test remove template in check mode
|
||||||
|
cs_template:
|
||||||
|
name: "ansible-template-test1"
|
||||||
|
state: absent
|
||||||
|
cross_zones: yes
|
||||||
|
register: template
|
||||||
|
check_mode: yes
|
||||||
|
- name: verify test remove template in check mode
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- template is changed
|
||||||
|
- template.name == "ansible-template-test1"
|
||||||
|
- template.display_text == "{{ cs_resource_prefix }}-template display_text"
|
||||||
|
- template.cross_zones == true
|
||||||
|
|
||||||
|
- name: test remove template
|
||||||
|
cs_template:
|
||||||
|
name: "ansible-template-test1"
|
||||||
|
state: absent
|
||||||
|
cross_zones: yes
|
||||||
|
register: template
|
||||||
|
- name: verify test remove template
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- template is changed
|
||||||
|
- template.name == "ansible-template-test1"
|
||||||
|
- template.display_text == "{{ cs_resource_prefix }}-template display_text"
|
||||||
|
- template.cross_zones == true
|
||||||
|
|
||||||
|
- name: test remove template idempotence
|
||||||
|
cs_template:
|
||||||
|
name: "ansible-template-test1"
|
||||||
|
state: absent
|
||||||
|
cross_zones: yes
|
||||||
|
register: template
|
||||||
|
- name: verify test remove template idempotence
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- template is not changed
|
176
test/integration/targets/cs_template/tasks/test2.yml
Normal file
176
test/integration/targets/cs_template/tasks/test2.yml
Normal file
|
@ -0,0 +1,176 @@
|
||||||
|
---
|
||||||
|
- name: setup template first template
|
||||||
|
cs_template:
|
||||||
|
name: ansible-template-test2
|
||||||
|
display_text: first template
|
||||||
|
state: absent
|
||||||
|
template_find_options: display_text
|
||||||
|
register: template
|
||||||
|
- name: verify setup template first template
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- template is successful
|
||||||
|
|
||||||
|
- name: setup template second template
|
||||||
|
cs_template:
|
||||||
|
name: ansible-template-test2
|
||||||
|
display_text: second template
|
||||||
|
state: absent
|
||||||
|
template_find_options: display_text
|
||||||
|
register: template
|
||||||
|
- name: verify setup template second template
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- template is successful
|
||||||
|
|
||||||
|
- name: test register first template
|
||||||
|
cs_template:
|
||||||
|
name: ansible-template-test2
|
||||||
|
display_text: first template
|
||||||
|
url: "{{ cs_template_url }}"
|
||||||
|
format: "{{ cs_template_format }}"
|
||||||
|
hypervisor: "{{ cs_template_hypervisor }}"
|
||||||
|
os_type: "{{ cs_template_os_type }}"
|
||||||
|
cross_zones: yes
|
||||||
|
template_find_options: display_text
|
||||||
|
register: template_first
|
||||||
|
- name: verify test register first template
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- template_first is changed
|
||||||
|
- template_first.name == "ansible-template-test2"
|
||||||
|
- template_first.display_text == "first template"
|
||||||
|
- template_first.cross_zones == true
|
||||||
|
|
||||||
|
- name: test register second template
|
||||||
|
cs_template:
|
||||||
|
name: ansible-template-test2
|
||||||
|
display_text: second template
|
||||||
|
url: "{{ cs_template_url }}"
|
||||||
|
format: "{{ cs_template_format }}"
|
||||||
|
hypervisor: "{{ cs_template_hypervisor }}"
|
||||||
|
os_type: "{{ cs_template_os_type }}"
|
||||||
|
cross_zones: yes
|
||||||
|
template_find_options: display_text
|
||||||
|
register: template_second
|
||||||
|
- name: verify test register second template
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- template_second is changed
|
||||||
|
- template_second.name == "ansible-template-test2"
|
||||||
|
- template_second.display_text == "second template"
|
||||||
|
- template_second.cross_zones == true
|
||||||
|
- template_second.id != template_first.id
|
||||||
|
|
||||||
|
- name: test multiple template same name absent without find options
|
||||||
|
cs_template:
|
||||||
|
name: ansible-template-test2
|
||||||
|
state: absent
|
||||||
|
register: template
|
||||||
|
ignore_errors: yes
|
||||||
|
- name: verify test multiple template same name absent without find options
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- template is failed
|
||||||
|
- template.msg.startswith('Multiple templates found')
|
||||||
|
|
||||||
|
- name: test update second template
|
||||||
|
cs_template:
|
||||||
|
name: ansible-template-test2
|
||||||
|
display_text: second template
|
||||||
|
url: "{{ cs_template_url }}"
|
||||||
|
format: "{{ cs_template_format }}"
|
||||||
|
hypervisor: "{{ cs_template_hypervisor }}"
|
||||||
|
os_type: "{{ cs_template_os_type }}"
|
||||||
|
is_featured: yes
|
||||||
|
is_public: yes
|
||||||
|
cross_zones: yes
|
||||||
|
template_find_options: display_text
|
||||||
|
register: template
|
||||||
|
- name: verify test update second template
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- template is changed
|
||||||
|
- template.name == "ansible-template-test2"
|
||||||
|
- template.display_text == "second template"
|
||||||
|
- template.cross_zones == true
|
||||||
|
- template.id == template_second.id
|
||||||
|
- template.is_featured == true
|
||||||
|
- template.is_public == true
|
||||||
|
|
||||||
|
- name: test update second template idempotence
|
||||||
|
cs_template:
|
||||||
|
name: ansible-template-test2
|
||||||
|
display_text: second template
|
||||||
|
url: "{{ cs_template_url }}"
|
||||||
|
format: "{{ cs_template_format }}"
|
||||||
|
hypervisor: "{{ cs_template_hypervisor }}"
|
||||||
|
os_type: "{{ cs_template_os_type }}"
|
||||||
|
is_featured: yes
|
||||||
|
is_public: yes
|
||||||
|
cross_zones: yes
|
||||||
|
template_find_options: display_text
|
||||||
|
register: template
|
||||||
|
- name: verify test update second template idempotence
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- template is not changed
|
||||||
|
- template.name == "ansible-template-test2"
|
||||||
|
- template.display_text == "second template"
|
||||||
|
- template.cross_zones == true
|
||||||
|
- template.id == template_second.id
|
||||||
|
- template.is_featured == true
|
||||||
|
|
||||||
|
- name: test update second template idempotence 2
|
||||||
|
cs_template:
|
||||||
|
name: ansible-template-test2
|
||||||
|
display_text: second template
|
||||||
|
url: "{{ cs_template_url }}"
|
||||||
|
format: "{{ cs_template_format }}"
|
||||||
|
hypervisor: "{{ cs_template_hypervisor }}"
|
||||||
|
os_type: "{{ cs_template_os_type }}"
|
||||||
|
cross_zones: yes
|
||||||
|
template_find_options: display_text
|
||||||
|
register: template
|
||||||
|
- name: verify test update second template idempotence
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- template is not changed
|
||||||
|
- template.name == "ansible-template-test2"
|
||||||
|
- template.display_text == "second template"
|
||||||
|
- template.cross_zones == true
|
||||||
|
- template.id == template_second.id
|
||||||
|
|
||||||
|
- name: test delete first template
|
||||||
|
cs_template:
|
||||||
|
name: ansible-template-test2
|
||||||
|
display_text: first template
|
||||||
|
state: absent
|
||||||
|
template_find_options: display_text
|
||||||
|
register: template
|
||||||
|
- name: verify test delete first template
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- template is changed
|
||||||
|
- template.name == "ansible-template-test2"
|
||||||
|
- template.display_text == "first template"
|
||||||
|
- template.cross_zones == true
|
||||||
|
- template.id == template_first.id
|
||||||
|
- template.is_featured == false
|
||||||
|
|
||||||
|
- name: test delete second template
|
||||||
|
cs_template:
|
||||||
|
name: ansible-template-test2
|
||||||
|
display_text: second template
|
||||||
|
state: absent
|
||||||
|
template_find_options: display_text
|
||||||
|
register: template
|
||||||
|
- name: verify test delete second template
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- template is changed
|
||||||
|
- template.name == "ansible-template-test2"
|
||||||
|
- template.display_text == "second template"
|
||||||
|
- template.cross_zones == true
|
||||||
|
- template.id == template_second.id
|
||||||
|
- template.is_featured == true
|
|
@ -177,9 +177,6 @@ lib/ansible/modules/cloud/cloudstack/cs_staticnat.py E324
|
||||||
lib/ansible/modules/cloud/cloudstack/cs_storage_pool.py E322
|
lib/ansible/modules/cloud/cloudstack/cs_storage_pool.py E322
|
||||||
lib/ansible/modules/cloud/cloudstack/cs_storage_pool.py E325
|
lib/ansible/modules/cloud/cloudstack/cs_storage_pool.py E325
|
||||||
lib/ansible/modules/cloud/cloudstack/cs_storage_pool.py E326
|
lib/ansible/modules/cloud/cloudstack/cs_storage_pool.py E326
|
||||||
lib/ansible/modules/cloud/cloudstack/cs_template.py E324
|
|
||||||
lib/ansible/modules/cloud/cloudstack/cs_template.py E325
|
|
||||||
lib/ansible/modules/cloud/cloudstack/cs_template.py E326
|
|
||||||
lib/ansible/modules/cloud/cloudstack/cs_vmsnapshot.py E325
|
lib/ansible/modules/cloud/cloudstack/cs_vmsnapshot.py E325
|
||||||
lib/ansible/modules/cloud/cloudstack/cs_volume.py E322
|
lib/ansible/modules/cloud/cloudstack/cs_volume.py E322
|
||||||
lib/ansible/modules/cloud/cloudstack/cs_volume.py E324
|
lib/ansible/modules/cloud/cloudstack/cs_volume.py E324
|
||||||
|
|
Loading…
Reference in a new issue