File: workflow.md

package info (click to toggle)
ruby-fog-openstack 1.1.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,784 kB
  • sloc: ruby: 47,937; makefile: 5; sh: 4
file content (131 lines) | stat: -rw-r--r-- 3,443 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# OpenStack Workflow (Mistral)

This document explains how to get started using OpenStack Workflow (Mistral) with Fog. It assumes you have read the [Getting Started with Fog and the OpenStack](getting_started.md) document.

Fog uses the [OpenStack Mistral API](http://docs.openstack.org/mistral/latest/user/rest_api_v2.html).

## Workflow Service

Get a handle for the Workflow service:

```ruby
service = Fog::OpenStack::Workflow.new({
  :openstack_auth_url  => 'http://KEYSTONE_HOST:KEYSTONE_PORT/v2.0/tokens', # OpenStack Keystone endpoint
  :openstack_username  => OPEN_STACK_USER,                                  # Your OpenStack Username
  :openstack_tenant    => OPEN_STACK_TENANT,                                # Your tenant id
  :openstack_api_key   => OPEN_STACK_PASSWORD,                              # Your OpenStack Password
  :connection_options  => {}                                                # Optional
})
```

Read more about the [Optional Connection Parameters](common/connection_params.md)

## Executions

A Workflow is a composition of one or more actions.

To execute a workflow, we create an execution:

```ruby
workflow = "tripleo.plan_management.v1.create_default_deployment_plan"
input = { :container => 'default' }
response = service.create_execution(workflow, input)
```

Execution status and result can be checked by:

```ruby
workflow_execution_id = response.body["id"]
response = mistral.get_execution(workflow_execution_id)
state = response.body["state"]
```

To execute an individual action, we create an action execution:

```ruby
input = { :container => 'default' }
service.create_action_execution("tripleo.get_capabilities", input)
```

For actions, the result is returned when create_action_execution completes.

## Workflows

### Create a workflow

```ruby
workflow_def = {
  :version => "2.0",
  :myworkflow => {
    :type        => "direct",
    :description => "description1",
    :tasks => {
      :create_vm => {
        :description => "create vm"
      }
    }
  }
}
response = service.create_workflow(workflow_def)
workflow_id = response.body["workflows"][0]["id"]
```

### Validate a workflow before creating it

```ruby
service.validate_workflow(workflow_def)
```

### Update a workflow

```ruby
workflow_def_new = {
  :version => "2.0",
  :myworkflow => {
    :type        => "direct",
    :description => "description2",
    :tasks => {
      :create_vm => {
        :description => "create vm"
      }
    }
  }
}
service.update_workflow(workflow_def_new)
```

### List workflow

```ruby
service.list_workflows
```

### Delete workflow

```ruby
service.delete_workflow(workflow_id)
```

## Other Mistral resources

In addition to workflows, the following Mistral resources are also supported:

* Workbooks
* Actions
* Executions
* Tasks
* Action Executions
* Cron Triggers
* Environments
* Validations

For examples on how to interact with these resources, please refer to
https://github.com/fog/fog-openstack/tree/master/examples/workflow/workflow-examples.rb

## Additional Resources

* [Mistral Wiki](https://wiki.openstack.org/wiki/Mistral)
* [Mistral DSL v2](http://docs.openstack.org/mistral/ocata/dsl/dsl_v2.html)
* [Mistral API v2](http://docs.openstack.org/mistral/latest/user/rest_api_v2.html)
* [Mistral python client](https://github.com/openstack/python-mistralclient) Can be useful to see how to interact with the API.
* [more resources and feedback](common/resources.md)