diff --git a/lib/fog/vcloud_director/compute.rb b/lib/fog/vcloud_director/compute.rb index 4b94639fa..e26158243 100644 --- a/lib/fog/vcloud_director/compute.rb +++ b/lib/fog/vcloud_director/compute.rb @@ -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) diff --git a/lib/fog/vcloud_director/models/compute/organization.rb b/lib/fog/vcloud_director/models/compute/organization.rb index 9a4f20d58..c96e31b2e 100644 --- a/lib/fog/vcloud_director/models/compute/organization.rb +++ b/lib/fog/vcloud_director/models/compute/organization.rb @@ -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 \ No newline at end of file +end diff --git a/lib/fog/vcloud_director/models/compute/task.rb b/lib/fog/vcloud_director/models/compute/task.rb index a42080c3f..e3e1b7be0 100644 --- a/lib/fog/vcloud_director/models/compute/task.rb +++ b/lib/fog/vcloud_director/models/compute/task.rb @@ -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 \ No newline at end of file +end diff --git a/lib/fog/vcloud_director/models/compute/tasks.rb b/lib/fog/vcloud_director/models/compute/tasks.rb index 0d484030b..49230b38d 100644 --- a/lib/fog/vcloud_director/models/compute/tasks.rb +++ b/lib/fog/vcloud_director/models/compute/tasks.rb @@ -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 \ No newline at end of file +end diff --git a/lib/fog/vcloud_director/requests/compute/post_task_cancel.rb b/lib/fog/vcloud_director/requests/compute/post_task_cancel.rb new file mode 100644 index 000000000..5ec8246bb --- /dev/null +++ b/lib/fog/vcloud_director/requests/compute/post_task_cancel.rb @@ -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