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'
|
:name => 'vAppTemplate 1'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
:edge_gateways => {
|
||||||
|
uuid => {
|
||||||
|
:name => 'MockEdgeGateway',
|
||||||
|
:networks => [uplink_network_uuid, default_network_uuid],
|
||||||
|
:vdc => vdc_uuid
|
||||||
|
}
|
||||||
|
},
|
||||||
:medias => {},
|
:medias => {},
|
||||||
:networks => {
|
:networks => {
|
||||||
default_network_uuid => {
|
default_network_uuid => {
|
||||||
|
@ -510,17 +517,20 @@ module Fog
|
||||||
:uuid => uuid
|
:uuid => uuid
|
||||||
},
|
},
|
||||||
:tasks => {},
|
:tasks => {},
|
||||||
:vdcs => {
|
:vdc_storage_classes => {
|
||||||
vdc_uuid => {
|
uuid => {
|
||||||
:description => 'vDC for mocking',
|
:default => true,
|
||||||
:name => 'MockVDC'
|
:enabled => true,
|
||||||
|
:limit => 2 * 1024 * 1024,
|
||||||
|
:name => 'DefaultMockStorageClass',
|
||||||
|
:units => 'MB',
|
||||||
|
:vdc => vdc_uuid,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
:edge_gateways => {
|
:vdcs => {
|
||||||
uuid => {
|
vdc_uuid => {
|
||||||
:name => 'MockEdgeGateway',
|
:description => 'vDC for mocking',
|
||||||
:vdc => vdc_uuid,
|
:name => 'MockVDC'
|
||||||
:networks => [uplink_network_uuid, default_network_uuid]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -136,12 +136,15 @@ module Fog
|
||||||
body[:ResourceEntities][:ResourceEntity] = resources
|
body[:ResourceEntities][:ResourceEntity] = resources
|
||||||
|
|
||||||
if api_version.to_f >= 5.1
|
if api_version.to_f >= 5.1
|
||||||
# TODO
|
body[:VdcStorageProfiles] = {}
|
||||||
#body[:VdcStorageProfiles] =
|
body[:VdcStorageProfiles][:VdcStorageProfile] =
|
||||||
# {:VdcStorageProfile=>
|
data[:vdc_storage_classes].select do |id, storage_class|
|
||||||
# [{:type=>"application/vnd.vmware.vcloud.vdcStorageProfile+xml",
|
storage_class[:vdc] == vdc_id
|
||||||
# :name=>profile[:name],
|
end.map do |id, storage_class|
|
||||||
# :href=>make_href("vdcStorageProfile/#{profile[:uuid]}")}]}
|
{:type => 'application/vnd.vmware.vcloud.vdcStorageProfile+xml',
|
||||||
|
:name => storage_class[:name],
|
||||||
|
:href => make_href("vdcStorageProfile/#{id}")}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
response.status = 200
|
response.status = 200
|
||||||
|
|
|
@ -24,6 +24,42 @@ module Fog
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -218,7 +218,7 @@ class VcloudDirector
|
||||||
|
|
||||||
# Container for references to storage profiles associated with a vDC.
|
# Container for references to storage profiles associated with a vDC.
|
||||||
VDC_STORAGE_PROFILES_TYPE = {
|
VDC_STORAGE_PROFILES_TYPE = {
|
||||||
:VdcStorageProfile => REFERENCE_TYPE
|
:VdcStorageProfile => [REFERENCE_TYPE]
|
||||||
}
|
}
|
||||||
|
|
||||||
# Allows you to specify certain capabilities of this virtual machine.
|
# Allows you to specify certain capabilities of this virtual machine.
|
||||||
|
@ -247,8 +247,7 @@ class VcloudDirector
|
||||||
:imageType => String,
|
:imageType => String,
|
||||||
:size => String,
|
:size => String,
|
||||||
:Owner => OWNER_TYPE,
|
:Owner => OWNER_TYPE,
|
||||||
# TODO:
|
:VdcStorageProfile => REFERENCE_TYPE
|
||||||
#:VdcStorageProfiles => VDC_STORAGE_PROFILES_TYPE # >= 5.1
|
|
||||||
})
|
})
|
||||||
|
|
||||||
METADATA_TYPE = RESOURCE_TYPE.merge({
|
METADATA_TYPE = RESOURCE_TYPE.merge({
|
||||||
|
@ -302,8 +301,15 @@ class VcloudDirector
|
||||||
:UsedNetworkCount => String,
|
:UsedNetworkCount => String,
|
||||||
:VmQuota => Fog::Nullable::String,
|
:VmQuota => Fog::Nullable::String,
|
||||||
:IsEnabled => 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.
|
# 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 = @service.get_vdc(@vdc_id).body
|
||||||
vdc[:AvailableNetworks][:Network] = [vdc[:AvailableNetworks][:Network]] if vdc[:AvailableNetworks][:Network].is_a?(Hash)
|
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)
|
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)
|
||||||
vdc[:VdcStorageProfiles][:VdcStorageProfile] = [vdc[:VdcStorageProfiles][:VdcStorageProfile]] if vdc[:VdcStorageProfiles][:VdcStorageProfile].is_a?(Hash)
|
|
||||||
end
|
|
||||||
vdc
|
vdc
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue