2013-06-12 12:50:31 -04:00
|
|
|
module Fog
|
2013-06-18 10:57:32 -04:00
|
|
|
module Compute
|
2013-08-27 05:19:54 -04:00
|
|
|
class VcloudDirector
|
2013-06-12 12:50:31 -04:00
|
|
|
class Real
|
2013-09-27 11:32:49 -04:00
|
|
|
# Retrieve a vDC.
|
|
|
|
#
|
2013-10-08 13:46:06 -04:00
|
|
|
# @param [String] id Object identifier of the vDC.
|
2013-09-27 11:32:49 -04:00
|
|
|
# @return [Excon::Response]
|
|
|
|
# * body<~Hash>:
|
2013-10-13 15:23:24 -04:00
|
|
|
#
|
2013-10-13 15:46:41 -04:00
|
|
|
# @raise [Fog::Compute::VcloudDirector::Forbidden]
|
|
|
|
#
|
2013-09-27 11:32:49 -04:00
|
|
|
# @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/GET-Vdc.html
|
2013-09-29 13:57:18 -04:00
|
|
|
# @since vCloud API version 0.9
|
2013-10-08 13:46:06 -04:00
|
|
|
def get_vdc(id)
|
2013-06-12 12:50:31 -04:00
|
|
|
request(
|
2013-09-29 13:57:18 -04:00
|
|
|
:expects => 200,
|
|
|
|
:idempotent => true,
|
|
|
|
:method => 'GET',
|
|
|
|
:parser => Fog::ToHashDocument.new,
|
2013-10-08 13:46:06 -04:00
|
|
|
:path => "vdc/#{id}"
|
2013-06-12 12:50:31 -04:00
|
|
|
)
|
|
|
|
end
|
2013-09-26 06:29:51 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
class Mock
|
|
|
|
def get_vdc(vdc_id)
|
2013-09-27 11:32:49 -04:00
|
|
|
response = Excon::Response.new
|
|
|
|
|
2013-09-29 16:27:58 -04:00
|
|
|
unless vdc = data[:vdcs][vdc_id]
|
2013-10-13 15:46:41 -04:00
|
|
|
raise Fog::Compute::VcloudDirector::Forbidden.new(
|
|
|
|
"No access to entity \"com.vmware.vcloud.entity.vdc:#{vdc_id}\"."
|
|
|
|
)
|
2013-09-27 11:32:49 -04:00
|
|
|
end
|
2013-09-26 06:29:51 -04:00
|
|
|
|
|
|
|
body =
|
|
|
|
{:xmlns=>xmlns,
|
|
|
|
:xmlns_xsi=>xmlns_xsi,
|
|
|
|
:status=>"1",
|
|
|
|
:name=>vdc[:name],
|
2013-09-29 16:27:58 -04:00
|
|
|
:id=>"urn:vcloud:vdc:#{vdc_id}",
|
2013-09-26 06:29:51 -04:00
|
|
|
:type=>"application/vnd.vmware.vcloud.vdc+xml",
|
2013-09-29 16:27:58 -04:00
|
|
|
:href=>make_href("vdc/#{vdc_id}"),
|
2013-09-26 06:29:51 -04:00
|
|
|
:xsi_schemaLocation=>xsi_schema_location,
|
|
|
|
:Link=>
|
|
|
|
[{:rel=>"up",
|
|
|
|
:type=>"application/vnd.vmware.vcloud.org+xml",
|
|
|
|
:href=>make_href("org/#{data[:org][:uuid]}")},
|
|
|
|
{:rel=>"down",
|
|
|
|
:type=>"application/vnd.vmware.vcloud.metadata+xml",
|
2013-09-29 16:27:58 -04:00
|
|
|
:href=>make_href("vdc/#{vdc_id}/metadata")},
|
2013-09-26 06:29:51 -04:00
|
|
|
{:rel=>"add",
|
|
|
|
:type=>"application/vnd.vmware.vcloud.uploadVAppTemplateParams+xml",
|
|
|
|
:href=>
|
2013-09-29 16:27:58 -04:00
|
|
|
make_href("vdc/#{vdc_id}/action/uploadVAppTemplate")},
|
2013-09-26 06:29:51 -04:00
|
|
|
{:rel=>"add",
|
|
|
|
:type=>"application/vnd.vmware.vcloud.media+xml",
|
2013-09-29 16:27:58 -04:00
|
|
|
:href=>make_href("vdc/#{vdc_id}/media")},
|
2013-09-26 06:29:51 -04:00
|
|
|
{:rel=>"add",
|
|
|
|
:type=>
|
|
|
|
"application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml",
|
|
|
|
:href=>
|
2013-09-29 16:27:58 -04:00
|
|
|
make_href("vdc/#{vdc_id}/action/instantiateVAppTemplate")},
|
2013-09-26 06:29:51 -04:00
|
|
|
{:rel=>"add",
|
|
|
|
:type=>"application/vnd.vmware.vcloud.cloneVAppParams+xml",
|
2013-09-29 16:27:58 -04:00
|
|
|
:href=>make_href("vdc/#{vdc_id}/action/cloneVApp")},
|
2013-09-26 06:29:51 -04:00
|
|
|
{:rel=>"add",
|
|
|
|
:type=>"application/vnd.vmware.vcloud.cloneVAppTemplateParams+xml",
|
|
|
|
:href=>
|
2013-09-29 16:27:58 -04:00
|
|
|
make_href("vdc/#{vdc_id}/action/cloneVAppTemplate")},
|
2013-09-26 06:29:51 -04:00
|
|
|
{:rel=>"add",
|
|
|
|
:type=>"application/vnd.vmware.vcloud.cloneMediaParams+xml",
|
2013-09-29 16:27:58 -04:00
|
|
|
:href=>make_href("vdc/#{vdc_id}/action/cloneMedia")},
|
2013-09-26 06:29:51 -04:00
|
|
|
{:rel=>"add",
|
|
|
|
:type=>"application/vnd.vmware.vcloud.captureVAppParams+xml",
|
2013-09-29 16:27:58 -04:00
|
|
|
:href=>make_href("vdc/#{vdc_id}/action/captureVApp")},
|
2013-09-26 06:29:51 -04:00
|
|
|
{:rel=>"add",
|
|
|
|
:type=>"application/vnd.vmware.vcloud.composeVAppParams+xml",
|
2013-09-29 16:27:58 -04:00
|
|
|
:href=>make_href("vdc/#{vdc_id}/action/composeVApp")},
|
2013-09-26 06:29:51 -04:00
|
|
|
{:rel=>"add",
|
|
|
|
:type=>"application/vnd.vmware.vcloud.diskCreateParams+xml",
|
2013-09-29 16:27:58 -04:00
|
|
|
:href=>make_href("vdc/#{vdc_id}/disk")},
|
2013-09-26 06:29:51 -04:00
|
|
|
{:rel=>"edgeGateways",
|
|
|
|
:type=>"application/vnd.vmware.vcloud.query.records+xml",
|
2013-09-29 16:27:58 -04:00
|
|
|
:href=>make_href("admin/vdc/#{vdc_id}/edgeGateways")},
|
2013-09-26 06:29:51 -04:00
|
|
|
{:rel=>"add",
|
|
|
|
:type=>"application/vnd.vmware.vcloud.orgVdcNetwork+xml",
|
2013-09-29 16:27:58 -04:00
|
|
|
:href=>make_href("admin/vdc/#{vdc_id}/networks")},
|
2013-09-26 06:29:51 -04:00
|
|
|
{:rel=>"orgVdcNetworks",
|
|
|
|
:type=>"application/vnd.vmware.vcloud.query.records+xml",
|
2013-09-29 16:27:58 -04:00
|
|
|
:href=>make_href("admin/vdc/#{vdc_id}/networks")}],
|
2013-09-26 06:29:51 -04:00
|
|
|
:Description=>vdc[:description]||'',
|
|
|
|
:AllocationModel=>"AllocationVApp",
|
|
|
|
:ComputeCapacity=>
|
|
|
|
{:Cpu=>
|
|
|
|
{:Units=>"MHz",
|
|
|
|
:Allocated=>"0",
|
|
|
|
:Limit=>"0",
|
|
|
|
:Reserved=>"0",
|
|
|
|
:Used=>"0",
|
|
|
|
:Overhead=>"0"},
|
|
|
|
:Memory=>
|
|
|
|
{:Units=>"MB",
|
|
|
|
:Allocated=>"0",
|
|
|
|
:Limit=>"0",
|
|
|
|
:Reserved=>"0",
|
|
|
|
:Used=>"0",
|
|
|
|
:Overhead=>"0"}},
|
|
|
|
:ResourceEntities => {},
|
|
|
|
:AvailableNetworks => {},
|
|
|
|
:Capabilities=>
|
|
|
|
{:SupportedHardwareVersions=>
|
|
|
|
{:SupportedHardwareVersion=>"vmx-08"}},
|
|
|
|
:NicQuota=>"0",
|
|
|
|
:NetworkQuota=>"20",
|
|
|
|
:UsedNetworkCount=>"0",
|
|
|
|
:VmQuota=>"100",
|
|
|
|
:IsEnabled=>"true"}
|
2013-06-12 12:50:31 -04:00
|
|
|
|
2013-09-29 16:27:58 -04:00
|
|
|
networks = data[:networks].map do |id, network|
|
|
|
|
{:type=>"application/vnd.vmware.vcloud.network+xml",
|
|
|
|
:name=>network[:name],
|
|
|
|
:href=>make_href("network/#{id}")}
|
2013-09-26 06:29:51 -04:00
|
|
|
end
|
2013-09-29 16:27:58 -04:00
|
|
|
networks = networks.first if networks.size == 1
|
|
|
|
body[:AvailableNetworks][:Network] = networks
|
2013-09-26 06:29:51 -04:00
|
|
|
|
2013-09-29 16:27:58 -04:00
|
|
|
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}")}
|
2013-09-26 06:29:51 -04:00
|
|
|
end
|
2013-09-29 16:27:58 -04:00
|
|
|
resources = resources.first if resources.size == 1
|
|
|
|
body[:ResourceEntities][:ResourceEntity] = resources
|
2013-09-26 06:29:51 -04:00
|
|
|
|
|
|
|
if api_version.to_f >= 5.1
|
2013-10-13 11:18:59 -04:00
|
|
|
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
|
2013-09-26 06:29:51 -04:00
|
|
|
end
|
|
|
|
|
2013-09-27 11:32:49 -04:00
|
|
|
response.status = 200
|
|
|
|
response.headers = {'Content-Type' => "#{body[:type]};version=#{api_version}"}
|
|
|
|
response.body = body
|
|
|
|
response
|
2013-09-26 06:29:51 -04:00
|
|
|
end
|
2013-06-12 12:50:31 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-09-16 13:13:09 -04:00
|
|
|
end
|