class Chef::Knife::VroWorkflowExecute

rubocop:disable Metrics/ClassLength rubocop:disable Style/AlignParameters

Attributes

parameters[RW]
workflow_id[RW]
workflow_name[RW]

Public Instance Methods

execute_workflow() click to toggle source
# File lib/chef/knife/vro_workflow_execute.rb, line 92
def execute_workflow
  parameters.each do |key, value|
    vro_client.parameter(key, value)
  end
  begin
    vro_client.execute
  rescue RestClient::BadRequest => e
    ui.error("The workflow execution request failed: #{e.response}")
    raise
  rescue => e
    ui.error("The workflow execution request failed: #{e.message}")
    raise
  end
end
missing_config_parameters() click to toggle source
# File lib/chef/knife/vro_workflow_execute.rb, line 121
def missing_config_parameters
  %i{vro_username vro_password vro_base_url}.each_with_object([]) do |param, memo|
    memo << param if config[param].nil?
  end
end
parse_and_validate_params!(args) click to toggle source
# File lib/chef/knife/vro_workflow_execute.rb, line 83
def parse_and_validate_params!(args)
  args.each_with_object({}) do |arg, memo|
    key, value = arg.split("=")
    raise "Invalid parameter, must be in KEY=VALUE format: #{arg}" if key.nil? || value.nil?

    memo[key] = value
  end
end
print_error_and_exit(msg) click to toggle source
print_execution_log() click to toggle source
print_output_parameters() click to toggle source
print_results() click to toggle source
run() click to toggle source
# File lib/chef/knife/vro_workflow_execute.rb, line 171
def run
  validate!

  set_parameters

  ui.msg("Starting workflow execution...")
  execution_id = execute_workflow

  ui.msg("Workflow execution #{execution_id} started. Waiting for it to complete...")
  wait_for_workflow

  ui.msg("Workflow execution complete.")

  print_results
end
set_parameters() click to toggle source
# File lib/chef/knife/vro_workflow_execute.rb, line 165
def set_parameters
  self.workflow_name = @name_args.shift
  self.workflow_id   = config[:vro_workflow_id]
  self.parameters    = parse_and_validate_params!(@name_args)
end
validate!() click to toggle source
# File lib/chef/knife/vro_workflow_execute.rb, line 127
def validate!
  unless missing_config_parameters.empty?
    print_error_and_exit("The following parameters are missing but required:" \
      "#{missing_config_parameters.join(", ")}")
  end
  print_error_and_exit("You must supply a workflow name.") if @name_args.empty?
end
verify_ssl?() click to toggle source
# File lib/chef/knife/vro_workflow_execute.rb, line 62
def verify_ssl?
  !config[:vro_disable_ssl_verify]
end
vro_client() click to toggle source
# File lib/chef/knife/vro_workflow_execute.rb, line 75
def vro_client
  @client ||= VcoWorkflows::Workflow.new(
    workflow_name,
    id: workflow_id,
    config: vro_config
  )
end
vro_config() click to toggle source
# File lib/chef/knife/vro_workflow_execute.rb, line 66
def vro_config
  @vro_config ||= VcoWorkflows::Config.new(
    url: config[:vro_base_url],
    username: config[:vro_username],
    password: config[:vro_password],
    verify_ssl: verify_ssl?
  )
end
wait_for_workflow() click to toggle source
# File lib/chef/knife/vro_workflow_execute.rb, line 107
def wait_for_workflow
  wait_time = config[:request_timeout]
  Timeout.timeout(wait_time) do
    loop do
      token = vro_client.token
      break unless token.alive?

      sleep 2
    end
  end
rescue Timeout::Error
  raise Timeout::Error, "Workflow did not complete in #{wait_time} seconds. Please check the vRO UI for more information."
end