1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[terremark] mock get_vdc

This commit is contained in:
Edward Muller 2010-04-29 06:15:07 +08:00 committed by Wesley Beary
parent 4905d740d0
commit fee99e253e
2 changed files with 131 additions and 3 deletions

View file

@ -34,7 +34,88 @@ module Fog
module Mock module Mock
def get_vdc(vdc_id) def get_vdc(vdc_id)
raise MockNotImplemented.new("Contributions welcome!") response = Excon::Response.new
if vdc = @data[:organizations].map { |org| org[:vdcs] }.flatten.detect { |vdc| vdc[:id] == vdc_id }
body = { "name" => vdc[:name],
"href" => "#{@base_url}/vdc/#{vdc[:id]}",
"StorageCapacity" => {},
"ComputeCapacity" => { "InstantiatedVmsQuota" => {},
"DeployedVmsQuota" => {},
"Cpu" => {},
"Memory" => {} },
"ResourceEntities" => [],
"AvailableNetworks" => [],
"links" => [] }
case self
when Fog::Terremark::Ecloud::Mock
body["StorageCapacity"] = { "Units" => "bytes * 10^9" }
vdc[:storage].each { |k,v| body["StorageCapacity"][k.to_s.capitalize] = v.to_s }
body["ComputeCapacity"] = { "InstantiatedVmsQuota" => {"Limit" => "-1", "Used" => "-1"},
"DeployedVmsQuota" => {"Limit" => "-1", "Used" => "-1"},
"Cpu" => { "Units" => "hz * 10^6" },
"Memory" => { "Units" => "bytes * 2^20" } }
[:cpu, :memory].each do |key|
vdc[key].each { |k,v| body["ComputeCapacity"][key.to_s.capitalize][k.to_s.capitalize] = v.to_s }
end
body["links"] << { "name" => "Public IPs",
"href" => "#{@base_url}/extensions/vdc/#{vdc[:id]}/publicIps",
"rel" => "down",
"type" => "application/vnd.tmrk.ecloud.publicIpsList+xml" }
body["links"] << { "name" => "Internet Services",
"href" => "#{@base_url}/extensions/vdc/#{vdc[:id]}/internetServices",
"rel" => "down",
"type" => "application/vnd.tmrk.ecloud.internetServicesList+xml" }
body["links"] << { "name" => "Firewall Access List",
"href" => "#{@base_url}/extensions/vdc/#{vdc[:id]}/firewallAcls",
"rel" => "down",
"type" => "application/vnd.tmrk.ecloud.firewallAclsList+xml" }
when Fog::Terremark::Vcloud::Mock
body["links"] << { "name" => "Public IPs",
"href" => "#{@base_url}/vdc/#{vdc[:id]}/publicIps",
"rel" => "down",
"type" => "application/xml" }
body["links"] << { "name" => "Internet Services",
"href" => "#{@base_url}/vdc/#{vdc[:id]}/internetServices",
"rel" => "down",
"type" => "application/xml" }
end
vdc[:vms].each do |vm|
body["ResourceEntities"] << { "name" => vm[:name],
"href" => "#{@base_url}/vapp/#{vm[:id]}",
"type" => "application/vnd.vmware.vcloud.vApp+xml" }
end
vdc[:networks].each do |network|
body["AvailableNetworks"] << { "name" => network[:name],
"href" => "#{@base_url}/network/#{network[:id]}",
"type" => "application/vnd.vmware.vcloud.network+xml" }
end
body["links"] << { "name" => vdc[:name],
"href" => "#{@base_url}/vdc/#{vdc[:id]}/catalog",
"rel" => "down",
"type" => "application/vnd.vmware.vcloud.catalog+xml" }
response.status = 200
response.body = body
response.headers = Fog::Terremark::Shared::Mock.headers(response.body, "application/vnd.vmware.vcloud.org+xml")
else
response.status = Fog::Terremark::Shared::Mock.unathorized_status
response.headers = Fog::Terremark::Shared::Mock.error_headers
end
response
end end
end end

View file

@ -69,10 +69,57 @@ module Fog
}, },
:vdcs => [ :vdcs => [
{ :id => 21, { :id => 21,
:name => "Boomstick" :name => "Boomstick",
:storage => { :used => 105, :allocated => 200 },
:cpu => { :allocated => 10000 },
:memory => { :allocated => 20480 },
:networks => [
{ :id => 31,
:name => "1.2.3.0/24",
:subnet => "1.2.3.0/24",
:gateway => "1.2.3.1",
:netmask => "255.255.255.0",
:fencemode => "isolated"
},
{ :id => 32,
:name => "4.5.6.0/24",
:subnet => "4.5.6.0/24",
:gateway => "4.5.6.1",
:netmask => "255.255.255.0",
:fencemode => "isolated"
},
],
:vms => [
{ :id => 41,
:name => "Broom 1"
},
{ :id => 42,
:name => "Broom 2"
},
{ :id => 43,
:name => "Email!"
}
]
}, },
{ :id => 22, { :id => 22,
:name => "Rock-n-Roll" :storage => { :used => 40, :allocated => 150 },
:cpu => { :allocated => 1000 },
:memory => { :allocated => 2048 },
:name => "Rock-n-Roll",
:networks => [
{ :id => 33,
:name => "7.8.9.0/24",
:subnet => "7.8.9.0/24",
:gateway => "7.8.9.1",
:netmask => "255.255.255.0",
:fencemode => "isolated"
}
],
:vms => [
{ :id => 44,
:name => "Master Blaster"
}
]
} }
] ]
} }