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
|
default: no
|
||||||
type: bool
|
type: bool
|
||||||
version_added: '2.8'
|
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
|
extends_documentation_fragment: cloudscale
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
@ -245,6 +250,12 @@ server_groups:
|
||||||
type: list
|
type: list
|
||||||
sample: [ {"href": "https://api.cloudscale.ch/v1/server-groups/...", "uuid": "...", "name": "db-group"} ]
|
sample: [ {"href": "https://api.cloudscale.ch/v1/server-groups/...", "uuid": "...", "name": "db-group"} ]
|
||||||
version_added: '2.8'
|
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
|
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('flavor', server_info, requires_stop=True)
|
||||||
server_info = self._update_param('name', server_info)
|
server_info = self._update_param('name', server_info)
|
||||||
|
server_info = self._update_param('tags', server_info)
|
||||||
|
|
||||||
if previous_state == "running":
|
if previous_state == "running":
|
||||||
server_info = self._start_stop_server(server_info, target_state="running", ignore_diff=True)
|
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'),
|
anti_affinity_with=dict(removed_in_version='2.11'),
|
||||||
server_groups=dict(type='list'),
|
server_groups=dict(type='list'),
|
||||||
user_data=dict(),
|
user_data=dict(),
|
||||||
force=dict(type='bool', default=False)
|
force=dict(type='bool', default=False),
|
||||||
|
tags=dict(type='dict'),
|
||||||
))
|
))
|
||||||
|
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
|
|
|
@ -12,6 +12,10 @@
|
||||||
image: '{{ cloudscale_test_image }}'
|
image: '{{ cloudscale_test_image }}'
|
||||||
ssh_keys: '{{ cloudscale_test_ssh_key }}'
|
ssh_keys: '{{ cloudscale_test_ssh_key }}'
|
||||||
server_groups: '{{ cloudscale_resource_prefix }}-group-1'
|
server_groups: '{{ cloudscale_resource_prefix }}-group-1'
|
||||||
|
tags:
|
||||||
|
project: ansible-test
|
||||||
|
stage: production
|
||||||
|
sla: 24-7
|
||||||
register: server
|
register: server
|
||||||
check_mode: yes
|
check_mode: yes
|
||||||
- name: Verify create a running server in check mode
|
- name: Verify create a running server in check mode
|
||||||
|
@ -27,6 +31,10 @@
|
||||||
image: '{{ cloudscale_test_image }}'
|
image: '{{ cloudscale_test_image }}'
|
||||||
ssh_keys: '{{ cloudscale_test_ssh_key }}'
|
ssh_keys: '{{ cloudscale_test_ssh_key }}'
|
||||||
server_groups: '{{ cloudscale_resource_prefix }}-group-1'
|
server_groups: '{{ cloudscale_resource_prefix }}-group-1'
|
||||||
|
tags:
|
||||||
|
project: ansible-test
|
||||||
|
stage: production
|
||||||
|
sla: 24-7
|
||||||
register: server
|
register: server
|
||||||
- name: Verify create a running server
|
- name: Verify create a running server
|
||||||
assert:
|
assert:
|
||||||
|
@ -34,6 +42,9 @@
|
||||||
- server is changed
|
- server is changed
|
||||||
- server.state == 'running'
|
- server.state == 'running'
|
||||||
- server.server_groups.0.name == '{{ cloudscale_resource_prefix }}-group-1'
|
- 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
|
- name: Test create a running server idempotence
|
||||||
cloudscale_server:
|
cloudscale_server:
|
||||||
|
@ -42,6 +53,10 @@
|
||||||
image: '{{ cloudscale_test_image }}'
|
image: '{{ cloudscale_test_image }}'
|
||||||
ssh_keys: '{{ cloudscale_test_ssh_key }}'
|
ssh_keys: '{{ cloudscale_test_ssh_key }}'
|
||||||
server_groups: '{{ cloudscale_resource_prefix }}-group-1'
|
server_groups: '{{ cloudscale_resource_prefix }}-group-1'
|
||||||
|
tags:
|
||||||
|
project: ansible-test
|
||||||
|
stage: production
|
||||||
|
sla: 24-7
|
||||||
register: server
|
register: server
|
||||||
- name: Verify create a running server idempotence
|
- name: Verify create a running server idempotence
|
||||||
assert:
|
assert:
|
||||||
|
@ -49,6 +64,128 @@
|
||||||
- server is not changed
|
- server is not changed
|
||||||
- server.state == 'running'
|
- server.state == 'running'
|
||||||
- server.server_groups.0.name == '{{ cloudscale_resource_prefix }}-group-1'
|
- 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
|
- name: Test update flavor of a running server without force in check mode
|
||||||
cloudscale_server:
|
cloudscale_server:
|
||||||
|
|
Loading…
Reference in a new issue