Skip to content

Commit

Permalink
fixes for vcloud to match up with new stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
geemus committed Sep 14, 2010
1 parent 2c349c1 commit 4076bba
Show file tree
Hide file tree
Showing 69 changed files with 299 additions and 273 deletions.
5 changes: 2 additions & 3 deletions lib/fog/bin.rb
Expand Up @@ -17,17 +17,16 @@ class << self
def modules
[
::AWS,
::Bluebox,
::GoGrid,
::Linode,
::Local,
::NewServers,
::Rackspace,
::Slicehost,
::Terremark,
::Vcloud,
::Bluebox
::Vcloud
].select {|_module_| _module_.initialized?}

end

end
Expand Down
24 changes: 17 additions & 7 deletions lib/fog/service.rb
Expand Up @@ -52,12 +52,28 @@ def new(options={})
end
end

setup_requirements

if Fog.mocking?
service::Mock.send(:include, service::Collections)
service::Mock.new(options)
else
service::Real.send(:include, service::Collections)
service::Real.new(options)
end
end

def setup_requirements
if superclass.respond_to?(:setup_requirements)
superclass.setup_requirements
end

unless @required
for collection in collections
require [@model_path, collection].join('/')
constant = collection.to_s.split('_').map {|characters| characters[0...1].upcase << characters[1..-1]}.join('')
service::Collections.module_eval <<-EOS, __FILE__, __LINE__
def #{collection}(attributes={})
def #{collection}(attributes = {})
#{service}::#{constant}.new({:connection => self}.merge(attributes))
end
EOS
Expand All @@ -70,12 +86,6 @@ def #{collection}(attributes={})
end
@required = true
end

if Fog.mocking?
service::Mock.new(options)
else
service::Real.new(options)
end
end

def model_path(new_path)
Expand Down
81 changes: 57 additions & 24 deletions lib/fog/vcloud.rb
@@ -1,10 +1,8 @@
require 'fog/vcloud/service'
require 'builder'
require 'fog/vcloud/model'
require 'fog/vcloud/collection'
require 'fog/vcloud/generators'
require 'fog/vcloud/terremark/ecloud'
require 'fog/vcloud/terremark/vcloud'
# ecloud/vcloud requires at the bottom so that the following will be defined

module URI
class Generic
Expand All @@ -21,7 +19,7 @@ class Vcloud < Fog::Service

model_path 'fog/vcloud/models'
model :vdc
model :vdcs
collection :vdcs

request_path 'fog/vcloud/requests'
request :login
Expand All @@ -32,7 +30,55 @@ class Vcloud < Fog::Service

class UnsupportedVersion < Exception ; end

module Shared

def default_organization_uri
@default_organization_uri ||= begin
unless @login_results
do_login
end
case @login_results.body[:Org]
when Array
@login_results.body[:Org].first[:href]
when Hash
@login_results.body[:Org][:href]
else
nil
end
end
end

# login handles the auth, but we just need the Set-Cookie
# header from that call.
def do_login
@login_results = login
@cookie = @login_results.headers['Set-Cookie']
end

def supported_versions
@supported_versions ||= get_versions(@versions_uri).body[:VersionInfo]
end

def xmlns
{ "xmlns" => "http://www.vmware.com/vcloud/v0.8",
"xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
"xmlns:xsd" => "http://www.w3.org/2001/XMLSchema" }
end

# private

def ensure_unparsed(uri)
if uri.is_a?(String)
uri
else
uri.to_s
end
end

end

class Real
include Shared
extend Fog::Vcloud::Generators

attr_accessor :login_uri
Expand Down Expand Up @@ -68,12 +114,6 @@ def default_organization_uri
end
end

def xmlns
{ "xmlns" => "http://www.vmware.com/vcloud/v0.8",
"xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
"xmlns:xsd" => "http://www.w3.org/2001/XMLSchema" }
end

def reload
@connections.each_value { |k,v| v.reset if v }
end
Expand All @@ -93,10 +133,6 @@ def request(params)
end
end

def supported_versions
@supported_versions ||= get_versions(@versions_uri).body[:VersionInfo]
end

private

def ensure_parsed(uri)
Expand All @@ -107,14 +143,6 @@ def ensure_parsed(uri)
end
end

def ensure_unparsed(uri)
if uri.is_a?(String)
uri
else
uri.to_s
end
end

def supported_version_numbers
case supported_versions
when Array
Expand Down Expand Up @@ -218,7 +246,9 @@ def do_request(params)
end
end

class Mock < Real
class Mock
include Shared

def self.base_url
"https://fakey.com/api/v0.8"
end
Expand Down Expand Up @@ -349,7 +379,7 @@ def ip_from_uri(uri)
end
end

def initialize(credentials = {})
def initialize(options = {})
@versions_uri = URI.parse('https://vcloud.fakey.com/api/versions')
end

Expand Down Expand Up @@ -383,3 +413,6 @@ def mock_data
end
end
end

require 'fog/vcloud/terremark/ecloud'
require 'fog/vcloud/terremark/vcloud'
2 changes: 1 addition & 1 deletion lib/fog/vcloud/collection.rb
@@ -1,5 +1,5 @@
module Fog
class Vcloud
class Vcloud < Fog::Service
class Collection < Fog::Collection

def load(objects)
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/vcloud/generators.rb
@@ -1,5 +1,5 @@
module Fog
class Vcloud
class Vcloud < Fog::Service
module Generators

def unauthenticated_basic_request(*args)
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/vcloud/model.rb
@@ -1,5 +1,5 @@
module Fog
class Vcloud
class Vcloud < Fog::Service
class Model < Fog::Model

attr_accessor :loaded
Expand Down
10 changes: 2 additions & 8 deletions lib/fog/vcloud/models/vdcs.rb
@@ -1,12 +1,7 @@
require 'fog/vcloud/models/vdc'

module Fog
class Vcloud

class Real
def vdcs(options = {})
@vdcs ||= Fog::Vcloud::Vdcs.new(options.merge(:connection => self))
end
end

class Vdcs < Fog::Vcloud::Collection

model Fog::Vcloud::Vdc
Expand Down Expand Up @@ -36,6 +31,5 @@ def organization_uri=(new_organization_uri)
end

end

end
end
28 changes: 0 additions & 28 deletions lib/fog/vcloud/service.rb

This file was deleted.

32 changes: 20 additions & 12 deletions lib/fog/vcloud/terremark/ecloud.rb
@@ -1,29 +1,29 @@
module Fog
class Vcloud
module Terremark
class Ecloud < Fog::Vcloud::Service
class Ecloud < Fog::Vcloud

model_path 'fog/vcloud/terremark/ecloud/models'
model :catalog_item
model :catalog
model :firewall_acl
model :firewall_acls
collection :firewall_acls
model :internet_service
model :internet_services
collection :internet_services
model :ip
model :ips
collection :ips
model :network
model :networks
collection :networks
model :node
model :nodes
collection :nodes
model :public_ip
model :public_ips
collection :public_ips
model :server
model :servers
collection :servers
model :task
model :tasks
collection :tasks
model :vdc
model :vdcs
collection :vdcs

request_path 'fog/vcloud/terremark/ecloud/requests'
request :add_internet_service
Expand Down Expand Up @@ -62,7 +62,12 @@ class Ecloud < Fog::Vcloud::Service
request :power_reset
request :power_shutdown

module Mock
class Mock < Fog::Vcloud::Mock
include Collections

def initialize(options={})
end

def self.base_url
"https://fakey.com/api/v0.8b-ext2.3"
end
Expand Down Expand Up @@ -186,10 +191,13 @@ def mock_data
end
end

module Real
class Real < Fog::Vcloud::Real
include Collections

def supporting_versions
["v0.8b-ext2.3", "0.8b-ext2.3"]
end

end

end
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/vcloud/terremark/ecloud/models/catalog.rb
@@ -1,7 +1,7 @@
module Fog
class Vcloud
module Terremark
module Ecloud
class Ecloud

class Catalog < Fog::Vcloud::Collection

Expand Down
4 changes: 2 additions & 2 deletions lib/fog/vcloud/terremark/ecloud/models/catalog_item.rb
@@ -1,10 +1,10 @@
module Fog
class Vcloud
module Terremark
module Ecloud
class Ecloud
class CatalogItem < Fog::Vcloud::Model

identity :href, :Href
identity :href, :aliases => :Href

ignore_attributes :xmlns, :xmlns_i, :xmlns_xsi, :xmlns_xsd

Expand Down
4 changes: 2 additions & 2 deletions lib/fog/vcloud/terremark/ecloud/models/firewall_acl.rb
@@ -1,10 +1,10 @@
module Fog
class Vcloud
module Terremark
module Ecloud
class Ecloud
class FirewallAcl < Fog::Vcloud::Model

identity :href, :Href
identity :href, :aliases => :Href

ignore_attributes :xmlns, :xmlns_i

Expand Down
4 changes: 3 additions & 1 deletion lib/fog/vcloud/terremark/ecloud/models/firewall_acls.rb
@@ -1,7 +1,9 @@
require 'lib/fog/vcloud/terremark/ecloud/models/firewall_acl'

module Fog
class Vcloud
module Terremark
module Ecloud
class Ecloud

class FirewallAcls < Fog::Vcloud::Collection

Expand Down

0 comments on commit 4076bba

Please sign in to comment.