cloudscale_floating_ip module (#33181)

* Refactor cloudscale API code

Move code common to all cloudscale cloud modules into a common base
class.

This is needed as a prepartion of the cloudscale_floating_ip module.

* cloudscale_floating_ip module

New cloud module to manage floating IPs on the cloudscale.ch IaaS
service.
This commit is contained in:
Gaudenz Steinlin 2017-12-11 15:48:35 +01:00 committed by John R Barker
parent d84e0861ef
commit a23da23491
8 changed files with 521 additions and 87 deletions

View file

@ -5,3 +5,4 @@
- cloudscale
roles:
- { role: cloudscale_server, tags: cloudscale_server }
- { role: cloudscale_floating_ip, tags: cloudscale_floating_ip }

View file

@ -0,0 +1,5 @@
---
cloudscale_test_flavor: flex-2
cloudscale_test_image: debian-9
cloudscale_test_ssh_key: |
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDSPmiqkvDH1/+MDAVDZT8381aYqp73Odz8cnD5hegNhqtXajqtiH0umVg7HybX3wt1HjcrwKJovZURcIbbcDvzdH2bnYbF93T4OLXA0bIfuIp6M86x1iutFtXdpN3TTicINrmSXEE2Ydm51iMu77B08ZERjVaToya2F7vC+egfoPvibf7OLxE336a5tPCywavvNihQjL8sjgpDT5AAScjb3YqK/6VLeQ18Ggt8/ufINsYkb+9/Ji/3OcGFeflnDXq80vPUyF3u4iIylob6RSZenC38cXmQB05tRNxS1B6BXCjMRdy0v4pa7oKM2GA4ADKpNrr0RI9ed+peRFwmsclH test@ansible

View file

@ -0,0 +1,2 @@
dependencies:
- prepare_tests

View file

@ -0,0 +1,94 @@
- name: Request floating IP
cloudscale_floating_ip:
server: '{{ test01.uuid }}'
ip_version: '{{ item.ip_version }}'
reverse_ptr: '{{ item.reverse_ptr | default(omit) }}'
prefix_length: '{{ item.prefix_length | default(omit) }}'
register: floating_ip
- name: Verify request floating IP
assert:
that:
- floating_ip | success
- floating_ip | changed
- (item.ip_version == 4 and floating_ip.ip | ipv4) or (item.ip_version == 6 and floating_ip.ip | ipv6)
- floating_ip.server == test01.uuid
- name: Check floating IP indempotence
cloudscale_floating_ip:
server: '{{ test01.uuid }}'
ip: '{{ floating_ip.ip }}'
register: floating_ip_indempotence
- name: Verify floating IP indempotence
assert:
that:
- floating_ip_indempotence | success
- not floating_ip_indempotence | changed
- floating_ip_indempotence.server == test01.uuid
- name: Check network parameter alias
cloudscale_floating_ip:
server: '{{ test01.uuid }}'
network: '{{ floating_ip.ip }}'
register: floating_ip_network
- name: Verify network parameter alias
assert:
that:
- floating_ip_network | success
- name: Move floating IP to second server
cloudscale_floating_ip:
server: '{{ test02.uuid }}'
ip: '{{ floating_ip.ip }}'
register: move_ip
- name: Verify move floating IPv4 to second server
assert:
that:
- move_ip | success
- move_ip | changed
- move_ip.server == test02.uuid
- name: Fail if server is missing on update
cloudscale_floating_ip:
ip: '{{ floating_ip.ip }}'
register: update_failed
ignore_errors: True
- name: Verify fail if server is missing on update
assert:
that:
- update_failed | failed
- "'Missing required parameter' in update_failed.msg"
- name: Release floating IP
cloudscale_floating_ip:
ip: '{{ floating_ip.ip }}'
state: 'absent'
register: release_ip
- name: Verify release floating IPs
assert:
that:
- release_ip | success
- release_ip | changed
- release_ip.state == 'absent'
- name: Release floating IP indempotence
cloudscale_floating_ip:
ip: '{{ floating_ip.ip }}'
state: 'absent'
register: release_ip
- name: Verify release floating IPs indempotence
assert:
that:
- release_ip | success
- not release_ip | changed
- release_ip.state == 'absent'
- name: Fail if server is missing on request
cloudscale_floating_ip:
ip_version: 6
register: request_failed
ignore_errors: True
- name: Verify fail if server is missing on request
assert:
that:
- request_failed | failed
- "'Missing required parameter' in request_failed.msg"

View file

@ -0,0 +1,33 @@
- name: Cloudscale floating IP tests
block:
- name: Create a server
cloudscale_server:
name: '{{ resource_prefix }}-test01'
flavor: '{{ cloudscale_test_flavor }}'
image: '{{ cloudscale_test_image }}'
ssh_keys: '{{ cloudscale_test_ssh_key }}'
register: test01
- name: Create a second server
cloudscale_server:
name: '{{ resource_prefix }}-test02'
flavor: '{{ cloudscale_test_flavor }}'
image: '{{ cloudscale_test_image }}'
ssh_keys: '{{ cloudscale_test_ssh_key }}'
register: test02
- include_tasks: floating_ip.yml
with_items:
- { 'ip_version': 4, 'reverse_ptr': 'my-floating-ipv4.example.com' }
- { 'ip_version': 6 }
- { 'ip_version': 6, 'prefix_length': 56 }
always:
- name: Delete servers
cloudscale_server:
uuid: '{{ item.uuid }}'
state: 'absent'
ignore_errors: True
with_items:
- '{{ test01 }}'
- '{{ test02 }}'