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

[vcloud_director] Raise provider-specific exceptions.

HEADS UP: This is a breaking change for anyone rescuing Excon errors.
This commit is contained in:
Nick Osborn 2013-10-13 20:46:41 +01:00
parent a4493b8c4f
commit 7a1d4e5075
37 changed files with 257 additions and 186 deletions

View file

@ -2,10 +2,66 @@ require 'fog/core'
module Fog
module VcloudDirector
extend Fog::Provider
service(:compute, 'vcloud_director/compute', 'Compute')
module Errors
class ServiceError < Fog::Errors::Error
attr_reader :minor_error_code
attr_reader :major_error_code
attr_reader :stack_trace
attr_reader :status_code
attr_reader :vendor_specific_error_code
def self.slurp(error, service=nil)
major_error_code = nil
message = nil
minor_error_code = nil
stack_trace = nil
status_code = nil
vendor_specific_error_code = nil
if error.response
status_code = error.response.status
unless error.response.body.empty?
_, media_type = error.response.headers.detect {|k,v| k.downcase == 'content-type'}
if media_type =~ /vnd\.vmware\.vcloud\.error\+xml/i
begin
document = Fog::ToHashDocument.new
Nokogiri::XML::SAX::Parser.new(document).parse_memory(error.response.body)
major_error_code = document.body[:majorErrorCode]
message = document.body[:message]
minor_error_code = document.body[:minorErrorCode]
stack_trace = document.body[:stackTrace]
vendor_specific_error_code = document.body[:vendorSpecificErrorCode]
rescue => e
Fog::Logger.warning("Received exception '#{e}' while decoding>> #{error.response.body}")
message = error.response.body
end
else
message = CGI::unescapeHTML(error.response.body)
end
end
end
new_error = super(error, message)
new_error.instance_variable_set(:@major_error_code, major_error_code)
new_error.instance_variable_set(:@minor_error_code, minor_error_code)
new_error.instance_variable_set(:@stack_trace, stack_trace)
new_error.instance_variable_set(:@status_code, status_code)
new_error.instance_variable_set(:@vendor_specific_error_code, vendor_specific_error_code)
new_error
end
end
class BadRequest < ServiceError; end
class Unauthorized < ServiceError; end
class Forbidden < ServiceError; end
class Conflict < ServiceError; end
class DuplicateName < ServiceError; end
class TaskError < ServiceError; end
end
service(:compute, 'vcloud_director/compute', 'Compute')
end
end

View file

@ -34,10 +34,15 @@ module Fog
API_VERSION = '5.1'
end
module Errors
class ServiceError < Fog::Errors::Error; end
class Task < ServiceError; end
end
class ServiceError < Fog::VcloudDirector::Errors::ServiceError; end
class BadRequest < Fog::VcloudDirector::Errors::BadRequest; end
class Unauthorized < Fog::VcloudDirector::Errors::Unauthorized; end
class Forbidden < Fog::VcloudDirector::Errors::Forbidden; end
class Conflict < Fog::VcloudDirector::Errors::Conflict; end
class DuplicateName < Fog::VcloudDirector::Errors::DuplicateName; end
class TaskError < Fog::VcloudDirector::Errors::TaskError; end
requires :vcloud_director_username, :vcloud_director_password, :vcloud_director_host
recognizes :vcloud_director_api_version
@ -385,13 +390,14 @@ module Fog
:path => path,
:query => params[:query]
})
rescue => e
raise e unless e.class.to_s =~ /^Excon::Errors/
if e.respond_to?(:response)
puts e.response.status
puts CGI::unescapeHTML(e.response.body)
rescue Excon::Errors::HTTPStatusError => error
raise case error
when Excon::Errors::BadRequest then BadRequest.slurp(error);
when Excon::Errors::Unauthorized then Unauthorized.slurp(error);
when Excon::Errors::Forbidden then Forbidden.slurp(error);
when Excon::Errors::Conflict then Conflict.slurp(error);
else ServiceError.slurp(error)
end
raise e
end
def process_task(response_body)
@ -407,7 +413,7 @@ module Fog
def wait_and_raise_unless_success(task)
task.wait_for { non_running? }
raise Errors::Task.new "status: #{task.status}, error: #{task.error}" unless task.success?
raise TaskError.new "status: #{task.status}, error: #{task.error}" unless task.success?
end
def add_id_from_href!(data={})
@ -596,10 +602,6 @@ module Fog
"#{@end_point}#{path}"
end
def valid_uuid?(uuid)
/^[\da-f]{8}(?:-[\da-f]{4}){3}-[\da-f]{12}$/.match(uuid.downcase)
end
def xmlns
'http://www.vmware.com/vcloud/v1.5'
end

View file

@ -46,20 +46,19 @@ module Fog
def undeploy(action='powerOff')
begin
response = service.post_undeploy_vapp(id, :UndeployPowerAction => action)
rescue Excon::Errors::BadRequest => ex
rescue Fog::Compute::VcloudDirector::BadRequest => ex
Fog::Logger.debug(ex.message)
return false
end
service.process_task(response.body)
end
# Power off all VMs in the vApp.
def power_off
requires :id
begin
response = service.post_power_off_vapp(id)
rescue Excon::Errors::BadRequest => ex
rescue Fog::Compute::VcloudDirector::BadRequest => ex
Fog::Logger.debug(ex.message)
return false
end
@ -71,7 +70,7 @@ module Fog
requires :id
begin
response = service.post_power_on_vapp(id)
rescue Excon::Errors::BadRequest => ex
rescue Fog::Compute::VcloudDirector::BadRequest => ex
Fog::Logger.debug(ex.message)
return false
end
@ -83,7 +82,7 @@ module Fog
requires :id
begin
response = service.post_reboot_vapp(id)
rescue Excon::Errors::BadRequest => ex
rescue Fog::Compute::VcloudDirector::BadRequest => ex
Fog::Logger.debug(ex.message)
return false
end
@ -95,7 +94,7 @@ module Fog
requires :id
begin
response = service.post_reset_vapp(id)
rescue Excon::Errors::BadRequest => ex
rescue Fog::Compute::VcloudDirector::BadRequest => ex
Fog::Logger.debug(ex.message)
return false
end
@ -107,7 +106,7 @@ module Fog
requires :id
begin
response = service.post_shutdown_vapp(id)
rescue Excon::Errors::BadRequest => ex
rescue Fog::Compute::VcloudDirector::BadRequest => ex
Fog::Logger.debug(ex.message)
return false
end
@ -119,7 +118,7 @@ module Fog
requires :id
begin
response = service.post_suspend_vapp(id)
rescue Excon::Errors::BadRequest => ex
rescue Fog::Compute::VcloudDirector::BadRequest => ex
Fog::Logger.debug(ex.message)
return false
end
@ -130,7 +129,7 @@ module Fog
requires :id
begin
response = service.delete_vapp(id)
rescue Excon::Errors::BadRequest => ex
rescue Fog::Compute::VcloudDirector::BadRequest => ex
Fog::Logger.debug(ex.message)
return false
end

View file

@ -47,7 +47,7 @@ module Fog
requires :id
begin
response = service.post_power_off_vapp(id)
rescue Excon::Errors::BadRequest => ex
rescue Fog::Compute::VcloudDirector::BadRequest => ex
Fog::Logger.debug(ex.message)
return false
end
@ -59,7 +59,7 @@ module Fog
requires :id
begin
response = service.post_power_on_vapp(id)
rescue Excon::Errors::BadRequest => ex
rescue Fog::Compute::VcloudDirector::BadRequest => ex
Fog::Logger.debug(ex.message)
return false
end
@ -72,7 +72,7 @@ module Fog
requires :id
begin
response = service.post_reboot_vapp(id)
rescue Excon::Errors::BadRequest => ex
rescue Fog::Compute::VcloudDirector::BadRequest => ex
Fog::Logger.debug(ex.message)
return false
end
@ -84,7 +84,7 @@ module Fog
requires :id
begin
response = service.post_reset_vapp(id)
rescue Excon::Errors::BadRequest => ex
rescue Fog::Compute::VcloudDirector::BadRequest => ex
Fog::Logger.debug(ex.message)
return false
end
@ -96,7 +96,7 @@ module Fog
requires :id
begin
response = service.post_shutdown_vapp(id)
rescue Excon::Errors::BadRequest => ex
rescue Fog::Compute::VcloudDirector::BadRequest => ex
Fog::Logger.debug(ex.message)
return false
end
@ -108,7 +108,7 @@ module Fog
requires :id
begin
response = service.post_suspend_vapp(id)
rescue Excon::Errors::BadRequest => ex
rescue Fog::Compute::VcloudDirector::BadRequest => ex
Fog::Logger.debug(ex.message)
return false
end

View file

@ -11,6 +11,8 @@ module Fog
# @return [Excon::Response]
# * body<~Hash>:
#
# @raise [Fog::Compute::VcloudDirector::Forbidden]
#
# @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/DELETE-Media.html
# @since vCloud API version 0.9
def delete_media(id)
@ -25,15 +27,10 @@ module Fog
class Mock
def delete_media(id)
response = Excon::Response.new
unless valid_uuid?(id)
response.status = 400
raise Excon::Errors.status_error({:expects => 202}, response)
end
unless media = data[:medias][id]
response.status = 403
raise Excon::Errors.status_error({:expects => 202}, response)
raise Fog::Compute::VcloudDirector::Forbidden.new(
"No access to entity \"(com.vmware.vcloud.entity.media:#{id})\""
)
end
Fog::Mock.not_implemented

View file

@ -11,6 +11,8 @@ module Fog
# @return [Excon::Response]
# * body<~Hash>:
#
# @raise [Fog::Compute::VcloudDirector::BadRequest]
#
# @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/DELETE-VApp.html
# @since vCloud API version 0.9
def delete_vapp(id)

View file

@ -8,6 +8,8 @@ module Fog
# @return [Excon::Response]
# * hash<~Hash>:
#
# @raise [Fog::Compute::VcloudDirector::Forbidden]
#
# @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/GET-Catalog.html
# @since vCloud API version 0.9
def get_catalog(id)
@ -23,15 +25,10 @@ module Fog
class Mock
def get_catalog(id)
response = Excon::Response.new
unless valid_uuid?(id)
response.status = 400
raise Excon::Error.status_error({:expects => 200}, response)
end
unless catalog = data[:catalogs][id]
response.status = 403
raise Excon::Error.status_error({:expects => 200}, response)
raise Fog::Compute::VcloudDirector::Forbidden.new(
"No access to entity \"(com.vmware.vcloud.entity.catalog:#{id})\"."
)
end
Fog::Mock.not_implemented

View file

@ -8,6 +8,8 @@ module Fog
# @return [Excon::Response]
# * body<~Hash>:
#
# @raise [Fog::Compute::VcloudDirector::Forbidden]
#
# @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/GET-EdgeGateway.html
# @since vCloud API version 5.1
def get_edge_gateway(id)
@ -23,15 +25,10 @@ module Fog
class Mock
def get_edge_gateway(id)
response = Excon::Response.new
unless valid_uuid?(id)
response.status = 400
raise Excon::Errors.status_error({:expects => 200}, response)
end
unless edge_gateway = data[:edge_gateways][id]
response.status = 403
raise Excon::Errors.status_error({:expects => 200}, response)
raise Fog::Compute::VcloudDirector::Forbidden.new(
"No access to entity \"(com.vmware.vcloud.entity.gateway:#{id})\""
)
end
vdc_id = edge_gateway[:vdc]
@ -41,7 +38,7 @@ module Fog
:xmlns_xsi => xmlns_xsi,
:status => "1",
:name => edge_gateway[:name],
:id => "urn:vcloud:gateway:27805d5d-868b-4678-b30b-11e14ad34eca",
:id => "urn:vcloud:gateway:#{id}",
:type => "application/vnd.vmware.admin.edgeGateway+xml",
:href => make_href("admin/edgeGateway/#{id}"),
:xsi_schemaLocation => xsi_schema_location,
@ -84,10 +81,11 @@ module Fog
data[:networks][network].merge extras
end
response.status = 200
response.headers = {'Content-Type' => "#{body[:type]};version=#{api_version}"}
response.body = body
response
Excon::Response.new(
:status => 200,
:headers => {'Content-Type' => "#{body[:type]};version=#{api_version}"},
:body => body
)
end
end
end

View file

@ -8,6 +8,8 @@ module Fog
# @return [Excon::Response]
# * body<~Hash>:
#
# @raise [Fog::Compute::VcloudDirector::Forbidden]
#
# @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/GET-Media.html
# @since vCloud API version 0.9
def get_media(id)
@ -23,15 +25,10 @@ module Fog
class Mock
def get_media(id)
response = Excon::Response.new
unless valid_uuid?(id)
response.status = 400
raise Excon::Errors.status_error({:expects => 200}, response)
end
unless media = data[:medias][id]
response.status = 403
raise Excon::Errors.status_error({:expects => 200}, response)
raise Fog::Compute::VcloudDirector::Forbidden.new(
"No access to entity \"(com.vmware.vcloud.entity.media:#{id})\"."
)
end
Fog::Mock.not_implemented

View file

@ -8,6 +8,8 @@ module Fog
# @return [Excon::Response]
# * body<~Hash>:
#
# @raise [Fog::Compute::VcloudDirector::Forbidden]
#
# @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/GET-MediaOwner.html
# @since vCloud API version 1.5
def get_media_owner(id)
@ -23,15 +25,10 @@ module Fog
class Mock
def get_media_owner(id)
response = Excon::Response.new
unless valid_uuid?(id)
response.status = 400
raise Excon::Errors.status_error({:expects => 200}, response)
end
unless media = data[:medias][id]
response.status = 403
raise Excon::Errors.status_error({:expects => 200}, response)
raise Fog::Compute::VcloudDirector::Forbidden.new(
"No access to entity \"com.vmware.vcloud.entity.media:#{id}\"."
)
end
Fog::Mock.not_implemented

View file

@ -10,6 +10,8 @@ module Fog
# @return [Excon::Response]
# * body<~Hash>:
#
# @raise [Fog::Compute::VcloudDirector::Forbidden]
#
# @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/GET-Network.html
# @since vCloud API version 0.9
def get_network(id)
@ -25,15 +27,10 @@ module Fog
class Mock
def get_network(id)
response = Excon::Response.new
unless valid_uuid?(id)
response.status = 400
raise Excon::Errors.status_error({:expect => 200}, response)
end
unless network = data[:networks][id]
response.status = 403
raise Excon::Errors.status_error({:expect => 200}, response)
raise Fog::Compute::VcloudDirector::Forbidden.new(
'This operation is denied.'
)
end
body =
@ -54,10 +51,11 @@ module Fog
:end_address=>ip_range[:EndAddress]}
end
response.status = 200
response.headers = {'Content-Type' => "#{body[:type]};version=#{api_version}"}
response.body = body
response
Excon::Response.new(
:status => 200,
:headers => {'Content-Type' => "#{body[:type]};version=#{api_version}"},
:body => body
)
end
end
end

View file

@ -11,6 +11,8 @@ module Fog
# @return [Excon::Response]
# * body<~Hash>:
#
# @raise [Fog::Compute::VcloudDirector::Forbidden]
#
# @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/GET-OrgVdcGateways.html
# @since vCloud API version 5.1
def get_org_vdc_gateways(id)
@ -26,15 +28,10 @@ module Fog
class Mock
def get_org_vdc_gateways(vdc_id)
response = Excon::Response.new
unless valid_uuid?(vdc_id)
response.status = 400
raise Excon::Errors.status_error({:expects => 200}, response)
end
unless vdc = data[:vdcs][vdc_id]
response.status = 403
raise Excon::Errors.status_error({:expects => 200}, response)
unless data[:vdcs][vdc_id]
raise Fog::Compute::VcloudDirector::Forbidden.new(
"No access to entity \"(com.vmware.vcloud.entity.vdc:#{vdc_id})\"."
)
end
body =
@ -72,10 +69,11 @@ module Fog
:isSyslogServerSettingInSync => "true"}
end
response.status = 200
response.headers = {'Content-Type' => "#{body[:type]};version=#{api_version}"}
response.body = body
response
Excon::Response.new(
:status => 200,
:headers => {'Content-Type' => "#{body[:type]};version=#{api_version}"},
:body => body
)
end
end
end

View file

@ -8,6 +8,8 @@ module Fog
# @return [Excon:Response]
# * body<~Hash>:
#
# @raise [Fog::Compute::VcloudDirector::Forbidden]
#
# @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/GET-Organization.html
# @since vCloud API version 0.9
def get_organization(id)
@ -26,15 +28,10 @@ module Fog
class Mock
def get_organization(id)
response = Excon::Response.new
unless valid_uuid?(id)
response.status = 400
raise Excon::Errors.status_error({:expects => 200}, response)
end
unless id == data[:org][:uuid]
response.status = 403
raise(Excon::Errors.status_error({:expects => 200}, response))
raise Fog::Compute::VcloudDirector::Forbidden.new(
"No access to entity \"com.vmware.vcloud.entity.org:#{id}\""
)
end
org = data[:org]
@ -92,10 +89,11 @@ module Fog
:rel=>"down"}
end
response.status = 200
response.headers = {'Content-Type' => "#{body[:type]};version=#{api_version}"}
response.body = body
response
Excon::Response.new(
:body => body,
:headers => {'Content-Type' => "#{body[:type]};version=#{api_version}"},
:status => 200
)
end
end
end

View file

@ -8,6 +8,8 @@ module Fog
# @return [Excon::Response]
# * body<~Hash>:
#
# @raise [Fog::Compute::VcloudDirector::Forbidden]
#
# @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/GET-Task.html
# @since vCloud API version 0.9
def get_task(id)
@ -23,15 +25,10 @@ module Fog
class Mock
def get_task(id)
response = Excon::Response.new
unless valid_uuid?(id)
response.status = 400
raise Excon::Error.status_error({:expects => 200}, response)
end
unless task = data[:tasks][id]
response.status = 403
raise Excon::Error.status_error({:expects => 200}, response)
raise Fog::Compute::VcloudDirector::Forbidden.new(
'This operation is denied.'
)
end
Fog::Mock.not_implemented

View file

@ -12,6 +12,8 @@ module Fog
# @return [Excon::Response]
# * body<~Hash>:
#
# @raise [Fog::Compute::VcloudDirector::Forbidden]
#
# @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/GET-TaskList.html
# @since vCloud API version 0.9
def get_task_list(id)
@ -27,15 +29,10 @@ module Fog
class Mock
def get_task_list(id)
response = Excon::Response.new
unless valid_uuid?(id)
response.status = 400
raise(Excon::Errors.status_error({:expects => 200}, response))
end
unless id == data[:org][:uuid]
response.status = 403
raise(Excon::Errors.status_error({:expects => 200}, response))
raise Fog::Compute::VcloudDirector::Forbidden.new(
"No access to entity \"com.vmware.vcloud.entity.org:#{id}\"."
)
end
body =
@ -76,10 +73,11 @@ module Fog
tasks = tasks.first if tasks.size == 1
body[:Task] = tasks
response.status = 200
response.headers = {'Content-Type' => "#{body[:type]};version=#{api_version}"}
response.body = body
response
Excon::Response.new(
:status => 200,
:headers => {'Content-Type' => "#{body[:type]};version=#{api_version}"},
:body => body
)
end
end
end

View file

@ -8,6 +8,8 @@ module Fog
# @return [Excon::Response]
# * body<~Hash>:
#
# @raise [Fog::Compute::VcloudDirector::Forbidden]
#
# @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/GET-Vdc.html
# @since vCloud API version 0.9
def get_vdc(id)
@ -25,13 +27,10 @@ module Fog
def get_vdc(vdc_id)
response = Excon::Response.new
unless valid_uuid?(vdc_id)
response.status = 400
raise Excon::Errors.status_error({:expects => 200}, response)
end
unless vdc = data[:vdcs][vdc_id]
response.status = 403
raise Excon::Errors.status_error({:expects => 200}, response)
raise Fog::Compute::VcloudDirector::Forbidden.new(
"No access to entity \"com.vmware.vcloud.entity.vdc:#{vdc_id}\"."
)
end
body =

View file

@ -29,6 +29,8 @@ module Fog
# that can specify a storage profile is created with no storage
# profile specified.
#
# @raise [Fog::Compute::VcloudDirector::Forbidden]
#
# @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/GET-VdcStorageClass.html
def get_vdc_storage_class(id)
request(
@ -43,11 +45,10 @@ module Fog
class Mock
def get_vdc_storage_class(id)
response = Excon::Response.new
unless vdc_storage_class = data[:vdc_storage_classes][id]
response.status = 403
raise Excon::Errors.status_error({:expects => 200}, response)
raise Fog::Compute::VcloudDirector::Forbidden.new(
"No access to entity \"(com.vmware.vcloud.entity.vdcstorageProfile:#{id})\"."
)
end
body =
@ -70,10 +71,11 @@ module Fog
:Limit=>vdc_storage_class[:limit].to_s,
:Default=>vdc_storage_class[:default].to_s}
response.status = 200
response.headers = {'Content-Type' => "#{body[:type]};version=#{api_version}"}
response.body = body
response
Excon::Response.new(
:status => 200,
:headers => {'Content-Type' => "#{body[:type]};version=#{api_version}"},
:body => body
)
end
end
end

View file

@ -9,7 +9,7 @@ module Fog
# @return [Excon::Response]
# * body<~Hash>:
#
# @raise [Excon::Errors::Conflict]
# @raise [Fog::Compute::VcloudDirector::Conflict]
#
# @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/POST-AcquireTicket.html
# @since vCloud API version 0.9

View file

@ -18,6 +18,8 @@ module Fog
# @return [Excon::Response]
# * body<~Hash>:
#
# @raise [Fog::Compute::VcloudDirector::BadRequest]
#
# @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/POST-PowerOffVApp.html
# @since vCloud API version 0.9
def post_power_off_vapp(id)

View file

@ -18,6 +18,8 @@ module Fog
# @return [Excon::Response]
# * body<~Hash>:
#
# @raise [Fog::Compute::VcloudDirector::BadRequest]
#
# @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/POST-PowerOnVApp.html
# @since vCloud API version 0.9
def post_power_on_vapp(id)

View file

@ -15,6 +15,8 @@ module Fog
# @return [Excon::Response]
# * body<~Hash>:
#
# @raise [Fog::Compute::VcloudDirector::BadRequest]
#
# @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/POST-RebootVApp.html
# @since vCloud API version 0.9
def post_reboot_vapp(id)

View file

@ -15,6 +15,8 @@ module Fog
# @return [Excon::Response]
# * body<~Hash>:
#
# @raise [Fog::Compute::VcloudDirector::BadRequest]
#
# @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/POST-ResetVApp.html
# @since vCloud API version 0.9
def post_reset_vapp(id)

View file

@ -15,6 +15,8 @@ module Fog
# @return [Excon::Response]
# * body<~Hash>:
#
# @raise [Fog::Compute::VcloudDirector::BadRequest]
#
# @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/POST-ShutdownVApp.html
# @since vCloud API version 0.9
def post_shutdown_vapp(id)

View file

@ -15,6 +15,8 @@ module Fog
# @return [Excon::Response]
# * body<~Hash>:
#
# @raise [Fog::Compute::VcloudDirector::BadRequest]
#
# @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/POST-SuspendVApp.html
# @since vCloud API version 0.9
def post_suspend_vapp(id)

View file

@ -29,6 +29,8 @@ module Fog
# @return [Excon::Response]
# * body<~Hash>:
#
# @raise [Fog::Compute::VcloudDirector::BadRequest]
#
# @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/POST-UndeployVApp.html
# @since vCloud API version 0.9
def post_undeploy_vapp(id, options={})

View file

@ -17,6 +17,9 @@ module Fog
# @return [Excon::Response]
# * body<~Hash>:
#
# @raise [Fog::Compute::VcloudDirector::BadRequest]
# @raise [Fog::Compute::VcloudDirector::Forbidden]
#
# @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/POST-UploadMedia.html
# @since vCloud API version 0.9
def post_upload_media(vdc_id, name, image_type, size, options={})
@ -48,23 +51,20 @@ module Fog
class Mock
def post_upload_media(vdc_id, name, image_type, size, options={})
response = Excon::Response.new
unless valid_uuid?(vdc_id)
response.status = 400
raise Excon::Errors.status_error({:expects => 201}, response)
end
unless ['iso','floppy'].include?(image_type)
response.status = 400
raise Excon::Errors.status_error({:expects => 201}, response)
raise Fog::Compute::VcloudDirector::BadRequest.new(
'The value of parameter imageType is incorrect.'
)
end
unless size =~ /^\d+$/
response.status = 400
raise Excon::Errors.status_error({:expects => 201}, response)
unless size.to_s =~ /^\d+$/
raise Fog::Compute::VcloudDirector::BadRequest.new(
'validation error on field \'size\': must be greater than or equal to 0'
)
end
unless vdc = data[:vdcs][vdc_id]
response.status = 403
raise Excon::Errors.status_error({:expects => 201}, response)
raise Fog::Compute::VcloudDirector::Forbidden.new(
"No access to entity \"(com.vmware.vcloud.entity.vdc:#{vdc_id})\"."
)
end
Fog::Mock.not_implemented

View file

@ -27,8 +27,7 @@ Shindo.tests('Compute::VcloudDirector | catalog requests', ['vclouddirector']) d
@service.get_catalogs_from_query.body
end
tests('Retrieve non-existent Catalog').raises(Excon::Errors::Forbidden) do
pending if Fog.mocking?
tests('Retrieve non-existent Catalog').raises(Fog::Compute::VcloudDirector::Forbidden) do
@service.get_catalog('00000000-0000-0000-0000-000000000000')
end

View file

@ -7,7 +7,7 @@ Shindo.tests('Compute::VcloudDirector | disk requests', ['vclouddirector']) do
@service.get_disks_from_query.body
end
tests('Retrieve non-existent Disk').raises(Excon::Errors::Forbidden) do
tests('Retrieve non-existent Disk').raises(Fog::Compute::VcloudDirector::Forbidden) do
pending if Fog.mocking?
@service.get_disk('00000000-0000-0000-0000-000000000000')
end

View file

@ -13,7 +13,7 @@ Shindo.tests('Compute::VcloudDirector | edge gateway requests', ['vclouddirector
tests('#get_org_vdc_gateways').data_matches_schema(VcloudDirector::Compute::Schema::QUERY_RESULT_RECORDS_TYPE) do
begin
@edge_gateways = @service.get_org_vdc_gateways(@vdc_id).body
rescue Excon::Errors::Unauthorized # bug, may be localised
rescue Fog::Compute::VcloudDirector::Unauthorized # bug, may be localised
retry
end
@ -34,10 +34,10 @@ Shindo.tests('Compute::VcloudDirector | edge gateway requests', ['vclouddirector
@service.get_edge_gateway(@edge_gateways[:EdgeGatewayRecord].first[:href].split('/').last).body
end
tests('Retrieve non-existent edge gateway').raises(Excon::Errors::Forbidden) do
tests('Retrieve non-existent edge gateway').raises(Fog::Compute::VcloudDirector::Forbidden) do
begin
@service.get_edge_gateway('00000000-0000-0000-0000-000000000000')
rescue Excon::Errors::Unauthorized # bug, may be localised
rescue Fog::Compute::VcloudDirector::Unauthorized # bug, may be localised
retry
end
end

View file

@ -4,9 +4,8 @@ Shindo.tests('Compute::VcloudDirector | media requests', ['vclouddirector']) do
@org = VcloudDirector::Compute::Helper.current_org(@service)
@media_name = VcloudDirector::Compute::Helper.test_name
pending if Fog.mocking?
tests('Upload and manipulate a media object') do
pending if Fog.mocking?
File.open(VcloudDirector::Compute::Helper.fixture('test.iso'), 'rb') do |iso|
tests('#post_upload_media').data_matches_schema(VcloudDirector::Compute::Schema::MEDIA_TYPE) do
pending if Fog.mocking?
@ -139,16 +138,17 @@ Shindo.tests('Compute::VcloudDirector | media requests', ['vclouddirector']) do
end
tests('Media item no longer exists') do
tests("#get_media(#{@media_id})").raises(Excon::Errors::Forbidden) do
pending if Fog.mocking?
tests("#get_media(#{@media_id})").raises(Fog::Compute::VcloudDirector::Forbidden) do
@service.get_media(@media_id)
end
tests("#get_media_owner(#{@media_id})").raises(Excon::Errors::Forbidden) do
tests("#get_media_owner(#{@media_id})").raises(Fog::Compute::VcloudDirector::Forbidden) do
@service.get_media_owner(@media_id)
end
tests("#get_media_metadata(#{@media_id})").raises(Excon::Errors::Forbidden) do
tests("#get_media_metadata(#{@media_id})").raises(Fog::Compute::VcloudDirector::Forbidden) do
@service.get_media_metadata(@media_id)
end
tests("#delete_media(#{@media_id})").raises(Excon::Errors::Forbidden) do
tests("#delete_media(#{@media_id})").raises(Fog::Compute::VcloudDirector::Forbidden) do
@service.delete_media(@media_id)
end
end
@ -158,8 +158,27 @@ Shindo.tests('Compute::VcloudDirector | media requests', ['vclouddirector']) do
@service.get_medias_from_query.body
end
tests('Upload to non-existent vDC').raises(Excon::Errors::Forbidden) do
tests('Invalid image_type').raises(Fog::Compute::VcloudDirector::BadRequest) do
@service.post_upload_media('00000000-0000-0000-0000-000000000000', 'test.iso', 'isox', 0)
end
tests('Invalid size').raises(Fog::Compute::VcloudDirector::BadRequest) do
@service.post_upload_media('00000000-0000-0000-0000-000000000000', 'test.iso', 'iso', -1)
end
tests('Upload to non-existent vDC').raises(Fog::Compute::VcloudDirector::Forbidden) do
@service.post_upload_media('00000000-0000-0000-0000-000000000000', 'test.iso', 'iso', 0)
end
tests('Retrieve non-existent Media').raises(Fog::Compute::VcloudDirector::Forbidden) do
@service.get_media('00000000-0000-0000-0000-000000000000')
end
tests('Retrieve owner of non-existent Media').raises(Fog::Compute::VcloudDirector::Forbidden) do
@service.get_media_owner('00000000-0000-0000-0000-000000000000')
end
tests('Delete non-existent Media').raises(Fog::Compute::VcloudDirector::Forbidden) do
@service.delete_media('00000000-0000-0000-0000-000000000000')
end
end

View file

@ -34,7 +34,7 @@ Shindo.tests('Compute::VcloudDirector | network requests', ['vclouddirector']) d
@service.get_network_metadata(@network_id).body
end
tests('Retrieve non-existent OrgNetwork').raises(Excon::Errors::Forbidden) do
tests('Retrieve non-existent OrgNetwork').raises(Fog::Compute::VcloudDirector::Forbidden) do
@service.get_network('00000000-0000-0000-0000-000000000000')
end

View file

@ -22,7 +22,7 @@ Shindo.tests('Compute::VcloudDirector | organization requests', ['vclouddirector
@service.get_organizations_from_query.body
end
tests('retrieve non-existent Org').raises(Excon::Errors::Forbidden) do
tests('retrieve non-existent Org').raises(Fog::Compute::VcloudDirector::Forbidden) do
@service.get_organization('00000000-0000-0000-0000-000000000000')
end

View file

@ -9,8 +9,12 @@ Shindo.tests('Compute::VcloudDirector | task requests', ['vclouddirector']) do
@tasks_list = @service.get_task_list(@org_uuid).body
end
tests('retrieve non-existent TasksList').raises(Excon::Errors::Forbidden) do
tests('retrieve non-existent TasksList').raises(Fog::Compute::VcloudDirector::Forbidden) do
@service.get_task_list('00000000-0000-0000-0000-000000000000')
end
tests('retrieve non-existent Task').raises(Fog::Compute::VcloudDirector::Forbidden) do
@service.get_task('00000000-0000-0000-0000-000000000000')
end
end

View file

@ -70,17 +70,17 @@ Shindo.tests('Compute::VcloudDirector | vapp requests', ['vclouddirector']) do
@service.get_vapps_in_lease_from_query.body
end
tests('Retrieve non-existent vApp').raises(Excon::Errors::Forbidden) do
tests('Retrieve non-existent vApp').raises(Fog::Compute::VcloudDirector::Forbidden) do
pending if Fog.mocking?
@service.get_vapp('00000000-0000-0000-0000-000000000000')
end
tests('Retrieve owner of non-existent vApp').raises(Excon::Errors::Forbidden) do
tests('Retrieve owner of non-existent vApp').raises(Fog::Compute::VcloudDirector::Forbidden) do
pending if Fog.mocking?
@service.get_vapp_owner('00000000-0000-0000-0000-000000000000')
end
tests('Delete non-existent vApp').raises(Excon::Errors::Forbidden) do
tests('Delete non-existent vApp').raises(Fog::Compute::VcloudDirector::Forbidden) do
pending if Fog.mocking?
@service.delete_vapp('00000000-0000-0000-0000-000000000000')
end

View file

@ -21,7 +21,7 @@ Shindo.tests('Compute::VcloudDirector | vdc_storage_profile requests', ['vcloudd
end
end
tests('Retrieve non-existent vDC storage profile').raises(Excon::Errors::Forbidden) do
tests('Retrieve non-existent vDC storage profile').raises(Fog::Compute::VcloudDirector::Forbidden) do
@service.get_vdc_storage_class('00000000-0000-0000-0000-000000000000')
end

View file

@ -25,7 +25,7 @@ Shindo.tests('Compute::VcloudDirector | vdc requests', ['vclouddirector']) do
@service.get_vdcs_from_query.body
end
tests('Retrieve non-existent vDC').raises(Excon::Errors::Forbidden) do
tests('Retrieve non-existent vDC').raises(Fog::Compute::VcloudDirector::Forbidden) do
@service.get_vdc('00000000-0000-0000-0000-000000000000')
end

View file

@ -105,17 +105,17 @@ Shindo.tests('Compute::VcloudDirector | vm requests', ['vclouddirector']) do
@service.get_vms_in_lease_from_query.body
end
#tests('Retrieve non-existent vApp').raises(Excon::Errors::Forbidden) do
#tests('Retrieve non-existent vApp').raises(Fog::Compute::VcloudDirector::Forbidden) do
# pending if Fog.mocking?
# @service.get_vapp('00000000-0000-0000-0000-000000000000')
#end
#tests('Retrieve owner of non-existent vApp').raises(Excon::Errors::Forbidden) do
#tests('Retrieve owner of non-existent vApp').raises(Fog::Compute::VcloudDirector::Forbidden) do
# pending if Fog.mocking?
# @service.get_vapp_owner('00000000-0000-0000-0000-000000000000')
#end
#tests('Delete non-existent vApp').raises(Excon::Errors::Forbidden) do
#tests('Delete non-existent vApp').raises(Fog::Compute::VcloudDirector::Forbidden) do
# pending if Fog.mocking?
# @service.delete_vapp('00000000-0000-0000-0000-000000000000')
#end