mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[vcloud_director] Improve support for Tasks.
- add Organization#tasks - add Task#cancel - rename Task#expirity_time to expiry_time - Task#progress is an integer - add missing Task#start_time - expose Task attributes introduced in 5.1 API
This commit is contained in:
parent
9bc7bdfd4d
commit
13ed21eaa5
5 changed files with 72 additions and 27 deletions
|
@ -108,7 +108,8 @@ module Fog
|
|||
request :get_href # this is used for manual testing
|
||||
request :get_vms_by_metadata
|
||||
request :get_vm
|
||||
|
||||
request :post_task_cancel
|
||||
|
||||
class Model < Fog::Model
|
||||
def initialize(attrs={})
|
||||
super(attrs)
|
||||
|
|
|
@ -5,30 +5,36 @@ module Fog
|
|||
class VcloudDirector
|
||||
|
||||
class Organization < Model
|
||||
|
||||
|
||||
identity :id
|
||||
|
||||
|
||||
attribute :name, :aliases => :FullName
|
||||
attribute :type
|
||||
attribute :href
|
||||
attribute :description, :aliases => :Description
|
||||
|
||||
|
||||
def vdcs
|
||||
requires :id
|
||||
service.vdcs(:organization => self)
|
||||
end
|
||||
|
||||
|
||||
def catalogs
|
||||
requires :id
|
||||
service.catalogs(:organization => self)
|
||||
end
|
||||
|
||||
|
||||
def networks
|
||||
requires :id
|
||||
service.networks(:organization => self)
|
||||
end
|
||||
|
||||
|
||||
def tasks
|
||||
requires :id
|
||||
service.tasks(:organization => self)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,30 +5,35 @@ module Fog
|
|||
class VcloudDirector
|
||||
|
||||
class Task < Fog::Model
|
||||
|
||||
|
||||
identity :id
|
||||
|
||||
|
||||
attribute :name
|
||||
attribute :type
|
||||
attribute :href
|
||||
attribute :status
|
||||
attribute :operation
|
||||
attribute :operation_name, :aliases => :operationName
|
||||
attribute :expirity_time, :aliases => :expiryTime, :type => :time
|
||||
attribute :expiry_time, :aliases => :expiryTime, :type => :time
|
||||
attribute :end_time, :aliases => :endTime, :type => :time
|
||||
attribute :start_time, :aliases => :startTime, :type => :time
|
||||
attribute :error, :aliases => :Error
|
||||
attribute :result, :aliases => :Result
|
||||
attribute :progress, :aliases => :Progress
|
||||
|
||||
|
||||
attribute :progress, :aliases => :Progress, :type => :integer
|
||||
|
||||
# Since 5.1
|
||||
attribute :operation_key, :aliases => :operationKey
|
||||
attribute :cancel_requested, :aliases => :cancelRequested, :type => :boolean
|
||||
attribute :service_namespace, :aliases => :serviceNamespace
|
||||
|
||||
def ready?
|
||||
status == 'success'
|
||||
end
|
||||
|
||||
|
||||
def success?
|
||||
status == 'success'
|
||||
end
|
||||
|
||||
|
||||
def non_running?
|
||||
if status == 'running'
|
||||
if progress.to_i == 0
|
||||
|
@ -41,8 +46,13 @@ module Fog
|
|||
end
|
||||
status != 'running'
|
||||
end
|
||||
|
||||
|
||||
def cancel
|
||||
service.post_task_cancel(id)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,22 +7,25 @@ module Fog
|
|||
|
||||
class Tasks < Collection
|
||||
model Fog::Compute::VcloudDirector::Task
|
||||
|
||||
|
||||
|
||||
|
||||
def all
|
||||
|
||||
end
|
||||
|
||||
attribute :organization
|
||||
|
||||
def get(id)
|
||||
data = service.get_task(id).body
|
||||
return nil unless data
|
||||
data[:id] = data[:href].split('/').last
|
||||
new(data)
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def item_list
|
||||
data = service.get_tasks_list(organization.id).body
|
||||
tasks = data[:Task].is_a?(Array) ? data[:Task] : [data[:Task]]
|
||||
tasks.each {|task| service.add_id_from_href!(task)}
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
25
lib/fog/vcloud_director/requests/compute/post_task_cancel.rb
Normal file
25
lib/fog/vcloud_director/requests/compute/post_task_cancel.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class VcloudDirector
|
||||
class Real
|
||||
|
||||
# Cancel a task.
|
||||
#
|
||||
# ==== Parameters
|
||||
# * task_id<~String> - The ID of the task you want to cancel.
|
||||
#
|
||||
# === Returns
|
||||
# * response<~Excon::Response>
|
||||
# # {Amazon API Reference}[http://docs.amazonwebservices.com/AWSEC2/2012-03-01/APIReference/ApiReference-query-DeleteNetworkInterface.html]
|
||||
def post_task_cancel(task_id)
|
||||
request(
|
||||
:expects => 204,
|
||||
:method => 'POST',
|
||||
:path => "task/#{task_id}/action/cancel"
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue