Class: Fog::Compute::Cloudstack::Job

Inherits:
Model
  • Object
show all
Defined in:
lib/fog/cloudstack/models/compute/job.rb

Instance Attribute Summary

Attributes inherited from Model

#collection, #service

Instance Method Summary collapse

Methods inherited from Model

#initialize, #inspect, #symbolize_keys, #to_json, #wait_for

Methods included from Attributes::ClassMethods

#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes

Methods included from Fog::Core::DeprecatedConnectionAccessors

#connection, #connection=, #prepare_service_value

Methods included from Attributes::InstanceMethods

#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #persisted?, #requires, #requires_one

Constructor Details

This class inherits a constructor from Fog::Model

Instance Method Details

#ready?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/fog/cloudstack/models/compute/job.rb', line 23

def ready?
  self.job_status != 0
end

#reloadObject



18
19
20
21
# File 'lib/fog/cloudstack/models/compute/job.rb', line 18

def reload
  requires :id
  merge_attributes(service.query_async_job_result('jobid' => self.id)['queryasyncjobresultresponse'])
end

#resultObject

so dirty



32
33
34
35
36
37
38
# File 'lib/fog/cloudstack/models/compute/job.rb', line 32

def result
  if successful? && model = Fog::Compute::Cloudstack.constants.find{|c| c.to_s.downcase == self.job_result.keys.first.to_s}.to_s
    collection = model.gsub(/.[A-Z]/){|w| "#{w[0,1]}_#{w[1,1].downcase}"}.downcase + "s" # cheap underscorize, assume simple pluralization
    service.send(collection).new(self.job_result.values.first)
  else self.job_result
  end
end

#successful?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/fog/cloudstack/models/compute/job.rb', line 27

def successful?
  self.job_result_code == 0
end