mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[vcloud_director] Add media-related requests.
This commit is contained in:
parent
b84097983c
commit
7c20489356
7 changed files with 260 additions and 1 deletions
|
@ -108,6 +108,10 @@ module Fog
|
|||
request :delete_vapp
|
||||
request :get_current_session
|
||||
request :get_supported_versions
|
||||
request :delete_media
|
||||
request :get_media
|
||||
request :get_media_owner
|
||||
request :post_upload_media
|
||||
|
||||
class Model < Fog::Model
|
||||
def initialize(attrs={})
|
||||
|
@ -385,6 +389,10 @@ module Fog
|
|||
@user_name ||= @vcloud_director_username.split('@').first
|
||||
end
|
||||
|
||||
def user_uuid
|
||||
@user_uuid ||= uuid
|
||||
end
|
||||
|
||||
def uuid
|
||||
[8,4,4,4,12].map {|i| Fog::Mock.random_hex(i)}.join('-')
|
||||
end
|
||||
|
|
44
lib/fog/vcloud_director/requests/compute/delete_media.rb
Normal file
44
lib/fog/vcloud_director/requests/compute/delete_media.rb
Normal file
|
@ -0,0 +1,44 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class VcloudDirector
|
||||
class Real
|
||||
# Delete a media object.
|
||||
#
|
||||
# This operation is asynchronous and returns a task that you can
|
||||
# monitor to track the progress of the request.
|
||||
#
|
||||
# @param [String] media_id Object identifier of the media object.
|
||||
# @return [Excon::Response]
|
||||
# * body<~Hash>:
|
||||
# @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/DELETE-Media.html
|
||||
# vCloud API Documentation
|
||||
# @since vCloud API version 0.9
|
||||
def delete_media(media_id)
|
||||
request(
|
||||
:expects => 202,
|
||||
:method => 'DELETE',
|
||||
:parser => Fog::ToHashDocument.new,
|
||||
:path => "media/#{media_id}"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def delete_media(media_id)
|
||||
response = Excon::Response.new
|
||||
|
||||
unless valid_uuid?(media_id)
|
||||
response.status = 400
|
||||
raise Excon::Errors.status_error({:expects => 202}, response)
|
||||
end
|
||||
unless data[:medias].has_key?(media_id)
|
||||
response.status = 403
|
||||
raise Excon::Errors.status_error({:expects => 202}, response)
|
||||
end
|
||||
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
42
lib/fog/vcloud_director/requests/compute/get_media.rb
Normal file
42
lib/fog/vcloud_director/requests/compute/get_media.rb
Normal file
|
@ -0,0 +1,42 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class VcloudDirector
|
||||
class Real
|
||||
# Retrieve a media object.
|
||||
#
|
||||
# @param [String] media_id Object identifier of the media object.
|
||||
# @return [Excon::Response]
|
||||
# * body<~Hash>:
|
||||
# @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/GET-Media.html
|
||||
# vCloud API Documentation
|
||||
# @since vCloud API version 0.9
|
||||
def get_media(media_id)
|
||||
request(
|
||||
:expects => 200,
|
||||
:idempotent => true,
|
||||
:method => 'GET',
|
||||
:parser => Fog::ToHashDocument.new,
|
||||
:path => "media/#{media_id}"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def get_media(media_id)
|
||||
response = Excon::Response.new
|
||||
|
||||
unless valid_uuid?(media_id)
|
||||
response.status = 400
|
||||
raise Excon::Errors.status_error({:expects => 200}, response)
|
||||
end
|
||||
unless data[:medias].has_key?(media_id)
|
||||
response.status = 403
|
||||
raise Excon::Errors.status_error({:expects => 200}, response)
|
||||
end
|
||||
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
42
lib/fog/vcloud_director/requests/compute/get_media_owner.rb
Normal file
42
lib/fog/vcloud_director/requests/compute/get_media_owner.rb
Normal file
|
@ -0,0 +1,42 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class VcloudDirector
|
||||
class Real
|
||||
# Retrieve the owner of a media object.
|
||||
#
|
||||
# @param [String] media_id Object identifier of the media object.
|
||||
# @return [Excon::Response]
|
||||
# * body<~Hash>:
|
||||
# @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/GET-MediaOwner.html
|
||||
# vCloud API Documentation
|
||||
# @since vCloud API version 1.5
|
||||
def get_media_owner(media_id)
|
||||
request(
|
||||
:expects => 200,
|
||||
:idempotent => true,
|
||||
:method => 'GET',
|
||||
:parser => Fog::ToHashDocument.new,
|
||||
:path => "media/#{media_id}/owner"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def get_media_owner(media_id)
|
||||
response = Excon::Response.new
|
||||
|
||||
unless valid_uuid?(media_id)
|
||||
response.status = 400
|
||||
raise Excon::Errors.status_error({:expects => 200}, response)
|
||||
end
|
||||
unless data[:medias].has_key?(media_id)
|
||||
response.status = 403
|
||||
raise Excon::Errors.status_error({:expects => 200}, response)
|
||||
end
|
||||
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,66 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class VcloudDirector
|
||||
class Real
|
||||
# Upload a media image.
|
||||
#
|
||||
# The response includes an upload link for the media image.
|
||||
#
|
||||
# @param [String] vdc_id Object identifier of the vDC.
|
||||
# @param [String] name The name of the media image.
|
||||
# @param [String] image_type Media image type. One of: iso, floppy.
|
||||
# @param [Integer] size Size of the media file, in bytes.
|
||||
# @param [Hash] options
|
||||
# @option options [String] :Description Optional description.
|
||||
# @return [Excon::Response]
|
||||
# * body<~Hash>:
|
||||
# @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/POST-UploadMedia.html
|
||||
# vCloud API Documentation
|
||||
# @since vCloud API version 0.9
|
||||
def post_upload_media(vdc_id, name, image_type, size, options={})
|
||||
body = <<-END
|
||||
<Media xmlns="http://www.vmware.com/vcloud/v1.5"
|
||||
name="#{name}"
|
||||
imageType="#{image_type}"
|
||||
size="#{size}">
|
||||
</Media>
|
||||
END
|
||||
|
||||
request(
|
||||
:body => body,
|
||||
:expects => 201,
|
||||
:headers => {'Content-Type' => 'application/vnd.vmware.vcloud.media+xml'},
|
||||
:method => 'POST',
|
||||
:parser => Fog::ToHashDocument.new,
|
||||
:path => "vdc/#{vdc_id}/media"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
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)
|
||||
end
|
||||
unless size =~ /^\d+$/
|
||||
response.status = 400
|
||||
raise Excon::Errors.status_error({:expects => 201}, response)
|
||||
end
|
||||
unless data[:vdcs].has_key?(vdc_id)
|
||||
response.status = 403
|
||||
raise Excon::Errors.status_error({:expects => 201}, response)
|
||||
end
|
||||
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
57
tests/vcloud_director/requests/compute/media_tests.rb
Normal file
57
tests/vcloud_director/requests/compute/media_tests.rb
Normal file
|
@ -0,0 +1,57 @@
|
|||
Shindo.tests('Compute::VcloudDirector | media requests', ['vclouddirector']) do
|
||||
|
||||
@service = Fog::Compute::VcloudDirector.new
|
||||
|
||||
tests('Get current organization') do
|
||||
session = @service.get_current_session.body
|
||||
link = session[:Link].detect do |l|
|
||||
l[:type] == 'application/vnd.vmware.vcloud.org+xml'
|
||||
end
|
||||
@org = @service.get_organization(link[:href].split('/').last).body
|
||||
end
|
||||
|
||||
tests('Each vDC') do
|
||||
@org[:Link].select do |l|
|
||||
l[:type] == 'application/vnd.vmware.vcloud.vdc+xml'
|
||||
end.each do |link|
|
||||
@vdc = @service.get_vdc(link[:href].split('/').last).body
|
||||
if @vdc[:ResourceEntities].is_a?(String)
|
||||
@vdc[:ResourceEntities] = {:ResourceEntity => []}
|
||||
elsif @vdc[:ResourceEntities][:ResourceEntity].is_a?(Hash)
|
||||
@vdc[:ResourceEntities][:ResourceEntity] = [@vdc[:ResourceEntities][:ResourceEntity]]
|
||||
end
|
||||
tests('Each Media') do
|
||||
@vdc[:ResourceEntities][:ResourceEntity].select do |r|
|
||||
r[:type] == 'application/vnd.vmware.vcloud.media+xml'
|
||||
end.each do |m|
|
||||
@media_id = m[:href].split('/').last
|
||||
tests("#get_media(#{@media_id})").data_matches_schema(VcloudDirector::Compute::Schema::MEDIA_TYPE) do
|
||||
pending if Fog.mocking?
|
||||
@service.get_media(@media_id).body
|
||||
end
|
||||
tests("#get_media_owner(#{@media_id})").data_matches_schema(VcloudDirector::Compute::Schema::OWNER_TYPE) do
|
||||
pending if Fog.mocking?
|
||||
@service.get_media_owner(@media_id).body
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
tests('Upload to non-existent vDC').raises(Excon::Errors::Forbidden) do
|
||||
@service.get_media('00000000-0000-0000-0000-000000000000')
|
||||
end
|
||||
|
||||
tests('Retrieve non-existent Media').raises(Excon::Errors::Forbidden) do
|
||||
@service.get_media('00000000-0000-0000-0000-000000000000')
|
||||
end
|
||||
|
||||
tests('Retrieve owner of non-existent Media').raises(Excon::Errors::Forbidden) do
|
||||
@service.get_media_owner('00000000-0000-0000-0000-000000000000')
|
||||
end
|
||||
|
||||
tests('Delete non-existent Media').raises(Excon::Errors::Forbidden) do
|
||||
@service.delete_media('00000000-0000-0000-0000-000000000000')
|
||||
end
|
||||
|
||||
end
|
|
@ -115,7 +115,7 @@ class VcloudDirector
|
|||
:status => Fog::Nullable::String,
|
||||
:Description => Fog::Nullable::String,
|
||||
# :Tasks => TASKS_IN_PROGRESS_TYPE,
|
||||
:Files => FILES_LIST_TYPE
|
||||
# :Files => FILES_LIST_TYPE
|
||||
})
|
||||
|
||||
# Container for references to ResourceEntity objects in this vDC.
|
||||
|
|
Loading…
Reference in a new issue