cloudscale_server: add tags support (#60396)
This commit is contained in:
parent
5298d312a2
commit
f02f5c4b5d
2 changed files with 151 additions and 1 deletions
|
@ -113,6 +113,11 @@ options:
|
|||
default: no
|
||||
type: bool
|
||||
version_added: '2.8'
|
||||
tags:
|
||||
description:
|
||||
- Tags assosiated with the servers. Set this to C({}) to clear any tags.
|
||||
type: dict
|
||||
version_added: '2.9'
|
||||
extends_documentation_fragment: cloudscale
|
||||
'''
|
||||
|
||||
|
@ -245,6 +250,12 @@ server_groups:
|
|||
type: list
|
||||
sample: [ {"href": "https://api.cloudscale.ch/v1/server-groups/...", "uuid": "...", "name": "db-group"} ]
|
||||
version_added: '2.8'
|
||||
tags:
|
||||
description: Tags assosiated with the volume.
|
||||
returned: success
|
||||
type: dict
|
||||
sample: { 'project': 'my project' }
|
||||
version_added: '2.9'
|
||||
'''
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
|
@ -453,6 +464,7 @@ class AnsibleCloudscaleServer(AnsibleCloudscaleBase):
|
|||
|
||||
server_info = self._update_param('flavor', server_info, requires_stop=True)
|
||||
server_info = self._update_param('name', server_info)
|
||||
server_info = self._update_param('tags', server_info)
|
||||
|
||||
if previous_state == "running":
|
||||
server_info = self._start_stop_server(server_info, target_state="running", ignore_diff=True)
|
||||
|
@ -508,7 +520,8 @@ def main():
|
|||
anti_affinity_with=dict(removed_in_version='2.11'),
|
||||
server_groups=dict(type='list'),
|
||||
user_data=dict(),
|
||||
force=dict(type='bool', default=False)
|
||||
force=dict(type='bool', default=False),
|
||||
tags=dict(type='dict'),
|
||||
))
|
||||
|
||||
module = AnsibleModule(
|
||||
|
|
|
@ -12,6 +12,10 @@
|
|||
image: '{{ cloudscale_test_image }}'
|
||||
ssh_keys: '{{ cloudscale_test_ssh_key }}'
|
||||
server_groups: '{{ cloudscale_resource_prefix }}-group-1'
|
||||
tags:
|
||||
project: ansible-test
|
||||
stage: production
|
||||
sla: 24-7
|
||||
register: server
|
||||
check_mode: yes
|
||||
- name: Verify create a running server in check mode
|
||||
|
@ -27,6 +31,10 @@
|
|||
image: '{{ cloudscale_test_image }}'
|
||||
ssh_keys: '{{ cloudscale_test_ssh_key }}'
|
||||
server_groups: '{{ cloudscale_resource_prefix }}-group-1'
|
||||
tags:
|
||||
project: ansible-test
|
||||
stage: production
|
||||
sla: 24-7
|
||||
register: server
|
||||
- name: Verify create a running server
|
||||
assert:
|
||||
|
@ -34,6 +42,9 @@
|
|||
- server is changed
|
||||
- server.state == 'running'
|
||||
- server.server_groups.0.name == '{{ cloudscale_resource_prefix }}-group-1'
|
||||
- server.tags.project == 'ansible-test'
|
||||
- server.tags.stage == 'production'
|
||||
- server.tags.sla == '24-7'
|
||||
|
||||
- name: Test create a running server idempotence
|
||||
cloudscale_server:
|
||||
|
@ -42,6 +53,10 @@
|
|||
image: '{{ cloudscale_test_image }}'
|
||||
ssh_keys: '{{ cloudscale_test_ssh_key }}'
|
||||
server_groups: '{{ cloudscale_resource_prefix }}-group-1'
|
||||
tags:
|
||||
project: ansible-test
|
||||
stage: production
|
||||
sla: 24-7
|
||||
register: server
|
||||
- name: Verify create a running server idempotence
|
||||
assert:
|
||||
|
@ -49,6 +64,128 @@
|
|||
- server is not changed
|
||||
- server.state == 'running'
|
||||
- server.server_groups.0.name == '{{ cloudscale_resource_prefix }}-group-1'
|
||||
- server.tags.project == 'ansible-test'
|
||||
- server.tags.stage == 'production'
|
||||
- server.tags.sla == '24-7'
|
||||
|
||||
- name: Test update tags in check mode
|
||||
cloudscale_server:
|
||||
name: '{{ cloudscale_resource_prefix }}-test'
|
||||
flavor: '{{ cloudscale_test_flavor }}'
|
||||
image: '{{ cloudscale_test_image }}'
|
||||
ssh_keys: '{{ cloudscale_test_ssh_key }}'
|
||||
server_groups: '{{ cloudscale_resource_prefix }}-group-1'
|
||||
tags:
|
||||
project: ansible-test
|
||||
stage: staging
|
||||
sla: 8-5
|
||||
register: server
|
||||
check_mode: yes
|
||||
- name: Verify update tags in check mode
|
||||
assert:
|
||||
that:
|
||||
- server is changed
|
||||
- server.state == 'running'
|
||||
- server.server_groups.0.name == '{{ cloudscale_resource_prefix }}-group-1'
|
||||
- server.tags.project == 'ansible-test'
|
||||
- server.tags.stage == 'production'
|
||||
- server.tags.sla == '24-7'
|
||||
|
||||
- name: Test update tags
|
||||
cloudscale_server:
|
||||
name: '{{ cloudscale_resource_prefix }}-test'
|
||||
flavor: '{{ cloudscale_test_flavor }}'
|
||||
image: '{{ cloudscale_test_image }}'
|
||||
ssh_keys: '{{ cloudscale_test_ssh_key }}'
|
||||
server_groups: '{{ cloudscale_resource_prefix }}-group-1'
|
||||
tags:
|
||||
project: ansible-test
|
||||
stage: staging
|
||||
sla: 8-5
|
||||
register: server
|
||||
- name: Verify update tags
|
||||
assert:
|
||||
that:
|
||||
- server is changed
|
||||
- server.state == 'running'
|
||||
- server.server_groups.0.name == '{{ cloudscale_resource_prefix }}-group-1'
|
||||
- server.tags.project == 'ansible-test'
|
||||
- server.tags.stage == 'staging'
|
||||
- server.tags.sla == '8-5'
|
||||
|
||||
- name: Test update tags idempotence
|
||||
cloudscale_server:
|
||||
name: '{{ cloudscale_resource_prefix }}-test'
|
||||
flavor: '{{ cloudscale_test_flavor }}'
|
||||
image: '{{ cloudscale_test_image }}'
|
||||
ssh_keys: '{{ cloudscale_test_ssh_key }}'
|
||||
server_groups: '{{ cloudscale_resource_prefix }}-group-1'
|
||||
tags:
|
||||
project: ansible-test
|
||||
stage: staging
|
||||
sla: 8-5
|
||||
register: server
|
||||
- name: Verify update tags idempotence
|
||||
assert:
|
||||
that:
|
||||
- server is not changed
|
||||
- server.state == 'running'
|
||||
- server.server_groups.0.name == '{{ cloudscale_resource_prefix }}-group-1'
|
||||
- server.tags.project == 'ansible-test'
|
||||
- server.tags.stage == 'staging'
|
||||
- server.tags.sla == '8-5'
|
||||
|
||||
- name: Test omit tags idempotence
|
||||
cloudscale_server:
|
||||
name: '{{ cloudscale_resource_prefix }}-test'
|
||||
flavor: '{{ cloudscale_test_flavor }}'
|
||||
image: '{{ cloudscale_test_image }}'
|
||||
ssh_keys: '{{ cloudscale_test_ssh_key }}'
|
||||
server_groups: '{{ cloudscale_resource_prefix }}-group-1'
|
||||
register: server
|
||||
- name: Verify update tags idempotence
|
||||
assert:
|
||||
that:
|
||||
- server is not changed
|
||||
- server.state == 'running'
|
||||
- server.server_groups.0.name == '{{ cloudscale_resource_prefix }}-group-1'
|
||||
- server.tags.project == 'ansible-test'
|
||||
- server.tags.stage == 'staging'
|
||||
- server.tags.sla == '8-5'
|
||||
|
||||
- name: Test delete tags
|
||||
cloudscale_server:
|
||||
name: '{{ cloudscale_resource_prefix }}-test'
|
||||
flavor: '{{ cloudscale_test_flavor }}'
|
||||
image: '{{ cloudscale_test_image }}'
|
||||
ssh_keys: '{{ cloudscale_test_ssh_key }}'
|
||||
server_groups: '{{ cloudscale_resource_prefix }}-group-1'
|
||||
tags: {}
|
||||
register: server
|
||||
- name: Verify delete tags
|
||||
assert:
|
||||
that:
|
||||
- server is changed
|
||||
- server.state == 'running'
|
||||
- server.server_groups.0.name == '{{ cloudscale_resource_prefix }}-group-1'
|
||||
- not server.tags
|
||||
|
||||
- name: Test delete tags idempotence
|
||||
cloudscale_server:
|
||||
name: '{{ cloudscale_resource_prefix }}-test'
|
||||
flavor: '{{ cloudscale_test_flavor }}'
|
||||
image: '{{ cloudscale_test_image }}'
|
||||
ssh_keys: '{{ cloudscale_test_ssh_key }}'
|
||||
server_groups: '{{ cloudscale_resource_prefix }}-group-1'
|
||||
tags: {}
|
||||
register: server
|
||||
- name: Verify delete tags idempotence
|
||||
assert:
|
||||
that:
|
||||
- server is not changed
|
||||
- server.state == 'running'
|
||||
- server.server_groups.0.name == '{{ cloudscale_resource_prefix }}-group-1'
|
||||
- not server.tags
|
||||
|
||||
- name: Test update flavor of a running server without force in check mode
|
||||
cloudscale_server:
|
||||
|
|
Loading…
Reference in a new issue