Module: Fog::Terremark::Shared::Mock
- Includes:
- Common
- Included in:
- Ecloud::Mock, Vcloud::Mock
- Defined in:
- lib/fog/terremark/shared.rb,
lib/fog/terremark/models/shared/vdcs.rb,
lib/fog/terremark/models/shared/tasks.rb,
lib/fog/terremark/models/shared/servers.rb,
lib/fog/terremark/models/shared/networks.rb,
lib/fog/terremark/models/shared/addresses.rb,
lib/fog/terremark/requests/shared/get_vdc.rb,
lib/fog/terremark/requests/shared/get_task.rb,
lib/fog/terremark/requests/shared/get_vapp.rb,
lib/fog/terremark/requests/shared/power_on.rb,
lib/fog/terremark/requests/shared/power_off.rb,
lib/fog/terremark/requests/shared/delete_vapp.rb,
lib/fog/terremark/requests/shared/deploy_vapp.rb,
lib/fog/terremark/requests/shared/get_catalog.rb,
lib/fog/terremark/requests/shared/get_network.rb,
lib/fog/terremark/requests/shared/power_reset.rb,
lib/fog/terremark/requests/shared/get_public_ip.rb,
lib/fog/terremark/requests/shared/get_public_ips.rb,
lib/fog/terremark/requests/shared/get_tasks_list.rb,
lib/fog/terremark/requests/shared/power_shutdown.rb,
lib/fog/terremark/requests/shared/get_network_ips.rb,
lib/fog/terremark/requests/shared/add_node_service.rb,
lib/fog/terremark/requests/shared/delete_public_ip.rb,
lib/fog/terremark/requests/shared/get_catalog_item.rb,
lib/fog/terremark/requests/shared/get_organization.rb,
lib/fog/terremark/requests/shared/get_node_services.rb,
lib/fog/terremark/requests/shared/get_organizations.rb,
lib/fog/terremark/requests/shared/get_vapp_template.rb,
lib/fog/terremark/requests/shared/delete_node_service.rb,
lib/fog/terremark/requests/shared/add_internet_service.rb,
lib/fog/terremark/requests/shared/get_internet_services.rb,
lib/fog/terremark/requests/shared/create_internet_service.rb,
lib/fog/terremark/requests/shared/delete_internet_service.rb,
lib/fog/terremark/requests/shared/instantiate_vapp_template.rb
Class Method Summary collapse
- .error_headers ⇒ Object
- .headers(body, content_type) ⇒ Object
- .mock_data ⇒ Object
- .status ⇒ Object
- .unathorized_status ⇒ Object
Instance Method Summary collapse
- #add_internet_service(ip_id) ⇒ Object
- #add_node_service(ip) ⇒ Object
- #addresses(options = {}) ⇒ Object
- #create_internet_service(vdc_id) ⇒ Object
- #delete_internet_service(internet_service_id) ⇒ Object
- #delete_node_service(node_id) ⇒ Object
- #delete_public_ip(public_ip_id) ⇒ Object
- #delete_vapp(vapp_id) ⇒ Object
- #deploy_vapp(vapp_id) ⇒ Object
- #get_catalog(vdc_id) ⇒ Object
- #get_catalog_item(catalog_item_id) ⇒ Object
- #get_internet_services(vdc_id) ⇒ Object
- #get_network(network_id) ⇒ Object
- #get_network_ips(network_id) ⇒ Object
- #get_node_services(vdc_id) ⇒ Object
- #get_organization(organization_id) ⇒ Object
- #get_organizations ⇒ Object
- #get_public_ip(public_ip_id) ⇒ Object
- #get_public_ips(vdc_id) ⇒ Object
- #get_task(task_id) ⇒ Object
- #get_tasks_list(tasks_list_id) ⇒ Object
- #get_vapp(vapp_id) ⇒ Object
- #get_vapp_template(vapp_template_id) ⇒ Object
- #get_vdc(vdc_id) ⇒ Object
- #initialize(options = {}) ⇒ Object
- #instatiate_vapp_template(vapp_template_id) ⇒ Object
- #networks(options = {}) ⇒ Object
- #power_off(vapp_id) ⇒ Object
- #power_on(vapp_id) ⇒ Object
- #power_shutdown(vapp_id) ⇒ Object
- #reset(vapp_id) ⇒ Object
- #servers(options = {}) ⇒ Object
- #tasks ⇒ Object
- #vdcs(options = {}) ⇒ Object
Methods included from Common
Class Method Details
.error_headers ⇒ Object
176 177 178 179 180 181 182 183 |
# File 'lib/fog/terremark/shared.rb', line 176 def self.error_headers {"X-Powered-By"=>"ASP.NET", "Date"=> Time.now.to_s, "Content-Type"=>"text/html", "Content-Length"=>"0", "Server"=>"Microsoft-IIS/7.0", "Cache-Control"=>"private"} end |
.headers(body, content_type) ⇒ Object
189 190 191 192 193 194 195 196 197 |
# File 'lib/fog/terremark/shared.rb', line 189 def self.headers(body, content_type) {"X-Powered-By"=>"ASP.NET", "Date"=> Time.now.to_s, "Content-Type"=> content_type, "Content-Length"=> body.to_s.length, "Server"=>"Microsoft-IIS/7.0", "Set-Cookie"=>"vcloud-token=ecb37bfc-56f0-421d-97e5-bf2gdf789457; path=/", "Cache-Control"=>"private"} end |
.mock_data ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/fog/terremark/shared.rb', line 91 def self.mock_data { :organizations => [ { :info => { :name => "Boom Inc.", :id => 1 }, :vdcs => [ { :id => 21, :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!" } ], :public_ips => [ { :id => 51, :name => "99.1.2.3" }, { :id => 52, :name => "99.1.2.4" }, { :id => 53, :name => "99.1.9.7" } ] }, { :id => 22, :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" } ], :public_ips => [ { :id => 54, :name => "99.99.99.99" } ] } ] } ] } end |
.status ⇒ Object
199 200 201 |
# File 'lib/fog/terremark/shared.rb', line 199 def self.status 200 end |
.unathorized_status ⇒ Object
185 186 187 |
# File 'lib/fog/terremark/shared.rb', line 185 def self.unathorized_status 401 end |
Instance Method Details
#add_internet_service(ip_id) ⇒ Object
56 57 58 |
# File 'lib/fog/terremark/requests/shared/add_internet_service.rb', line 56 def add_internet_service(ip_id) Fog::Mock.not_implemented end |
#add_node_service(ip) ⇒ Object
56 57 58 |
# File 'lib/fog/terremark/requests/shared/add_node_service.rb', line 56 def add_node_service(ip) Fog::Mock.not_implemented end |
#addresses(options = {}) ⇒ Object
6 7 8 |
# File 'lib/fog/terremark/models/shared/addresses.rb', line 6 def addresses( = {}) Fog::Terremark::Shared::Addresses.new(.merge(:connection => self)) end |
#create_internet_service(vdc_id) ⇒ Object
56 57 58 |
# File 'lib/fog/terremark/requests/shared/create_internet_service.rb', line 56 def create_internet_service(vdc_id) Fog::Mock.not_implemented end |
#delete_internet_service(internet_service_id) ⇒ Object
23 24 25 |
# File 'lib/fog/terremark/requests/shared/delete_internet_service.rb', line 23 def delete_internet_service(internet_service_id) Fog::Mock.not_implemented end |
#delete_node_service(node_id) ⇒ Object
23 24 25 |
# File 'lib/fog/terremark/requests/shared/delete_node_service.rb', line 23 def delete_node_service(node_id) Fog::Mock.not_implemented end |
#delete_public_ip(public_ip_id) ⇒ Object
23 24 25 |
# File 'lib/fog/terremark/requests/shared/delete_public_ip.rb', line 23 def delete_public_ip(public_ip_id) Fog::Mock.not_implemented end |
#delete_vapp(vapp_id) ⇒ Object
23 24 25 |
# File 'lib/fog/terremark/requests/shared/delete_vapp.rb', line 23 def delete_vapp(vapp_id) Fog::Mock.not_implemented end |
#deploy_vapp(vapp_id) ⇒ Object
36 37 38 |
# File 'lib/fog/terremark/requests/shared/deploy_vapp.rb', line 36 def deploy_vapp(vapp_id) Fog::Mock.not_implemented end |
#get_catalog(vdc_id) ⇒ Object
33 34 35 |
# File 'lib/fog/terremark/requests/shared/get_catalog.rb', line 33 def get_catalog(vdc_id) Fog::Mock.not_implemented end |
#get_catalog_item(catalog_item_id) ⇒ Object
36 37 38 |
# File 'lib/fog/terremark/requests/shared/get_catalog_item.rb', line 36 def get_catalog_item(catalog_item_id) Fog::Mock.not_implemented end |
#get_internet_services(vdc_id) ⇒ Object
36 37 38 |
# File 'lib/fog/terremark/requests/shared/get_internet_services.rb', line 36 def get_internet_services(vdc_id) Fog::Mock.not_implemented end |
#get_network(network_id) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/fog/terremark/requests/shared/get_network.rb', line 28 def get_network(network_id) network_id = network_id.to_i response = Excon::Response.new if network = @data[:organizations].map { |org| org[:vdcs].map { |vdc| vdc[:networks] } }.flatten.detect { |network| network[:id] == network_id } body = { "links" => [], "type" => "application/vnd.vmware.vcloud.network+xml", "href" => "#{@base_url}/network/#{network_id}" } network.each_key do |key| body[key.to_s] = network[key] end link = { "name" => "IP Addresses", "rel" => "down", "type" => "application/xml" } link["href"] = case self when Fog::Terremark::Ecloud::Mock "#{@base_url}/extensions/network/#{network_id}/ips" when Fog::Terremark::Vcloud::Mock "#{@base_url}/network/#{network_id}/ipAddresses" end body["links"] << link response.status = 200 response.body = body response.headers = Fog::Terremark::Shared::Mock.headers(response.body, case self when Fog::Terremark::Ecloud::Mock "application/vnd.vmware.vcloud.network+xml" when Fog::Terremark::Vcloud::Mock "application/xml; charset=utf-8" end ) else response.status = Fog::Terremark::Shared::Mock.unathorized_status response.headers = Fog::Terremark::Shared::Mock.error_headers end response end |
#get_network_ips(network_id) ⇒ Object
32 33 34 |
# File 'lib/fog/terremark/requests/shared/get_network_ips.rb', line 32 def get_network_ips(network_id) Fog::Mock.not_implemented end |
#get_node_services(vdc_id) ⇒ Object
31 32 33 |
# File 'lib/fog/terremark/requests/shared/get_node_services.rb', line 31 def get_node_services(vdc_id) Fog::Mock.not_implemented end |
#get_organization(organization_id) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/fog/terremark/requests/shared/get_organization.rb', line 35 def get_organization(organization_id) organization_id = organization_id.to_i response = Excon::Response.new if org = @data[:organizations].detect { |org| org[:info][:id] == organization_id } body = { "name" => org[:info][:name], "href" => "#{@base_url}/org/#{org[:info][:id]}", "Links" => [] } body["Links"] = case self when Fog::Terremark::Vcloud::Mock _vdc_links(org[:vdcs][0]) when Fog::Terremark::Ecloud::Mock org[:vdcs].map do |vdc| _vdc_links(vdc) end.flatten end 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 |
#get_organizations ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/fog/terremark/requests/shared/get_organizations.rb', line 32 def get_organizations response = Excon::Response.new org_list = @data[:organizations].map do |organization| { "name" => organization[:info][:name], "href" => "#{@base_url}/org/#{organization[:info][:id]}", "type" => "application/vnd.vmware.vcloud.org+xml" } end response.body = { "OrgList" => org_list } response.status = 200 response.headers = Fog::Terremark::Shared::Mock.headers(response.body, "application/vnd.vmware.vcloud.orgList+xml") response end |
#get_public_ip(public_ip_id) ⇒ Object
34 35 36 |
# File 'lib/fog/terremark/requests/shared/get_public_ip.rb', line 34 def get_public_ip(public_ip_id) Fog::Mock.not_implemented end |
#get_public_ips(vdc_id) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/fog/terremark/requests/shared/get_public_ips.rb', line 34 def get_public_ips(vdc_id) vdc_id = vdc_id.to_i response = Excon::Response.new if vdc = @data[:organizations].map { |org| org[:vdcs] }.flatten.detect { |vdc| vdc[:id] == vdc_id } body = { "PublicIpAddresses" => [] } vdc[:public_ips].each do |ip| ip = { "name" => ip[:name], "href" => case self when Fog::Terremark::Ecloud::Mock "#{@base_url}/extensions/publicIp/#{ip[:id]}" when Fog::Terremark::Vcloud::Mock "#{@base_url}/PublicIps/#{ip[:id]}" end, "id" => ip[:id].to_s } body["PublicIpAddresses"] << ip end response.status = 200 response.body = body response.headers = Fog::Terremark::Shared::Mock.headers(response.body, case self when Fog::Terremark::Ecloud::Mock "application/vnd.tmrk.ecloud.publicIpsList+xml" when Fog::Terremark::Vcloud::Mock "application/xml; charset=utf-8" end ) else response.status = Fog::Terremark::Shared::Mock.unathorized_status response.headers = Fog::Terremark::Shared::Mock.error_headers end response end |
#get_task(task_id) ⇒ Object
40 41 42 |
# File 'lib/fog/terremark/requests/shared/get_task.rb', line 40 def get_task(task_id) Fog::Mock.not_implemented end |
#get_tasks_list(tasks_list_id) ⇒ Object
33 34 35 |
# File 'lib/fog/terremark/requests/shared/get_tasks_list.rb', line 33 def get_tasks_list(tasks_list_id) Fog::Mock.not_implemented end |
#get_vapp(vapp_id) ⇒ Object
43 44 45 |
# File 'lib/fog/terremark/requests/shared/get_vapp.rb', line 43 def get_vapp(vapp_id) Fog::Mock.not_implemented end |
#get_vapp_template(vapp_template_id) ⇒ Object
36 37 38 |
# File 'lib/fog/terremark/requests/shared/get_vapp_template.rb', line 36 def get_vapp_template(vapp_template_id) Fog::Mock.not_implemented end |
#get_vdc(vdc_id) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/fog/terremark/requests/shared/get_vdc.rb', line 36 def get_vdc(vdc_id) vdc_id = vdc_id.to_i 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 |
#initialize(options = {}) ⇒ Object
203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/fog/terremark/shared.rb', line 203 def initialize(={}) self.class.instance_eval ' def self.data @data ||= Hash.new do |hash, key| hash[key] = Fog::Terremark::Shared::Mock.mock_data end end' self.class.instance_eval ' def self.reset_data(keys=data.keys) for key in [*keys] data.delete(key) end end' end |
#instatiate_vapp_template(vapp_template_id) ⇒ Object
72 73 74 |
# File 'lib/fog/terremark/requests/shared/instantiate_vapp_template.rb', line 72 def instatiate_vapp_template(vapp_template_id) Fog::Mock.not_implemented end |
#networks(options = {}) ⇒ Object
6 7 8 |
# File 'lib/fog/terremark/models/shared/networks.rb', line 6 def networks( = {}) Fog::Terremark::Shared::Networks.new(.merge(:connection => self)) end |
#power_off(vapp_id) ⇒ Object
36 37 38 |
# File 'lib/fog/terremark/requests/shared/power_off.rb', line 36 def power_off(vapp_id) Fog::Mock.not_implemented end |
#power_on(vapp_id) ⇒ Object
36 37 38 |
# File 'lib/fog/terremark/requests/shared/power_on.rb', line 36 def power_on(vapp_id) Fog::Mock.not_implemented end |
#power_shutdown(vapp_id) ⇒ Object
25 26 27 |
# File 'lib/fog/terremark/requests/shared/power_shutdown.rb', line 25 def power_shutdown(vapp_id) Fog::Mock.not_implemented end |
#reset(vapp_id) ⇒ Object
36 37 38 |
# File 'lib/fog/terremark/requests/shared/power_reset.rb', line 36 def reset(vapp_id) Fog::Mock.not_implemented end |
#servers(options = {}) ⇒ Object
9 10 11 |
# File 'lib/fog/terremark/models/shared/servers.rb', line 9 def servers( = {}) Fog::Terremark::Shared::Servers.new(.merge(:connection => self)) end |