Adding new example - upgrade ubuntu VM kernel

* Fixed some nits in README.rst

Change-Id: I6cc75ee033733c48745b935885c00918487435a2
This commit is contained in:
Nikolay Mahotkin 2015-10-19 13:25:58 +03:00
parent 97f1c8ec4f
commit e2bcdd3b1b
2 changed files with 86 additions and 1 deletions

View File

@ -1,5 +1,5 @@
================================================
OpenStack actions examples (based on v3 API/DSL)
OpenStack actions examples (based on v2 API/DSL)
================================================
These examples demonstrate how to use OpenStack Mistral actions in Mistral
@ -92,3 +92,46 @@ To run the example:
5. See the result of the workflow (virtual machine identifier)::
mistral execution-get-output <execution_id>
Update kernel
-------------
Workflow ``update_kernel`` located in file ``update_kernel.yaml`` demonstrates
how to do some job on each VM in a tenant, particularly, how to upgrade VM kernel.
Workflow can take either an array of **vm_ids** or all VMs in a tenant. Note that
this workflow requires gateway VM with assigned floating IP which should be able to
access to guest network in a tenant.
**NOTE**: The workflow uses *std.ssh_proxied* action which requires existing private key
file at executor host in **<home-user-directory>/.ssh/<private_key_filename>**
**NOTE**: This upgrade kernel command works only for Ubuntu.
To run the example:
1. Load workflow from ``update_kernel.yaml``::
mistral workflow-create update_kernel.yaml
2. Create ``input.json`` file containing workflow input parameters as follows::
{
"private_key_filename": "my_key.pem",
"gateway_host": "172.16.111.16",
}
or::
{
"private_key_filename": "my_key.pem",
"gateway_host": "172.16.111.16",
"vm_ids": ["5486c382-fce3-4bde-abb3-51273a98c006", "7485f786-bcd1-8def-fed7-25637a89e600"]
}
3. Start workflow::
mistral execution-create upgrade_kernel_on_vms input.json
4. Using execution id from the previous step wait for completion (workflow ``SUCCESS`` state)::
mistral execution-get <execution_id>

View File

@ -0,0 +1,42 @@
---
version: '2.0'
upgrade_kernel_on_vms:
input:
- private_key_filename
- gateway_host
- vm_ids: null
- username: ubuntu
tasks:
schedule_upgrade:
on-success:
- get_hosts: <% $.vm_ids != null %>
- get_vms: <% $.vm_ids = null %>
get_vms:
action: nova.servers_list
publish:
vm_ids: <% task(get_vms).result.id %>
keep-result: false
on-success:
- get_hosts
get_hosts:
with-items: id in <% $.vm_ids %>
action: nova.servers_get server=<% $.id %>
publish:
hosts: <% task(get_hosts).result.select({ip => $.addresses.get($.addresses.keys().first()).where($.get("OS-EXT-IPS:type") = fixed).first().addr}).ip %>
keep-result: false
on-success:
- upgrade_vm
upgrade_vm: # Works for ubuntu
with-items: host in <% $.hosts %>
action: std.ssh_proxied
input:
host: <% $.host %>
gateway_host: <% $.gateway_host %>
private_key_filename: <% $.private_key_filename %>
username: <% $.username %>
cmd: "sudo apt-get update && sudo apt-get install linux-image-generic-lts-$(lsb_release -sc) -y"