Commit 87681d4a authored by Jose Castro Leon's avatar Jose Castro Leon

Add region support in instance_snapshot

parent d3950388
Pipeline #1047545 passed with stages
in 5 minutes and 26 seconds
...@@ -17,11 +17,15 @@ instance_snapshot: ...@@ -17,11 +17,15 @@ instance_snapshot:
- instance_stop: false - instance_stop: false
- to_addr_success: null - to_addr_success: null
- to_addr_error: null - to_addr_error: null
- action_region: "cern"
tasks: tasks:
check_server_by_name: check_server_by_name:
description: 'Checks if there is an instance with the name specified as parameter' description: 'Checks if there is an instance with the name specified as parameter'
action: nova.servers_find name=<% $.instance %> action: nova.servers_find
input:
name: <% $.instance %>
action_region: <% $.action_region %>
publish: publish:
instance: <% task(check_server_by_name).result.id %> instance: <% task(check_server_by_name).result.id %>
on-success: on-success:
...@@ -31,7 +35,10 @@ instance_snapshot: ...@@ -31,7 +35,10 @@ instance_snapshot:
check_server: check_server:
description: 'Retrieves information about the server and identifies if is a boot from image or boot from volume instance' description: 'Retrieves information about the server and identifies if is a boot from image or boot from volume instance'
action: nova.servers_find id=<% $.instance %> action: nova.servers_find
input:
id: <% $.instance %>
action_region: <% $.action_region %>
publish: publish:
server: <% dict(id => task(check_server).result.id, name => task(check_server).result.name, status => task(check_server).result.status) %> server: <% dict(id => task(check_server).result.id, name => task(check_server).result.name, status => task(check_server).result.status) %>
snapshot_name: <% $.pattern.format(task(check_server).result.name, now().format("%Y%m%d%H%M")) %> snapshot_name: <% $.pattern.format(task(check_server).result.name, now().format("%Y%m%d%H%M")) %>
...@@ -53,7 +60,10 @@ instance_snapshot: ...@@ -53,7 +60,10 @@ instance_snapshot:
stop_instance: stop_instance:
description: 'Stops the instance for consistency' description: 'Stops the instance for consistency'
action: nova.servers_stop server=<% $.instance %> action: nova.servers_stop
input:
server: <% $.instance %>
action_region: <% $.action_region %>
on-success: on-success:
- wait_for_stop_instance - wait_for_stop_instance
on-error: on-error:
...@@ -61,7 +71,11 @@ instance_snapshot: ...@@ -61,7 +71,11 @@ instance_snapshot:
wait_for_stop_instance: wait_for_stop_instance:
description: 'Waits until the instance is shutoff to continue' description: 'Waits until the instance is shutoff to continue'
action: nova.servers_find id=<% $.instance %> status='SHUTOFF' action: nova.servers_find
input:
id: <% $.instance %>
status: 'SHUTOFF'
action_region: <% $.action_region %>
retry: retry:
delay: 5 delay: 5
count: 40 count: 40
...@@ -80,7 +94,11 @@ instance_snapshot: ...@@ -80,7 +94,11 @@ instance_snapshot:
image_snapshot: image_snapshot:
description: 'Creates an snapshot of the instance' description: 'Creates an snapshot of the instance'
action: nova.servers_create_image server=<% task(check_server).published.server.id %> image_name=<% $.snapshot_name %> action: nova.servers_create_image
input:
server: <% task(check_server).published.server.id %>
image_name: <% $.snapshot_name %>
action_region: <% $.action_region %>
publish: publish:
i_snap_id: <% task(image_snapshot).result %> i_snap_id: <% task(image_snapshot).result %>
on-success: on-success:
...@@ -93,7 +111,10 @@ instance_snapshot: ...@@ -93,7 +111,10 @@ instance_snapshot:
wait_for_image_snapshot: wait_for_image_snapshot:
description: 'Waits until the snapshot is flagged as saving' description: 'Waits until the snapshot is flagged as saving'
action: glance.images_get id=<% $.i_snap_id %> action: glance.images_get
input:
id: <% $.i_snap_id %>
action_region: <% $.action_region %>
retry: retry:
delay: 10 delay: 10
count: 720 count: 720
...@@ -108,6 +129,8 @@ instance_snapshot: ...@@ -108,6 +129,8 @@ instance_snapshot:
check_number_of_images: check_number_of_images:
description: 'Checks how many snapshots have been taken already' description: 'Checks how many snapshots have been taken already'
action: glance.images_list action: glance.images_list
input:
action_region: <% $.action_region %>
publish: publish:
images: <% task(check_number_of_images).result.where($.visibility='private').where(regex(task(check_server).published.snapshot_regex).matches($.name)).orderBy($.updated_at).id %> images: <% task(check_number_of_images).result.where($.visibility='private').where(regex(task(check_server).published.snapshot_regex).matches($.name)).orderBy($.updated_at).id %>
on-success: on-success:
...@@ -119,7 +142,10 @@ instance_snapshot: ...@@ -119,7 +142,10 @@ instance_snapshot:
cleanup_images: cleanup_images:
description: 'Deletes older snapshots if max_snapshots has been reached' description: 'Deletes older snapshots if max_snapshots has been reached'
with-items: image_id in <% $.images.take($.images.len() - $.max_snapshots) %> with-items: image_id in <% $.images.take($.images.len() - $.max_snapshots) %>
action: glance.image_delete image_id=<% $.image_id%> action: glance.image_delete
input:
image_id: <% $.image_id %>
action_region: <% $.action_region %>
on-success: on-success:
- success_task - success_task
on-error: on-error:
...@@ -128,7 +154,10 @@ instance_snapshot: ...@@ -128,7 +154,10 @@ instance_snapshot:
identify_volumes: identify_volumes:
description: 'Retrieves the bootable volume (mounted on /dev/vda)' description: 'Retrieves the bootable volume (mounted on /dev/vda)'
with-items: volume_id in <% $.volume_ids %> with-items: volume_id in <% $.volume_ids %>
action: cinder.volumes_get volume_id=<% $.volume_id %> action: cinder.volumes_get
input:
volume_id: <% $.volume_id %>
action_region: <% $.action_region %>
publish: publish:
volume_id: <% task(identify_volumes).result.first().get("attachments").where($.device = '/dev/vda').volume_id.first() %> volume_id: <% task(identify_volumes).result.first().get("attachments").where($.device = '/dev/vda').volume_id.first() %>
on-success: on-success:
...@@ -138,7 +167,12 @@ instance_snapshot: ...@@ -138,7 +167,12 @@ instance_snapshot:
volume_snapshot: volume_snapshot:
description: 'Creates a snapshot of the bootable volume' description: 'Creates a snapshot of the bootable volume'
action: cinder.volume_snapshots_create volume_id=<% $.volume_id %> name=<% $.snapshot_name %> force=true action: cinder.volume_snapshots_create
input:
volume_id: <% $.volume_id %>
name: <% $.snapshot_name %>
force: true
action_region: <% $.action_region %>
publish: publish:
v_snap_id: <% task(volume_snapshot).result.id %> v_snap_id: <% task(volume_snapshot).result.id %>
on-success: on-success:
...@@ -150,7 +184,11 @@ instance_snapshot: ...@@ -150,7 +184,11 @@ instance_snapshot:
wait_for_volume_snapshot: wait_for_volume_snapshot:
description: 'Waits until the snapshot has been marked as available' description: 'Waits until the snapshot has been marked as available'
action: cinder.volume_snapshots_find id=<% $.v_snap_id %> status='available' action: cinder.volume_snapshots_find
input:
id: <% $.v_snap_id %>
status: 'available'
action_region: <% $.action_region %>
retry: retry:
delay: 5 delay: 5
count: 40 count: 40
...@@ -163,6 +201,8 @@ instance_snapshot: ...@@ -163,6 +201,8 @@ instance_snapshot:
check_number_of_volume_snapshots: check_number_of_volume_snapshots:
description: 'Checks how many snapshots have been taken already' description: 'Checks how many snapshots have been taken already'
action: cinder.volume_snapshots_list action: cinder.volume_snapshots_list
input:
action_region: <% $.action_region %>
publish: publish:
snapshots: <% task(check_number_of_volume_snapshots).result.where($.status='available').where(regex(task(check_server).published.snapshot_regex).matches($.name)).orderBy($.updated_at).id %> snapshots: <% task(check_number_of_volume_snapshots).result.where($.status='available').where(regex(task(check_server).published.snapshot_regex).matches($.name)).orderBy($.updated_at).id %>
on-success: on-success:
...@@ -174,7 +214,10 @@ instance_snapshot: ...@@ -174,7 +214,10 @@ instance_snapshot:
cleanup_volume_snapshots: cleanup_volume_snapshots:
description: 'Deletes older snapshots if max_snapshots has been reached' description: 'Deletes older snapshots if max_snapshots has been reached'
with-items: s_id in <% $.snapshots.take($.snapshots.len() - $.max_snapshots) %> with-items: s_id in <% $.snapshots.take($.snapshots.len() - $.max_snapshots) %>
action: cinder.volume_snapshots_delete snapshot=<% $.s_id %> action: cinder.volume_snapshots_delete
input:
snapshot: <% $.s_id %>
action_region: <% $.action_region %>
on-success: on-success:
- success_task - success_task
on-error: on-error:
...@@ -196,7 +239,10 @@ instance_snapshot: ...@@ -196,7 +239,10 @@ instance_snapshot:
start_instance: start_instance:
description: 'Starts the instance ' description: 'Starts the instance '
action: nova.servers_start server=<% $.instance %> action: nova.servers_start
input:
server: <% $.instance %>
action_region: <% $.action_region %>
send_success_mail: send_success_mail:
description: 'Sends a success mail to the end user' description: 'Sends a success mail to the end user'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment