mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[vcloud_director] Mocking for vDC storage profiles.
This commit is contained in:
parent
67d9f862c3
commit
ee27759fa4
6 changed files with 104 additions and 23 deletions
|
@ -450,6 +450,13 @@ module Fog
|
|||
:name => 'vAppTemplate 1'
|
||||
}
|
||||
},
|
||||
:edge_gateways => {
|
||||
uuid => {
|
||||
:name => 'MockEdgeGateway',
|
||||
:networks => [uplink_network_uuid, default_network_uuid],
|
||||
:vdc => vdc_uuid
|
||||
}
|
||||
},
|
||||
:medias => {},
|
||||
:networks => {
|
||||
default_network_uuid => {
|
||||
|
@ -510,17 +517,20 @@ module Fog
|
|||
:uuid => uuid
|
||||
},
|
||||
:tasks => {},
|
||||
:vdcs => {
|
||||
vdc_uuid => {
|
||||
:description => 'vDC for mocking',
|
||||
:name => 'MockVDC'
|
||||
:vdc_storage_classes => {
|
||||
uuid => {
|
||||
:default => true,
|
||||
:enabled => true,
|
||||
:limit => 2 * 1024 * 1024,
|
||||
:name => 'DefaultMockStorageClass',
|
||||
:units => 'MB',
|
||||
:vdc => vdc_uuid,
|
||||
}
|
||||
},
|
||||
:edge_gateways => {
|
||||
uuid => {
|
||||
:name => 'MockEdgeGateway',
|
||||
:vdc => vdc_uuid,
|
||||
:networks => [uplink_network_uuid, default_network_uuid]
|
||||
:vdcs => {
|
||||
vdc_uuid => {
|
||||
:description => 'vDC for mocking',
|
||||
:name => 'MockVDC'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -136,12 +136,15 @@ module Fog
|
|||
body[:ResourceEntities][:ResourceEntity] = resources
|
||||
|
||||
if api_version.to_f >= 5.1
|
||||
# TODO
|
||||
#body[:VdcStorageProfiles] =
|
||||
# {:VdcStorageProfile=>
|
||||
# [{:type=>"application/vnd.vmware.vcloud.vdcStorageProfile+xml",
|
||||
# :name=>profile[:name],
|
||||
# :href=>make_href("vdcStorageProfile/#{profile[:uuid]}")}]}
|
||||
body[:VdcStorageProfiles] = {}
|
||||
body[:VdcStorageProfiles][:VdcStorageProfile] =
|
||||
data[:vdc_storage_classes].select do |id, storage_class|
|
||||
storage_class[:vdc] == vdc_id
|
||||
end.map do |id, storage_class|
|
||||
{:type => 'application/vnd.vmware.vcloud.vdcStorageProfile+xml',
|
||||
:name => storage_class[:name],
|
||||
:href => make_href("vdcStorageProfile/#{id}")}
|
||||
end
|
||||
end
|
||||
|
||||
response.status = 200
|
||||
|
|
|
@ -24,6 +24,42 @@ module Fog
|
|||
)
|
||||
end
|
||||
end
|
||||
|
||||
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)
|
||||
end
|
||||
|
||||
body =
|
||||
{:xmlns=>xmlns,
|
||||
:xmlns_xsi=>xmlns_xsi,
|
||||
:name=>vdc_storage_class[:name],
|
||||
:id=>"urn:vcloud:vdcstorageProfile:#{id}",
|
||||
:type=>"application/vnd.vmware.vcloud.vdcStorageProfile+xml",
|
||||
:href=>make_href("api/vdcStorageProfile/#{id}"),
|
||||
:xsi_schemaLocation=>xsi_schema_location,
|
||||
:Link=>
|
||||
[{:rel=>"up",
|
||||
:type=>"application/vnd.vmware.vcloud.vdc+xml",
|
||||
:href=>make_href("vdc/#{vdc_storage_class[:vdc]}")},
|
||||
{:rel=>"down",
|
||||
:type=>"application/vnd.vmware.vcloud.metadata+xml",
|
||||
:href=>make_href("vdcStorageProfile/#{id}/metadata")}],
|
||||
:Enabled=>vdc_storage_class[:enabled].to_s,
|
||||
:Units=>vdc_storage_class[:units],
|
||||
: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
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -218,7 +218,7 @@ class VcloudDirector
|
|||
|
||||
# Container for references to storage profiles associated with a vDC.
|
||||
VDC_STORAGE_PROFILES_TYPE = {
|
||||
:VdcStorageProfile => REFERENCE_TYPE
|
||||
:VdcStorageProfile => [REFERENCE_TYPE]
|
||||
}
|
||||
|
||||
# Allows you to specify certain capabilities of this virtual machine.
|
||||
|
@ -247,8 +247,7 @@ class VcloudDirector
|
|||
:imageType => String,
|
||||
:size => String,
|
||||
:Owner => OWNER_TYPE,
|
||||
# TODO:
|
||||
#:VdcStorageProfiles => VDC_STORAGE_PROFILES_TYPE # >= 5.1
|
||||
:VdcStorageProfile => REFERENCE_TYPE
|
||||
})
|
||||
|
||||
METADATA_TYPE = RESOURCE_TYPE.merge({
|
||||
|
@ -302,8 +301,15 @@ class VcloudDirector
|
|||
:UsedNetworkCount => String,
|
||||
:VmQuota => Fog::Nullable::String,
|
||||
:IsEnabled => Fog::Nullable::String,
|
||||
# TODO:
|
||||
#:VdcStorageProfiles => VDC_STORAGE_PROFILES_TYPE # >= 5.1
|
||||
:VdcStorageProfiles => VDC_STORAGE_PROFILES_TYPE # >= 5.1
|
||||
})
|
||||
|
||||
# Represents a storage profile in an organization vDC.
|
||||
VDC_STORAGE_PROFILE_TYPE = ENTITY_TYPE.merge({
|
||||
:Enabled => Fog::Nullable::String,
|
||||
:Units => String,
|
||||
:Limit => String,
|
||||
:Default => String
|
||||
})
|
||||
|
||||
# Information about an individual operating system.
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
Shindo.tests('Compute::VcloudDirector | vdc_storage_profile requests', ['vclouddirector']) do
|
||||
|
||||
@service = Fog::Compute::VcloudDirector.new
|
||||
@org = VcloudDirector::Compute::Helper.current_org(@service)
|
||||
@vdc_id = VcloudDirector::Compute::Helper.first_vdc_id(@org)
|
||||
@vdc = @service.get_vdc(@vdc_id).body
|
||||
|
||||
@vdc[:VdcStorageProfiles][:VdcStorageProfile] = [@vdc[:VdcStorageProfiles][:VdcStorageProfile]] if @vdc[:VdcStorageProfiles][:VdcStorageProfile].is_a?(Hash)
|
||||
@vdc[:VdcStorageProfiles][:VdcStorageProfile].each do |storage_profile|
|
||||
@vdc_storage_profile_id = storage_profile[:href].split('/').last
|
||||
|
||||
tests(storage_profile[:name]) do
|
||||
tests("#get_vdc_storage_class").data_matches_schema(VcloudDirector::Compute::Schema::VDC_STORAGE_PROFILE_TYPE) do
|
||||
@service.get_vdc_storage_class(@vdc_storage_profile_id).body
|
||||
end
|
||||
|
||||
tests('#get_vdc_storage_class_metadata').data_matches_schema(VcloudDirector::Compute::Schema::METADATA_TYPE) do
|
||||
pending if Fog.mocking?
|
||||
@service.get_vdc_storage_class_metadata(@vdc_storage_profile_id).body
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
tests('Retrieve non-existent vDC storage profile').raises(Excon::Errors::Forbidden) do
|
||||
@service.get_vdc_storage_class('00000000-0000-0000-0000-000000000000')
|
||||
end
|
||||
|
||||
end
|
|
@ -11,9 +11,7 @@ Shindo.tests('Compute::VcloudDirector | vdc requests', ['vclouddirector']) do
|
|||
vdc = @service.get_vdc(@vdc_id).body
|
||||
vdc[:AvailableNetworks][:Network] = [vdc[:AvailableNetworks][:Network]] if vdc[:AvailableNetworks][:Network].is_a?(Hash)
|
||||
vdc[:ResourceEntities][:ResourceEntity] = [vdc[:ResourceEntities][:ResourceEntity]] if vdc[:ResourceEntities][:ResourceEntity].is_a?(Hash)
|
||||
if vdc.has_key?(:VdcStorageProfiles)
|
||||
vdc[:VdcStorageProfiles][:VdcStorageProfile] = [vdc[:VdcStorageProfiles][:VdcStorageProfile]] if vdc[:VdcStorageProfiles][:VdcStorageProfile].is_a?(Hash)
|
||||
end
|
||||
vdc[:VdcStorageProfiles][:VdcStorageProfile] = [vdc[:VdcStorageProfiles][:VdcStorageProfile]] if vdc[:VdcStorageProfiles][:VdcStorageProfile].is_a?(Hash)
|
||||
vdc
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue