From 70b3b3e0d4670d23f3de18d941d7eab0b779b179 Mon Sep 17 00:00:00 2001 From: Nikolay Mahotkin Date: Mon, 19 Oct 2015 13:32:01 +0300 Subject: [PATCH] Adding new example - crawl data from VMs Change-Id: I289646d4f47912c03f1595f8c861eba910acea34 --- examples/v2/openstack/README.rst | 54 +++++++++++++ .../v2/openstack/crawl_specific_data.yaml | 77 +++++++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 examples/v2/openstack/crawl_specific_data.yaml diff --git a/examples/v2/openstack/README.rst b/examples/v2/openstack/README.rst index 5181500..90c5cf4 100644 --- a/examples/v2/openstack/README.rst +++ b/examples/v2/openstack/README.rst @@ -135,3 +135,57 @@ or:: mistral execution-get + +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 **/.ssh/** +**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 + diff --git a/examples/v2/openstack/crawl_specific_data.yaml b/examples/v2/openstack/crawl_specific_data.yaml new file mode 100644 index 0000000..dffbd46 --- /dev/null +++ b/examples/v2/openstack/crawl_specific_data.yaml @@ -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 %>