Merge "Adding new example - crawl data from VMs"

This commit is contained in:
Jenkins 2015-10-20 15:26:38 +00:00 committed by Gerrit Code Review
commit c9dcb71060
2 changed files with 131 additions and 0 deletions

View File

@ -135,3 +135,57 @@ or::
mistral execution-get <execution_id>
Crawl specific data
-------------------
Workflow ``crawl_specific_data`` located in file ``crawl_specific_data.yaml`` demonstrates
how to do some job on each VM in a tenant, particularly, how to get specific data from VMs and
send this data via email. 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 ``crawl_specific_data.yaml``::
mistral workflow-create crawl_specific_data.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"]
}
or, if you want to see email report, provide also an email info::
{
"private_key_filename": "my_key.pem",
"gateway_host": "172.16.111.16",
"from_email": "my_email@example.com",
"to_email": "admin_email@example.com",
"smtp_server": "smtp.gmail.com:587",
"smtp_password": "secret"
}
3. Start workflow::
mistral execution-create crawl_data_from_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,77 @@
---
version: '2.0'
crawl_data_from_vms:
input:
- gateway_host
- private_key_name: id_rsa
- vm_ids: null
- username: ubuntu
- filename: /var/log/auth.log
# Email info
- smtp_server: null
- smtp_password: null
- from_email: null
- to_email: null
tasks:
schedule_get_data:
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:
- get_data
get_data:
with-items: host in <% $.hosts %>
action: std.ssh_proxied
input:
host: <% $.host %>
username: <% $.username %>
private_key_name: <% $.private_key_name %>
gateway_host: <% $.gateway_host %>
cmd: "cat <% $.filename %>"
on-success:
- send_report_email: <% $.smtp_server != null %>
on-error:
- send_error_email: <% $.smtp_server != null %>
send_report_email:
action: std.email
input:
from_addr: <% $.from_email %>
to_addrs: [<% $.to_email %>]
smtp_server: <% $.smtp_server %>
smtp_password: <% $.smtp_password %>
subject: VMs data from tenant
body: |
VMs data from tenant <% $.openstack.project_id %>:
<% json_pp(task(get_data).result).replace("\\n", "\n") %>
send_error_email:
action: std.email
input:
from_addr: <% $.from_email %>
to_addrs: [<% $.to_email %>]
smtp_server: <% $.smtp_server %>
smtp_password: <% $.smtp_password %>
subject: (ERROR) VMs data from tenant
body: |
Failure while getting data from VMs: <% execution().state_info %>