mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Merge pull request #2130 from nosborn/vcloud_director_tasks
[vcloud_director] Improve support for Tasks.
This commit is contained in:
commit
f36c4f038f
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_href # this is used for manual testing
|
||||||
request :get_vms_by_metadata
|
request :get_vms_by_metadata
|
||||||
request :get_vm
|
request :get_vm
|
||||||
|
request :post_task_cancel
|
||||||
|
|
||||||
class Model < Fog::Model
|
class Model < Fog::Model
|
||||||
def initialize(attrs={})
|
def initialize(attrs={})
|
||||||
super(attrs)
|
super(attrs)
|
||||||
|
|
|
@ -5,30 +5,36 @@ module Fog
|
||||||
class VcloudDirector
|
class VcloudDirector
|
||||||
|
|
||||||
class Organization < Model
|
class Organization < Model
|
||||||
|
|
||||||
identity :id
|
identity :id
|
||||||
|
|
||||||
attribute :name, :aliases => :FullName
|
attribute :name, :aliases => :FullName
|
||||||
attribute :type
|
attribute :type
|
||||||
attribute :href
|
attribute :href
|
||||||
attribute :description, :aliases => :Description
|
attribute :description, :aliases => :Description
|
||||||
|
|
||||||
def vdcs
|
def vdcs
|
||||||
requires :id
|
requires :id
|
||||||
service.vdcs(:organization => self)
|
service.vdcs(:organization => self)
|
||||||
end
|
end
|
||||||
|
|
||||||
def catalogs
|
def catalogs
|
||||||
requires :id
|
requires :id
|
||||||
service.catalogs(:organization => self)
|
service.catalogs(:organization => self)
|
||||||
end
|
end
|
||||||
|
|
||||||
def networks
|
def networks
|
||||||
requires :id
|
requires :id
|
||||||
service.networks(:organization => self)
|
service.networks(:organization => self)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def tasks
|
||||||
|
requires :id
|
||||||
|
service.tasks(:organization => self)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,30 +5,35 @@ module Fog
|
||||||
class VcloudDirector
|
class VcloudDirector
|
||||||
|
|
||||||
class Task < Fog::Model
|
class Task < Fog::Model
|
||||||
|
|
||||||
identity :id
|
identity :id
|
||||||
|
|
||||||
attribute :name
|
attribute :name
|
||||||
attribute :type
|
attribute :type
|
||||||
attribute :href
|
attribute :href
|
||||||
attribute :status
|
attribute :status
|
||||||
attribute :operation
|
attribute :operation
|
||||||
attribute :operation_name, :aliases => :operationName
|
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 :end_time, :aliases => :endTime, :type => :time
|
||||||
|
attribute :start_time, :aliases => :startTime, :type => :time
|
||||||
attribute :error, :aliases => :Error
|
attribute :error, :aliases => :Error
|
||||||
attribute :result, :aliases => :Result
|
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?
|
def ready?
|
||||||
status == 'success'
|
status == 'success'
|
||||||
end
|
end
|
||||||
|
|
||||||
def success?
|
def success?
|
||||||
status == 'success'
|
status == 'success'
|
||||||
end
|
end
|
||||||
|
|
||||||
def non_running?
|
def non_running?
|
||||||
if status == 'running'
|
if status == 'running'
|
||||||
if progress.to_i == 0
|
if progress.to_i == 0
|
||||||
|
@ -41,8 +46,13 @@ module Fog
|
||||||
end
|
end
|
||||||
status != 'running'
|
status != 'running'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def cancel
|
||||||
|
service.post_task_cancel(id)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,22 +7,25 @@ module Fog
|
||||||
|
|
||||||
class Tasks < Collection
|
class Tasks < Collection
|
||||||
model Fog::Compute::VcloudDirector::Task
|
model Fog::Compute::VcloudDirector::Task
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
attribute :organization
|
||||||
def all
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
def get(id)
|
def get(id)
|
||||||
data = service.get_task(id).body
|
data = service.get_task(id).body
|
||||||
return nil unless data
|
return nil unless data
|
||||||
data[:id] = data[:href].split('/').last
|
data[:id] = data[:href].split('/').last
|
||||||
new(data)
|
new(data)
|
||||||
end
|
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
|
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