fog-terremark-0.1.0/0000755000004100000410000000000013312111667014306 5ustar www-datawww-datafog-terremark-0.1.0/.travis.yml0000644000004100000410000000066213312111667016423 0ustar www-datawww-datamatrix: include: - rvm: 1.8.7 gemfile: gemfiles/Gemfile.1.9.2- - rvm: 1.9.2 gemfile: gemfiles/Gemfile.1.9.2- - rvm: 1.9.3 gemfile: gemfiles/Gemfile.1.9.3+ - rvm: 2.0.0 gemfile: gemfiles/Gemfile.1.9.3+ - rvm: 2.1.4 gemfile: gemfiles/Gemfile.1.9.3+ env: COVERAGE=true - rvm: ree gemfile: gemfiles/Gemfile.1.9.2- - rvm: jruby gemfile: gemfiles/Gemfile.1.9.3+ fog-terremark-0.1.0/README.md0000644000004100000410000000244013312111667015565 0ustar www-datawww-data# Fog::Terremark ![Gem Version](https://badge.fury.io/rb/fog-terremark.svg) [![Build Status](https://travis-ci.org/fog/fog-terremark.svg?branch=master)](https://travis-ci.org/fog/fog-terremark) [![Dependency Status](https://gemnasium.com/fog/fog-terremark.svg)](https://gemnasium.com/fog/fog-terremark) [![Coverage Status](https://img.shields.io/coveralls/fog/fog-terremark.svg)](https://coveralls.io/r/fog/fog-terremark?branch=master) [![Code Climate](https://codeclimate.com/github/fog/fog-terremark.png)](https://codeclimate.com/github/fog/fog-terremark) Module for the "fog" gem to support Terremark vCloud ## Help Needed This gem needs a maintainer. If you want to work on it, please contact [@geemus](mailto:geemus@gmail.com) or [@plribeiro3000](mailto:plribeiro3000@gmail.com) ## Installation Add this line to your application's Gemfile: ```ruby gem "fog-terremark" ``` And then execute: $ bundle Or install it yourself as: $ gem install fog-terremark ## Usage TODO: Write usage instructions here ## Contributing 1. Fork it ( https://github.com/fog/fog-terremark/fork ) 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am "Add some feature"`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create a new Pull Request fog-terremark-0.1.0/gemfiles/0000755000004100000410000000000013312111667016101 5ustar www-datawww-datafog-terremark-0.1.0/gemfiles/Gemfile.1.9.3+0000644000004100000410000000016713312111667020122 0ustar www-datawww-datasource :rubygems gem "activesupport", ">= 3.0", "< 4" gem "mime-types", "< 2.0" gem "fog-core" gemspec :path => "../"fog-terremark-0.1.0/gemfiles/Gemfile.1.9.2-0000644000004100000410000000021013312111667020110 0ustar www-datawww-datasource :rubygems gem "mime-types", "< 2.0" gem "nokogiri", "< 1.6" gem "rest-client", "~> 1.6.8" gem "fog-core" gemspec :path => "../"fog-terremark-0.1.0/LICENSE.md0000644000004100000410000000220213312111667015706 0ustar www-datawww-dataThe MIT License (MIT) Copyright (c) 2014-2014 [CONTRIBUTORS.md](https://github.com/fog/fog-terremark/blob/master/CONTRIBUTORS.md) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.fog-terremark-0.1.0/spec/0000755000004100000410000000000013312111667015240 5ustar www-datawww-datafog-terremark-0.1.0/spec/minitest_helper.rb0000644000004100000410000000171013312111667020757 0ustar www-datawww-datarequire "minitest/spec" require "minitest/autorun" require "turn" require "vcr" Turn.config do |c| # use one of output formats: # :outline - turn"s original case/test outline mode [default] # :progress - indicates progress with progress bar # :dotted - test/unit"s traditional dot-progress mode # :pretty - new pretty reporter # :marshal - dump output as YAML (normal run mode only) # :cue - interactive testing # c.format = :outline # turn on invoke/execute tracing, enable full backtrace c.trace = 20 # use humanized test names (works only with :outline format) c.natural = true end VCR.configure do |c| c.cassette_library_dir = "spec/cassettes" c.hook_into :excon c.debug_logger = $stderr end if ENV["COVERAGE"] require "coveralls" require "simplecov" SimpleCov.start do add_filter "/spec/" end end require File.join(File.dirname(__FILE__), "../lib/fog/terremark.rb") Coveralls.wear! if ENV["COVERAGE"] fog-terremark-0.1.0/spec/cassettes/0000755000004100000410000000000013312111667017236 5ustar www-datawww-datafog-terremark-0.1.0/spec/cassettes/get_login_token.yml0000644000004100000410000000237413312111667023136 0ustar www-datawww-data--- http_interactions: - request: method: post uri: https://services.vcloudexpress.terremark.com/api/v0.8a-ext1.6/login body: encoding: US-ASCII string: "" headers: User-Agent: - fog-core/1.25.0 Authorization: - Basic CREDENTIALS Content-Type: - application/vnd.vmware.vcloud.orgList+xml response: status: code: 200 message: headers: Cache-Control: - private Content-Length: - "328" Content-Type: - application/vnd.vmware.vcloud.orgList+xml Server: - Microsoft-IIS/7.0 X-AspNet-Version: - 4.0.30319 Set-Cookie: - vcloud-token=TOKEN; path=/ X-Powered-By: - ASP.NET Date: - Mon, 24 Nov 2014 20:39:30 GMT body: encoding: UTF-8 string: |- http_version: recorded_at: Mon, 24 Nov 2014 20:39:30 GMT recorded_with: VCR 2.9.3 fog-terremark-0.1.0/spec/credentials_spec.rb0000644000004100000410000000052013312111667021071 0ustar www-datawww-datarequire "minitest_helper" describe Fog::Terremark::Vcloud do it "gets a login token" do VCR.use_cassette("get_login_token") do service = Fog::Terremark::Vcloud.new( :terremark_vcloud_username => "test@example.com", :terremark_vcloud_password => "123456") service.send(:auth_token) end end end fog-terremark-0.1.0/.rubocop.yml0000644000004100000410000000054113312111667016560 0ustar www-datawww-dataMetrics/LineLength: Enabled: false Style/EachWithObject: Enabled: false Style/Encoding: EnforcedStyle: when_needed Style/FormatString: Enabled: false Style/HashSyntax: EnforcedStyle: hash_rockets Style/SignalException: EnforcedStyle: only_raise Style/StringLiterals: EnforcedStyle: double_quotes Style/ExtraSpacing: Enabled: falsefog-terremark-0.1.0/CONTRIBUTORS.md0000644000004100000410000000066613312111667016575 0ustar www-datawww-data* Athir Nuaimi * Chirag Jog * David Calavera * Edward Muller * James Herdman * Juris Galang * marios * Nathan Buesgens * Paul Thornthwaite * Paulo Henrique Lopes Ribeiro * Wesley Beary fog-terremark-0.1.0/.gitignore0000644000004100000410000000031013312111667016270 0ustar www-datawww-data*.gem *.rbc .bundle .config .yardoc Gemfile.lock InstalledFiles _yardoc coverage doc/ lib/bundler/man pkg rdoc spec/reports test/tmp test/version_tmp tmp *.bundle *.so *.o *.a mkmf.log gemfiles/*.lockfog-terremark-0.1.0/Rakefile0000644000004100000410000000033013312111667015747 0ustar www-datawww-datarequire "bundler/gem_tasks" require "rake/testtask" Rake::TestTask.new do |t| t.libs.push %w(spec) t.test_files = FileList["spec/**/*_spec.rb"] t.verbose = true end desc "Default Task" task :default => :test fog-terremark-0.1.0/lib/0000755000004100000410000000000013312111667015054 5ustar www-datawww-datafog-terremark-0.1.0/lib/fog/0000755000004100000410000000000013312111667015627 5ustar www-datawww-datafog-terremark-0.1.0/lib/fog/terremark.rb0000644000004100000410000000063113312111667020150 0ustar www-datawww-datarequire "fog/core" require "fog/xml" require File.expand_path("../terremark/version", __FILE__) module Fog module Terremark autoload :Vcloud, File.expand_path("../terremark/vcloud", __FILE__) end module Compute autoload :Terremark, File.expand_path("../compute/terremark", __FILE__) end module Parsers autoload :Terremark, File.expand_path("../parsers/terremark", __FILE__) end end fog-terremark-0.1.0/lib/fog/parsers/0000755000004100000410000000000013312111667017306 5ustar www-datawww-datafog-terremark-0.1.0/lib/fog/parsers/terremark.rb0000644000004100000410000000341013312111667021625 0ustar www-datawww-datamodule Fog module Parsers module Terremark autoload :Base, File.expand_path("../terremark/base", __FILE__) autoload :GetCatalog, File.expand_path("../terremark/get_catalog", __FILE__) autoload :GetCatalogItem, File.expand_path("../terremark/get_catalog_item", __FILE__) autoload :GetInternetServices, File.expand_path("../terremark/get_internet_services", __FILE__) autoload :GetKeysList, File.expand_path("../terremark/get_keys_list", __FILE__) autoload :GetNetworkIps, File.expand_path("../terremark/get_network_ips", __FILE__) autoload :GetNodeServices, File.expand_path("../terremark/get_node_services", __FILE__) autoload :GetOrganization, File.expand_path("../terremark/get_organization", __FILE__) autoload :GetOrganizations, File.expand_path("../terremark/get_organizations", __FILE__) autoload :GetPublicIps, File.expand_path("../terremark/get_public_ips", __FILE__) autoload :GetTasksList, File.expand_path("../terremark/get_tasks_list", __FILE__) autoload :GetVappTemplate, File.expand_path("../terremark/get_vapp_template", __FILE__) autoload :GetVdc, File.expand_path("../terremark/get_vdc", __FILE__) autoload :InstantiateVappTemplate, File.expand_path("../terremark/instantiate_vapp_template", __FILE__) autoload :InternetService, File.expand_path("../terremark/internet_service", __FILE__) autoload :Network, File.expand_path("../terremark/network", __FILE__) autoload :NodeService, File.expand_path("../terremark/node_service", __FILE__) autoload :PublicIp, File.expand_path("../terremark/public_ip", __FILE__) autoload :Task, File.expand_path("../terremark/task", __FILE__) autoload :Vapp, File.expand_path("../terremark/vapp", __FILE__) end end end fog-terremark-0.1.0/lib/fog/parsers/terremark/0000755000004100000410000000000013312111667021302 5ustar www-datawww-datafog-terremark-0.1.0/lib/fog/parsers/terremark/get_tasks_list.rb0000644000004100000410000000140513312111667024646 0ustar www-datawww-datamodule Fog module Parsers module Terremark class GetTasksList < Base def reset @response = { "Tasks" => [] } @task = {} end def start_element(name, attributes) super case name when "Owner", "Result" data = extract_templates(attributes) @task[name] = data when "Task" @task = extract_templates(attributes) when "TasksList" tasks_list = extract_templates(attributes) @response["href"] = tasks_list["href"] end end def end_element(name) if name == "Task" @response["Tasks"] << @task @task = {} end end end end end end fog-terremark-0.1.0/lib/fog/parsers/terremark/get_vdc.rb0000644000004100000410000000527213312111667023250 0ustar www-datawww-datamodule Fog module Parsers module Terremark class GetVdc < Base def reset @in_storage_capacity = false @in_cpu = false @in_memory = false @in_instantiated_vms_quota = false @in_deployed_vms_quota = false @response = { "links" => [], "AvailableNetworks" => [], "ComputeCapacity" => { "Cpu" => {}, "DeployedVmsQuota" => {}, "InstantiatedVmsQuota" => {}, "Memory" => {} }, "StorageCapacity" => {}, "ResourceEntities" => [] } end def start_element(name, attributes) super case name when "Cpu" @in_cpu = true when "DeployedVmsQuota" @in_deployed_vms_quota = true when "InstantiatedVmsQuota" @in_instantiated_vms_quota = true when "Link" link = extract_attributes(attributes) @response["links"] << link when "Memory" @in_memory = true when "Network" network = extract_attributes(attributes) @response["AvailableNetworks"] << network when "ResourceEntity" resource_entity = extract_attributes(attributes) @response["ResourceEntities"] << resource_entity when "StorageCapacity" @in_storage_capacity = true when "Vdc" vdc = extract_attributes(attributes) @response["href"] = vdc["href"] @response["name"] = vdc["name"] end end def end_element(name) case name when "Allocated", "Limit", "Units", "Used" if @in_cpu @response["ComputeCapacity"]["Cpu"][name] = value elsif @in_deployed_vms_quota @response["ComputeCapacity"]["DeployedVmsQuota"][name] = value elsif @in_instantiated_vms_quota @response["ComputeCapacity"]["InstantiatedVmsQuota"][name] = value elsif @in_memory @response["ComputeCapacity"]["Memory"][name] = value elsif @in_storage_capacity @response["StorageCapacity"][name] = value end when "Cpu" @in_cpu = false when "DeployedVmsQuota" @in_deployed_vms_quota = false when "InstantiatedVmsQuota" @in_instantiated_vms_quota = false when "Memory" @in_memory = false when "StorageCapacity" @in_storage_capacity = false when "Type" @response[name] = value end end end end end end fog-terremark-0.1.0/lib/fog/parsers/terremark/node_service.rb0000644000004100000410000000110413312111667024270 0ustar www-datawww-datamodule Fog module Parsers module Terremark class NodeService < Base def reset @response = {} end def end_element(name) case name when "Description", "Href", "IpAddress", "Name", "Protocol" @response[name] = value when "Enabled" if value == "false" @response[name] = false else @response[name] = true end when "Id", "Port" @response[name] = value.to_i end end end end end end fog-terremark-0.1.0/lib/fog/parsers/terremark/get_keys_list.rb0000644000004100000410000000160313312111667024474 0ustar www-datawww-datamodule Fog module Parsers module Terremark class GetKeysList < Base def reset @response = { "Keys" => [] } @key = {} end def start_element(name, attributes) super case name when "Id", "Href", "Name", "IsDefault", "FingerPrint" data = extract_attributes(attributes) @key[name] = data when "Key" @key = extract_attributes(attributes) when "Keys" keys_list = extract_attributes(attributes) @response["href"] = keys_list["href"] end end def end_element(name) case name when "Id", "Href", "Name", "IsDefault", "FingerPrint" @key[name] = value when "Key" @response["Keys"] << @key @key = {} end end end end end end fog-terremark-0.1.0/lib/fog/parsers/terremark/get_vapp_template.rb0000644000004100000410000000125013312111667025325 0ustar www-datawww-datamodule Fog module Parsers module Terremark class GetVappTemplate < Base def reset @response = { "Links" => [] } end def start_element(name, attributes) super case name when "Link" link = extract_attributes(attributes) @response["Links"] << link when "VAppTemplate" vapp_template = extract_attributes(attributes) @response["name"] = vapp_template["name"] end end def end_element(name) if name == "Description" @response["Description"] = value end end end end end end fog-terremark-0.1.0/lib/fog/parsers/terremark/network.rb0000644000004100000410000000160113312111667023316 0ustar www-datawww-datamodule Fog module Parsers module Terremark class Network < Base def reset @response = { "links" => [] } end def start_element(name,attributes=[]) super case name when "Network" @response = extract_attributes(attributes) if @response.key?("name") @response["subnet"] = @response["name"] end if @response.key?("href") @response["id"] = @response["href"].split("/").last end when "Link" link = extract_attributes(attributes) @response["links"] << link end end def end_element(name) case name when "Gateway", "Netmask", "FenceMode" @response[name.downcase] = value end end end end end end fog-terremark-0.1.0/lib/fog/parsers/terremark/vapp.rb0000644000004100000410000000335413312111667022602 0ustar www-datawww-datamodule Fog module Parsers module Terremark class Vapp < Base def reset @response = { "Links" => [], "VirtualHardware" => {}, "OperatingSystem" => {} } @in_operating_system = false @resource_type = nil end def start_element(name, attributes) super case name when "Link" link = extract_attributes(attributes) @response["Links"] << link when "OperatingSystemSection" @in_operating_system = true when "VApp" vapp = extract_attributes(attributes) @response.merge!(vapp.reject { |key, _value| !["href", "name", "size", "status", "type"].include?(key) }) end end def end_element(name) case name when "IpAddress" @response["IpAddress"] = value when "Description" if @in_operating_system @response["OperatingSystem"][name] = value @in_operating_system = false end when "ResourceType" @resource_type = value case value when "3" @get_cpu = true # cpu when "4" # memory @get_ram = true when "17" # disks @get_disks = true end when "VirtualQuantity" case @resource_type when "3" @response["VirtualHardware"]["cpu"] = value when "4" @response["VirtualHardware"]["ram"] = value when "17" @response["VirtualHardware"]["disks"] ||= [] @response["VirtualHardware"]["disks"] << value end end end end end end end fog-terremark-0.1.0/lib/fog/parsers/terremark/base.rb0000644000004100000410000000121513312111667022540 0ustar www-datawww-datamodule Fog module Parsers module Terremark class Base < Fog::Parsers::Base def extract_attributes(attributes_xml) attributes = {} until attributes_xml.empty? if attributes_xml.first.is_a?(Array) until attributes_xml.first.empty? attribute = attributes_xml.first.shift attributes[attribute.localname] = attribute.value end else attribute = attributes_xml.shift attributes[attribute.localname] = attribute.value end end attributes end end end end end fog-terremark-0.1.0/lib/fog/parsers/terremark/task.rb0000644000004100000410000000112413312111667022567 0ustar www-datawww-datamodule Fog module Parsers module Terremark class Task < Base def reset @response = {} end def start_element(name, attributes) super case name when "Owner", "Result", "Link", "Error" data = extract_attributes(attributes) @response[name] = data when "Task" task = extract_attributes(attributes) @response.merge!(task.reject { |key, _value| !["endTime", "href", "startTime", "status", "type"].include?(key) }) end end end end end end fog-terremark-0.1.0/lib/fog/parsers/terremark/get_organizations.rb0000644000004100000410000000131413312111667025354 0ustar www-datawww-datamodule Fog module Parsers module Terremark class GetOrganizations < Base def reset @response = { "OrgList" => [] } end def start_element(name, attributes) super if name == "Org" organization = extract_attributes(attributes) until attributes.empty? if attributes.first.is_a?(Array) attribute = attributes.shift organization[attribute.first] = attribute.last else organization[attributes.shift] = attributes.shift end end @response["OrgList"] << organization end end end end end end fog-terremark-0.1.0/lib/fog/parsers/terremark/get_network_ips.rb0000644000004100000410000000074613312111667025041 0ustar www-datawww-datamodule Fog module Parsers module Terremark class GetNetworkIps< Base def reset @ip_address = {} @response = { "IpAddresses" => [] } 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 fog-terremark-0.1.0/lib/fog/parsers/terremark/public_ip.rb0000644000004100000410000000056513312111667023603 0ustar www-datawww-datamodule Fog module Parsers module Terremark class PublicIp < Base def reset @response = {} end def end_element(name) case name when "Href", "Name" @response[name.downcase] = value when "Id" @response["id"] = value.to_i end end end end end end fog-terremark-0.1.0/lib/fog/parsers/terremark/get_catalog.rb0000644000004100000410000000136513312111667024105 0ustar www-datawww-datamodule Fog module Parsers module Terremark class GetCatalog < Base def reset @response = { "CatalogItems" => [] } end def start_element(name, attributes) super case name when "CatalogItem" catalog_item = extract_attributes(attributes) catalog_item["id"] = catalog_item["href"].split("/").last @response["CatalogItems"] << catalog_item when "Catalog" catalog = extract_attributes(attributes) @response["name"] = catalog["name"] end end def end_element(name) if name == "Description" @response[name] = value end end end end end end fog-terremark-0.1.0/lib/fog/parsers/terremark/internet_service.rb0000644000004100000410000000273213312111667025203 0ustar www-datawww-datamodule Fog module Parsers module Terremark class InternetService < Base def reset @in_public_ip_address = false @response = { "PublicIpAddress" => {} } end def start_element(name, attributes) super case name when "Href" data = extract_attributes(attributes) if @in_public_ip_address @response["PublicIpAddress"][name] = data else @response[name] = data end when "PublicIpAddress" @in_public_ip_address = true end end def end_element(name) case name when "Description", "Protocol" @response[name] = value when "Enabled" if value == "false" @response[name] = false else @response[name] = true end when "Id" if @in_public_ip_address @response["PublicIpAddress"][name] = value.to_i else @response[name] = value.to_i end when "Name" if @in_public_ip_address @response["PublicIpAddress"][name] = value else @response[name] = value end when "Port", "Timeout" @response[name] = value.to_i when "PublicIpAddress" @in_public_ip_address = false end end end end end end fog-terremark-0.1.0/lib/fog/parsers/terremark/get_public_ips.rb0000644000004100000410000000105213312111667024615 0ustar www-datawww-datamodule Fog module Parsers module Terremark class GetPublicIps< Base def reset @ip_address = {} @response = { "PublicIpAddresses" => [] } end def end_element(name) case name when "Href", "Name" @ip_address[name.downcase] = value when "Id" @ip_address["id"] = value.to_i when "PublicIPAddress" @response["PublicIpAddresses"] << @ip_address @ip_address = {} end end end end end end fog-terremark-0.1.0/lib/fog/parsers/terremark/get_node_services.rb0000644000004100000410000000136113312111667025317 0ustar www-datawww-datamodule Fog module Parsers module Terremark class GetNodeServices < Base def reset @node_service = {} @response = { "NodeServices" => [] } end def end_element(name) case name when "Description", "Href", "Name", "IpAddress" @node_service[name] = value when "Enabled" if value == "true" @node_service[name] = true else @node_service[name] = false end when "Id", "Port" @node_service[name] = value.to_i when "NodeService" @response["NodeServices"] << @node_service @node_service = {} end end end end end end fog-terremark-0.1.0/lib/fog/parsers/terremark/instantiate_vapp_template.rb0000644000004100000410000000120013312111667027064 0ustar www-datawww-datamodule Fog module Parsers module Terremark class InstantiateVappTemplate < Base def reset @property_key @response = { "Links" => [] } end def start_element(name, attributes) super case name when "Link" link = extract_attributes(attributes) @response["Links"] << link when "VApp" vapp_template = extract_attributes(attributes) @response.merge!(vapp_template.reject { |key, _value| !["href", "name", "size", "status", "type"].include?(key) }) end end end end end end fog-terremark-0.1.0/lib/fog/parsers/terremark/get_internet_services.rb0000644000004100000410000000312313312111667026220 0ustar www-datawww-datamodule Fog module Parsers module Terremark class GetInternetServices < Base def reset @in_public_ip_address = false @internet_service = {} @response = { "InternetServices" => [] } end def start_element(name, attributes) super case name when "PublicIpAddress" @in_public_ip_address = true end end def end_element(name) case name when "Description", "Protocol" @internet_service[name] = value when "Enabled" if value == "true" @internet_service[name] = true else @internet_service[name] = false end when "Href", "Name" if @in_public_ip_address @internet_service["PublicIpAddress"] ||= {} @internet_service["PublicIpAddress"][name] = value else @internet_service[name] = value end when "Id" if @in_public_ip_address @internet_service["PublicIpAddress"] ||= {} @internet_service["PublicIpAddress"][name] = value.to_i else @internet_service[name] = value.to_i end when "InternetService" @response["InternetServices"] << @internet_service @internet_service = {} when "Port", "Timeout" @internet_service[name] = value.to_i when "PublicIpAddress" @in_public_ip_address = false end end end end end end fog-terremark-0.1.0/lib/fog/parsers/terremark/get_catalog_item.rb0000644000004100000410000000136513312111667025123 0ustar www-datawww-datamodule Fog module Parsers module Terremark class GetCatalogItem < Base def reset @response = { "Entity" => {}, "Properties" => {} } end def start_element(name, attributes) super case name when "Entity" @response["Entity"] = extract_attributes(attributes) when "CatalogItem" catalog_item = extract_attributes(attributes) @response["name"] = catalog_item["name"] when "Property" @property_key = attributes.value end end def end_element(name) if name == "Property" @response["Properties"][@property_key] = value end end end end end end fog-terremark-0.1.0/lib/fog/parsers/terremark/get_organization.rb0000644000004100000410000000237013312111667025174 0ustar www-datawww-datamodule Fog module Parsers module Terremark class GetOrganization < Base def reset @response = { "Links" => [] } end def start_element(name, attributes) super case name when "Link" link = extract_attributes(attributes) until attributes.empty? if attributes.first.is_a?(Array) attribute = attributes.shift link[attribute.first] = attribute.last else link[attributes.shift] = attributes.shift end end @response["Links"] << link when "Org" org = extract_attributes(attributes) until attributes.empty? if attributes.first.is_a?(Array) attribute = attributes.shift org[attribute.first] = attribute.last else org[attributes.shift] = attributes.shift end end @response["href"] = org["href"] @response["name"] = org["name"] end end def end_element(name) if name == "Description" @response[name] = value end end end end end end fog-terremark-0.1.0/lib/fog/bin/0000755000004100000410000000000013312111667016377 5ustar www-datawww-datafog-terremark-0.1.0/lib/fog/bin/terremark.rb0000644000004100000410000000132213312111667020716 0ustar www-datawww-dataclass Terremark < Fog::Bin class << self def available? Fog::Terremark::VCLOUD_OPTIONS.all? {|requirement| Fog.credentials.include?(requirement)} end def terremark_service(service) case service when :vcloud Fog::Terremark::Vcloud else raise "Unsupported Terremark Service" end end def [](service) @@connections ||= Hash.new do |hash, key| credentials = Fog.credentials.reject do |k,v| case key when :vcloud !Fog::Terremark::VCLOUD_OPTIONS.include?(k) end end hash[key] = terremark_service(key).new(credentials) end @@connections[service] end end end fog-terremark-0.1.0/lib/fog/terremark/0000755000004100000410000000000013312111667017623 5ustar www-datawww-datafog-terremark-0.1.0/lib/fog/terremark/version.rb0000644000004100000410000000007613312111667021640 0ustar www-datawww-datamodule Fog module Terremark VERSION = "0.1.0" end end fog-terremark-0.1.0/lib/fog/terremark/vcloud.rb0000644000004100000410000000147213312111667021450 0ustar www-datawww-datamodule Fog module Terremark class Vcloud < Fog::Compute::Terremark autoload :Mock, File.expand_path("../vcloud/mock", __FILE__) autoload :Real, File.expand_path("../vcloud/real", __FILE__) HOST = "services.vcloudexpress.terremark.com" PATH = "/api/v0.8a-ext1.6" PORT = 443 SCHEME = "https" def self.new(options = {}) Fog::Logger.deprecation("Fog::Terremark::Vcloud is deprecated, to be replaced with Vcloud 1.0 someday/maybe [light_black](#{caller.first})[/]") super end def default_ssh_key if default_ssh_key @default_ssh_key ||= begin keys = get_keys_list(default_organization_id).body["Keys"] keys.find { |item| item["IsDefault"] == "true" } end end end end end end fog-terremark-0.1.0/lib/fog/terremark/vcloud/0000755000004100000410000000000013312111667021117 5ustar www-datawww-datafog-terremark-0.1.0/lib/fog/terremark/vcloud/real.rb0000644000004100000410000000417513312111667022376 0ustar www-datawww-datamodule Fog module Terremark class Vcloud class Real < Fog::Compute::Terremark::Real def initialize(options={}) @terremark_password = options[:terremark_vcloud_password] @terremark_username = options[:terremark_vcloud_username] @connection_options = options[:connection_options] || {} @host = options[:host] || Fog::Terremark::Vcloud::HOST @path = options[:path] || Fog::Terremark::Vcloud::PATH @persistent = options[:persistent] || false @port = options[:port] || Fog::Terremark::Vcloud::PORT @scheme = options[:scheme] || Fog::Terremark::Vcloud::SCHEME @connection = Fog::XML::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options) end def default_vdc_id if default_organization_id @default_vdc_id ||= begin vdcs = get_organization(default_organization_id).body["Links"].select do |link| link["type"] == "application/vnd.vmware.vcloud.vdc+xml" end if vdcs.length == 1 vdcs.first["href"].split("/").last.to_i else nil end end else nil end end def default_network_id if default_vdc_id @default_network_id ||= begin networks = get_vdc(default_vdc_id).body["AvailableNetworks"] if networks.length == 1 networks.first["href"].split("/").last.to_i else nil end end else nil end end def default_public_ip_id if default_vdc_id @default_public_ip_id ||= begin ips = get_public_ips(default_vdc_id).body["PublicIpAddresses"] if ips.length == 1 ips.first["href"].split("/").last.to_i else nil end end else nil end end end end end end fog-terremark-0.1.0/lib/fog/terremark/vcloud/mock.rb0000644000004100000410000000107713312111667022402 0ustar www-datawww-datamodule Fog module Terremark class Vcloud class Mock < Fog::Compute::Terremark::Mock def initialize(option = {}) super @base_url = Fog::Terremark::Vcloud::SCHEME + "://" + Fog::Terremark::Vcloud::HOST + Fog::Terremark::Vcloud::PATH @terremark_username = options[:terremark_vcloud_username] end def data self.class.data[@terremark_username] end def reset_data self.class.data.delete(@terremark_username) end end end end end fog-terremark-0.1.0/lib/fog/compute/0000755000004100000410000000000013312111667017303 5ustar www-datawww-datafog-terremark-0.1.0/lib/fog/compute/terremark.rb0000644000004100000410000000356013312111667021630 0ustar www-datawww-datamodule Fog module Compute class Terremark < Fog::Service autoload :Common, File.expand_path("../terremark/common", __FILE__) autoload :Parser, File.expand_path("../terremark/parser", __FILE__) autoload :Real, File.expand_path("../terremark/real", __FILE__) autoload :Mock, File.expand_path("../terremark/mock", __FILE__) requires :terremark_vcloud_username, :terremark_vcloud_password model_path "fog/compute/terremark/models" model :address collection :addresses model :image collection :images model :internetservice collection :internetservices model :network collection :networks model :nodeservice collection :nodeservices model :server collection :servers model :task collection :tasks model :vdc collection :vdcs request_path "fog/compute/terremark/requests" request :add_internet_service request :add_node_service request :configure_vapp request :create_internet_service request :delete_internet_service request :delete_node_service request :delete_public_ip request :delete_vapp request :deploy_vapp request :get_catalog request :get_catalog_item request :get_internet_services request :get_keys_list request :get_network request :get_network_ips request :get_node_services request :get_organization request :get_organizations request :get_public_ip request :get_public_ips request :get_task request :get_tasks_list request :get_vapp request :get_vapp_template request :get_vdc request :instantiate_vapp_template request :power_off request :power_on request :power_reset request :power_shutdown end end endfog-terremark-0.1.0/lib/fog/compute/terremark/0000755000004100000410000000000013312111667021277 5ustar www-datawww-datafog-terremark-0.1.0/lib/fog/compute/terremark/requests/0000755000004100000410000000000013312111667023152 5ustar www-datawww-datafog-terremark-0.1.0/lib/fog/compute/terremark/requests/create_internet_service.rb0000644000004100000410000000454513312111667030402 0ustar www-datawww-datamodule Fog module Compute class Terremark class Real # Reserve requested resources and deploy vApp # # ==== Parameters # * vdc_id<~Integer> - Id of vDc to add internet service to # * name<~String> - Name of service # * protocol<~String> - Protocol of service # * port<~Integer> - Port of service # * options<~Hash>: # * Enabled<~Boolean>: defaults to true # * Description<~String>: optional description # # ==== Returns # * response<~Excon::Response>: # * body<~Hash>: # * "endTime"<~String> - endTime of task # * "href"<~String> - link to task # * "startTime"<~String> - startTime of task # * "status"<~String> - status of task # * "type"<~String> - type of task # * "Owner"<~String> - # * "href"<~String> - href of owner # * "name"<~String> - name of owner # * "type"<~String> - type of owner def create_internet_service(vdc_id, name, protocol, port, options = {}) unless options.key?("Enabled") options["Enabled"] = true end #Sample: "https://services.vcloudexpress.terremark.com/api/extensions/v1.6/vdc/3142/internetServices" path = vdcs.get(vdc_id).links.detect { |item| item["name"] == "Internet Services" }["href"].split(@host)[1] data = <<-DATA #{name} #{protocol.upcase} #{port} #{options['Enabled']} #{options['Description']} DATA response = request( :body => data, :expects => 200, :headers => { "Content-Type" => "application/vnd.tmrk.vCloud.internetService+xml" }, :method => "POST", :parser => Fog::Parsers::Terremark::InternetService.new, :path => path, :override_path => true ) response end end end end end fog-terremark-0.1.0/lib/fog/compute/terremark/requests/get_tasks_list.rb0000644000004100000410000000157313312111667026524 0ustar www-datawww-datamodule Fog module Compute class Terremark class Real # Get list of tasks # # ==== Parameters # * tasks_list_id<~Integer> - Id of tasks lists to view # # ==== Returns # * response<~Excon::Response>: # * body<~Hash>: # * "CatalogItems"<~Array> # * "href"<~String> - linke to item # * "name"<~String> - name of item # * "type"<~String> - type of item # * "description"<~String> - Description of catalog # * "name"<~String> - Name of catalog def get_tasks_list(tasks_list_id) request( :expects => 200, :method => "GET", :parser => Fog::Parsers::Terremark::GetTasksList.new, :path => "tasksList/#{tasks_list_id}" ) end end end end end fog-terremark-0.1.0/lib/fog/compute/terremark/requests/get_vdc.rb0000644000004100000410000001227313312111667025117 0ustar www-datawww-datamodule Fog module Compute class Terremark class Real # Get details of a vdc # # ==== Parameters # * vdc_id<~Integer> - Id of vdc to lookup # # ==== Returns # * response<~Excon::Response>: # * body<~Hash>: # FIXME # * "CatalogItems"<~Array> # * "href"<~String> - linke to item # * "name"<~String> - name of item # * "type"<~String> - type of item # * "description"<~String> - Description of catalog # * "name"<~String> - Name of catalog def get_vdc(vdc_id) request( :expects => 200, :method => "GET", :parser => Fog::Parsers::Terremark::GetVdc.new, :path => "vdc/#{vdc_id}" ) end end class Mock def get_vdc(vdc_id) vdc_id = vdc_id.to_i response = Excon::Response.new vdc = self.data[:organizations].map { |org| org[:vdcs] }.flatten.find { |vdc| vdc[:id] == vdc_id } if vdc 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::Compute::Terremark::Mock.headers(response.body, "application/vnd.vmware.vcloud.org+xml") else response.status = Fog::Compute::Terremark::Mock.unathorized_status response.headers = Fog::Compute::Terremark::Mock.error_headers end response end end end end end fog-terremark-0.1.0/lib/fog/compute/terremark/requests/delete_public_ip.rb0000644000004100000410000000075413312111667026775 0ustar www-datawww-datamodule Fog module Compute class Terremark class Real # Destroy a public ip # # ==== Parameters # * public_ip_id<~Integer> - Id of public ip to destroy # def delete_public_ip(public_ip_id) request( :expects => 200, :method => "DELETE", :path => "api/extensions/v1.6/publicIp/#{public_ip_id}", :override_path => true ) end end end end end fog-terremark-0.1.0/lib/fog/compute/terremark/requests/get_keys_list.rb0000644000004100000410000000204613312111667026346 0ustar www-datawww-datamodule Fog module Compute class Terremark class Real # Get list of SSH keys for an organization # # ==== Parameters # * organization_id<~Integer> - Id of organization to lookup # # ==== Returns # * response<~Excon::Response>: # * body<~Hash>: # * "description"<~String> - Description of organization # * "links"<~Array> - An array of links to entities in the organization # * "href"<~String> - location of link # * "name"<~String> - name of link # * "rel"<~String> - action to perform # * "type"<~String> - type of link def get_keys_list(organization_id) response = request( :expects => 200, :method => "GET", :parser => Fog::Parsers::Terremark::GetKeysList.new, :path => "api/extensions/v1.6/org/#{organization_id}/keys", :override_path => true ) response end end end end end fog-terremark-0.1.0/lib/fog/compute/terremark/requests/power_on.rb0000644000004100000410000000176213312111667025335 0ustar www-datawww-datamodule Fog module Compute class Terremark class Real # Power on a vapp # # ==== Parameters # * vapp_id<~Integer> - Id of vapp to power on # # ==== Returns # * response<~Excon::Response>: # * body<~Hash>: # * "endTime"<~String> - endTime of task # * "href"<~String> - link to task # * "startTime"<~String> - startTime of task # * "status"<~String> - status of task # * "type"<~String> - type of task # * "Owner"<~String> - # * "href"<~String> - href of owner # * "name"<~String> - name of owner # * "type"<~String> - type of owner def power_on(vapp_id) request( :expects => 202, :method => "POST", :parser => Fog::Parsers::Terremark::Task.new, :path => "vApp/#{vapp_id}/power/action/powerOn" ) end end end end end fog-terremark-0.1.0/lib/fog/compute/terremark/requests/add_internet_service.rb0000644000004100000410000000413013312111667027655 0ustar www-datawww-datamodule Fog module Compute class Terremark class Real # Reserve requested resources and deploy vApp # # ==== Parameters # * ip_id<~Integer> - Id of ip to add service to # * name<~String> - Name of service # * protocol<~String> - Protocol of service # * port<~Integer> - Port of service # * options<~Hash>: # * Enabled<~Boolean>: defaults to true # * Description<~String>: optional description # # ==== Returns # * response<~Excon::Response>: # * body<~Hash>: # * "endTime"<~String> - endTime of task # * "href"<~String> - link to task # * "startTime"<~String> - startTime of task # * "status"<~String> - status of task # * "type"<~String> - type of task # * "Owner"<~String> - # * "href"<~String> - href of owner # * "name"<~String> - name of owner # * "type"<~String> - type of owner def add_internet_service(ip_id, name, protocol, port, options = {}) unless options.key?("Enabled") options["Enabled"] = true end data = <<-DATA #{name} #{protocol.upcase} #{port} #{options['Enabled']} #{options['Description']} DATA request( :body => data, :expects => 200, :headers => { "Content-Type" => "application/xml" }, :method => "POST", :parser => Fog::Parsers::Terremark::InternetService.new, :path => "api/extensions/v1.6/publicIp/#{ip_id}/internetServices", :override_path => true ) end end end end end fog-terremark-0.1.0/lib/fog/compute/terremark/requests/get_vapp_template.rb0000644000004100000410000000166013312111667027202 0ustar www-datawww-datamodule Fog module Compute class Terremark class Real # Get details of a vapp template # # ==== Parameters # * vapp_template_id<~Integer> - Id of vapp template to lookup # # ==== Returns # * response<~Excon::Response>: # * body<~Hash>: # FIXME # * "CatalogItems"<~Array> # * "href"<~String> - linke to item # * "name"<~String> - name of item # * "type"<~String> - type of item # * "description"<~String> - Description of catalog # * "name"<~String> - Name of catalog def get_vapp_template(vapp_template_id) request( :expects => 200, :method => "GET", :parser => Fog::Parsers::Terremark::GetVappTemplate.new, :path => "vAppTemplate/#{vapp_template_id}" ) end end end end end fog-terremark-0.1.0/lib/fog/compute/terremark/requests/delete_node_service.rb0000644000004100000410000000076113312111667027472 0ustar www-datawww-datamodule Fog module Compute class Terremark class Real # Destroy a node # # ==== Parameters # * node_service_id<~Integer> - Id of node to destroy # def delete_node_service(node_service_id) request( :expects => 200, :method => "DELETE", :path => "api/extensions/v1.6/nodeService/#{node_service_id}", :override_path => true ) end end end end end fog-terremark-0.1.0/lib/fog/compute/terremark/requests/delete_internet_service.rb0000644000004100000410000000102513312111667030367 0ustar www-datawww-datamodule Fog module Compute class Terremark class Real # Destroy an internet service # # ==== Parameters # * internet_service_id<~Integer> - Id of service to destroy # def delete_internet_service(internet_service_id) request( :expects => 200, :method => "DELETE", :path => "api/extensions/v1.6/internetService/#{internet_service_id}", :override_path => true ) end end end end end fog-terremark-0.1.0/lib/fog/compute/terremark/requests/power_reset.rb0000644000004100000410000000175513312111667026045 0ustar www-datawww-datamodule Fog module Compute class Terremark class Real # Reset a vapp # # ==== Parameters # * vapp_id<~Integer> - Id of vapp to reset # # ==== Returns # * response<~Excon::Response>: # * body<~Hash>: # * "endTime"<~String> - endTime of task # * "href"<~String> - link to task # * "startTime"<~String> - startTime of task # * "status"<~String> - status of task # * "type"<~String> - type of task # * "Owner"<~String> - # * "href"<~String> - href of owner # * "name"<~String> - name of owner # * "type"<~String> - type of owner def power_reset(vapp_id) request( :expects => 202, :method => "POST", :parser => Fog::Parsers::Terremark::Task.new, :path => "vApp/#{vapp_id}/power/action/reset" ) end end end end end fog-terremark-0.1.0/lib/fog/compute/terremark/requests/add_node_service.rb0000644000004100000410000000407213312111667026757 0ustar www-datawww-datamodule Fog module Compute class Terremark class Real # Reserve requested resources and deploy vApp # # ==== Parameters # * service_id<~String> - Id of service to add node to # * ip<~String> - Private ip of server to add to node # * name<~String> - Name of service # * port<~Integer> - Port of service # * options<~Hash>: # * Enabled<~Boolean>: defaults to true # * Description<~String>: optional description # # ==== Returns # * response<~Excon::Response>: # * body<~Hash>: # * "endTime"<~String> - endTime of task # * "href"<~String> - link to task # * "startTime"<~String> - startTime of task # * "status"<~String> - status of task # * "type"<~String> - type of task # * "Owner"<~String> - # * "href"<~String> - href of owner # * "name"<~String> - name of owner # * "type"<~String> - type of owner def add_node_service(service_id, ip, name, port, options = {}) unless options.key?("Enabled") options["Enabled"] = true end data = <<-DATA #{ip}#{name}#{port}#{options['Enabled']}#{options['Description']} DATA response = request( :body => data, :expects => 200, :headers => { "Content-Type" => "application/vnd.tmrk.vCloud.nodeService+xml" }, :method => "POST", :parser => Fog::Parsers::Terremark::NodeService.new, :path => "api/extensions/v1.6/internetService/#{service_id}/nodeServices", :override_path => true ) response end end end end end fog-terremark-0.1.0/lib/fog/compute/terremark/requests/power_off.rb0000644000004100000410000000176613312111667025477 0ustar www-datawww-datamodule Fog module Compute class Terremark class Real # Power off a vapp # # ==== Parameters # * vapp_id<~Integer> - Id of vapp to power off # # ==== Returns # * response<~Excon::Response>: # * body<~Hash>: # * "endTime"<~String> - endTime of task # * "href"<~String> - link to task # * "startTime"<~String> - startTime of task # * "status"<~String> - status of task # * "type"<~String> - type of task # * "Owner"<~String> - # * "href"<~String> - href of owner # * "name"<~String> - name of owner # * "type"<~String> - type of owner def power_off(vapp_id) request( :expects => 202, :method => "POST", :parser => Fog::Parsers::Terremark::Task.new, :path => "vApp/#{vapp_id}/power/action/powerOff" ) end end end end end fog-terremark-0.1.0/lib/fog/compute/terremark/requests/get_task.rb0000644000004100000410000000223513312111667025302 0ustar www-datawww-datamodule Fog module Compute class Terremark class Real # Get details of a task # # ==== Parameters # * task_id<~Integer> - Id of task to lookup # # ==== Returns # * response<~Excon::Response>: # * body<~Hash>: # * "endTime"<~String> - endTime of task # * "href"<~String> - link to task # * "startTime"<~String> - startTime of task # * "status"<~String> - status of task # * "type"<~String> - type of task # * "Owner"<~String> - # * "href"<~String> - href of owner # * "name"<~String> - name of owner # * "type"<~String> - type of owner # * "Result"<~String> - # * "href"<~String> - href of result # * "name"<~String> - name of result # * "type"<~String> - type of result def get_task(task_id) request( :expects => 200, :method => "GET", :parser => Fog::Parsers::Terremark::Task.new, :path => "task/#{task_id}" ) end end end end end fog-terremark-0.1.0/lib/fog/compute/terremark/requests/get_network.rb0000644000004100000410000000516213312111667026033 0ustar www-datawww-datamodule Fog module Compute class Terremark class 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(network_id) request( :expects => 200, :method => "GET", :parser => Fog::Parsers::Terremark::Network.new, :path => "network/#{network_id}" ) end end class Mock def get_network(network_id) network_id = network_id.to_i response = Excon::Response.new network = self.data[:organizations].map { |org| org[:vdcs].map { |vdc| vdc[:networks] } }.flatten.find { |network| network[:id] == network_id } if network 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::Compute::Terremark::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::Compute::Terremark::Mock.unathorized_status response.headers = Fog::Compute::Terremark::Mock.error_headers end response end end end end end fog-terremark-0.1.0/lib/fog/compute/terremark/requests/delete_vapp.rb0000644000004100000410000000062213312111667025767 0ustar www-datawww-datamodule Fog module Compute class Terremark class Real # Destroy a vapp # # ==== Parameters # * vapp_id<~Integer> - Id of vapp to destroy # def delete_vapp(vapp_id) request( :expects => 202, :method => "DELETE", :path => "vApp/#{vapp_id}" ) end end end end end fog-terremark-0.1.0/lib/fog/compute/terremark/requests/get_vapp.rb0000644000004100000410000000225713312111667025312 0ustar www-datawww-datamodule Fog module Compute class Terremark class Real # Get details of a vapp # # ==== Parameters # * vapp_id<~Integer> - Id of vapp to lookup # # ==== Returns # * response<~Excon::Response>: # * body<~Hash>: # FIXME # * "endTime"<~String> - endTime of task # * "href"<~String> - link to task # * "startTime"<~String> - startTime of task # * "status"<~String> - status of task # * "type"<~String> - type of task # * "Owner"<~String> - # * "href"<~String> - href of owner # * "name"<~String> - name of owner # * "type"<~String> - type of owner # * "Result"<~String> - # * "href"<~String> - href of result # * "name"<~String> - name of result # * "type"<~String> - type of result def get_vapp(vapp_id) request( :expects => 200, :method => "GET", :parser => Fog::Parsers::Terremark::Vapp.new, :path => "vapp/#{vapp_id}" ) end end end end end fog-terremark-0.1.0/lib/fog/compute/terremark/requests/get_organizations.rb0000644000004100000410000000256613312111667027236 0ustar www-datawww-datamodule Fog module Compute class Terremark # doc stub class Real # Get list of organizations # # ==== Returns # * response<~Excon::Response>: # * body<~Array>: # * "description"<~String> - Description of organization # * "links"<~Array> - An array of links to entities in the organization # * "name"<~String> - Name of organization def organizations request( :expects => 200, :headers => auth_headers, :method => "POST", :parser => Fog::Parsers::Terremark::GetOrganizations.new, :path => "login" ) end end # doc stub class Mock def organizations response = Excon::Response.new response.body = { "OrgList" => org_fixture } response.status = 200 response.headers = Fog::Compute::Terremark::Mock.headers(response.body, "application/vnd.vmware.vcloud.orgList+xml") response end def org_fixture data[:organizations].map do |organization| { "name" => organization[:info][:name], "href" => "#{@base_url}/org/#{organization[:info][:id]}", "type" => "application/vnd.vmware.vcloud.org+xml" } end end end end end end fog-terremark-0.1.0/lib/fog/compute/terremark/requests/get_network_ips.rb0000644000004100000410000000141513312111667026703 0ustar www-datawww-datamodule Fog module Compute class Terremark class 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::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 end end end fog-terremark-0.1.0/lib/fog/compute/terremark/requests/get_catalog.rb0000644000004100000410000000155613312111667025757 0ustar www-datawww-datamodule Fog module Compute class Terremark class Real # Get details of a catalog # # ==== Parameters # * vdc_id<~Integer> - Id of vdc to view catalog for # # ==== Returns # * response<~Excon::Response>: # * body<~Hash>: # * "CatalogItems"<~Array> # * "href"<~String> - linke to item # * "name"<~String> - name of item # * "type"<~String> - type of item # * "description"<~String> - Description of catalog # * "name"<~String> - Name of catalog def get_catalog(vdc_id) request( :expects => 200, :method => "GET", :parser => Fog::Parsers::Terremark::GetCatalog.new, :path => "vdc/#{vdc_id}/catalog" ) end end end end end fog-terremark-0.1.0/lib/fog/compute/terremark/requests/configure_vapp.rb0000644000004100000410000000736213312111667026516 0ustar www-datawww-datamodule Fog module Compute class Terremark class Real def configure_vapp(vapp_id, vapp_name, options = {}) items = "" vapp_uri = [@host, @path, "vApp", vapp_id.to_s].join("/") if options["vcpus"] vcpu_item = <<-DATA 13#{options['vcpus']} DATA items << vcpu_item end if options["memory"] memory_item = <<-DATA 2438#{options['memory']} DATA items << memory_item end #Default root disk virtual_disk_item = <<-DATA 0 10485769171048576 DATA items << virtual_disk_item #Additional disks if options["virtual_disks"] options["virtual_disks"].each do |disk| actual_size = disk.to_i * 1024 * 1024 virtual_disk_item = <<-DATA -1#{actual_size}917#{actual_size} DATA items << virtual_disk_item end end data = <<-DATA Virtual Hardware#{items} DATA request( :body => data, :expects => 202, :headers => { "Content-Type" => "application/vnd.vmware.vCloud.vApp+xml" }, :method => "PUT", :path => "vapp/#{vapp_id}" ) end end end end end fog-terremark-0.1.0/lib/fog/compute/terremark/requests/get_public_ips.rb0000644000004100000410000000521113312111667026466 0ustar www-datawww-datamodule Fog module Compute class Terremark class Real # Get list of public ips # # ==== Parameters # * vdc_id<~Integer> - Id of vdc to find public ips for # # ==== Returns # * response<~Excon::Response>: # * body<~Hash>: # * "PublicIpAddresses"<~Array> # * "href"<~String> - link to item # * "name"<~String> - name of item def get_public_ips(vdc_id) opts = { :expects => 200, :method => "GET", :parser => Fog::Parsers::Terremark::GetPublicIps.new, :path => "vdc/#{vdc_id}/publicIps" } if self.class == Fog::Terremark::Ecloud::Real opts[:path] = "extensions/vdc/#{vdc_id}/publicIps" end request(opts) end end class Mock def get_public_ips(vdc_id) vdc_id = vdc_id.to_i response = Excon::Response.new vdc = self.data[:organizations].map { |org| org[:vdcs] }.flatten.find { |vdc| vdc[:id] == vdc_id } if vdc 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::Compute::Terremark::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::Compute::Terremark::Mock.unathorized_status response.headers = Fog::Compute::Terremark::Mock.error_headers end response end end end end end fog-terremark-0.1.0/lib/fog/compute/terremark/requests/get_node_services.rb0000644000004100000410000000133313312111667027166 0ustar www-datawww-datamodule Fog module Compute class Terremark class Real # Get a list of all internet services for a vdc # # ==== Parameters # * service_id<~Integer> - Id of internet service that we want a list of nodes for # # ==== Returns # * response<~Excon::Response>: # * body<~Hash>: # def get_node_services(service_id) request( :expects => 200, :method => "GET", :parser => Fog::Parsers::Terremark::GetNodeServices.new, :path => "api/extensions/v1.6/internetService/#{service_id}/nodeServices", :override_path => true ) end end end end end fog-terremark-0.1.0/lib/fog/compute/terremark/requests/get_public_ip.rb0000644000004100000410000000157613312111667026315 0ustar www-datawww-datamodule Fog module Compute class Terremark class Real # Get details for a public ip # # ==== Parameters # * public_ip_id<~Integer> - Id of public ip to look up # # ==== Returns # * response<~Excon::Response>: # * body<~Hash>: # * "PublicIpAddresses"<~Array> # * "href"<~String> - linke to item # * "name"<~String> - name of item def get_public_ip(public_ip_id) opts = { :expects => 200, :method => "GET", :parser => Fog::Parsers::Terremark::PublicIp.new, :path => "publicIps/#{public_ip_id}" } if self.class == Fog::Terremark::Ecloud::Real opts[:path] = "extensions/publicIp/#{public_ip_id}" end request(opts) end end end end end fog-terremark-0.1.0/lib/fog/compute/terremark/requests/instantiate_vapp_template.rb0000644000004100000410000001031413312111667030742 0ustar www-datawww-datamodule Fog module Compute class Terremark class Real # Instatiate a vapp template # # ==== Parameters # * name<~String>: Name of the resulting vapp .. must start with letter, up to 15 chars alphanumeric. # * options<~Hash>: # * cpus<~Integer>: Number of cpus in [1, 2, 4, 8], defaults to 1 # * memory<~Integer>: Amount of memory either 512 or a multiple of 1024, defaults to 512 # * vapp_template<~String>: id of the vapp template to be instantiated # ==== Returns # * response<~Excon::Response>: # * body<~Hash>: # * "Links;<~Array> (e.g. up to vdc) # * "href"<~String> Link to the resulting vapp # * "name"<~String> - name of item # * "type"<~String> - type of item # * "status"<~String> - 0(pending) --> 2(off) -->4(on) def instantiate_vapp_template(name, vapp_template, options = {}) raise ArgumentError.new("Name must be fewer than 15 characters") unless name.length < 15 raise ArgumentError.new("vApp Image Template is a compulsary parameter") unless vapp_template options["ssh_key_fingerprint"] ||= default_ssh_key["FingerPrint"] options["cpus"] ||= 1 options["memory"] ||= 512 options["network_id"] ||= default_network_id options["vdc_id"] ||= default_vdc_id options["primary_dns"] ||= "208.67.222.222" options["secondary_dns"] ||= "208.67.220.220" data = <<-DATA 1 3 #{options['cpus']} 2 4 #{options['memory']} DATA request( :body => data, :expects => 200, :headers => { "Content-Type" => "application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml" }, :method => "POST", :parser => Fog::Parsers::Terremark::InstantiateVappTemplate.new, :path => "vdc/#{options['vdc_id']}/action/instantiatevAppTemplate" ) end end end end end fog-terremark-0.1.0/lib/fog/compute/terremark/requests/get_internet_services.rb0000644000004100000410000000200013312111667030061 0ustar www-datawww-datamodule Fog module Compute class Terremark class Real # Get a list of all internet services for a vdc # # ==== Parameters # * vdc_id<~Integer> - Id of vDc to get list of internet services for # # ==== Returns # * response<~Excon::Response>: # * body<~Hash>: # * "InternetServices"<~Array> # * "id"<~String> => id of the internet service # * "name"<~String> => name of service # * "PublicIPAddress"<~Hash> # * "Id"<~String> => id of the public IP # * "name"<~String> => actual ip address # def get_internet_services(vdc_id) request( :expects => 200, :method => "GET", :parser => Fog::Parsers::Terremark::GetInternetServices.new, :path => "api/extensions/v1.6/vdc/#{vdc_id}/internetServices", :override_path => true ) end end end end end fog-terremark-0.1.0/lib/fog/compute/terremark/requests/get_catalog_item.rb0000644000004100000410000000165013312111667026770 0ustar www-datawww-datamodule Fog module Compute class Terremark class Real # Get details of a catalog item # # ==== Parameters # * catalog_item_id<~Integer> - Id of catalog item to lookup # # ==== Returns # * response<~Excon::Response>: # * body<~Hash>: # FIXME # * "CatalogItems"<~Array> # * "href"<~String> - linke to item # * "name"<~String> - name of item # * "type"<~String> - type of item # * "description"<~String> - Description of catalog # * "name"<~String> - Name of catalog def get_catalog_item(catalog_item_id) request( :expects => 200, :method => "GET", :parser => Fog::Parsers::Terremark::GetCatalogItem.new, :path => "catalogItem/#{catalog_item_id}" ) end end end end end fog-terremark-0.1.0/lib/fog/compute/terremark/requests/deploy_vapp.rb0000644000004100000410000000201013312111667026012 0ustar www-datawww-datamodule Fog module Compute class Terremark class Real # Reserve requested resources and deploy vApp # # ==== Parameters # * vapp_id<~Integer> - Id of vApp to deploy # # ==== Returns # * response<~Excon::Response>: # * body<~Hash>: # * "endTime"<~String> - endTime of task # * "href"<~String> - link to task # * "startTime"<~String> - startTime of task # * "status"<~String> - status of task # * "type"<~String> - type of task # * "Owner"<~String> - # * "href"<~String> - href of owner # * "name"<~String> - name of owner # * "type"<~String> - type of owner def deploy_vapp(vapp_id) request( :expects => 202, :method => "POST", :parser => Fog::Parsers::Terremark::Task.new, :path => "vApp/#{vapp_id}/action/deploy" ) end end end end end fog-terremark-0.1.0/lib/fog/compute/terremark/requests/get_organization.rb0000644000004100000410000000607313312111667027050 0ustar www-datawww-datamodule Fog module Compute class Terremark class Real # Get details of an organization # # ==== Parameters # * organization_id<~Integer> - Id of organization to lookup # # ==== Returns # * response<~Excon::Response>: # * body<~Hash>: # * "description"<~String> - Description of organization # * "links"<~Array> - An array of links to entities in the organization # * "href"<~String> - location of link # * "name"<~String> - name of link # * "rel"<~String> - action to perform # * "type"<~String> - type of link # * "name"<~String> - Name of organization def get_organization(organization_id) response = request( :expects => 200, :method => "GET", :parser => Fog::Parsers::Terremark::GetOrganization.new, :path => "org/#{organization_id}" ) response end end class Mock def get_organization(organization_id) organization_id = organization_id.to_i response = Excon::Response.new if org = data[:organizations].detect { |attributes| attributes[: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::Compute::Terremark::Mock.headers(response.body, "application/vnd.vmware.vcloud.org+xml") else response.status = Fog::Compute::Terremark::Mock.unathorized_status response.headers = Fog::Compute::Terremark::Mock.error_headers end response end private def _vdc_links(vdc) [ { "name" => vdc[:name], "href" => "#{@base_url}/vdc/#{vdc[:id]}", "rel" => "down", "type" => "application/vnd.vmware.vcloud.vdc+xml" }, { "name" => "#{vdc[:name]} Catalog", "href" => "#{@base_url}/vdc/#{vdc[:id]}/catalog", "rel" => "down", "type" => "application/vnd.vmware.vcloud.catalog+xml" }, { "name" => "#{vdc[:name]} Tasks List", "href" => "#{@base_url}/vdc/#{vdc[:id]}/taskslist", "rel" => "down", "type" => "application/vnd.vmware.vcloud.tasksList+xml" } ] end end end end end fog-terremark-0.1.0/lib/fog/compute/terremark/requests/power_shutdown.rb0000644000004100000410000000072413312111667026571 0ustar www-datawww-datamodule Fog module Compute class Terremark class Real # Shutdown a vapp # # ==== Parameters # * vapp_id<~Integer> - Id of vapp to shutdown # # ==== Returns # Nothing def power_shutdown(vapp_id) request( :expects => 204, :method => "POST", :path => "vApp/#{vapp_id}/power/action/shutdown" ) end end end end end fog-terremark-0.1.0/lib/fog/compute/terremark/models/0000755000004100000410000000000013312111667022562 5ustar www-datawww-datafog-terremark-0.1.0/lib/fog/compute/terremark/models/addresses.rb0000644000004100000410000000122313312111667025062 0ustar www-datawww-datamodule Fog module Compute class Terremark class Addresses < Fog::Collection model Fog::Compute::Terremark::Address def all load(service.get_public_ips(vdc_id).body["PublicIpAddresses"]) end def get(ip_id) if ip_id && ip = service.get_public_ip(ip_id).body new(ip) elsif !ip_id nil end rescue Excon::Errors::Forbidden nil end def vdc_id @vdc_id ||= service.default_vdc_id end private def vdc_id=(new_vdc_id) @vdc_id = new_vdc_id end end end end end fog-terremark-0.1.0/lib/fog/compute/terremark/models/image.rb0000644000004100000410000000037513312111667024176 0ustar www-datawww-datamodule Fog module Compute class Terremark class Image < Fog::Model identity :id attribute :name end private def href=(new_href) self.id = new_href.split("/").last.to_i end end end end fog-terremark-0.1.0/lib/fog/compute/terremark/models/address.rb0000644000004100000410000000060713312111667024537 0ustar www-datawww-datamodule Fog module Compute class Terremark class Address < Fog::Model identity :id attribute :ip, :aliases => "name" def destroy requires :id service.delete_public_ip(id) true end private def href=(new_href) self.id = new_href.split("/").last.to_i end end end end end fog-terremark-0.1.0/lib/fog/compute/terremark/models/vdc.rb0000644000004100000410000000132413312111667023663 0ustar www-datawww-datamodule Fog module Compute class Terremark class Vdc < Fog::Model identity :id attribute :name attribute :ResourceEntities attribute :AvailableNetworks attribute :links def networks service.networks(:vdc_id => id) end def addresses service.addresses(:vdc_id => id) end def servers service.servers(:vdc_id => id) end def images service.images(:vdc_id => id) end private def href=(new_href) self.id = new_href.split("/").last.to_i end def type=(_new_type); end def rel=(_new_rel); end end end end end fog-terremark-0.1.0/lib/fog/compute/terremark/models/network.rb0000644000004100000410000000107313312111667024601 0ustar www-datawww-datamodule Fog module Compute class Terremark class Network < Fog::Model identity :id attribute :name attribute :subnet attribute :gateway attribute :netmask attribute :fencemode attribute :links def ips #Until there is a real models for these ? service.get_network_ips(id).body["IpAddresses"] end private def href=(new_href) self.id = new_href.split("/").last.to_i end def type=(_new_type); end end end end end fog-terremark-0.1.0/lib/fog/compute/terremark/models/nodeservice.rb0000644000004100000410000000164413312111667025422 0ustar www-datawww-datamodule Fog module Compute class Terremark class NodeService < Fog::Model identity :Id attribute :Name attribute :Href attribute :Port attribute :Description attribute :IpAddress attribute :Enabled attribute :InternetServiceId def destroy service.delete_node_service(self.Id) end def save requires :Name, :Port, :InternetServiceId data = service.add_node_service( self.InternetServiceId, self.IpAddress, self.Name, self.Port, "Enabled" => "true", "Description" => self.Name ) merge_attributes(data.body) true end private attr_writer :type, :size, :Links def href=(new_href) self.id = new_href.split("/").last.to_i end end end end end fog-terremark-0.1.0/lib/fog/compute/terremark/models/vdcs.rb0000644000004100000410000000150513312111667024047 0ustar www-datawww-datamodule Fog module Compute class Terremark class Vdcs < Fog::Collection model Fog::Compute::Terremark::Vdc def all data = service.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 = service.get_vdc(vdc_id).body new(vdc) elsif !vdc_id nil end rescue Excon::Errors::Forbidden nil end def organization_id @organization_id ||= service.default_organization_id end private def organization_id=(new_organization_id) @organization_id = new_organization_id end end end end end fog-terremark-0.1.0/lib/fog/compute/terremark/models/internetservice.rb0000644000004100000410000000324413312111667026323 0ustar www-datawww-datamodule Fog module Compute class Terremark class InternetService < Fog::Model identity :Id attribute :Name attribute :Port attribute :Protocol attribute :Description attribute :PublicIpAddress attribute :public_ip_address_id def destroy(delete_public_ip = true) service.delete_internet_service(self.Id) service.delete_public_ip(self.PublicIpAddress["Id"]) if delete_public_ip true end def save requires :Name, :Protocol, :Port if !public_ip_address_id #Create the first internet service and allocate public IP data = service.create_internet_service( vdc = service.default_vdc_id, name = self.Name, protocol = self.Protocol, port = self.Port, options = { "Enabled" => "true", "Description" => self.Name } ) else #create additional services to existing Public IP data = service.add_internet_service( ip_id = public_ip_address_id, name = self.Name, protocol = self.Protocol, port = self.Port, options = { "Enabled" => "true", "Description" => self.Name } ) end merge_attributes(data.body) true end private attr_writer :type, :size, :Links def href=(new_href) self.id = new_href.split("/").last.to_i end end end end end fog-terremark-0.1.0/lib/fog/compute/terremark/models/internetservices.rb0000644000004100000410000000114213312111667026501 0ustar www-datawww-datamodule Fog module Compute class Terremark class InternetServices < Fog::Collection model Fog::Compute::Terremark::InternetService def all data = service.get_internet_services(vdc_id).body["InternetServices"] load(data) end def get(service_id) service.get_internet_services(vdc_id) internet_service = services.body["InternetServices"].select {|item| item["Id"] == service_id} new(internet_service) end def vdc_id @vdc_id ||= service.default_vdc_id end end end end end fog-terremark-0.1.0/lib/fog/compute/terremark/models/nodeservices.rb0000644000004100000410000000050613312111667025601 0ustar www-datawww-datamodule Fog module Compute class Terremark class NodeServices < Fog::Collection model Fog::Compute::Terremark::NodeService def all(internet_service_id) data = service.get_node_services(internet_service_id).body["NodeServices"] load(data) end end end end end fog-terremark-0.1.0/lib/fog/compute/terremark/models/task.rb0000644000004100000410000000230613312111667024052 0ustar www-datawww-datamodule Fog module Compute class Terremark class Task < Fog::Model identity :id attribute :end_time, :aliases => "endTime" attribute :owner, :aliases => "Owner" attribute :result, :aliases => "Result" attribute :start_time, :aliases => "startTime" attribute :status attribute :link, :aliases => "Link" attribute :error, :aliases => "Error" def initialize(attributes = {}) new_owner = attributes.delete("Owner") new_result = attributes.delete("Result") new_error = attributes.delete("Error") new_cancel_link = attributes.delete("Link") super self.owner = service.parse(new_owner) if new_result self.result = service.parse(new_result) end self.error = service.parse(new_error) if new_error @cancel_link = service.parse(new_cancel_link) if new_cancel_link end def ready? @status == "success" end private def href=(new_href) @id = new_href.split("/").last.to_i end def type=(_new_type); end end end end end fog-terremark-0.1.0/lib/fog/compute/terremark/models/servers.rb0000644000004100000410000000131413312111667024577 0ustar www-datawww-datamodule Fog module Compute class Terremark class Servers < Fog::Collection model Fog::Compute::Terremark::Server def all data = [] service.get_vdc(vdc_id).body["ResourceEntities"].select do |entity| data << service.servers.get(entity["href"].split("/").last) end data end def get(server_id) if server_id new(service.get_vapp(server_id).body) else nil end end def vdc_id @vdc_id ||= service.default_vdc_id end private def vdc_id=(new_vdc_id) @vdc_id = new_vdc_id end end end end end fog-terremark-0.1.0/lib/fog/compute/terremark/models/server.rb0000644000004100000410000001375513312111667024430 0ustar www-datawww-datamodule Fog module Compute class Terremark class Server < Fog::Model module VAppStatus BEING_CREATED = "0" BEING_DEPLOYED = "1" POWERED_OFF = "2" POWERED_ON = "4" end identity :id attribute :name attribute :image attribute :vcpus attribute :memory attribute :sshkeyFingerPrint attribute :powerOn attribute :status attribute :OperatingSystem attribute :VirtualHardware attribute :IpAddress def reload merge_attributes(service.get_vapp(id).body) end def destroy case self.status when VAppStatus::BEING_CREATED, VAppStatus::BEING_DEPLOYED return false when VAppStatus::POWERED_ON service.power_off(self.id).body wait_for { off? } end #Failsafe .. Always check if we are ready wait_for { ready? } service.delete_vapp(self.id) true end def PublicIpAddress @PublicIpAddress ||= if internet_services.size > 0 internet_services[0].PublicIpAddress["Name"] end @PublicIpAddress end def internet_services @internet_services ||= service.internetservices.all.select { |item| item.Name == self.name } end def delete_internet_services #Find the internet service while (inet_service = internet_services.pop) do nodes = service.nodeservices.all(inet_service.Id) #Delete all the associated nodes nodes.select { |item| item.destroy } #Clear out the services inet_service.destroy(delete_public_ip = !(internet_services.size > 0)) end true end # { "0" => "Being created", "2" => "Powered Off", "4" => "Powered On"} def ready? status == VAppStatus::POWERED_OFF end def on? status == VAppStatus::POWERED_ON end def off? status == VAppStatus::POWERED_OFF end def power_on(_options = {}) requires :id begin service.power_on(id) rescue Excon::Errors::InternalServerError => e # Frankly we shoudln't get here ... raise e unless e.to_s =~ /because it is already powered on/ end true end def power_off requires :id begin service.power_off(id) rescue Excon::Errors::InternalServerError => e # Frankly we shoudln't get here ... raise e unless e.to_s =~ /because it is already powered off/ end true end def shutdown requires :id begin service.power_shutdown(id) rescue Excon::Errors::InternalServerError => e # Frankly we shoudln't get here ... raise e unless e.to_s =~ /because it is already powered off/ end true end def power_reset requires :id service.power_reset(id) true end def graceful_restart requires :id shutdown wait_for { off? } power_on end def create_internet_services(internet_spec) public_ip_info = nil internet_service_id = nil internet_spec.each do |proto, ports| for port in ports if not public_ip_info #Create the first internet service and allocate public IP inet_services = service.internetservices.create({ "Name" => self.name, "Protocol" => proto, "Port" => port, }) internet_service_id = inet_services.Id public_ip_info = inet_services.PublicIpAddress else #create additional services to existing Public IP inet_services = service.internetservices.create({ "public_ip_address_id" => public_ip_info["Id"], "Name" => self.name, "Protocol" => proto, "Port" => port, } ) internet_service_id = inet_services.Id end #Create the associate node service to the server service.nodeservices.create({"Name" => self.name, "IpAddress" => self.IpAddress, "Port" => port, "InternetServiceId" => internet_service_id }) end end true end def save requires :name if powerOn end data = service.instantiate_vapp_template( server_name=name, vapp_template=image, options={ "ssh_key_fingerprint" => sshkeyFingerPrint, "cpus" => vcpus, "memory" => memory }) merge_attributes(data.body) wait_for { ready? } #Optional, incase further configuration required. if powerOn power_on wait_for { ready? } end true end private attr_writer :type, :size, :Links def href=(new_href) self.id = new_href.split("/").last.to_i end end end end end fog-terremark-0.1.0/lib/fog/compute/terremark/models/networks.rb0000644000004100000410000000146413312111667024770 0ustar www-datawww-datamodule Fog module Compute class Terremark class Networks < Fog::Collection model Fog::Compute::Terremark::Network def all data = service.get_vdc(vdc_id).body["AvailableNetworks"].map do |network| service.get_network(network["href"].split("/").last).body end load(data) end def get(network_id) network = service.get_network(network_id).body if network_id && network new(network) elsif !network_id nil end rescue Excon::Errors::Forbidden nil end def vdc_id @vdc_id ||= service.default_vdc_id end private def vdc_id=(new_vdc_id) @vdc_id = new_vdc_id end end end end end fog-terremark-0.1.0/lib/fog/compute/terremark/models/tasks.rb0000644000004100000410000000204413312111667024234 0ustar www-datawww-datamodule Fog module Compute class Terremark class Tasks < Fog::Collection model Fog::Compute::Terremark::Task def all data = service.get_tasks_list(task_list_id).body["Tasks"] load(data) end def get(task_id) task = service.get_task(task_id).body if task_id && task new(task) elsif !task_id nil end rescue Excon::Errors::Forbidden nil end def task_list_id organization = service.get_organization(service.default_organization_id).body @task_list_id ||= if service.default_organization_id && organization organization["Links"].detect { |link| link["type"] == "application/vnd.vmware.vcloud.tasksList+xml" }["href"].split("/").last.to_i else nil end end private def task_list_id=(new_task_list_id) @task_list_id = new_task_list_id end end end end end fog-terremark-0.1.0/lib/fog/compute/terremark/models/images.rb0000644000004100000410000000105313312111667024353 0ustar www-datawww-datamodule Fog module Compute class Terremark class Images < Fog::Collection model Fog::Compute::Terremark::Image def all data = service.get_catalog(vdc_id).body["CatalogItems"].select do |entity| entity["type"] == "application/vnd.vmware.vcloud.catalogItem+xml" end load(data) end def vdc_id @vdc_id ||= service.default_vdc_id end private def vdc_id=(new_vdc_id) @vdc_id = new_vdc_id end end end end end fog-terremark-0.1.0/lib/fog/compute/terremark/common.rb0000644000004100000410000000064213312111667023116 0ustar www-datawww-datamodule Fog module Compute class Terremark # doc stub module Common def default_organization_id @default_organization_id ||= begin org_list = organizations.body["OrgList"] if org_list.length == 1 org_list.first["href"].split("/").last.to_i else nil end end end end end end end fog-terremark-0.1.0/lib/fog/compute/terremark/parser.rb0000644000004100000410000000047513312111667023126 0ustar www-datawww-datamodule Fog module Compute class Terremark module Parser def parse(data) case data["type"] when "application/vnd.vmware.vcloud.vApp+xml" servers.new(data.merge!(:service => self)) else data end end end end end end fog-terremark-0.1.0/lib/fog/compute/terremark/real.rb0000644000004100000410000000466013312111667022555 0ustar www-datawww-datamodule Fog module Compute class Terremark # documentation stub class Real include Common def initialize(options = {}) @terremark_username = options[:terremark_vcloud_username] @terremark_password = options[:terremark_vcloud_password] end private def auth_token response = @connection.request( :expects => 200, :headers => auth_headers, :host => @host, :method => "POST", :parser => Fog::Parsers::Terremark::GetOrganizations.new, :path => "#{@path}/login" ) response.headers["Set-Cookie"] end def auth_headers credentials = "#{@terremark_username}:#{@terremark_password}" encoded_credentials = Base64.encode64(credentials) # remove newlines because strict_encode64 is not compatible with 1.8 encoded_credentials = encoded_credentials.gsub(/\n/, "") { "Authorization" => "Basic #{encoded_credentials}", # Terremark said they're going to remove passing in the # Content-Type to login in a future release "Content-Type" => "application/vnd.vmware.vcloud.orgList+xml" } end def reload @connection.reset end def request(params) @cookie ||= auth_token begin do_request(params) rescue Excon::Errors::Unauthorized @cookie = auth_token do_request(params) end end def do_request(params) @connection.request( :body => params[:body], :expects => params[:expects], :headers => make_headers(params), :host => @host, :method => params[:method], :parser => params[:parser], :path => make_path(params) ) end def make_headers(params) headers = {} headers.merge!("Cookie" => @cookie) if @cookie headers.merge!(params[:headers] || {}) end def make_path(params) if params[:path] if params[:override_path] == true params[:path] else "#{@path}/#{params[:path]}" end else "#{@path}" end end end end end end fog-terremark-0.1.0/lib/fog/compute/terremark/mock.rb0000644000004100000410000001254013312111667022557 0ustar www-datawww-datamodule Fog module Compute class Terremark class Mock include Common 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 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 def self.unathorized_status 401 end 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 def self.status 200 end def initialize(_options={}) self.class.instance_eval " def self.data @data ||= Hash.new do |hash, key| hash[key] = Fog::Compute::Terremark::Mock.mock_data end end" self.class.instance_eval " def self.reset @data = nil end def self.reset_data(keys=data.keys) for key in [*keys] data.delete(key) end end" end end end end endfog-terremark-0.1.0/CONTRIBUTING.md0000644000004100000410000000156313312111667016544 0ustar www-datawww-data## Getting Involved New contributors are always welcome, when it doubt please ask questions. We strive to be an open and welcoming community. Please be nice to one another. ### Coding * Pick a task: * Offer feedback on open [pull requests](https://github.com/fog/fog-terremark/pulls). * Review open [issues](https://github.com/fog/fog-terremark/issues) for things to help on. * [Create an issue](https://github.com/fog/fog-terremark/issues/new) to start a discussion on additions or features. * Fork the project, add your changes and tests to cover them in a topic branch. * Commit your changes and rebase against `fog/fog-terremark` to ensure everything is up to date. * [Submit a pull request](https://github.com/fog/fog-terremark/compare/) ### Non-Coding * Offer feedback on open [issues](https://github.com/fog/fog-terremark/issues). * Organize or volunteer at events.fog-terremark-0.1.0/.ruby-gemset0000644000004100000410000000001513312111667016546 0ustar www-datawww-datafog-terremarkfog-terremark-0.1.0/Gemfile0000644000004100000410000000014213312111667015576 0ustar www-datawww-datasource "https://rubygems.org" # Specify your gem's dependencies in fog-terremark.gemspec gemspec fog-terremark-0.1.0/.ruby-version0000644000004100000410000000000613312111667016747 0ustar www-datawww-data2.1.5 fog-terremark-0.1.0/fog-terremark.gemspec0000644000004100000410000000265513312111667020430 0ustar www-datawww-data# coding: utf-8 lib = File.expand_path("../lib", __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require "fog/terremark/version" Gem::Specification.new do |spec| spec.name = "fog-terremark" spec.version = Fog::Terremark::VERSION spec.authors = ["Paulo Henrique Lopes Ribeiro"] spec.email = ["plribeiro3000@gmail.com"] spec.summary = "Module for the 'fog' gem to support Terremark vCloud." spec.description = <<-EOS This library can be used as a module for `fog` or as standalone provider to use the Terremark vCloud in applications. EOS spec.homepage = "" spec.license = "MIT" files = `git ls-files -z`.split("\x0") files.delete(".hound.yml") spec.files = files spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) } spec.test_files = spec.files.grep(/^(test|spec|features)\//) spec.require_paths = ["lib"] spec.add_dependency "fog-core" spec.add_dependency "fog-xml" spec.add_development_dependency "rake" spec.add_development_dependency "minitest" spec.add_development_dependency "turn" spec.add_development_dependency "pry" spec.add_development_dependency "vcr" if RUBY_VERSION.to_f > 1.9 spec.add_development_dependency "coveralls" spec.add_development_dependency "rubocop" end end