mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[vcloud_director] Do ensure_list in request methods.
Mitigation for Fog::ToHashDocument. This is (still) a short-term fix until we get to real response parsers.
This commit is contained in:
parent
94b3533ba5
commit
353b50acfc
40 changed files with 199 additions and 113 deletions
|
@ -308,10 +308,6 @@ module Fog
|
|||
items = item_list.map {|item| get_by_id(item[:id])}
|
||||
load(items)
|
||||
end
|
||||
|
||||
def ensure_list(items)
|
||||
items.is_a?(Hash) ? [items] : items
|
||||
end
|
||||
end
|
||||
|
||||
class Real
|
||||
|
@ -436,6 +432,23 @@ module Fog
|
|||
@vcloud_token = nil
|
||||
@org_name = nil
|
||||
end
|
||||
|
||||
# Compensate for Fog::ToHashDocument shortcomings.
|
||||
# @param [Hash] hash
|
||||
# @param [String,Symbol] key1
|
||||
# @param [String,Symbol] key2
|
||||
# @return [Hash]
|
||||
def ensure_list!(hash, key1, key2=nil)
|
||||
if key2.nil?
|
||||
hash[key1] ||= []
|
||||
hash[key1] = [hash[key1]] if hash[key1].is_a?(Hash)
|
||||
else
|
||||
hash[key1] ||= {key2 => []}
|
||||
hash[key1] = {key2 => []} if hash[key1].empty?
|
||||
hash[key1][key2] = [hash[key1][key2]] if hash[key1][key2].is_a?(Hash)
|
||||
end
|
||||
hash
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
|
|
@ -14,8 +14,10 @@ module Fog
|
|||
|
||||
def item_list
|
||||
data = service.get_catalog(catalog.id).body
|
||||
items = ensure_list(data[:CatalogItems][:CatalogItem]).select { |link| link[:type] == "application/vnd.vmware.vcloud.catalogItem+xml" }
|
||||
items.each{|item| service.add_id_from_href!(item) }
|
||||
items = data[:CatalogItems][:CatalogItem].select do |link|
|
||||
link[:type] == 'application/vnd.vmware.vcloud.catalogItem+xml'
|
||||
end
|
||||
items.each {|item| service.add_id_from_href!(item)}
|
||||
items
|
||||
end
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ module Fog
|
|||
def item_list
|
||||
data = service.get_vdc(vdc.id).body
|
||||
return [] if data[:ResourceEntities].empty?
|
||||
items = ensure_list(data[:ResourceEntities][:ResourceEntity]).select do |resource|
|
||||
items = data[:ResourceEntities][:ResourceEntity].select do |resource|
|
||||
resource[:type] == 'application/vnd.vmware.vcloud.media+xml'
|
||||
end
|
||||
items.each {|item| service.add_id_from_href!(item)}
|
||||
|
|
|
@ -19,7 +19,7 @@ module Fog
|
|||
|
||||
def item_list
|
||||
data = service.get_organizations.body
|
||||
orgs = ensure_list(data[:Org])
|
||||
orgs = data[:Org]
|
||||
orgs.each {|org| service.add_id_from_href!(org)}
|
||||
orgs
|
||||
end
|
||||
|
|
|
@ -21,8 +21,7 @@ module Fog
|
|||
|
||||
def item_list
|
||||
data = service.get_task_list(organization.id).body
|
||||
tasks = ensure_list(data[:Task])
|
||||
tasks.each {|task| service.add_id_from_href!(task)}
|
||||
data[:Task].each {|task| service.add_id_from_href!(task)}
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -22,7 +22,7 @@ module Fog
|
|||
def item_list
|
||||
data = service.get_vdc(vdc.id).body
|
||||
return [] if data[:ResourceEntities].empty?
|
||||
resource_entities = data[:ResourceEntities][:ResourceEntity].is_a?(Hash) ? [ data[:ResourceEntities][:ResourceEntity] ] : data[:ResourceEntities][:ResourceEntity]
|
||||
resource_entities = data[:ResourceEntities][:ResourceEntity]
|
||||
items = resource_entities.select { |link| link[:type] == "application/vnd.vmware.vcloud.vApp+xml" }
|
||||
items.each{|item| service.add_id_from_href!(item) }
|
||||
items
|
||||
|
|
|
@ -13,13 +13,15 @@ module Fog
|
|||
# @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)
|
||||
request(
|
||||
response = request(
|
||||
:expects => 200,
|
||||
:idempotent => true,
|
||||
:method => 'GET',
|
||||
:parser => Fog::ToHashDocument.new,
|
||||
:path => "catalog/#{id}"
|
||||
)
|
||||
ensure_list! response.body, :CatalogItems, :CatalogItem
|
||||
response
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -72,9 +72,10 @@ module Fog
|
|||
:path => 'catalogs/query',
|
||||
:query => query.map {|q| URI.escape(q)}.join('&')
|
||||
)
|
||||
response.body[:Link] = [response.body[:Link]] if response.body[:Link].is_a?(Hash)
|
||||
response.body[:CatalogRecord] = [response.body[:CatalogRecord]] if response.body[:CatalogRecord].is_a?(Hash)
|
||||
response.body[:CatalogRecord] ||= []
|
||||
ensure_list! response.body, :Link
|
||||
ensure_list! response.body,
|
||||
response.body[:type] == 'application/vnd.vmware.vcloud.query.references+xml' ?
|
||||
:CatalogReference : :CatalogRecord
|
||||
|
||||
%w[firstPage previousPage nextPage lastPage].each do |rel|
|
||||
if link = response.body[:Link].detect {|l| l[:rel] == rel}
|
||||
|
|
|
@ -72,9 +72,10 @@ module Fog
|
|||
:path => 'disks/query',
|
||||
:query => query.map {|q| URI.escape(q)}.join('&')
|
||||
)
|
||||
response.body[:Link] = [response.body[:Link]] if response.body[:Link].is_a?(Hash)
|
||||
response.body[:DiskRecord] = [response.body[:DiskRecord]] if response.body[:DiskRecord].is_a?(Hash)
|
||||
response.body[:DiskRecord] ||= []
|
||||
ensure_list! response.body, :Link
|
||||
ensure_list! response.body,
|
||||
response.body[:type] == 'application/vnd.vmware.vcloud.query.references+xml' ?
|
||||
:DiskReference : :DiskRecord
|
||||
|
||||
%w[firstPage previousPage nextPage lastPage].each do |rel|
|
||||
if link = response.body[:Link].detect {|l| l[:rel] == rel}
|
||||
|
|
|
@ -29,7 +29,7 @@ module Fog
|
|||
:parser => Fog::ToHashDocument.new,
|
||||
:path => "entity/#{id}"
|
||||
})
|
||||
response.body[:Link] = [response.body[:Link]] if response.body[:Link].is_a?(Hash)
|
||||
ensure_list! response.body, :Link
|
||||
response
|
||||
end
|
||||
end
|
||||
|
|
|
@ -95,10 +95,12 @@ module Fog
|
|||
:path => 'query',
|
||||
:query => query.map {|q| URI.escape(q)}.join('&')
|
||||
)
|
||||
response.body[:Link] = [response.body[:Link]] if response.body[:Link].is_a?(Hash)
|
||||
record = "#{response.body[:name]}Record".to_sym
|
||||
response.body[record] = [response.body[record]] if response.body[record].is_a?(Hash)
|
||||
response.body[record] ||= []
|
||||
ensure_list! response.body, :Link
|
||||
# TODO: figure out the right key (this isn't it)
|
||||
#ensure_list! response.body,
|
||||
# response.body[:type] == 'application/vnd.vmware.vcloud.query.references+xml' ?
|
||||
# "#{response.body[:name]}Reference".to_sym :
|
||||
# "#{response.body[:name]}Record".to_sym
|
||||
|
||||
%w[firstPage previousPage nextPage lastPage].each do |rel|
|
||||
if link = response.body[:Link].detect {|l| l[:rel] == rel}
|
||||
|
|
|
@ -73,9 +73,10 @@ module Fog
|
|||
:path => 'admin/groups/query',
|
||||
:query => query.map {|q| URI.escape(q)}.join('&')
|
||||
)
|
||||
response.body[:Link] = [response.body[:Link]] if response.body[:Link].is_a?(Hash)
|
||||
response.body[:GroupRecord] = [response.body[:GroupRecord]] if response.body[:GroupRecord].is_a?(Hash)
|
||||
response.body[:GroupRecord] ||= []
|
||||
ensure_list! response.body, :Link
|
||||
ensure_list! response.body,
|
||||
response.body[:type] == 'application/vnd.vmware.vcloud.query.references+xml' ?
|
||||
:GroupReference : :GroupRecord
|
||||
|
||||
%w[firstPage previousPage nextPage lastPage].each do |rel|
|
||||
if link = response.body[:Link].detect {|l| l[:rel] == rel}
|
||||
|
|
|
@ -72,9 +72,10 @@ module Fog
|
|||
:path => 'mediaList/query',
|
||||
:query => query.map {|q| URI.escape(q)}.join('&')
|
||||
)
|
||||
response.body[:Link] = [response.body[:Link]] if response.body[:Link].is_a?(Hash)
|
||||
response.body[:MediaRecord] = [response.body[:MediaRecord]] if response.body[:MediaRecord].is_a?(Hash)
|
||||
response.body[:MediaRecord] ||= []
|
||||
ensure_list! response.body, :Link
|
||||
ensure_list! response.body,
|
||||
response.body[:type] == 'application/vnd.vmware.vcloud.query.references+xml' ?
|
||||
:MediaReference : :MediaRecord
|
||||
|
||||
%w[firstPage previousPage nextPage lastPage].each do |rel|
|
||||
if link = response.body[:Link].detect {|l| l[:rel] == rel}
|
||||
|
|
|
@ -16,13 +16,15 @@ module Fog
|
|||
# @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)
|
||||
request(
|
||||
response = request(
|
||||
:expects => 200,
|
||||
:idempotent => true,
|
||||
:method => 'GET',
|
||||
:parser => Fog::ToHashDocument.new,
|
||||
:path => "admin/vdc/#{id}/edgeGateways"
|
||||
)
|
||||
ensure_list! response.body, :EdgeGatewayRecord
|
||||
response
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -20,8 +20,7 @@ module Fog
|
|||
:parser => Fog::ToHashDocument.new,
|
||||
:path => "org/#{id}"
|
||||
})
|
||||
response.body[:Tasks] ||= {:Task => []}
|
||||
response.body[:Tasks][:Task] = [response.body[:Tasks][:Task]] if response.body[:Tasks][:Task].is_a?(Hash)
|
||||
ensure_list! response.body, :Tasks, :Task
|
||||
response
|
||||
end
|
||||
end
|
||||
|
|
|
@ -25,7 +25,7 @@ module Fog
|
|||
:parser => Fog::ToHashDocument.new,
|
||||
:path => 'org'
|
||||
})
|
||||
response.body[:Org] = [response.body[:Org]] if response.body[:Org].is_a?(Hash)
|
||||
ensure_list! response.body, :Org
|
||||
response
|
||||
end
|
||||
end
|
||||
|
|
|
@ -73,9 +73,10 @@ module Fog
|
|||
:path => 'admin/orgs/query',
|
||||
:query => query.map {|q| URI.escape(q)}.join('&')
|
||||
)
|
||||
response.body[:Link] = [response.body[:Link]] if response.body[:Link].is_a?(Hash)
|
||||
response.body[:OrganizationRecord] = [response.body[:OrganizationRecord]] if response.body[:OrganizationRecord].is_a?(Hash)
|
||||
response.body[:OrganizationRecord] ||= []
|
||||
ensure_list! response.body, :Link
|
||||
ensure_list! response.body,
|
||||
response.body[:type] == 'application/vnd.vmware.vcloud.query.references+xml' ?
|
||||
:OrganizationReference : :OrganizationRecord
|
||||
|
||||
%w[firstPage previousPage nextPage lastPage].each do |rel|
|
||||
if link = response.body[:Link].detect {|l| l[:rel] == rel}
|
||||
|
|
|
@ -17,13 +17,15 @@ module Fog
|
|||
# @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)
|
||||
request(
|
||||
response = request(
|
||||
:expects => 200,
|
||||
:idempotent => true,
|
||||
:method => 'GET',
|
||||
:parser => Fog::ToHashDocument.new,
|
||||
:path => "tasksList/#{id}"
|
||||
)
|
||||
ensure_list! response.body, :Task
|
||||
response
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -73,9 +73,10 @@ module Fog
|
|||
:path => 'admin/users/query',
|
||||
:query => query.map {|q| URI.escape(q)}.join('&')
|
||||
)
|
||||
response.body[:Link] = [response.body[:Link]] if response.body[:Link].is_a?(Hash)
|
||||
response.body[:UserRecord] = [response.body[:UserRecord]] if response.body[:UserRecord].is_a?(Hash)
|
||||
response.body[:UserRecord] ||= []
|
||||
ensure_list! response.body, :Link
|
||||
ensure_list! response.body,
|
||||
response.body[:type] == 'application/vnd.vmware.vcloud.query.references+xml' ?
|
||||
:UserReference : :UserRecord
|
||||
|
||||
%w[firstPage previousPage nextPage lastPage].each do |rel|
|
||||
if link = response.body[:Link].detect {|l| l[:rel] == rel}
|
||||
|
|
|
@ -11,13 +11,15 @@ module Fog
|
|||
# @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/GET-VApp.html
|
||||
# @since vCloud API version 0.9
|
||||
def get_vapp(id)
|
||||
request(
|
||||
response = request(
|
||||
:expects => 200,
|
||||
:idempotent => true,
|
||||
:method => 'GET',
|
||||
:parser => Fog::ToHashDocument.new,
|
||||
:path => "vApp/#{id}"
|
||||
)
|
||||
ensure_list! response.body, :Children, :Vm
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -73,9 +73,10 @@ module Fog
|
|||
:path => 'vAppTemplates/query',
|
||||
:query => query.map {|q| URI.escape(q)}.join('&')
|
||||
)
|
||||
response.body[:Link] = [response.body[:Link]] if response.body[:Link].is_a?(Hash)
|
||||
response.body[:VAppTemplateRecord] = [response.body[:VAppTemplateRecord]] if response.body[:VAppTemplateRecord].is_a?(Hash)
|
||||
response.body[:VAppTemplateRecord] ||= []
|
||||
ensure_list! response.body, :Link
|
||||
ensure_list! response.body,
|
||||
response.body[:type] == 'application/vnd.vmware.vcloud.query.references+xml' ?
|
||||
:VAppTemplateReference : :VAppTemplateRecord
|
||||
|
||||
%w[firstPage previousPage nextPage lastPage].each do |rel|
|
||||
if link = response.body[:Link].detect {|l| l[:rel] == rel}
|
||||
|
|
|
@ -72,9 +72,10 @@ module Fog
|
|||
:path => 'vApps/query',
|
||||
:query => query.map {|q| URI.escape(q)}.join('&')
|
||||
)
|
||||
response.body[:Link] = [response.body[:Link]] if response.body[:Link].is_a?(Hash)
|
||||
response.body[:VAppRecord] = [response.body[:VAppRecord]] if response.body[:VAppRecord].is_a?(Hash)
|
||||
response.body[:VAppRecord] ||= []
|
||||
ensure_list! response.body, :Link
|
||||
ensure_list! response.body,
|
||||
response.body[:type] == 'application/vnd.vmware.vcloud.query.references+xml' ?
|
||||
:VAppReference : :VAppRecord
|
||||
|
||||
%w[firstPage previousPage nextPage lastPage].each do |rel|
|
||||
if link = response.body[:Link].detect {|l| l[:rel] == rel}
|
||||
|
|
|
@ -13,13 +13,17 @@ module Fog
|
|||
# @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)
|
||||
request(
|
||||
response = request(
|
||||
:expects => 200,
|
||||
:idempotent => true,
|
||||
:method => 'GET',
|
||||
:parser => Fog::ToHashDocument.new,
|
||||
:path => "vdc/#{id}"
|
||||
)
|
||||
ensure_list! response.body, :ResourceEntities, :ResourceEntity
|
||||
ensure_list! response.body, :AvailableNetworks, :Network
|
||||
ensure_list! response.body, :VdcStorageProfiles, :VdcStorageProfile
|
||||
response
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -117,22 +121,19 @@ module Fog
|
|||
:VmQuota=>"100",
|
||||
:IsEnabled=>"true"}
|
||||
|
||||
networks = data[:networks].map do |id, network|
|
||||
{:type=>"application/vnd.vmware.vcloud.network+xml",
|
||||
:name=>network[:name],
|
||||
:href=>make_href("network/#{id}")}
|
||||
end
|
||||
networks = networks.first if networks.size == 1
|
||||
body[:AvailableNetworks][:Network] = networks
|
||||
body[:ResourceEntities][:ResourceEntity] =
|
||||
data[:catalog_items].map do |id, item|
|
||||
{:type=>"application/vnd.vmware.vcloud.#{item[:type]}+xml",
|
||||
:name=>item[:name],
|
||||
:href=>make_href("#{item[:type]}/#{item[:type]}-#{id}")}
|
||||
end
|
||||
|
||||
resources = data[:catalog_items].map do |id, item|
|
||||
{:type=>"application/vnd.vmware.vcloud.#{item[:type]}+xml",
|
||||
:name=>item[:name],
|
||||
:href=>
|
||||
make_href("#{item[:type]}/#{item[:type]}-#{id}")}
|
||||
body[:AvailableNetworks][:Network] =
|
||||
data[:networks].map do |id, network|
|
||||
{:type=>"application/vnd.vmware.vcloud.network+xml",
|
||||
:name=>network[:name],
|
||||
:href=>make_href("network/#{id}")}
|
||||
end
|
||||
resources = resources.first if resources.size == 1
|
||||
body[:ResourceEntities][:ResourceEntity] = resources
|
||||
|
||||
if api_version.to_f >= 5.1
|
||||
body[:VdcStorageProfiles] = {}
|
||||
|
|
|
@ -72,9 +72,10 @@ module Fog
|
|||
:path => 'admin/vdcs/query',
|
||||
:query => query.map {|q| URI.escape(q)}.join('&')
|
||||
)
|
||||
response.body[:Link] = [response.body[:Link]] if response.body[:Link].is_a?(Hash)
|
||||
response.body[:OrgVdcRecord] = [response.body[:OrgVdcRecord]] if response.body[:OrgVdcRecord].is_a?(Hash)
|
||||
response.body[:OrgVdcRecord] ||= []
|
||||
ensure_list! response.body, :Link
|
||||
ensure_list! response.body,
|
||||
response.body[:type] == 'application/vnd.vmware.vcloud.query.references+xml' ?
|
||||
:OrgVdcReference : :OrgVdcRecord
|
||||
|
||||
%w[firstPage previousPage nextPage lastPage].each do |rel|
|
||||
if link = response.body[:Link].detect {|l| l[:rel] == rel}
|
||||
|
|
|
@ -73,9 +73,10 @@ module Fog
|
|||
:path => 'vms/query',
|
||||
:query => query.map {|q| URI.escape(q)}.join('&')
|
||||
)
|
||||
response.body[:Link] = [response.body[:Link]] if response.body[:Link].is_a?(Hash)
|
||||
response.body[:VMRecord] = [response.body[:VMRecord]] if response.body[:VMRecord].is_a?(Hash)
|
||||
response.body[:VMRecord] ||= []
|
||||
ensure_list! response.body, :Link
|
||||
ensure_list! response.body,
|
||||
response.body[:type] == 'application/vnd.vmware.vcloud.query.references+xml' ?
|
||||
:VMReference : :VMRecord
|
||||
|
||||
%w[firstPage previousPage nextPage lastPage].each do |rel|
|
||||
if link = response.body[:Link].detect {|l| l[:rel] == rel}
|
||||
|
|
|
@ -2,9 +2,11 @@ require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
|||
|
||||
Shindo.tests("Compute::VcloudDirector | catalog_items", ['vclouddirector', 'all']) do
|
||||
pending if Fog.mocking?
|
||||
tests("#There is more than one catalog").returns(true){ catalog.catalog_items.size >= 1 }
|
||||
|
||||
pending if catalog.nil?
|
||||
catalog_items = catalog.catalog_items
|
||||
pending if catalog_items.empty?
|
||||
tests("#There is one or more catalog item").returns(true) { catalog_items.size >= 1 }
|
||||
catalog_item = catalog_items.first
|
||||
|
||||
tests("Compute::VcloudDirector | catalog_item") do
|
||||
|
|
|
@ -2,9 +2,10 @@ require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
|||
|
||||
Shindo.tests("Compute::VcloudDirector | catalogs", ['vclouddirector', 'all']) do
|
||||
pending if Fog.mocking?
|
||||
tests("#There is one or more catalog").returns(true){ organization.catalogs.size >= 1 }
|
||||
|
||||
pending if organization.catalogs.empty?
|
||||
catalogs = organization.catalogs
|
||||
tests("#There is one or more catalog").returns(true) { catalogs.size >= 1 }
|
||||
catalog = catalogs.first
|
||||
|
||||
tests("Compute::VcloudDirector | catalog") do
|
||||
|
|
|
@ -22,9 +22,17 @@ Shindo.tests('Compute::VcloudDirector | catalog requests', ['vclouddirector']) d
|
|||
@service.get_control_access_params_catalog(@org[:href].split('/').last, @catalog_id).body
|
||||
end
|
||||
|
||||
tests('#get_catalogs_from_query').data_matches_schema(VcloudDirector::Compute::Schema::CONTAINER_TYPE) do
|
||||
tests('#get_catalogs_from_query') do
|
||||
pending if Fog.mocking?
|
||||
@service.get_catalogs_from_query.body
|
||||
%w[idrecords records references].each do |format|
|
||||
tests(":format => #{format}") do
|
||||
tests('#body').data_matches_schema(VcloudDirector::Compute::Schema::CONTAINER_TYPE) do
|
||||
@body = @service.get_catalogs_from_query(:format => format).body
|
||||
end
|
||||
key = (format == 'references') ? 'CatalogReference' : 'CatalogRecord'
|
||||
tests("#body.key?(:#{key})").returns(true) { @body.key?(key.to_sym) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
tests('Retrieve non-existent Catalog').raises(Fog::Compute::VcloudDirector::Forbidden) do
|
||||
|
|
|
@ -2,9 +2,17 @@ Shindo.tests('Compute::VcloudDirector | disk requests', ['vclouddirector']) do
|
|||
|
||||
@service = Fog::Compute::VcloudDirector.new
|
||||
|
||||
tests('#get_disks_from_query').data_matches_schema(VcloudDirector::Compute::Schema::CONTAINER_TYPE) do
|
||||
tests('#get_disks_from_query') do
|
||||
pending if Fog.mocking?
|
||||
@service.get_disks_from_query.body
|
||||
%w[idrecords records references].each do |format|
|
||||
tests(":format => #{format}") do
|
||||
tests('#body').data_matches_schema(VcloudDirector::Compute::Schema::CONTAINER_TYPE) do
|
||||
@body = @service.get_disks_from_query(:format => format).body
|
||||
end
|
||||
key = (format == 'references') ? 'DiskReference' : 'DiskRecord'
|
||||
tests("#body.key?(:#{key})").returns(true) { @body.key?(key.to_sym) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
tests('Retrieve non-existent Disk').raises(Fog::Compute::VcloudDirector::Forbidden) do
|
||||
|
|
|
@ -16,12 +16,6 @@ Shindo.tests('Compute::VcloudDirector | edge gateway requests', ['vclouddirector
|
|||
rescue Fog::Compute::VcloudDirector::Unauthorized # bug, may be localised
|
||||
retry
|
||||
end
|
||||
|
||||
# ensure that EdgeGatewayRecord is a list
|
||||
if @edge_gateways[:EdgeGatewayRecord].is_a?(Hash)
|
||||
@edge_gateways[:EdgeGatewayRecord] = [@edge_gateways[:EdgeGatewayRecord]]
|
||||
end
|
||||
|
||||
@edge_gateways
|
||||
end
|
||||
|
||||
|
|
|
@ -2,9 +2,17 @@ Shindo.tests('Compute::VcloudDirector | groups requests', ['vclouddirector']) do
|
|||
|
||||
@service = Fog::Compute::VcloudDirector.new
|
||||
|
||||
tests('#get_groups_from_query').data_matches_schema(VcloudDirector::Compute::Schema::CONTAINER_TYPE) do
|
||||
tests('#get_groups_from_query') do
|
||||
pending if Fog.mocking?
|
||||
@service.get_groups_from_query.body
|
||||
%w[idrecords records references].each do |format|
|
||||
tests(":format => #{format}") do
|
||||
tests('#body').data_matches_schema(VcloudDirector::Compute::Schema::CONTAINER_TYPE) do
|
||||
@body = @service.get_groups_from_query(:format => format).body
|
||||
end
|
||||
key = (format == 'references') ? 'GroupReference' : 'GroupRecord'
|
||||
tests("#body.key?(:#{key})").returns(true) { @body.key?(key.to_sym) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -153,9 +153,17 @@ Shindo.tests('Compute::VcloudDirector | media requests', ['vclouddirector']) do
|
|||
end
|
||||
end
|
||||
|
||||
tests('#get_medias_from_query').data_matches_schema(VcloudDirector::Compute::Schema::CONTAINER_TYPE) do
|
||||
tests('#get_medias_from_query') do
|
||||
pending if Fog.mocking?
|
||||
@service.get_medias_from_query.body
|
||||
%w[idrecords records references].each do |format|
|
||||
tests(":format => #{format}") do
|
||||
tests('#body').data_matches_schema(VcloudDirector::Compute::Schema::CONTAINER_TYPE) do
|
||||
@body = @service.get_medias_from_query(:format => format).body
|
||||
end
|
||||
key = (format == 'references') ? 'MediaReference' : 'MediaRecord'
|
||||
tests("#body.key?(:#{key})").returns(true) { @body.key?(key.to_sym) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
tests('Invalid image_type').raises(Fog::Compute::VcloudDirector::BadRequest) do
|
||||
|
|
|
@ -17,9 +17,17 @@ Shindo.tests('Compute::VcloudDirector | organization requests', ['vclouddirector
|
|||
@service.get_organization_metadata(@org_uuid).body
|
||||
end
|
||||
|
||||
tests('#get_organizations_from_query').data_matches_schema(VcloudDirector::Compute::Schema::CONTAINER_TYPE) do
|
||||
tests('#get_organizations_from_query') do
|
||||
pending if Fog.mocking?
|
||||
@service.get_organizations_from_query.body
|
||||
%w[idrecords records references].each do |format|
|
||||
tests(":format => #{format}") do
|
||||
tests('#body').data_matches_schema(VcloudDirector::Compute::Schema::CONTAINER_TYPE) do
|
||||
@body = @service.get_organizations_from_query(:format => format).body
|
||||
end
|
||||
key = (format == 'references') ? 'OrganizationReference' : 'OrganizationRecord'
|
||||
tests("#body.key?(:#{key})").returns(true) { @body.key?(key.to_sym) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
tests('retrieve non-existent Org').raises(Fog::Compute::VcloudDirector::Forbidden) do
|
||||
|
|
|
@ -9,7 +9,6 @@ Shindo.tests('Compute::VcloudDirector | ovf requests', ['vclouddirector']) do
|
|||
l[:type] == 'application/vnd.vmware.vcloud.vdc+xml'
|
||||
end
|
||||
@vdc = @service.get_vdc(link[:href].split('/').last).body
|
||||
@vdc[:ResourceEntities][:ResourceEntity] = [@vdc[:ResourceEntities][:ResourceEntity]] if @vdc[:ResourceEntities][:ResourceEntity].is_a?(Hash)
|
||||
end
|
||||
|
||||
# 'Envelope' is the outer type of the parsed XML document.
|
||||
|
|
|
@ -148,7 +148,7 @@ class VcloudDirector
|
|||
|
||||
VAPP_CHILDREN_TYPE = {
|
||||
#:VApp => ABSTRACT_VAPP_TYPE,
|
||||
:Vm => ABSTRACT_VAPP_TYPE
|
||||
:Vm => [ABSTRACT_VAPP_TYPE]
|
||||
}
|
||||
|
||||
# Controls access to the resource.
|
||||
|
@ -286,7 +286,6 @@ class VcloudDirector
|
|||
TASKS_LIST_TYPE = ENTITY_TYPE.merge({
|
||||
#:Task => TASK_TYPE
|
||||
})
|
||||
|
||||
# Represents a vApp.
|
||||
VAPP_TYPE = ABSTRACT_VAPP_TYPE.merge({
|
||||
:ovfDescriptorUploaded => String,
|
||||
|
|
|
@ -2,9 +2,17 @@ Shindo.tests('Compute::VcloudDirector | users requests', ['vclouddirector']) do
|
|||
|
||||
@service = Fog::Compute::VcloudDirector.new
|
||||
|
||||
tests('#get_users_from_query').data_matches_schema(VcloudDirector::Compute::Schema::CONTAINER_TYPE) do
|
||||
tests('#get_users_from_query') do
|
||||
pending if Fog.mocking?
|
||||
@service.get_users_from_query.body
|
||||
%w[idrecords records references].each do |format|
|
||||
tests(":format => #{format}") do
|
||||
tests('#body').data_matches_schema(VcloudDirector::Compute::Schema::CONTAINER_TYPE) do
|
||||
@body = @service.get_users_from_query(:format => format).body
|
||||
end
|
||||
key = (format == 'references') ? 'UserReference' : 'UserRecord'
|
||||
tests("#body.key?(:#{key})").returns(true) { @body.key?(key.to_sym) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -8,11 +8,6 @@ Shindo.tests('Compute::VcloudDirector | vapp requests', ['vclouddirector']) do
|
|||
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 vApp') do
|
||||
@vdc[:ResourceEntities][:ResourceEntity].select do |r|
|
||||
r[:type] == 'application/vnd.vmware.vcloud.vApp+xml'
|
||||
|
@ -65,9 +60,17 @@ Shindo.tests('Compute::VcloudDirector | vapp requests', ['vclouddirector']) do
|
|||
end
|
||||
end
|
||||
|
||||
tests('#get_vapps_in_lease_from_query').data_matches_schema(VcloudDirector::Compute::Schema::CONTAINER_TYPE) do
|
||||
tests('#get_vapps_in_lease_from_query') do
|
||||
pending if Fog.mocking?
|
||||
@service.get_vapps_in_lease_from_query.body
|
||||
%w[idrecords records references].each do |format|
|
||||
tests(":format => #{format}") do
|
||||
tests('#body').data_matches_schema(VcloudDirector::Compute::Schema::CONTAINER_TYPE) do
|
||||
@body = @service.get_vapps_in_lease_from_query(:format => format).body
|
||||
end
|
||||
key = (format == 'references') ? 'VAppReference' : 'VAppRecord'
|
||||
tests("#body.key?(:#{key})").returns(true) { @body.key?(key.to_sym) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
tests('Retrieve non-existent vApp').raises(Fog::Compute::VcloudDirector::Forbidden) do
|
||||
|
|
|
@ -5,7 +5,6 @@ Shindo.tests('Compute::VcloudDirector | vdc_storage_profile requests', ['vcloudd
|
|||
@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
|
||||
|
||||
|
|
|
@ -8,11 +8,7 @@ Shindo.tests('Compute::VcloudDirector | vdc requests', ['vclouddirector']) do
|
|||
l[:rel] == 'down' && l[:type] == 'application/vnd.vmware.vcloud.vdc+xml'
|
||||
end
|
||||
@vdc_id = link[:href].split('/').last
|
||||
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)
|
||||
vdc[:VdcStorageProfiles][:VdcStorageProfile] = [vdc[:VdcStorageProfiles][:VdcStorageProfile]] if vdc[:VdcStorageProfiles][:VdcStorageProfile].is_a?(Hash)
|
||||
vdc
|
||||
@service.get_vdc(@vdc_id).body
|
||||
end
|
||||
|
||||
tests('#get_vdc_metadata').data_matches_schema(VcloudDirector::Compute::Schema::METADATA_TYPE) do
|
||||
|
@ -20,9 +16,17 @@ Shindo.tests('Compute::VcloudDirector | vdc requests', ['vclouddirector']) do
|
|||
@service.get_vdc_metadata(@vdc_id).body
|
||||
end
|
||||
|
||||
tests('#get_vdcs_from_query').data_matches_schema(VcloudDirector::Compute::Schema::CONTAINER_TYPE) do
|
||||
tests('#get_vdcs_from_query') do
|
||||
pending if Fog.mocking?
|
||||
@service.get_vdcs_from_query.body
|
||||
%w[idrecords records references].each do |format|
|
||||
tests(":format => #{format}") do
|
||||
tests('#body').data_matches_schema(VcloudDirector::Compute::Schema::CONTAINER_TYPE) do
|
||||
@body = @service.get_vdcs_from_query(:format => format).body
|
||||
end
|
||||
key = (format == 'references') ? 'OrgVdcReference' : 'OrgVdcRecord'
|
||||
tests("#body.key?(:#{key})").returns(true) { @body.key?(key.to_sym) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
tests('Retrieve non-existent vDC').raises(Fog::Compute::VcloudDirector::Forbidden) do
|
||||
|
|
|
@ -8,11 +8,6 @@ Shindo.tests('Compute::VcloudDirector | vm requests', ['vclouddirector']) do
|
|||
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 vApp') do
|
||||
@vdc[:ResourceEntities][:ResourceEntity].select do |r|
|
||||
r[:type] == 'application/vnd.vmware.vcloud.vApp+xml'
|
||||
|
@ -100,9 +95,17 @@ Shindo.tests('Compute::VcloudDirector | vm requests', ['vclouddirector']) do
|
|||
end
|
||||
end
|
||||
|
||||
tests('#get_vms_in_lease_from_query').data_matches_schema(VcloudDirector::Compute::Schema::CONTAINER_TYPE) do
|
||||
tests('#get_vms_in_lease_from_query') do
|
||||
pending if Fog.mocking?
|
||||
@service.get_vms_in_lease_from_query.body
|
||||
%w[idrecords records references].each do |format|
|
||||
tests(":format => #{format}") do
|
||||
tests('#body').data_matches_schema(VcloudDirector::Compute::Schema::CONTAINER_TYPE) do
|
||||
@body = @service.get_vms_in_lease_from_query(:format => format).body
|
||||
end
|
||||
key = (format == 'references') ? 'VMReference' : 'VMRecord'
|
||||
tests("#body.key?(:#{key})").returns(true) { @body.key?(key.to_sym) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#tests('Retrieve non-existent vApp').raises(Fog::Compute::VcloudDirector::Forbidden) do
|
||||
|
|
Loading…
Add table
Reference in a new issue