2012-05-21 19:53:53 -04:00
|
|
|
module Fog
|
|
|
|
module Compute
|
|
|
|
class Cloudstack
|
|
|
|
class Job < Fog::Model
|
|
|
|
identity :id, :aliases => 'jobid'
|
|
|
|
attribute :user_id, :aliases => 'userid'
|
|
|
|
attribute :account_id, :aliases => 'accountid'
|
|
|
|
attribute :cmd
|
2012-05-22 19:47:53 -04:00
|
|
|
attribute :job_status, :aliases => 'jobstatus', :type => :integer
|
2012-05-21 19:53:53 -04:00
|
|
|
attribute :job_result_type, :aliases => 'jobresulttype'
|
2012-05-22 19:47:53 -04:00
|
|
|
attribute :job_result_code, :aliases => 'jobresultcode', :type => :integer
|
|
|
|
attribute :job_proc_status, :aliases => 'jobprocstatus', :type => :integer
|
2012-05-21 19:53:53 -04:00
|
|
|
|
2012-05-22 19:47:53 -04:00
|
|
|
attribute :created_at, :aliases => 'created', :type => :time
|
2012-05-21 19:53:53 -04:00
|
|
|
attribute :job_result, :aliases => 'jobresult'
|
|
|
|
|
|
|
|
def reload
|
|
|
|
requires :id
|
2012-12-22 18:28:53 -05:00
|
|
|
merge_attributes(service.query_async_job_result('jobid' => self.id)['queryasyncjobresultresponse'])
|
2012-05-21 19:53:53 -04:00
|
|
|
end
|
2012-05-22 19:47:53 -04:00
|
|
|
|
2012-07-17 18:24:04 -04:00
|
|
|
def ready?
|
2012-05-22 19:47:53 -04:00
|
|
|
self.job_status != 0
|
|
|
|
end
|
2012-07-17 18:24:04 -04:00
|
|
|
|
|
|
|
def successful?
|
|
|
|
self.job_result_code == 0
|
|
|
|
end
|
|
|
|
|
|
|
|
# so dirty
|
|
|
|
def result
|
|
|
|
if successful? && model = Fog::Compute::Cloudstack.constants.find{|c| c.to_s.downcase == self.job_result.keys.first.to_s}.to_s
|
2012-09-02 07:51:17 -04:00
|
|
|
collection = model.gsub(/.[A-Z]/){|w| "#{w[0,1]}_#{w[1,1].downcase}"}.downcase + "s" # cheap underscorize, assume simple pluralization
|
2012-12-22 18:28:53 -05:00
|
|
|
service.send(collection).new(self.job_result.values.first)
|
2012-07-17 18:24:04 -04:00
|
|
|
else self.job_result
|
|
|
|
end
|
|
|
|
end
|
2012-05-21 19:53:53 -04:00
|
|
|
end # Job
|
|
|
|
end # Cloudstack
|
|
|
|
end # Compute
|
|
|
|
end # Fog
|