Class: Fog::OpenStack::Workflow::V2::Real

Inherits:
Object
  • Object
show all
Includes:
Core
Defined in:
lib/fog/openstack/workflow/v2.rb,
lib/fog/openstack/workflow/v2/requests/get_task.rb,
lib/fog/openstack/workflow/v2/requests/get_action.rb,
lib/fog/openstack/workflow/v2/requests/list_tasks.rb,
lib/fog/openstack/workflow/v2/requests/rerun_task.rb,
lib/fog/openstack/workflow/v2/requests/get_workbook.rb,
lib/fog/openstack/workflow/v2/requests/get_workflow.rb,
lib/fog/openstack/workflow/v2/requests/list_actions.rb,
lib/fog/openstack/workflow/v2/requests/create_action.rb,
lib/fog/openstack/workflow/v2/requests/delete_action.rb,
lib/fog/openstack/workflow/v2/requests/get_execution.rb,
lib/fog/openstack/workflow/v2/requests/list_services.rb,
lib/fog/openstack/workflow/v2/requests/update_action.rb,
lib/fog/openstack/workflow/v2/requests/list_workbooks.rb,
lib/fog/openstack/workflow/v2/requests/list_workflows.rb,
lib/fog/openstack/workflow/v2/requests/create_workbook.rb,
lib/fog/openstack/workflow/v2/requests/create_workflow.rb,
lib/fog/openstack/workflow/v2/requests/delete_workbook.rb,
lib/fog/openstack/workflow/v2/requests/delete_workflow.rb,
lib/fog/openstack/workflow/v2/requests/get_environment.rb,
lib/fog/openstack/workflow/v2/requests/list_executions.rb,
lib/fog/openstack/workflow/v2/requests/update_workbook.rb,
lib/fog/openstack/workflow/v2/requests/update_workflow.rb,
lib/fog/openstack/workflow/v2/requests/validate_action.rb,
lib/fog/openstack/workflow/v2/requests/create_execution.rb,
lib/fog/openstack/workflow/v2/requests/delete_execution.rb,
lib/fog/openstack/workflow/v2/requests/get_cron_trigger.rb,
lib/fog/openstack/workflow/v2/requests/update_execution.rb,
lib/fog/openstack/workflow/v2/requests/list_environments.rb,
lib/fog/openstack/workflow/v2/requests/validate_workbook.rb,
lib/fog/openstack/workflow/v2/requests/validate_workflow.rb,
lib/fog/openstack/workflow/v2/requests/create_environment.rb,
lib/fog/openstack/workflow/v2/requests/delete_environment.rb,
lib/fog/openstack/workflow/v2/requests/list_cron_triggers.rb,
lib/fog/openstack/workflow/v2/requests/update_environment.rb,
lib/fog/openstack/workflow/v2/requests/create_cron_trigger.rb,
lib/fog/openstack/workflow/v2/requests/delete_cron_trigger.rb,
lib/fog/openstack/workflow/v2/requests/get_action_execution.rb,
lib/fog/openstack/workflow/v2/requests/list_action_executions.rb,
lib/fog/openstack/workflow/v2/requests/create_action_execution.rb,
lib/fog/openstack/workflow/v2/requests/delete_action_execution.rb,
lib/fog/openstack/workflow/v2/requests/update_action_execution.rb

Instance Attribute Summary

Attributes included from Core

#auth_token, #auth_token_expiration, #current_tenant, #current_user, #current_user_id, #openstack_cache_ttl, #openstack_domain_id, #openstack_domain_name, #openstack_identity_api_version, #openstack_project_domain, #openstack_project_domain_id, #openstack_project_id, #openstack_user_domain, #openstack_user_domain_id, #unscoped_token

Instance Method Summary collapse

Methods included from Core

#credentials, #initialize, not_found_class, #reload

Instance Method Details

#create_action(definition) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/fog/openstack/workflow/v2/requests/create_action.rb', line 6

def create_action(definition)
  body = Fog::JSON.encode(definition)
  request(
    :body    => body,
    :expects => 201,
    :method  => "POST",
    :path    => "actions"
  )
end

#create_action_execution(action, input = {}, params = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/fog/openstack/workflow/v2/requests/create_action_execution.rb', line 6

def create_action_execution(action, input = {}, params = {})
  data = {:name => action}
  data[:input] = Fog::JSON.encode(input) unless input.empty?
  data[:params] = Fog::JSON.encode(params) unless params.empty?
  body = Fog::JSON.encode(data)
  request(
    :body    => body,
    :expects => 201,
    :method  => "POST",
    :path    => "action_executions"
  )
end

#create_cron_trigger(name, workflow_identifier, workflow_input = nil, workflow_params = nil, pattern = "* * * * *", first_time = nil, count = nil) ⇒ Object



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
# File 'lib/fog/openstack/workflow/v2/requests/create_cron_trigger.rb', line 6

def create_cron_trigger(name,
                        workflow_identifier,
                        workflow_input = nil,
                        workflow_params = nil,
                        pattern = "* * * * *",
                        first_time = nil,
                        count = nil)
  data = {
    :name                 => name,
    :pattern              => pattern,
    :first_execution_time => first_time,
    :remaining_executions => count
  }
  if workflow_identifier
    data[:workflow_id] = workflow_identifier
  end
  if workflow_input
    data[:workflow_input] = Fog::JSON.encode(workflow_input)
  end
  if workflow_params
    data[:workflow_params] = Fog::JSON.encode(workflow_params)
  end
  body = Fog::JSON.encode(data)
  request(
    :body    => body,
    :expects => 201,
    :method  => "POST",
    :path    => "cron_triggers"
  )
end

#create_environment(definition) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/fog/openstack/workflow/v2/requests/create_environment.rb', line 6

def create_environment(definition)
  unless definition["variables"].nil?
    definition["variables"] = Fog::JSON.encode(definition["variables"])
  end
  body = Fog::JSON.encode(definition)
  request(
    :body    => body,
    :expects => 201,
    :method  => "POST",
    :path    => "environments"
  )
end

#create_execution(workflow, input = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/fog/openstack/workflow/v2/requests/create_execution.rb', line 6

def create_execution(workflow, input = {})
  data = {:workflow_name => workflow}
  data[:input] = Fog::JSON.encode(input) unless input.empty?
  body = Fog::JSON.encode(data)
  request(
    :body    => body,
    :expects => 201,
    :method  => "POST",
    :path    => "executions"
  )
end

#create_workbook(definition) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/fog/openstack/workflow/v2/requests/create_workbook.rb', line 6

def create_workbook(definition)
  body = Fog::JSON.encode(definition)
  request(
    :body    => body,
    :expects => 201,
    :method  => "POST",
    :path    => "workbooks"
  )
end

#create_workflow(definition) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/fog/openstack/workflow/v2/requests/create_workflow.rb', line 6

def create_workflow(definition)
  body = Fog::JSON.encode(definition)
  request(
    :body    => body,
    :expects => 201,
    :method  => "POST",
    :path    => "workflows"
  )
end

#default_path_prefixObject



100
101
102
# File 'lib/fog/openstack/workflow/v2.rb', line 100

def default_path_prefix
  'v2'
end

#default_service_typeObject



104
105
106
# File 'lib/fog/openstack/workflow/v2.rb', line 104

def default_service_type
  %w[workflowv2]
end

#delete_action(name) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/fog/openstack/workflow/v2/requests/delete_action.rb', line 6

def delete_action(name)
  request(
    :expects => 204,
    :method  => "DELETE",
    :path    => "actions/#{URI.encode(name)}"
  )
end

#delete_action_execution(id) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/fog/openstack/workflow/v2/requests/delete_action_execution.rb', line 6

def delete_action_execution(id)
  request(
    :expects => 204,
    :method  => "DELETE",
    :path    => "action_executions/#{id}"
  )
end

#delete_cron_trigger(name) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/fog/openstack/workflow/v2/requests/delete_cron_trigger.rb', line 6

def delete_cron_trigger(name)
  request(
    :expects => 204,
    :method  => "DELETE",
    :path    => "cron_triggers/#{URI.encode(name)}"
  )
end

#delete_environment(name) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/fog/openstack/workflow/v2/requests/delete_environment.rb', line 6

def delete_environment(name)
  request(
    :expects => 204,
    :method  => "DELETE",
    :path    => "environments/#{URI.encode(name)}"
  )
end

#delete_execution(id) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/fog/openstack/workflow/v2/requests/delete_execution.rb', line 6

def delete_execution(id)
  request(
    :expects => 204,
    :method  => "DELETE",
    :path    => "executions/#{id}"
  )
end

#delete_workbook(name) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/fog/openstack/workflow/v2/requests/delete_workbook.rb', line 6

def delete_workbook(name)
  request(
    :expects => 204,
    :method  => "DELETE",
    :path    => "workbooks/#{URI.encode(name)}"
  )
end

#delete_workflow(identifier) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/fog/openstack/workflow/v2/requests/delete_workflow.rb', line 6

def delete_workflow(identifier)
  request(
    :expects => 204,
    :method  => "DELETE",
    :path    => "workflows/#{identifier}"
  )
end

#get_action(name) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/fog/openstack/workflow/v2/requests/get_action.rb', line 6

def get_action(name)
  request(
    :expects => 200,
    :method  => "GET",
    :path    => "actions/#{URI.encode(name)}"
  )
end

#get_action_execution(execution_id) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/fog/openstack/workflow/v2/requests/get_action_execution.rb', line 6

def get_action_execution(execution_id)
  request(
    :expects => 200,
    :method  => "GET",
    :path    => "action_executions/#{execution_id}"
  )
end

#get_cron_trigger(name) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/fog/openstack/workflow/v2/requests/get_cron_trigger.rb', line 6

def get_cron_trigger(name)
  request(
    :expects => 200,
    :method  => "GET",
    :path    => "cron_triggers/#{URI.encode(name)}"
  )
end

#get_environment(name) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/fog/openstack/workflow/v2/requests/get_environment.rb', line 6

def get_environment(name)
  request(
    :expects => 200,
    :method  => "GET",
    :path    => "environments/#{URI.encode(name)}"
  )
end

#get_execution(execution_id) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/fog/openstack/workflow/v2/requests/get_execution.rb', line 6

def get_execution(execution_id)
  request(
    :expects => 200,
    :method  => "GET",
    :path    => "executions/#{execution_id}"
  )
end

#get_task(id) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/fog/openstack/workflow/v2/requests/get_task.rb', line 6

def get_task(id)
  request(
    :expects => 200,
    :method  => "GET",
    :path    => "tasks/#{id}"
  )
end

#get_workbook(name) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/fog/openstack/workflow/v2/requests/get_workbook.rb', line 6

def get_workbook(name)
  request(
    :expects => 200,
    :method  => "GET",
    :path    => "workbooks/#{URI.encode(name)}"
  )
end

#get_workflow(identifier) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/fog/openstack/workflow/v2/requests/get_workflow.rb', line 6

def get_workflow(identifier)
  request(
    :expects => 200,
    :method  => "GET",
    :path    => "workflows/#{identifier}"
  )
end

#list_action_executionsObject



6
7
8
9
10
11
12
# File 'lib/fog/openstack/workflow/v2/requests/list_action_executions.rb', line 6

def list_action_executions
  request(
    :expects => 200,
    :method  => "GET",
    :path    => "action_executions"
  )
end

#list_actions(params = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/fog/openstack/workflow/v2/requests/list_actions.rb', line 6

def list_actions(params = {})
  body = Fog::JSON.encode(params)
  request(
    :body    => body,
    :expects => 200,
    :method  => "GET",
    :path    => "actions"
  )
end

#list_cron_triggersObject



6
7
8
9
10
11
12
# File 'lib/fog/openstack/workflow/v2/requests/list_cron_triggers.rb', line 6

def list_cron_triggers
  request(
    :expects => 200,
    :method  => "GET",
    :path    => "cron_triggers"
  )
end

#list_environmentsObject



6
7
8
9
10
11
12
# File 'lib/fog/openstack/workflow/v2/requests/list_environments.rb', line 6

def list_environments
  request(
    :expects => 200,
    :method  => "GET",
    :path    => "environments"
  )
end

#list_executionsObject



6
7
8
9
10
11
12
# File 'lib/fog/openstack/workflow/v2/requests/list_executions.rb', line 6

def list_executions
  request(
    :expects => 200,
    :method  => "GET",
    :path    => "executions"
  )
end

#list_servicesObject



6
7
8
9
10
11
12
# File 'lib/fog/openstack/workflow/v2/requests/list_services.rb', line 6

def list_services
  request(
    :expects => 200,
    :method  => "GET",
    :path    => "services"
  )
end

#list_tasks(workflow_execution_id) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/fog/openstack/workflow/v2/requests/list_tasks.rb', line 6

def list_tasks(workflow_execution_id)
  request(
    :expects => 200,
    :method  => "GET",
    :path    => "executions/#{workflow_execution_id}/tasks"
  )
end

#list_workbooksObject



6
7
8
9
10
11
12
# File 'lib/fog/openstack/workflow/v2/requests/list_workbooks.rb', line 6

def list_workbooks
  request(
    :expects => 200,
    :method  => "GET",
    :path    => "workbooks"
  )
end

#list_workflows(params = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/fog/openstack/workflow/v2/requests/list_workflows.rb', line 6

def list_workflows(params = {})
  body = Fog::JSON.encode(params)
  request(
    :body    => body,
    :expects => 200,
    :method  => "GET",
    :path    => "workflows"
  )
end

#request(params) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/fog/openstack/workflow/v2.rb', line 108

def request(params)
  response = @connection.request(
    params.merge(
      :headers => {
        'Content-Type' => 'application/json',
        'X-Auth-Token' => @auth_token
      }.merge!(params[:headers] || {}),
      :path    => "#{@path}/#{params[:path]}"
    )
  )
rescue Excon::Errors::Unauthorized    => error
  if error.response.body != "Bad username or password" # token expiration
    @openstack_must_reauthenticate = true
    authenticate
    retry
  else # bad credentials
    raise error
  end
rescue Excon::Errors::HTTPStatusError => error
  raise case error
        when Excon::Errors::NotFound
          Fog::OpenStack::Workflow::NotFound.slurp(error)
        else
          error
        end
else
  unless response.body.empty?
    response.body = Fog::JSON.decode(response.body)
  end
  response
end

#rerun_task(task_ex_id) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/fog/openstack/workflow/v2/requests/rerun_task.rb', line 6

def rerun_task(task_ex_id)
  rerun_payload = {
    :id    => task_ex_id,
    :state => 'RUNNING',
    :reset => true
  }
  body = Fog::JSON.encode(rerun_payload)
  request(
    :body    => body,
    :expects => 200,
    :method  => "PUT",
    :path    => "tasks/#{task_ex_id}"
  )
end

#update_action(definition) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/fog/openstack/workflow/v2/requests/update_action.rb', line 6

def update_action(definition)
  body = Fog::JSON.encode(definition)
  request(
    :body    => body,
    :expects => 200,
    :method  => "PUT",
    :path    => "actions"
  )
end

#update_action_execution(id, name, value) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/fog/openstack/workflow/v2/requests/update_action_execution.rb', line 6

def update_action_execution(id, name, value)
  # valid values for name are:
  # state, output
  # https://github.com/openstack/python-mistralclient/blob/master/mistralclient/commands/v2/action_executions.py
  data = {:id => id}
  data[name] = Fog::JSON.encode(value)
  body = Fog::JSON.encode(data)
  request(
    :body    => body,
    :expects => 200,
    :method  => "PUT",
    :path    => "action_executions"
  )
end

#update_environment(definition) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/fog/openstack/workflow/v2/requests/update_environment.rb', line 6

def update_environment(definition)
  unless definition["variables"].nil?
    definition["variables"] = Fog::JSON.encode(definition["variables"])
  end
  body = Fog::JSON.encode(definition)
  request(
    :body    => body,
    :expects => 200,
    :method  => "PUT",
    :path    => "environments"
  )
end

#update_execution(id, name, value) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/fog/openstack/workflow/v2/requests/update_execution.rb', line 6

def update_execution(id, name, value)
  # valid values for name are:
  # state, description, env
  # https://github.com/openstack/python-mistralclient/blob/master/mistralclient/commands/v2/executions.py
  data = {:id => id}
  data[name] = Fog::JSON.encode(value)
  body = Fog::JSON.encode(data)
  request(
    :body    => body,
    :expects => 200,
    :method  => "PUT",
    :path    => "executions"
  )
end

#update_workbook(definition) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/fog/openstack/workflow/v2/requests/update_workbook.rb', line 6

def update_workbook(definition)
  body = Fog::JSON.encode(definition)
  request(
    :body    => body,
    :expects => 200,
    :method  => "PUT",
    :path    => "workbooks"
  )
end

#update_workflow(definition) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/fog/openstack/workflow/v2/requests/update_workflow.rb', line 6

def update_workflow(definition)
  body = Fog::JSON.encode(definition)
  request(
    :body    => body,
    :expects => 200,
    :method  => "PUT",
    :path    => "workflows"
  )
end

#validate_action(definition) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/fog/openstack/workflow/v2/requests/validate_action.rb', line 6

def validate_action(definition)
  body = Fog::JSON.encode(definition)
  request(
    :body    => body,
    :expects => 200,
    :method  => "POST",
    :path    => "actions/validate"
  )
end

#validate_workbook(definition) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/fog/openstack/workflow/v2/requests/validate_workbook.rb', line 6

def validate_workbook(definition)
  body = Fog::JSON.encode(definition)
  request(
    :body    => body,
    :expects => 200,
    :method  => "POST",
    :path    => "workbooks/validate"
  )
end

#validate_workflow(definition) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/fog/openstack/workflow/v2/requests/validate_workflow.rb', line 6

def validate_workflow(definition)
  body = Fog::JSON.encode(definition)
  request(
    :body    => body,
    :expects => 200,
    :method  => "POST",
    :path    => "workflows/validate"
  )
end