1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[cloudstack|compute] support async jobs

This commit is contained in:
Jason Hansen & Josh Lane 2012-05-21 16:53:53 -07:00
parent 1d866ac238
commit ff9fd54c1a
7 changed files with 100 additions and 7 deletions

View file

@ -19,6 +19,8 @@ module Fog
model_path 'fog/cloudstack/models/compute'
model :address
model :job
collection :jobs
model :server
collection :servers
model :image

View file

@ -0,0 +1,25 @@
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
attribute :job_status, :aliases => 'jobstatus'
attribute :job_result_type, :aliases => 'jobresulttype'
attribute :job_result_code, :aliases => 'jobresultcode'
attribute :job_proc_status, :aliases => 'jobprocstatus'
attribute :created_at, :aliases => 'created', :type => :time
attribute :job_result, :aliases => 'jobresult'
def reload
requires :id
merge_attributes(connection.query_async_job_result('jobid' => self.id)['queryasyncjobresultresponse'])
end
end # Job
end # Cloudstack
end # Compute
end # Fog

View file

@ -0,0 +1,28 @@
require 'fog/core/collection'
require 'fog/cloudstack/models/compute/job'
module Fog
module Compute
class Cloudstack
class Jobs < Fog::Collection
model Fog::Compute::Cloudstack::Job
def all
data = connection.list_async_jobs["listasyncjobsresponse"]["asyncjobs"] || []
load(data)
end
def get(job_id)
if job = connection.query_async_job_result('jobid' => job_id)["listasyncjobsresponse"]["asyncjobs"].first
new(job)
end
rescue Fog::Compute::Cloudstack::BadRequest
nil
end
end
end
end
end

View file

@ -42,6 +42,14 @@ module Fog
state == 'Running'
end
def reboot
requires :id
data = connection.reboot_virtual_machine('id' => self.id) # FIXME: does this ever fail?
job = Job.new(data["rebootvirtualmachineresponse"])
job.connection= self.connection
job
end
def save
requires :image_id, :flavor_id, :zone_id

View file

@ -10,11 +10,23 @@ module Fog
options.merge!(
'command' => 'listAsyncJobs'
)
request(options)
end
end
end
end
end
end # Real
class Mock
def list_async_jobs(options={})
# FIXME: support paging
jobs = self.data[:jobs]
{
'listasyncjobsresponse' => {
'count' => jobs.size,
'asyncjobs' => jobs
}
}
end
end # Mock
end # Cloudstack
end # Compute
end # Fog

View file

@ -19,10 +19,17 @@ module Fog
class Mock
def list_service_offerings(options={})
flavors = self.data[:flavors].values
flavors = []
if service_offering_id = options['id']
flavor = self.data[:flavors][service_offering_id]
raise Fog::Compute::Cloudstack::BadRequest unless flavor
flavors = [flavor]
else
flavors = self.data[:flavors].values
end
{
"listserviceofferingsresponse" =>
"listserviceofferingsresponse" =>
{
"count" => flavors.size,
"serviceoffering"=> flavors

View file

@ -15,6 +15,17 @@ module Fog
end
end
class Mock
def reboot_virtual_machine(options={})
job_id = Fog::Cloudstack.uuid
{
"rebootvirtualmachineresponse" => {
"jobid" => job_id
}
}
end
end
end
end
end