Commit d3950388 authored by Jose Castro Leon's avatar Jose Castro Leon

Refactor instance_snapshot and replace nova_image_find

parent b28ff1ae
Pipeline #1047350 passed with stages
in 5 minutes and 21 seconds
......@@ -38,36 +38,43 @@ instance_snapshot:
snapshot_regex: <% $.pattern.format(task(check_server).result.name, '*') %>
volume_ids: <% task(check_server).result.get('os-extended-volumes:volumes_attached').id %>
on-success:
- image_check_server_for_stop: <% task(check_server).result.image %>
- identify_volumes: <% not task(check_server).result.image %>
- check_server_for_stop
on-error:
- error_task
image_check_server_for_stop:
check_server_for_stop:
description: 'Checks if the instance needs to be stopped'
action: std.noop
on-success:
- image_stop_instance: <% $.instance_stop and task(check_server).published.server.status = 'ACTIVE' %>
- image_snapshot: <% not $.instance_stop or not task(check_server).published.server.status = 'ACTIVE' %>
- stop_instance: <% $.instance_stop and task(check_server).published.server.status = 'ACTIVE' %>
- check_boot_source: <% not $.instance_stop or not task(check_server).published.server.status = 'ACTIVE' %>
on-error:
- error_task
image_stop_instance:
stop_instance:
description: 'Stops the instance for consistency'
action: nova.servers_stop server=<% $.instance %>
on-success:
- wait_for_image_stop_instance
- wait_for_stop_instance
on-error:
- error_task
wait_for_image_stop_instance:
wait_for_stop_instance:
description: 'Waits until the instance is shutoff to continue'
action: nova.servers_find id=<% $.instance %> status='SHUTOFF'
retry:
delay: 5
count: 40
on-success:
- image_snapshot
- check_boot_source
on-error:
- error_task
check_boot_source:
action: std.noop
on-success:
- image_snapshot: <% task(check_server).result.image %>
- identify_volumes: <% not task(check_server).result.image %>
on-error:
- error_task
......@@ -86,16 +93,17 @@ instance_snapshot:
wait_for_image_snapshot:
description: 'Waits until the snapshot is flagged as saving'
action: nova.images_find id=<% $.i_snap_id %> status='SAVING'
action: glance.images_get id=<% $.i_snap_id %>
retry:
delay: 10
count: 720
break-on: <% task(wait_for_image_snapshot).result.status = 'error' %>
continue-on: <% task(wait_for_image_snapshot).result.status = 'queued' %>
on-success:
- check_number_of_images
- start_instance: <% $.instance_stop and task(check_server).published.server.status = 'ACTIVE' %>
on-error:
- error_task
- start_instance: <% $.instance_stop and task(check_server).published.server.status = 'ACTIVE' %>
check_number_of_images:
description: 'Checks how many snapshots have been taken already'
......@@ -124,35 +132,7 @@ instance_snapshot:
publish:
volume_id: <% task(identify_volumes).result.first().get("attachments").where($.device = '/dev/vda').volume_id.first() %>
on-success:
- volume_check_server_for_stop: <% task(identify_volumes).result.first().get("attachments").where($.device = '/dev/vda') %>
on-error:
- error_task
volume_check_server_for_stop:
description: 'Checks if the instance needs to be stopped'
action: std.noop
on-success:
- volume_stop_instance: <% $.instance_stop and task(check_server).published.server.status = 'ACTIVE' %>
- volume_snapshot: <% not $.instance_stop or not task(check_server).published.server.status = 'ACTIVE' %>
on-error:
- error_task
volume_stop_instance:
description: 'Stops the instance for consistency'
action: nova.servers_stop server=<% $.instance %>
on-success:
- wait_for_volume_stop_instance
on-error:
- error_task
wait_for_volume_stop_instance:
description: 'Waits until the instance is shutoff to continue'
action: nova.servers_find id=<% $.instance %> status='SHUTOFF'
retry:
delay: 5
count: 40
on-success:
- volume_snapshot
- volume_snapshot: <% task(identify_volumes).result.first().get("attachments").where($.device = '/dev/vda') %>
on-error:
- error_task
......@@ -167,7 +147,6 @@ instance_snapshot:
- start_instance: <% not $.wait and $.instance_stop and task(check_server).published.server.status = 'ACTIVE'%>
on-error:
- error_task
- start_instance: <% $.instance_stop and task(check_server).published.server.status = 'ACTIVE' %>
wait_for_volume_snapshot:
description: 'Waits until the snapshot has been marked as available'
......@@ -180,7 +159,6 @@ instance_snapshot:
- start_instance: <% $.instance_stop and task(check_server).published.server.status = 'ACTIVE' %>
on-error:
- error_task
- start_instance: <% $.instance_stop and task(check_server).published.server.status = 'ACTIVE' %>
check_number_of_volume_snapshots:
description: 'Checks how many snapshots have been taken already'
......@@ -202,10 +180,6 @@ instance_snapshot:
on-error:
- error_task
start_instance:
description: 'Starts the instance '
action: nova.servers_start server=<% $.instance %>
success_task:
description: 'Checks if a success mail has to be sent to the end user'
action: std.noop
......@@ -217,8 +191,13 @@ instance_snapshot:
action: std.noop
on-success:
- send_error_mail: <% $.to_addr_error %>
- start_instance: <% $.instance_stop and task(check_server).published.server.status = 'ACTIVE' %>
- fail
start_instance:
description: 'Starts the instance '
action: nova.servers_start server=<% $.instance %>
send_success_mail:
description: 'Sends a success mail to the end user'
action: std.email
......@@ -247,4 +226,3 @@ instance_snapshot:
-- Thanks, Cloud Infrastructure Team.
from_addr: 'noreply@cern.ch'
smtp_server: 'cernmx.cern.ch'
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