class Rocci::Compute
OCCI Compute
class.
Public Instance Methods
create_check_destroy()
click to toggle source
Create, check and destroy resource
# File lib/probe/occi/rocci/compute.rb, line 26 def create_check_destroy # Build resource res = @client.get_resource('compute') res.model = model res.title = @opts.vmname res.hostname = res.title # Fill resource mixin if @opts.template.include?('http') orig_mxn = model.get_by_id(@opts.template) else orig_mxn = @client.get_mixin(@opts.template, 'os_tpl', true) end if orig_mxn.nil? fail Occi::Api::Client::Errors::AmbiguousNameError, 'Invalid, non-existing or ambiguous mixin (template) name' end res.mixins << orig_mxn # Create and commit resource response = create(res) new_vm = response.gsub!(@opts.endpoint.chomp('/'), '') # Following block checks out for sucessfull VM deployment # and clean up then begin timeout(@opts.timeout) do loop do d = describe(new_vm).first if d.attributes.occi.compute.state == 'active' # puts "OK, resource did enter 'active' state in time" break end sleep @opts.timeout / 5 end end rescue Timeout::Error raise Timeout::Error, "Resource did not enter 'active' state in time!" ensure delete new_vm end end