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

Add validation of user parameters that converts the values from string to boolean and integer

parent 4dffd12b
Pipeline #1048032 passed with stages
in 5 minutes and 31 seconds
......@@ -20,6 +20,16 @@ instance_snapshot:
- action_region: "cern"
tasks:
validation:
description: 'Validates and convers input data if passed as strings'
action: std.noop
publish:
wait: <% let(var => $.wait) -> switch(isBoolean($var) => $var, not isBoolean($var) => $var.toLower() = 'true') %>
instance_stop: <% let(var => $.instance_stop) -> switch(isBoolean($var) => $var, not isBoolean($var) => $var.toLower() = 'true') %>
max_snapshots: <% int($.max_snapshots) %>
on-success:
check_server_by_name
check_server_by_name:
description: 'Checks if there is an instance with the name specified as parameter'
action: nova.servers_find
......@@ -53,8 +63,8 @@ instance_snapshot:
description: 'Checks if the instance needs to be stopped'
action: std.noop
on-success:
- 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' %>
- stop_instance: <% task(validation).published.instance_stop and task(check_server).published.server.status = 'ACTIVE' %>
- check_boot_source: <% not task(validation).published.instance_stop or not task(check_server).published.server.status = 'ACTIVE' %>
on-error:
- error_task
......@@ -102,9 +112,9 @@ instance_snapshot:
publish:
i_snap_id: <% task(image_snapshot).result %>
on-success:
- wait_for_image_snapshot: <% $.wait %>
- check_number_of_images: <% not $.wait %>
- start_instance: <% not $.wait and $.instance_stop and task(check_server).published.server.status = 'ACTIVE'%>
- wait_for_image_snapshot: <% task(validation).published.wait %>
- check_number_of_images: <% not task(validation).published.wait %>
- start_instance: <% not task(validation).published.wait and task(validation).published.instance_stop and task(check_server).published.server.status = 'ACTIVE'%>
on-error:
- error_task
......@@ -121,7 +131,7 @@ instance_snapshot:
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' %>
- start_instance: <% task(validation).published.instance_stop and task(check_server).published.server.status = 'ACTIVE' %>
on-error:
- error_task
......@@ -133,14 +143,14 @@ instance_snapshot:
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 %>
on-success:
- cleanup_images: <% $.max_snapshots > 0 and $.max_snapshots < task(check_number_of_images).result.where($.visibility='private').where(regex(task(check_server).published.snapshot_regex).matches($.name)).count() %>
- success_task: <% $.max_snapshots <= 0 or $.max_snapshots >= task(check_number_of_images).result.where($.visibility='private').where(regex(task(check_server).published.snapshot_regex).matches($.name)).count() %>
- cleanup_images: <% task(validation).published.max_snapshots > 0 and task(validation).published.max_snapshots < task(check_number_of_images).result.where($.visibility='private').where(regex(task(check_server).published.snapshot_regex).matches($.name)).count() %>
- success_task: <% task(validation).published.max_snapshots <= 0 or task(validation).published.max_snapshots >= task(check_number_of_images).result.where($.visibility='private').where(regex(task(check_server).published.snapshot_regex).matches($.name)).count() %>
on-error:
- error_task
cleanup_images:
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() - task(validation).published.max_snapshots) %>
action: glance.images_delete
input:
image_id: <% $.image_id %>
......@@ -175,9 +185,9 @@ instance_snapshot:
publish:
v_snap_id: <% task(volume_snapshot).result.id %>
on-success:
- wait_for_volume_snapshot: <% $.wait %>
- check_number_of_volume_snapshots: <% not $.wait %>
- start_instance: <% not $.wait and $.instance_stop and task(check_server).published.server.status = 'ACTIVE'%>
- wait_for_volume_snapshot: <% task(validation).published.wait %>
- check_number_of_volume_snapshots: <% not task(validation).published.wait %>
- start_instance: <% not task(validation).published.wait and task(validation).published.instance_stop and task(check_server).published.server.status = 'ACTIVE'%>
on-error:
- error_task
......@@ -193,7 +203,7 @@ instance_snapshot:
count: 40
on-success:
- check_number_of_volume_snapshots
- start_instance: <% $.instance_stop and task(check_server).published.server.status = 'ACTIVE' %>
- start_instance: <% task(validation).published.instance_stop and task(check_server).published.server.status = 'ACTIVE' %>
on-error:
- error_task
......@@ -205,14 +215,14 @@ instance_snapshot:
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 %>
on-success:
- cleanup_volume_snapshots: <% $.max_snapshots > 0 and $.max_snapshots < task(check_number_of_volume_snapshots).result.where($.status='available').where(regex(task(check_server).published.snapshot_regex).matches($.name)).count() %>
- success_task: <% $.max_snapshots <= 0 or $.max_snapshots >= task(check_number_of_volume_snapshots).result.where($.status='available').where(regex(task(check_server).published.snapshot_regex).matches($.name)).count() %>
- cleanup_volume_snapshots: <% task(validation).published.max_snapshots > 0 and task(validation).published.max_snapshots < task(check_number_of_volume_snapshots).result.where($.status='available').where(regex(task(check_server).published.snapshot_regex).matches($.name)).count() %>
- success_task: <% task(validation).published.max_snapshots <= 0 or task(validation).published.max_snapshots >= task(check_number_of_volume_snapshots).result.where($.status='available').where(regex(task(check_server).published.snapshot_regex).matches($.name)).count() %>
on-error:
- error_task
cleanup_volume_snapshots:
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() - task(validation).published.max_snapshots) %>
action: cinder.volume_snapshots_delete
input:
snapshot: <% $.s_id %>
......@@ -233,7 +243,7 @@ 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' %>
- start_instance: <% task(validation).published.instance_stop and task(check_server).published.server.status = 'ACTIVE' %>
- fail
start_instance:
......
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