forked from fog/fog
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Edward Muller
authored and
Wesley Beary
committed
Jun 5, 2010
1 parent
93ea9de
commit c85ce34
Showing
15 changed files
with
401 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require 'fog/model' | ||
|
||
module Fog | ||
module Vcloud | ||
module Terremark | ||
module Ecloud | ||
class PublicIp < Fog::Vcloud::Model | ||
|
||
identity :href | ||
|
||
attribute :name | ||
attribute :type | ||
attribute :id | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module Fog | ||
module Vcloud | ||
module Terremark | ||
module Ecloud | ||
|
||
module Mock | ||
def public_ips(options = {}) | ||
@public_ips ||= Fog::Vcloud::Terremark::Ecloud::PublicIps.new(options.merge(:connection => self)) | ||
end | ||
end | ||
|
||
module Real | ||
def public_ips(options = {}) | ||
@public_ips ||= Fog::Vcloud::Terremark::Ecloud::PublicIps.new(options.merge(:connection => self)) | ||
end | ||
end | ||
|
||
class PublicIps < Fog::Vcloud::Collection | ||
|
||
attr_accessor :href | ||
|
||
model Fog::Vcloud::Terremark::Ecloud::PublicIp | ||
|
||
get_request :get_public_ip | ||
vcloud_type "application/vnd.tmrk.ecloud.publicIp+xml" | ||
all_request lambda { |public_ips| public_ips.connection.get_public_ips(public_ips.href) } | ||
|
||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module Fog | ||
module Parsers | ||
module Vcloud | ||
module Terremark | ||
module Ecloud | ||
|
||
class GetPublicIp < Fog::Parsers::Vcloud::Base | ||
|
||
def reset | ||
@response = Struct::TmrkEcloudPublicIp.new("application/vnd.tmrk.ecloud.publicIp+xml") | ||
end | ||
|
||
def end_element(name) | ||
case name | ||
when 'Href' | ||
@response[name.downcase] = URI.parse(@value) | ||
when 'Name' | ||
@response[name.downcase] = @value | ||
when 'Id' | ||
@response['id'] = @value.to_i | ||
end | ||
end | ||
|
||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
module Fog | ||
module Parsers | ||
module Vcloud | ||
module Terremark | ||
module Ecloud | ||
|
||
class GetPublicIps < Fog::Parsers::Vcloud::Base | ||
|
||
def reset | ||
@response = Struct::TmrkEcloudPublicIpList.new([]) | ||
end | ||
|
||
def start_element(name, attributes) | ||
@value = nil | ||
case name | ||
when 'PublicIPAddress' | ||
@ip_address = Struct::TmrkEcloudPublicIp.new("application/vnd.tmrk.ecloud.publicIp+xml") | ||
end | ||
end | ||
|
||
def end_element(name) | ||
case name | ||
when 'Href' | ||
@ip_address[name.downcase] = URI.parse(@value) | ||
when 'Name' | ||
@ip_address[name.downcase] = @value | ||
when 'Id' | ||
@ip_address[name.downcase] = @value.to_i | ||
when 'PublicIPAddress' | ||
@response.links << @ip_address | ||
end | ||
end | ||
|
||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
module Fog | ||
module Vcloud | ||
module Terremark | ||
module Ecloud | ||
|
||
module Real | ||
|
||
def get_public_ip(public_ip_uri) | ||
opts = { | ||
:expects => 200, | ||
:method => 'GET', | ||
:parser => Fog::Parsers::Vcloud::Terremark::Ecloud::GetPublicIp.new, | ||
:uri => public_ip_uri | ||
} | ||
if self.class == Fog::Terremark::Ecloud::Real | ||
opts[:path] = "extensions/publicIp/#{public_ip_id}" | ||
end | ||
request(opts) | ||
end | ||
|
||
end | ||
|
||
module Mock | ||
# | ||
#Based off of: | ||
#http://support.theenterprisecloud.com/kb/default.asp?id=567&Lang=1&SID= | ||
# | ||
|
||
def get_public_ip(public_ip_uri) | ||
ip_id = public_ip_uri.to_s.split('/')[-1] | ||
if ip = mock_data[:organizations].map { |org| org[:vdcs] }.flatten.map { |vdc| vdc[:public_ips] }.flatten.detect { |ip| ip[:id].to_s == ip_id } | ||
xml = Builder::XmlMarkup.new | ||
mock_it(Fog::Parsers::Vcloud::Terremark::Ecloud::GetPublicIp.new, 200, | ||
xml.PublicIp(:xmlns => "urn:tmrk:eCloudExtensions-2.0", :"xmlns:i" => "http://www.w3.org/2001/XMLSchema-instance") { | ||
xml.Id(ip[:id]) | ||
xml.Href("https://fakey.com/api/v0.8/extensions/publicIp/#{ip[:id]}") | ||
xml.Name(ip[:name]) | ||
}, { 'Content-Type' => 'application/vnd.tmrk.ecloud.publicIp+xml' } | ||
) | ||
else | ||
mock_error 200, "401 Unauthorized" | ||
end | ||
end | ||
|
||
end | ||
end | ||
end | ||
end | ||
end |
47 changes: 47 additions & 0 deletions
47
lib/fog/vcloud/terremark/ecloud/requests/get_public_ips.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
module Fog | ||
module Vcloud | ||
module Terremark | ||
module Ecloud | ||
|
||
module Real | ||
|
||
def get_public_ips(public_ips_uri) | ||
request( | ||
:expects => 200, | ||
:method => 'GET', | ||
:parser => Fog::Parsers::Vcloud::Terremark::Ecloud::GetPublicIps.new, | ||
:uri => public_ips_uri | ||
) | ||
end | ||
end | ||
|
||
module Mock | ||
|
||
# | ||
#Based off of: | ||
#http://support.theenterprisecloud.com/kb/default.asp?id=577&Lang=1&SID= | ||
# | ||
def get_public_ips(public_ips_uri) | ||
if vdc = mock_data[:organizations].map { |org| org[:vdcs] }.flatten.detect { |vdc| vdc[:href].split('/').last == public_ips_uri.to_s.split('/')[-2] } | ||
xml = Builder::XmlMarkup.new | ||
mock_it Fog::Parsers::Vcloud::Terremark::Ecloud::GetPublicIps.new, 200, | ||
xml.PublicIPAddresses { | ||
vdc[:public_ips].each do |ip| | ||
xml.PublicIPAddress { | ||
xml.Id(ip[:id]) | ||
xml.Href("https://fakey.com/api/v0.8/extensions/publicIp/#{ip[:id]}") | ||
xml.Name(ip[:name]) | ||
} | ||
end | ||
}, { 'Content-Type' => 'application/vnd.tmrk.ecloud.publicIpsList+xml'} | ||
else | ||
mock_error 200, "401 Unauthorized" | ||
end | ||
end | ||
|
||
end | ||
end | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.