mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[terremark] get_network_ips, Network#ips, Vdc(s) models
This commit is contained in:
parent
e74b5d29f6
commit
751023ae8c
8 changed files with 212 additions and 45 deletions
84
Gemfile.lock
84
Gemfile.lock
|
@ -1,4 +1,45 @@
|
|||
---
|
||||
dependencies:
|
||||
formatador:
|
||||
group:
|
||||
- :default
|
||||
version: ">= 0.0.10"
|
||||
rake:
|
||||
group:
|
||||
- :default
|
||||
version: ">= 0"
|
||||
ruby-hmac:
|
||||
group:
|
||||
- :default
|
||||
version: ">= 0"
|
||||
mime-types:
|
||||
group:
|
||||
- :default
|
||||
version: ">= 0"
|
||||
rspec:
|
||||
group:
|
||||
- :default
|
||||
version: ">= 0"
|
||||
net-ssh:
|
||||
group:
|
||||
- :default
|
||||
version: ">= 0"
|
||||
json:
|
||||
group:
|
||||
- :default
|
||||
version: ">= 0"
|
||||
excon:
|
||||
group:
|
||||
- :default
|
||||
version: ">= 0.0.21"
|
||||
shindo:
|
||||
group:
|
||||
- :default
|
||||
version: ">= 0"
|
||||
nokogiri:
|
||||
group:
|
||||
- :default
|
||||
version: ">= 0"
|
||||
specs:
|
||||
- rake:
|
||||
version: 0.8.7
|
||||
|
@ -9,7 +50,7 @@ specs:
|
|||
- formatador:
|
||||
version: 0.0.13
|
||||
- json:
|
||||
version: 1.4.0
|
||||
version: 1.4.1
|
||||
- mime-types:
|
||||
version: "1.16"
|
||||
- net-ssh:
|
||||
|
@ -26,44 +67,3 @@ hash: e443f12a9a7794f2ff4fc8e8d201b12b1e8b30bb
|
|||
sources:
|
||||
- Rubygems:
|
||||
uri: http://gemcutter.org
|
||||
dependencies:
|
||||
formatador:
|
||||
version: ">= 0.0.10"
|
||||
group:
|
||||
- :default
|
||||
nokogiri:
|
||||
version: ">= 0"
|
||||
group:
|
||||
- :default
|
||||
rake:
|
||||
version: ">= 0"
|
||||
group:
|
||||
- :default
|
||||
rspec:
|
||||
version: ">= 0"
|
||||
group:
|
||||
- :default
|
||||
ruby-hmac:
|
||||
version: ">= 0"
|
||||
group:
|
||||
- :default
|
||||
mime-types:
|
||||
version: ">= 0"
|
||||
group:
|
||||
- :default
|
||||
net-ssh:
|
||||
version: ">= 0"
|
||||
group:
|
||||
- :default
|
||||
json:
|
||||
version: ">= 0"
|
||||
group:
|
||||
- :default
|
||||
excon:
|
||||
version: ">= 0.0.21"
|
||||
group:
|
||||
- :default
|
||||
shindo:
|
||||
version: ">= 0"
|
||||
group:
|
||||
- :default
|
||||
|
|
|
@ -15,6 +15,11 @@ module Fog
|
|||
attribute :fencemode
|
||||
attribute :links
|
||||
|
||||
def ips
|
||||
#Until there is a real model for these ?
|
||||
connection.get_network_ips(@id).body['IpAddresses']
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def href=(new_href)
|
||||
|
|
35
lib/fog/terremark/models/shared/vdc.rb
Normal file
35
lib/fog/terremark/models/shared/vdc.rb
Normal file
|
@ -0,0 +1,35 @@
|
|||
require 'fog/model'
|
||||
|
||||
module Fog
|
||||
module Terremark
|
||||
module Shared
|
||||
|
||||
class Vdc < Fog::Model
|
||||
|
||||
identity :id
|
||||
|
||||
attribute :name
|
||||
|
||||
def networks
|
||||
connection.networks(:vdc_id => @id)
|
||||
end
|
||||
|
||||
def addresses
|
||||
connection.addresses(:vdc_id => @id)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def href=(new_href)
|
||||
@id = new_href.split('/').last.to_i
|
||||
end
|
||||
|
||||
def type=(new_type); end
|
||||
|
||||
def rel=(new_rel); end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
52
lib/fog/terremark/models/shared/vdcs.rb
Normal file
52
lib/fog/terremark/models/shared/vdcs.rb
Normal file
|
@ -0,0 +1,52 @@
|
|||
module Fog
|
||||
module Terremark
|
||||
module Shared
|
||||
|
||||
module Mock
|
||||
def vdcs(options = {})
|
||||
Fog::Terremark::Shared::Vdcs.new(options.merge(:connection => self))
|
||||
end
|
||||
end
|
||||
|
||||
module Real
|
||||
def vdcs(options = {})
|
||||
Fog::Terremark::Shared::Vdcs.new(options.merge(:connection => self))
|
||||
end
|
||||
end
|
||||
|
||||
class Vdcs < Fog::Collection
|
||||
|
||||
model Fog::Terremark::Shared::Vdc
|
||||
|
||||
def all
|
||||
data = connection.get_organization(organization_id).body['Links'].select do |entity|
|
||||
entity['type'] == 'application/vnd.vmware.vcloud.vdc+xml'
|
||||
end
|
||||
load(data)
|
||||
end
|
||||
|
||||
def get(vdc_id)
|
||||
if vdc_id && vdc = connection.get_vdc(vdc_id).body
|
||||
new(vdc)
|
||||
elsif !vdc_id
|
||||
nil
|
||||
end
|
||||
rescue Excon::Errors::Forbidden
|
||||
nil
|
||||
end
|
||||
|
||||
def organization_id
|
||||
@vdc_id ||= connection.default_organization_id
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def organization_id=(new_organization_id)
|
||||
@organization_id = new_organization_id
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
33
lib/fog/terremark/parsers/shared/get_network_ips.rb
Normal file
33
lib/fog/terremark/parsers/shared/get_network_ips.rb
Normal file
|
@ -0,0 +1,33 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module Terremark
|
||||
module Shared
|
||||
|
||||
class GetNetworkIps< Fog::Parsers::Base
|
||||
|
||||
def reset
|
||||
@ip_address = {}
|
||||
@response = { 'IpAddresses' => [] }
|
||||
end
|
||||
|
||||
def start_element(name,attributes=[])
|
||||
@value = ''
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
case name
|
||||
when 'Name', 'Status', 'Server'
|
||||
@ip_address[name.downcase] = @value
|
||||
when 'IpAddress'
|
||||
@response['IpAddresses'] << @ip_address
|
||||
@ip_address = {}
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -11,9 +11,7 @@ module Fog
|
|||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'PublicIpAddresses'<~Array>
|
||||
# * 'href'<~String> - linke to item
|
||||
# * 'name'<~String> - name of item
|
||||
# FIXME
|
||||
def get_network(network_id)
|
||||
request(
|
||||
:expects => 200,
|
||||
|
|
40
lib/fog/terremark/requests/shared/get_network_ips.rb
Normal file
40
lib/fog/terremark/requests/shared/get_network_ips.rb
Normal file
|
@ -0,0 +1,40 @@
|
|||
module Fog
|
||||
module Terremark
|
||||
module Shared
|
||||
module Real
|
||||
|
||||
# Get details for a Network
|
||||
#
|
||||
# ==== Parameters
|
||||
# * network_id<~Integer> - Id of the network to look up
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# FIXME
|
||||
def get_network_ips(network_id)
|
||||
opts = {
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:parser => Fog::Parsers::Terremark::Shared::GetNetworkIps.new,
|
||||
:path => "network/#{network_id}/ipAddresses"
|
||||
}
|
||||
if self.is_a?(Fog::Terremark::Ecloud::Real)
|
||||
opts[:path] = "/extensions/network/#{network_id}/ips"
|
||||
end
|
||||
request(opts)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
module Mock
|
||||
|
||||
def get_network_ips(network_id)
|
||||
raise MockNotImplemented.new("Contributions welcome!")
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -87,9 +87,12 @@ module Fog
|
|||
require 'fog/terremark/models/shared/servers'
|
||||
require 'fog/terremark/models/shared/task'
|
||||
require 'fog/terremark/models/shared/tasks'
|
||||
require 'fog/terremark/models/shared/vdc'
|
||||
require 'fog/terremark/models/shared/vdcs'
|
||||
require 'fog/terremark/parsers/shared/get_catalog'
|
||||
require 'fog/terremark/parsers/shared/get_catalog_item'
|
||||
require 'fog/terremark/parsers/shared/get_internet_services'
|
||||
require 'fog/terremark/parsers/shared/get_network_ips'
|
||||
require 'fog/terremark/parsers/shared/get_node_services'
|
||||
require 'fog/terremark/parsers/shared/get_organization'
|
||||
require 'fog/terremark/parsers/shared/get_organizations'
|
||||
|
@ -116,6 +119,7 @@ module Fog
|
|||
require 'fog/terremark/requests/shared/get_catalog_item'
|
||||
require 'fog/terremark/requests/shared/get_internet_services'
|
||||
require 'fog/terremark/requests/shared/get_network'
|
||||
require 'fog/terremark/requests/shared/get_network_ips'
|
||||
require 'fog/terremark/requests/shared/get_node_services'
|
||||
require 'fog/terremark/requests/shared/get_organization'
|
||||
require 'fog/terremark/requests/shared/get_organizations'
|
||||
|
|
Loading…
Reference in a new issue