Navigation Menu

Skip to content

Commit

Permalink
[TerremarkEcloud] initial
Browse files Browse the repository at this point in the history
  • Loading branch information
danp authored and geemus committed Jan 21, 2011
1 parent f11d447 commit 5e6797f
Show file tree
Hide file tree
Showing 38 changed files with 1,413 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/fog/bin.rb
Expand Up @@ -16,6 +16,7 @@ def providers
::Rackspace,
::Slicehost,
::Terremark,
::TerremarkEcloud,
::Zerigo
].select {|provider| provider.available?}
end
Expand Down Expand Up @@ -83,5 +84,6 @@ def collections
require 'fog/bin/rackspace'
require 'fog/bin/slicehost'
require 'fog/bin/terremark'
require 'fog/bin/terremark_ecloud'
require 'fog/bin/vcloud'
require 'fog/bin/zerigo'
28 changes: 28 additions & 0 deletions lib/fog/bin/terremark_ecloud.rb
@@ -0,0 +1,28 @@
class TerremarkEcloud < Fog::Bin
class << self

def class_for(key)
case key
when :compute
Fog::TerremarkEcloud::Compute
else
# @todo Replace most instances of ArgumentError with NotImplementedError
# @todo For a list of widely supported Exceptions, see:
# => http://www.zenspider.com/Languages/Ruby/QuickRef.html#35
raise ArgumentError, "Unsupported #{self} service: #{key}"
end
end

def [](service)
@@connections ||= Hash.new do |hash, key|
hash[key] = class_for(key).new
end
@@connections[service]
end

def services
[:compute]
end

end
end
3 changes: 3 additions & 0 deletions lib/fog/compute.rb
Expand Up @@ -28,6 +28,9 @@ def self.new(attributes)
when 'Slicehost'
require 'fog/compute/slicehost'
Fog::Slicehost::Compute.new(attributes)
when 'TerremarkEcloud'
require 'fog/compute/terremark_ecloud'
Fog::TerremarkEcloud::Compute.new(attributes)
else
raise ArgumentError.new("#{provider} is not a recognized compute provider")
end
Expand Down
41 changes: 41 additions & 0 deletions lib/fog/compute/parsers/terremark_ecloud/get_catalog.rb
@@ -0,0 +1,41 @@
module Fog
module Parsers
module TerremarkEcloud
module Compute

class GetCatalog < Fog::Parsers::Base

def reset
@response = { 'catalogItems' => [] }
end

def start_element(name, attrs = [])
case name
when 'Catalog'
@response['name'] = attr_value('name', attrs)
@response['uri'] = attr_value('href', attrs)
when 'CatalogItems'
@in_catalog_items = true
when 'CatalogItem'
if @in_catalog_items
@response['catalogItems'].push({
'name' => attr_value('name', attrs),
'uri' => attr_value('href', attrs)
})
end
end

super
end

def end_element(name)
case name
when 'CatalogItems'
@in_catalog_items = false
end
end
end
end
end
end
end
43 changes: 43 additions & 0 deletions lib/fog/compute/parsers/terremark_ecloud/get_catalog_item.rb
@@ -0,0 +1,43 @@
module Fog
module Parsers
module TerremarkEcloud
module Compute

class GetCatalogItem < Fog::Parsers::Base

def reset
@response = { 'properties' => [] }
end

def start_element(name, attrs = [])
case name
when 'CatalogItem'
@response['name'] = attr_value('name', attrs)
@response['uri'] = attr_value('href', attrs)
when 'Link', 'Entity'
href = attr_value('href', attrs)

case attr_value('type', attrs)
when 'application/vnd.tmrk.ecloud.catalogItemCustomizationParameters+xml'
@response['customization_uri'] = href
when 'application/vnd.vmware.vcloud.vAppTemplate+xml'
@response['template_uri'] = href
end
when 'Property'
@property_key = attr_value('key', attrs)
end

super
end

def end_element(name)
case name
when 'Property'
@response['properties'].push({ 'key' => @property_key, 'value' => @value})
end
end
end
end
end
end
end
55 changes: 55 additions & 0 deletions lib/fog/compute/parsers/terremark_ecloud/get_network.rb
@@ -0,0 +1,55 @@
module Fog
module Parsers
module TerremarkEcloud
module Compute

class GetNetwork < Fog::Parsers::Base

def reset
@response = { 'configuration' => {}, 'features' => {} }
end

def start_element(name, attrs = [])
case name
when 'Network'
@response['name'] = attr_value('name', attrs)
@response['uri'] = attr_value('href', attrs)
when 'Link'
href = attr_value('href', attrs)

case attr_value('name', attrs) # wut
when @response['name']
@response['extensions_uri'] = href
when 'IP Addresses'
@response['extensions_ips_uri'] = href
end
when 'Configuration'
@in_configuration = true
when 'Features'
@in_features = true
end

super
end

def end_element(name)
case name
when 'Configuration'
@in_configuration = false
when 'Gateway', 'Netmask'
if @in_configuration
@response['configuration'][name.downcase] = @value
end
when 'Features'
@in_features = false
else
if @in_features
@response['features'][name] = @value
end
end
end
end
end
end
end
end
33 changes: 33 additions & 0 deletions lib/fog/compute/parsers/terremark_ecloud/get_network_extensions.rb
@@ -0,0 +1,33 @@
module Fog
module Parsers
module TerremarkEcloud
module Compute

class GetNetworkExtensions < Fog::Parsers::Base

def end_element(name)
case name
when 'Name'
@response['name'] = @value
when 'Href'
@response['uri'] = @value
when 'RnatAddress'
@response['rnatAddress'] = @value
when 'Address'
@response['address'] = @value
when 'BroadcastAddress'
@response['broadcastAddress'] = @value
when 'GatewayAddress'
@response['gatewayAddress'] = @value
when 'NetworkType'
@response['type'] = @value
when 'FriendlyName'
@response['friendlyName'] = @value
end
end

end
end
end
end
end
39 changes: 39 additions & 0 deletions lib/fog/compute/parsers/terremark_ecloud/get_organization.rb
@@ -0,0 +1,39 @@
module Fog
module Parsers
module TerremarkEcloud
module Compute

class GetOrganization < Fog::Parsers::Base

def reset
@response = { 'vdcs' => [] }
end

def start_element(name, attrs = [])
case name
when 'Org'
@response['name'] = attr_value('name', attrs)
@response['uri'] = attr_value('href', attrs)
when 'Link'
href = attr_value('href', attrs)

case attr_value('type', attrs)
when 'application/vnd.vmware.vcloud.vdc+xml'
@response['vdcs'].push({ 'name' => attr_value('name', attrs), 'uri' => href })
when 'application/vnd.vmware.vcloud.catalog+xml'
@response['catalog_uri'] = href
when 'application/vnd.vmware.vcloud.tasksList+xml'
@response['tasksList_uri'] = href
when 'application/vnd.tmrk.ecloud.keysList+xml'
@response['keysList_uri'] = href
when 'application/vnd.tmrk.ecloud.tagsList+xml'
@response['tagsList_uri'] = href
end
end
end

end
end
end
end
end
35 changes: 35 additions & 0 deletions lib/fog/compute/parsers/terremark_ecloud/get_task.rb
@@ -0,0 +1,35 @@
module Fog
module Parsers
module TerremarkEcloud
module Compute

class GetTask < Fog::Parsers::Base

def reset
@response = { 'owner' => {}, 'result' => {} }
end

def start_element(name, attrs = [])
case name
when 'Task'
@response['uri'] = attr_value('href', attrs)
@response['status'] = attr_value('status', attrs)
@response['startTime'] = (start_time = attr_value('startTime', attrs) and Time.parse(start_time))
@response['endTime'] = (end_time = attr_value('endTime', attrs) and Time.parse(end_time))
when 'Owner', 'Result'
href, type, this_name = %w(href type name).map {|a| attr_value(a, attrs) }
@response[name.downcase] = {
'uri' => href,
'type' => type,
'name' => this_name
}
end

super
end

end
end
end
end
end

0 comments on commit 5e6797f

Please sign in to comment.