Class: Rocci::Compute
- Defined in:
- lib/probe/occi/rocci/compute.rb
Overview
OCCI Compute class.
Instance Method Summary collapse
-
#create_check_destroy ⇒ Object
Create, check and destroy resource.
Methods inherited from Resource
#all, #entity, #find, inherited, #initialize
Constructor Details
This class inherits a constructor from Rocci::Resource
Instance Method Details
#create_check_destroy ⇒ Object
Create, check and destroy resource
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 |
# 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 |