Class: Kitchen::Driver::Vro

Inherits:
Base
  • Object
show all
Defined in:
lib/kitchen/driver/vro.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#workflow_idObject

Returns the value of attribute workflow_id.



26
27
28
# File 'lib/kitchen/driver/vro.rb', line 26

def workflow_id
  @workflow_id
end

#workflow_nameObject

Returns the value of attribute workflow_name.



26
27
28
# File 'lib/kitchen/driver/vro.rb', line 26

def workflow_name
  @workflow_name
end

Instance Method Details

#create(state) ⇒ Object



48
49
50
51
52
53
54
55
56
57
# File 'lib/kitchen/driver/vro.rb', line 48

def create(state)
  return unless state[:server_id].nil?

  info("Executing the create-server workflow...")
  execute_create_workflow(state)

  info("Server #{state[:hostname]} (#{state[:server_id]}) created.  Waiting for it to be ready...")
  wait_for_server(state)
  info("Server #{state[:hostname]} (#{state[:server_id]}) ready.")
end

#destroy(state) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/kitchen/driver/vro.rb', line 59

def destroy(state)
  return if state[:server_id].nil?

  info("Executing the destroy-server workflow for #{state[:hostname]} (#{state[:server_id]})...")
  execute_destroy_workflow(state)
  info("Server #{state[:hostname]} (#{state[:server_id]}) destroyed.")
end

#execute_create_workflow(state) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/kitchen/driver/vro.rb', line 94

def execute_create_workflow(state)
  set_workflow_vars(config[:create_workflow_name], config[:create_workflow_id])
  set_workflow_parameters(config[:create_workflow_parameters])
  execute_workflow
  wait_for_workflow

  raise "The workflow did not complete successfully. Check the vRO UI for more info." unless workflow_successful?

  validate_create_output_parameters!

  state[:server_id] = output_parameter_value("server_id")
  state[:hostname]  = output_parameter_value("ip_address")
end

#execute_destroy_workflow(state) ⇒ Object



108
109
110
111
112
113
114
115
116
# File 'lib/kitchen/driver/vro.rb', line 108

def execute_destroy_workflow(state)
  set_workflow_vars(config[:destroy_workflow_name], config[:destroy_workflow_id])
  set_workflow_parameters(config[:destroy_workflow_parameters])
  vro_client.parameter("server_id", state[:server_id])
  execute_workflow
  wait_for_workflow

  raise "The workflow did not complete successfully. Check the vRO UI for more info." unless workflow_successful?
end

#execute_workflowObject



118
119
120
121
122
123
124
125
126
# File 'lib/kitchen/driver/vro.rb', line 118

def execute_workflow
  vro_client.execute
rescue RestClient::BadRequest => e
  error("The workflow execution request failed: #{e.response}")
  raise
rescue => e
  error("The workflow execution request failed: #{e.message}")
  raise
end

#nameObject



44
45
46
# File 'lib/kitchen/driver/vro.rb', line 44

def name
  "vRO"
end

#output_parameter_empty?(key) ⇒ Boolean

Returns:

  • (Boolean)


164
165
166
# File 'lib/kitchen/driver/vro.rb', line 164

def output_parameter_empty?(key)
  output_parameter_value(key).nil? || output_parameter_value(key).empty?
end

#output_parameter_value(key) ⇒ Object



160
161
162
# File 'lib/kitchen/driver/vro.rb', line 160

def output_parameter_value(key)
  output_parameters[key].value.to_s
end

#output_parametersObject



156
157
158
# File 'lib/kitchen/driver/vro.rb', line 156

def output_parameters
  @output_parameters ||= vro_client.token.output_parameters
end

#set_workflow_parameters(data) ⇒ Object

rubocop:disable Style/AccessorMethodName



150
151
152
153
154
# File 'lib/kitchen/driver/vro.rb', line 150

def set_workflow_parameters(data) # rubocop:disable Style/AccessorMethodName
  data.each do |key, value|
    vro_client.parameter(key.to_s, value)
  end
end

#set_workflow_vars(name, id) ⇒ Object



88
89
90
91
92
# File 'lib/kitchen/driver/vro.rb', line 88

def set_workflow_vars(name, id)
  @vro_client    = nil
  @workflow_name = name
  @workflow_id   = id
end

#validate_create_output_parameters!Object



168
169
170
171
172
173
174
# File 'lib/kitchen/driver/vro.rb', line 168

def validate_create_output_parameters!
  raise "The workflow output did not contain a server_id and ip_address parameter." unless
    output_parameters.key?("server_id") && output_parameters.key?("ip_address")

  raise "The server_id parameter was empty." if output_parameter_empty?("server_id")
  raise "The ip_address parameter was empty." if output_parameter_empty?("ip_address")
end

#verify_ssl?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/kitchen/driver/vro.rb', line 84

def verify_ssl?
  !config[:vro_disable_ssl_verify]
end

#vro_clientObject



76
77
78
79
80
81
82
# File 'lib/kitchen/driver/vro.rb', line 76

def vro_client
  @vro_client ||= VcoWorkflows::Workflow.new(
    workflow_name,
    id: workflow_id,
    config: vro_config
  )
end

#vro_configObject



67
68
69
70
71
72
73
74
# File 'lib/kitchen/driver/vro.rb', line 67

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_server(state) ⇒ Object



142
143
144
145
146
147
148
# File 'lib/kitchen/driver/vro.rb', line 142

def wait_for_server(state)
  instance.transport.connection(state).wait_until_ready
rescue
  error("Server #{state[:hostname]} (#{state[:server_id]}) not reachable. Destroying server...")
  destroy(state)
  raise
end

#wait_for_workflowObject



128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/kitchen/driver/vro.rb', line 128

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

#workflow_successful?Boolean

Returns:

  • (Boolean)


176
177
178
# File 'lib/kitchen/driver/vro.rb', line 176

def workflow_successful?
  vro_client.token.state == "completed"
end