Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[ecloud] improvements and some mocking

  • Loading branch information...
commit 853755d32fb09426b0593501f458d60d307d36ba 1 parent 4e047e9
@ehowe ehowe authored ehowe committed
Showing with 2,799 additions and 676 deletions.
  1. +2 −2 lib/fog/core/collection.rb
  2. +19 −5 lib/fog/ecloud.rb
  3. +663 −351 lib/fog/ecloud/compute.rb
  4. +14 −10 lib/fog/ecloud/models/compute/admin_organization.rb
  5. +0 −5 lib/fog/ecloud/models/compute/admin_organizations.rb
  6. +20 −8 lib/fog/ecloud/models/compute/compute_pool.rb
  7. +27 −0 lib/fog/ecloud/models/compute/detached_disk.rb
  8. +31 −0 lib/fog/ecloud/models/compute/detached_disks.rb
  9. +13 −6 lib/fog/ecloud/models/compute/environment.rb
  10. +1 −1  lib/fog/ecloud/models/compute/environments.rb
  11. +2 −0  lib/fog/ecloud/models/compute/group.rb
  12. +16 −5 lib/fog/ecloud/models/compute/groups.rb
  13. +4 −4 lib/fog/ecloud/models/compute/hardware_configuration.rb
  14. +1 −1  lib/fog/ecloud/models/compute/hardware_configurations.rb
  15. +19 −13 lib/fog/ecloud/models/compute/internet_service.rb
  16. +9 −6 lib/fog/ecloud/models/compute/internet_services.rb
  17. +17 −3 lib/fog/ecloud/models/compute/ip_address.rb
  18. +6 −1 lib/fog/ecloud/models/compute/ip_addresses.rb
  19. +1 −1  lib/fog/ecloud/models/compute/layout.rb
  20. +18 −8 lib/fog/ecloud/models/compute/network.rb
  21. +8 −4 lib/fog/ecloud/models/compute/networks.rb
  22. +8 −2 lib/fog/ecloud/models/compute/node.rb
  23. +5 −2 lib/fog/ecloud/models/compute/nodes.rb
  24. +1 −1  lib/fog/ecloud/models/compute/operating_system_family.rb
  25. +5 −5 lib/fog/ecloud/models/compute/organization.rb
  26. +1 −1  lib/fog/ecloud/models/compute/public_ip.rb
  27. +5 −2 lib/fog/ecloud/models/compute/public_ips.rb
  28. +5 −2 lib/fog/ecloud/models/compute/row.rb
  29. +6 −3 lib/fog/ecloud/models/compute/rows.rb
  30. +123 −77 lib/fog/ecloud/models/compute/server.rb
  31. +15 −12 lib/fog/ecloud/models/compute/servers.rb
  32. +1 −1  lib/fog/ecloud/models/compute/ssh_key.rb
  33. +3 −0  lib/fog/ecloud/models/compute/task.rb
  34. +8 −9 lib/fog/ecloud/models/compute/template.rb
  35. +32 −0 lib/fog/ecloud/models/compute/virtual_machine_assigned_ip.rb
  36. +27 −0 lib/fog/ecloud/models/compute/virtual_machine_assigned_ips.rb
  37. +1 −2  lib/fog/ecloud/requests/compute/admin_edit_authentication_levels.rb
  38. +14 −0 lib/fog/ecloud/requests/compute/get_admin_organization.rb
  39. +0 −11 lib/fog/ecloud/requests/compute/get_admin_organizations.rb
  40. +11 −0 lib/fog/ecloud/requests/compute/get_compute_pool.rb
  41. +21 −0 lib/fog/ecloud/requests/compute/get_compute_pools.rb
  42. +21 −0 lib/fog/ecloud/requests/compute/get_detached_disk.rb
  43. +33 −0 lib/fog/ecloud/requests/compute/get_detached_disks.rb
  44. +21 −0 lib/fog/ecloud/requests/compute/get_environment.rb
  45. +8 −1 lib/fog/ecloud/requests/compute/get_group.rb
  46. +8 −1 lib/fog/ecloud/requests/compute/get_groups.rb
  47. +19 −0 lib/fog/ecloud/requests/compute/get_hardware_configuration.rb
  48. +4 −0 lib/fog/ecloud/requests/compute/get_hardware_configurations.rb
  49. +12 −0 lib/fog/ecloud/requests/compute/get_internet_service.rb
  50. +8 −0 lib/fog/ecloud/requests/compute/get_internet_services.rb
  51. +11 −0 lib/fog/ecloud/requests/compute/get_ip_address.rb
  52. +0 −11 lib/fog/ecloud/requests/compute/get_ip_addresses.rb
  53. +8 −1 lib/fog/ecloud/requests/compute/get_layout.rb
  54. +8 −1 lib/fog/ecloud/requests/compute/get_layouts.rb
  55. +11 −0 lib/fog/ecloud/requests/compute/get_network.rb
  56. +20 −0 lib/fog/ecloud/requests/compute/get_networks.rb
  57. +11 −0 lib/fog/ecloud/requests/compute/get_node.rb
  58. +9 −0 lib/fog/ecloud/requests/compute/get_nodes.rb
  59. +14 −0 lib/fog/ecloud/requests/compute/get_operating_system.rb
  60. +20 −0 lib/fog/ecloud/requests/compute/get_operating_system_families.rb
  61. +0 −11 lib/fog/ecloud/requests/compute/get_operating_system_family.rb
  62. +14 −0 lib/fog/ecloud/requests/compute/get_organization.rb
  63. +14 −2 lib/fog/ecloud/requests/compute/get_organizations.rb
  64. +11 −1 lib/fog/ecloud/requests/compute/get_public_ip.rb
  65. +22 −0 lib/fog/ecloud/requests/compute/get_public_ips.rb
  66. +8 −1 lib/fog/ecloud/requests/compute/get_row.rb
  67. +2 −1  lib/fog/ecloud/requests/compute/get_rows.rb
  68. +11 −0 lib/fog/ecloud/requests/compute/get_server.rb
  69. +32 −1 lib/fog/ecloud/requests/compute/get_servers.rb
  70. +11 −0 lib/fog/ecloud/requests/compute/get_ssh_key.rb
  71. +20 −0 lib/fog/ecloud/requests/compute/get_ssh_keys.rb
  72. +4 −2 lib/fog/ecloud/requests/compute/get_task.rb
  73. +11 −0 lib/fog/ecloud/requests/compute/get_template.rb
  74. +38 −0 lib/fog/ecloud/requests/compute/get_templates.rb
  75. +44 −0 lib/fog/ecloud/requests/compute/get_virtual_machine_assigned_ips.rb
  76. +16 −1 lib/fog/ecloud/requests/compute/groups_delete.rb
  77. +36 −1 lib/fog/ecloud/requests/compute/internet_service_create.rb
  78. +23 −0 lib/fog/ecloud/requests/compute/internet_service_delete.rb
  79. +49 −1 lib/fog/ecloud/requests/compute/node_service_create.rb
  80. +24 −0 lib/fog/ecloud/requests/compute/node_service_delete.rb
  81. +11 −1 lib/fog/ecloud/requests/compute/rows_delete.rb
  82. +0 −40 lib/fog/ecloud/requests/compute/virtual_machine_add_ip.rb
  83. +62 −0 lib/fog/ecloud/requests/compute/virtual_machine_attach_disk.rb
  84. +136 −16 lib/fog/ecloud/requests/compute/virtual_machine_create_from_template.rb
  85. +36 −1 lib/fog/ecloud/requests/compute/virtual_machine_delete.rb
  86. +71 −0 lib/fog/ecloud/requests/compute/virtual_machine_detach_disk.rb
  87. +82 −0 lib/fog/ecloud/requests/compute/virtual_machine_edit_assigned_ips.rb
  88. +27 −3 lib/fog/ecloud/requests/compute/virtual_machine_edit_hardware_configuration.rb
  89. +120 −6 lib/fog/ecloud/requests/compute/virtual_machine_import.rb
  90. +27 −6 tests/compute/helper.rb
  91. +1 −1  tests/compute/models/flavors_tests.rb
  92. +2 −0  tests/compute/models/server_tests.rb
  93. +2 −1  tests/compute/models/servers_tests.rb
  94. +16 −0 tests/ecloud/compute/models/admin_organization_tests.rb
  95. +17 −0 tests/ecloud/compute/models/compute_pool_tests.rb
  96. +26 −0 tests/ecloud/compute/models/detached_disk_tests.rb
  97. +23 −0 tests/ecloud/compute/models/environment_tests.rb
  98. +28 −0 tests/ecloud/compute/models/internet_service_tests.rb
  99. +19 −0 tests/ecloud/compute/models/ip_address_tests.rb
  100. +17 −0 tests/ecloud/compute/models/network_tests.rb
  101. +13 −0 tests/ecloud/compute/models/operating_system_families_tests.rb
  102. +22 −0 tests/ecloud/compute/models/operating_system_tests.rb
  103. +21 −0 tests/ecloud/compute/models/organization_tests.rb
  104. +19 −0 tests/ecloud/compute/models/public_ip_tests.rb
  105. +143 −0 tests/ecloud/compute/models/server_tests.rb
  106. +19 −0 tests/ecloud/compute/models/ssh_key_tests.rb
  107. +20 −0 tests/ecloud/compute/models/template_tests.rb
View
4 lib/fog/core/collection.rb
@@ -103,10 +103,10 @@ def new(attributes = {})
raise(ArgumentError.new("Initialization parameters must be an attributes hash, got #{attributes.class} #{attributes.inspect}"))
end
model.new(
- attributes.merge(
+ {
:collection => self,
:connection => connection
- )
+ }.merge(attributes)
)
end
View
24 lib/fog/ecloud.rb
@@ -2,16 +2,30 @@
module Fog
module Ecloud
+ ECLOUD_OPTIONS = [:ecloud_authentication_method]
extend Fog::Provider
service(:compute, 'ecloud/compute', 'Compute')
- end
-end
+ def self.keep(hash, *keys)
+ {}.tap do |kept|
+ keys.each{|k| kept[k]= hash[k] if hash.key?(k)}
+ end
+ end
-module Fog
- module Ecloud
- ECLOUD_OPTIONS = [:ecloud_authentication_method]
+ def self.slice(hash, *keys)
+ hash.dup.tap do |sliced|
+ keys.each{|k| sliced.delete(k)}
+ end
+ end
+
+ def self.ip_address
+ 4.times.map{ Fog::Mock.random_numbers(3) }.join(".")
+ end
+
+ def self.mac_address
+ 6.times.map{ Fog::Mock.random_numbers(2) }.join(":")
+ end
end
end
View
1,014 lib/fog/ecloud/compute.rb
@@ -1,33 +1,12 @@
require 'fog/ecloud/collection'
-module Fog
- module Ecloud
- class Model < Fog::Model
-
- attr_accessor :loaded
- alias_method :loaded?, :loaded
-
- def reload
- instance = super
- @loaded = true
- instance
- end
-
- def load_unless_loaded!
- unless @loaded
- reload
- end
- end
+require 'fog/ecloud/model'
+require 'builder'
- end
- end
-end
module Fog
module Compute
-
-
class Ecloud < Fog::Service
-
API_URL = "https://services.enterprisecloud.terremark.com"
+
attr_reader :authentication_method, :version
#### Credentials
@@ -38,346 +17,271 @@ class Ecloud < Fog::Service
model_path 'fog/ecloud/models/compute'
model :organization
collection :organizations
- model :location
- collection :locations
- model :catalog_item
- collection :catalog
- model :catalog_configuration
- collection :catalog_configurations
- model :environment
- collection :environments
- model :task
- collection :tasks
- model :compute_pool
- collection :compute_pools
- model :server
- collection :servers
- model :hardware_configuration
- collection :hardware_configurations
- model :server_configuration_option
- collection :server_configuration_options
- model :guest_process
- collection :guest_processes
- model :layout
- collection :layouts
- model :row
- collection :rows
- model :group
- collection :groups
- model :internet_service
- collection :internet_services
- model :node
- collection :nodes
- model :monitor
- collection :monitors
- model :cpu_usage_detail
- collection :cpu_usage_detail_summary
- model :memory_usage_detail
- collection :memory_usage_detail_summary
- model :storage_usage_detail
- collection :storage_usage_detail_summary
- model :operating_system_family
- collection :operating_system_families
- model :operating_system
- collection :operating_systems
- model :template
- collection :templates
- model :firewall_acl
- collection :firewall_acls
- model :network
- collection :networks
- model :ip_address
- collection :ip_addresses
- model :physical_device
- collection :physical_devices
- model :public_ip
- collection :public_ips
- model :trusted_network_group
- collection :trusted_network_groups
- model :backup_internet_service
- collection :backup_internet_services
- model :rnat
- collection :rnats
- model :association
- collection :associations
- model :tag
- collection :tags
- model :admin_organization
- collection :admin_organizations
- model :ssh_key
- collection :ssh_keys
- model :password_complexity_rule
- collection :password_complexity_rules
- model :authentication_level
- collection :authentication_levels
- model :login_banner
- collection :login_banners
- model :user
- collection :users
- model :role
- collection :roles
- model :ssh_key
- collection :ssh_keys
- model :support_ticket
- collection :support_tickets
+ model :location
+ collection :locations
+ model :catalog_item
+ collection :catalog
+ model :catalog_configuration
+ collection :catalog_configurations
+ model :environment
+ collection :environments
+ model :task
+ collection :tasks
+ model :compute_pool
+ collection :compute_pools
+ model :server
+ collection :servers
+ model :virtual_machine_assigned_ip
+ collection :virtual_machine_assigned_ips
+ model :hardware_configuration
+ collection :hardware_configurations
+ model :server_configuration_option
+ collection :server_configuration_options
+ model :guest_process
+ collection :guest_processes
+ model :layout
+ collection :layouts
+ model :row
+ collection :rows
+ model :group
+ collection :groups
+ model :internet_service
+ collection :internet_services
+ model :node
+ collection :nodes
+ model :monitor
+ collection :monitors
+ model :cpu_usage_detail
+ collection :cpu_usage_detail_summary
+ model :memory_usage_detail
+ collection :memory_usage_detail_summary
+ model :storage_usage_detail
+ collection :storage_usage_detail_summary
+ model :operating_system_family
+ collection :operating_system_families
+ model :operating_system
+ collection :operating_systems
+ model :template
+ collection :templates
+ model :firewall_acl
+ collection :firewall_acls
+ model :network
+ collection :networks
+ model :ip_address
+ collection :ip_addresses
+ model :physical_device
+ collection :physical_devices
+ model :public_ip
+ collection :public_ips
+ model :trusted_network_group
+ collection :trusted_network_groups
+ model :backup_internet_service
+ collection :backup_internet_services
+ model :rnat
+ collection :rnats
+ model :association
+ collection :associations
+ model :tag
+ collection :tags
+ model :admin_organization
+ collection :admin_organizations
+ model :ssh_key
+ collection :ssh_keys
+ model :password_complexity_rule
+ collection :password_complexity_rules
+ model :authentication_level
+ collection :authentication_levels
+ model :login_banner
+ collection :login_banners
+ model :user
+ collection :users
+ model :role
+ collection :roles
+ model :ssh_key
+ collection :ssh_keys
+ model :support_ticket
+ collection :support_tickets
+ model :detached_disk
+ collection :detached_disks
#### Requests
request_path 'fog/ecloud/requests/compute'
- request :get_organization
- request :get_organizations
- request :get_location
- request :get_locations
- request :get_environment
- request :get_task
- request :get_tasks
+ request :backup_internet_service_create
+ request :backup_internet_service_delete
+ request :backup_internet_service_edit
+ request :compute_pool_edit
+ request :firewall_acls_create
+ request :firewall_acls_delete
+ request :get_admin_organization
+ request :get_api_key
+ request :get_api_keys
+ request :get_association
+ request :get_associations
+ request :get_authentication_level
+ request :get_authentication_levels
+ request :get_backup_internet_service
+ request :get_backup_internet_services
+ request :get_catalog
+ request :get_catalog_configuration
+ request :get_catalog_configurations
+ request :get_catalog_item
request :get_compute_pool
request :get_compute_pools
- request :get_server
- request :get_servers
- request :get_network
- request :get_networks
- request :get_physical_device
- request :get_physical_devices
- request :get_layout
- request :get_layouts
- request :get_row
- request :get_rows
- request :get_group
- request :get_groups
- request :get_public_ip
- request :get_public_ips
- request :get_network_summary
- request :get_internet_service
- request :get_internet_services
- request :get_node
- request :get_nodes
+ request :get_cpu_usage_detail
+ request :get_cpu_usage_detail_summary
+ request :get_environment
request :get_firewall_acl
request :get_firewall_acls
- request :get_trusted_network_group
- request :get_trusted_network_groups
- request :get_catalog
- request :get_catalog_item
- request :get_tag
- request :get_tags
- request :get_hardware_configuration
- request :get_hardware_configurations
- request :get_server_configuration_option
- request :get_server_configuration_options
+ request :get_group
+ request :get_groups
request :get_guest_process
request :get_guest_processes
- request :get_cpu_usage_detail
- request :get_cpu_usage_detail_summary
+ request :get_hardware_configuration
+ request :get_internet_service
+ request :get_internet_services
+ request :get_ip_address
+ request :get_layout
+ request :get_layouts
+ request :get_location
+ request :get_locations
+ request :get_login_banner
+ request :get_login_banners
request :get_memory_usage_detail
request :get_memory_usage_detail_summary
- request :get_storage_usage_detail
- request :get_storage_usage_detail_summary
- request :get_operating_system_family
- request :get_operating_system_families
- request :get_operating_system
- request :get_template
- request :get_templates
request :get_monitor
request :get_monitors
- request :get_backup_internet_service
- request :get_backup_internet_services
- request :get_rnat
- request :get_rnats
- request :get_association
- request :get_associations
- request :get_admin_organization
- request :get_admin_organizations
- request :get_ssh_key
- request :get_ssh_keys
+ request :get_network
+ request :get_network_summary
+ request :get_networks
+ request :get_node
+ request :get_nodes
+ request :get_operating_system
+ request :get_operating_system_families
+ request :get_organization
+ request :get_organizations
request :get_password_complexity_rule
request :get_password_complexity_rules
- request :get_authentication_level
- request :get_authentication_levels
- request :get_login_banner
- request :get_login_banners
- request :get_user
- request :get_users
+ request :get_physical_device
+ request :get_physical_devices
+ request :get_public_ip
+ request :get_public_ips
+ request :get_rnat
+ request :get_rnats
request :get_role
request :get_roles
- request :get_api_key
- request :get_api_keys
+ request :get_row
+ request :get_rows
+ request :get_server
+ request :get_server_configuration_option
+ request :get_server_configuration_options
+ request :get_servers
+ request :get_ssh_key
+ request :get_ssh_keys
+ request :get_storage_usage_detail
+ request :get_storage_usage_detail_summary
request :get_support_ticket
request :get_support_tickets
- request :get_ip_address
- request :get_ip_addresses
- request :get_catalog_configuration
- request :get_catalog_configurations
- request :compute_pool_edit
- request :virtual_machine_create_from_template
- request :virtual_machine_import
- request :virtual_machine_copy
- request :virtual_machine_copy_identical
- request :virtual_machine_edit
- request :virtual_machine_add_ip
- request :virtual_machine_edit_hardware_configuration
- request :virtual_machine_delete
- request :virtual_machine_upload_file
+ request :get_tag
+ request :get_tags
+ request :get_task
+ request :get_tasks
+ request :get_template
+ request :get_templates
+ request :get_trusted_network_group
+ request :get_trusted_network_groups
+ request :get_user
+ request :get_users
+ request :get_virtual_machine_assigned_ips
+ request :get_detached_disks
+ request :get_detached_disk
+ request :groups_create
+ request :groups_delete
+ request :groups_edit
+ request :groups_movedown
+ request :groups_moveup
request :internet_service_create
- request :internet_service_edit
request :internet_service_delete
- request :backup_internet_service_create
- request :backup_internet_service_edit
- request :backup_internet_service_delete
- request :node_service_create
- request :node_service_delete
- request :node_service_edit
+ request :internet_service_edit
request :monitors_create_default
- request :monitors_create_ping
- request :monitors_create_http
request :monitors_create_ecv
+ request :monitors_create_http
request :monitors_create_loopback
- request :monitors_edit_ping
- request :monitors_edit_http
+ request :monitors_create_ping
+ request :monitors_disable
request :monitors_edit_ecv
+ request :monitors_edit_http
+ request :monitors_edit_ping
request :monitors_enable
- request :monitors_disable
- request :rnat_associations_edit_network
+ request :node_service_create
+ request :node_service_delete
+ request :node_service_edit
+ request :power_off
+ request :power_on
+ request :power_reset
+ request :power_shutdown
+ request :public_ip_activate
request :rnat_associations_create_device
request :rnat_associations_delete
+ request :rnat_associations_edit_network
request :rows_create
+ request :rows_delete
request :rows_edit
- request :rows_moveup
request :rows_movedown
- request :rows_delete
- request :groups_create
- request :groups_edit
- request :groups_moveup
- request :groups_movedown
- request :groups_delete
+ request :rows_moveup
request :trusted_network_groups_create
- request :trusted_network_groups_edit
request :trusted_network_groups_delete
- request :firewall_acls_create
- request :firewall_acls_delete
- request :public_ip_activate
- request :power_on
- request :power_off
- request :power_reset
- request :power_shutdown
+ request :trusted_network_groups_edit
+ request :virtual_machine_edit_assigned_ips
+ request :virtual_machine_copy
+ request :virtual_machine_copy_identical
+ request :virtual_machine_create_from_template
+ request :virtual_machine_delete
+ request :virtual_machine_edit
+ request :virtual_machine_edit_hardware_configuration
+ request :virtual_machine_import
+ request :virtual_machine_upload_file
+ request :virtual_machine_detach_disk
+ request :virtual_machine_attach_disk
module Shared
attr_reader :versions_uri
- def default_organization_uri
- @default_organization_uri ||= begin
- unless @login_results
- do_login
- end
- case @login_results.body[:Org]
- when Array
- @login_results.body[:Org].first[:href]
- when Hash
- @login_results.body[:Org][:href]
- else
- nil
- end
- end
- end
-
- # login handles the auth, but we just need the Set-Cookie
- # header from that call.
- def do_login
- @login_results = get_organizations
- end
-
- def ecloud_xmlns
- {
- "xmlns" => "urn:tmrk:eCloudExtensions-2.8",
- "xmlns:i" => "http://www.w3.org/2001/XMLSchema-instance"
- }
- end
-
- def ensure_unparsed(uri)
- if uri.is_a?(String)
- uri
- else
- uri.to_s
- end
- end
-
- def supported_versions
- @supported_versions ||= get_versions(@versions_uri).body[:VersionInfo]
- end
-
- def xmlns
- { "xmlns" => "http://www.vmware.com/vcloud/v0.8",
- "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
- "xmlns:xsd" => "http://www.w3.org/2001/XMLSchema" }
- end
-
def validate_data(required_opts = [], options = {})
unless required_opts.all? { |opt| options.has_key?(opt) }
raise ArgumentError.new("Required data missing: #{(required_opts - options.keys).map(&:inspect).join(", ")}")
end
end
- end
-
- class Mock
- def self.data
- @data ||= Hash.new do |hash, key|
- hash[key] = {}
- end
- end
-
- def self.reset
- @data = nil
- end
-
- def initialize(options={})
- @ecloud_api_key = options[:ecloud]
- end
-
- def data
- self.class.data[@ecloud_api_key]
+ def id_from_uri(uri)
+ uri.match(/(\d+)$/)[1].to_i
end
- def reset_data
- self.class.data.delete(@ecloud_api_key)
+ def default_organization_uri
+ "/cloudapi/ecloud/organizations/"
end
end
-
class Real
include Shared
class << self
- def basic_request(*args)
- self.class_eval <<-EOS, __FILE__,__LINE__
- def #{args[0]}(uri)
- request({
- :expects => #{args[1] || 200},
- :method => '#{args[2] || 'GET'}',
- :headers => #{args[3] ? args[3].inspect : '{}'},
- :body => '#{args[4] ? args[4] : ''}',
- :parse => true,
- :uri => uri })
- end
- EOS
- end
-
- def unauthenticated_basic_request(*args)
- self.class_eval <<-EOS, __FILE__,__LINE__
- def #{args[0]}(uri)
- unauthenticated_request({
- :expects => #{args[1] || 200},
- :method => '#{args[2] || 'GET'}',
- :headers => #{args[3] ? args[3].inspect : '{}'},
- :parse => true,
- :uri => uri })
- end
- EOS
+ def basic_request(name, expects=[200], method=:get, headers={}, body='')
+ define_method(name) do |uri|
+ request({
+ :expects => expects,
+ :method => method,
+ :headers => headers,
+ :body => body,
+ :parse => true,
+ :uri => uri
+ })
+ end
end
end
def initialize(options = {})
- require 'builder'
require 'fog/core/parser'
@connections = {}
@connection_options = options[:connection_options] || {}
@@ -392,26 +296,14 @@ def initialize(options = {})
@username = options[:ecloud_username]
@password = options[:ecloud_password]
if @username.nil? || @password.nil?
- raise RuntimeError, "No credentials (cloud auth, or basic auth) passed!"
+ raise ArgumentError, "No credentials (cloud auth, or basic auth) passed!"
end
else
- @hmac = Fog::HMAC.new("sha256", @private_key)
+ @hmac = Fog::HMAC.new("sha256", @private_key)
end
end
- def default_organization_uri
- "/cloudapi/ecloud/organizations/"
- end
-
def request(params)
- begin
- do_request(params)
- rescue Excon::Errors::Unauthorized => e
- raise RuntimeError, "Invalid authentication data: #{e}"
- end
- end
-
- def do_request(params)
# Convert the uri to a URI if it's a string.
if params[:uri].is_a?(String)
params[:uri] = URI.parse(@host + params[:uri])
@@ -426,13 +318,16 @@ def do_request(params)
headers = set_extra_headers_for(params) || set_extra_headers_for({})
# Make the request
- options = {:expects => params[:expects] || 200, :method => params[:method] || 'GET', :path => params[:uri].path + "#{"?#{params[:uri].query}" if params[:uri].query}", :headers => headers}
- unless params[:body].empty?
+ options = {
+ :expects => (params[:expects] || 200),
+ :method => params[:method] || 'GET',
+ :path => params[:uri].path + "#{"?#{params[:uri].query}" if params[:uri].query}",
+ :headers => headers
+ }
+ unless params[:body].nil? || params[:body].empty?
options.merge!({:body => params[:body]})
end
- #puts options[:body].inspect
response = @connections[host_url].request(options)
-
# Parse the response body into a hash
unless response.body.empty?
if params[:parse]
@@ -444,6 +339,7 @@ def do_request(params)
response.body = document.body
end
end
+
response
end
@@ -451,27 +347,27 @@ def do_request(params)
# if Authorization and x-tmrk-authorization are used, the x-tmrk-authorization takes precendence.
def set_extra_headers_for(params)
- maor_headers = {
- 'x-tmrk-version' => @version,
- 'Date' => Time.now.utc.strftime("%a, %d %b %Y %H:%M:%S GMT"),
- }
- params[:headers].merge!(maor_headers)
- if params[:method]=="POST" || params[:method]=="PUT"
- params[:headers].merge!({"Content-Type" => 'application/xml'}) unless params[:headers]['Content-Type']
- params[:headers].merge!({"Accept" => 'application/xml'})
- end
- unless params[:body].empty?
+ params[:headers] = {
+ 'x-tmrk-version' => @version,
+ 'Date' => Time.now.utc.strftime("%a, %d %b %Y %H:%M:%S GMT"),
+ }.merge(params[:headers] || {})
+ if params[:method]=="POST" || params[:method]=="PUT"
+ params[:headers].merge!({"Content-Type" => 'application/xml'}) unless params[:headers]['Content-Type']
+ params[:headers].merge!({"Accept" => 'application/xml'})
+ end
+ unless params[:body].nil? || params[:body].empty?
params[:headers].merge!({"x-tmrk-contenthash" => "Sha256 #{Base64.encode64(Digest::SHA2.digest(params[:body].to_s)).chomp}"})
- end
- if @authentication_method == :basic_auth
- params[:headers].merge!({'Authorization' => "Basic #{Base64.encode64(@username+":"+@password).delete("\r\n")}"})
- elsif @authentication_method == :cloud_api_auth
- signature = cloud_api_signature(params)
- params[:headers].merge!({
- "x-tmrk-authorization" => %{CloudApi AccessKey="#{@access_key}" SignatureType="HmacSha256" Signature="#{signature}"}
- })
- end
- params[:headers]
+ end
+ if @authentication_method == :basic_auth
+ params[:headers].merge!({'Authorization' => "Basic #{Base64.encode64(@username+":"+@password).delete("\r\n")}"})
+ elsif @authentication_method == :cloud_api_auth
+ signature = cloud_api_signature(params)
+ params[:headers].merge!({
+ "x-tmrk-authorization" => %{CloudApi AccessKey="#{@access_key}" SignatureType="HmacSha256" Signature="#{signature}"},
+ "Authorization" => %{CloudApi AccessKey="#{@access_key}" SignatureType="HmacSha256" Signature="#{signature}"}
+ })
+ end
+ params[:headers]
end
def cloud_api_signature(params)
@@ -480,13 +376,14 @@ def cloud_api_signature(params)
path = params[:uri].path
canonicalized_headers = canonicalize_headers(headers)
canonicalized_resource = canonicalize_resource(path)
- string = [ verb,
- headers['Content-Length'].to_s,
- headers['Content-Type'].to_s,
- headers['Date'].to_s,
- canonicalized_headers,
- canonicalized_resource + "\n"
- ].join("\n")
+ string = [
+ verb,
+ headers['Content-Length'].to_s,
+ headers['Content-Type'].to_s,
+ headers['Date'].to_s,
+ canonicalized_headers,
+ canonicalized_resource + "\n"
+ ].join("\n")
Base64.encode64(@hmac.sign(string)).chomp
end
@@ -510,6 +407,421 @@ def canonicalize_resource(path)
end
+ class Mock
+ include Shared
+
+ def self.data
+ @data ||= Hash.new do |hash, key|
+ hash[key] = begin
+ compute_pool_id = Fog.credentials[:ecloud_compute_pool_id] || Fog::Mock.random_numbers(3).to_i
+ environment_id = Fog.credentials[:ecloud_environment_id] || Fog::Mock.random_numbers(3).to_i
+ public_ip_id = Fog.credentials[:ecloud_public_ip_id] || Fog::Mock.random_numbers(6).to_i
+ internet_service_id = Fog::Mock.random_numbers(6).to_i
+ node_service_id = Fog::Mock.random_numbers(6).to_i
+ environment_name = Fog.credentials[:ecloud_environment_name] || Fog::Mock.random_letters(12)
+ location_id = Fog::Mock.random_numbers(4).to_i
+ network_id = Fog.credentials[:ecloud_network_id] || Fog::Mock.random_numbers(6).to_i
+ network_ip = Fog::Ecloud.ip_address
+ public_ip = Fog.credentials[:ecloud_public_ip_name] || Fog::Ecloud.ip_address
+ ip_address_id = Fog::Ecloud.ip_address
+ ip_address2_id = Fog::Ecloud.ip_address
+ operating_system_id = Fog::Mock.random_numbers(7).to_i
+ operating_system_family_id = Fog::Mock.random_numbers(7).to_i
+ organization_id = Fog::Mock.random_numbers(7).to_i
+ organization_name = Fog::Mock.random_letters(7)
+ template_id = Fog.credentials[:ecloud_template_id] || Fog::Mock.random_numbers(7).to_i
+ ssh_key_id = Fog.credentials[:ecloud_ssh_key_id] || Fog::Mock.random_numbers(4).to_i
+ ssh_key_name = Fog.credentials[:ecloud_ssh_key_name] || "root"
+
+ environment = {
+ :id => environment_id,
+ :href => "/cloudapi/ecloud/environments/#{environment_id}",
+ :name => environment_name,
+ :type => "application/vnd.tmrk.cloud.environment"
+ }
+
+ organization = {
+ :href => "/cloudapi/ecloud/organizations/#{organization_id}",
+ :type => "application/vnd.tmrk.cloud.organization",
+ :name => organization_name,
+ :Links => {
+ :Link => [
+ Fog::Ecloud.keep(environment, :href, :name, :type),
+ {
+ :href => "/cloudapi/ecloud/admin/organizations/#{organization_id}",
+ :name => organization_name,
+ :type => "application/vnd.tmrk.cloud.admin.organization",
+ :rel => "alternate",
+ },
+ {
+ :href => "/cloudapi/ecloud/devicetags/organizations/#{organization_id}",
+ :type => "application/vnd.tmrk.cloud.deviceTag; type=collection",
+ :rel => "down",
+ },
+ {
+ :href => "/cloudapi/ecloud/alerts/organizations/#{organization_id}",
+ :type => "application/vnd.tmrk.cloud.alertLog",
+ :rel => "down",
+ },
+ ],
+ },
+ :Locations => {
+ :Location => [
+ {
+ :href => "/cloudapi/ecloud/locations/#{location_id}",
+ :name => organization_name,
+ :Catalog => {
+ :href => "/cloudapi/ecloud/admin/catalog/organizations/#{organization_id}/locations/#{location_id}",
+ :type => "application/vnd.tmrk.cloud.admin.catalogEntry; type=collection"
+ },
+ :Environments => { :Environment => [environment] }
+ }
+ ]
+ }
+ }
+ environment.merge!(
+ :Links => {
+ :Link => [ Fog::Ecloud.keep(organization, :href, :name, :type), ]
+ }
+ )
+
+ admin_organization = {
+ :id => organization_id,
+ :href => "/cloudapi/ecloud/admin/organizations/#{organization_id}",
+ :type => "application/vnd.tmrk.cloud.admin.organization",
+ :name => organization_name,
+ :Links => {
+ :Link => [
+ Fog::Ecloud.keep(organization, :href, :type, :name)
+ ],
+ },
+ :organization_id => organization_id,
+ }
+
+ compute_pool = {
+ :id => compute_pool_id,
+ :href => "/cloudapi/ecloud/computepools/#{compute_pool_id}",
+ :name => Fog::Mock.random_letters(12),
+ :type => "application/vnd.tmrk.cloud.computePool",
+ :environment_id => environment_id,
+ :Links => {
+ :Link => [
+ Fog::Ecloud.keep(organization, :href, :name, :type),
+ Fog::Ecloud.keep(environment, :href, :name, :type),
+ ]
+ }
+ }
+
+
+ public_ip = {
+ :id => public_ip_id,
+ :href => "/cloudapi/ecloud/publicips/#{public_ip_id}",
+ :name => public_ip,
+ :type => "application/vnd.tmrk.cloud.publicIp",
+ :IpType => "none",
+ :environment_id => environment_id,
+ :Links => {
+ :Link => [
+ Fog::Ecloud.keep(environment, :href, :name, :type),
+ ],
+ },
+ :InternetServices => {
+ :InternetService => [
+ ],
+ },
+ }
+
+ internet_service = {
+ :id => internet_service_id,
+ :href => "/cloudapi/ecloud/internetservices/#{internet_service_id}",
+ :name => Fog::Mock.random_letters(6),
+ :type => "application/vnd.tmrk.cloud.internetService",
+ :public_ip_id => public_ip_id,
+ :Links => {
+ :Link => [
+ Fog::Ecloud.keep(public_ip, :href, :name, :type),
+ ],
+ },
+ :NodeServices => {
+ :NodeService => [
+ ]
+ },
+ }
+
+ node_service = {
+ :id => node_service_id,
+ :href => "/cloudapi/ecloud/nodeservices/#{node_service_id}",
+ :name => Fog::Mock.random_letters(6),
+ :type => "application/vnd.tmrk.cloud.nodeService",
+ :internet_service_id => internet_service_id,
+ :Links => {
+ :Link => [
+ Fog::Ecloud.keep(internet_service, :href, :name, :type)
+ ],
+ },
+ }
+
+ internet_service[:NodeServices][:NodeService].push(node_service)
+ public_ip[:InternetServices][:InternetService].push(internet_service)
+
+ network = {
+ :id => network_id,
+ :href => "/cloudapi/ecloud/networks/#{network_id}",
+ :name => "#{network_ip}/#{Fog::Mock.random_numbers(2)}",
+ :type => "application/vnd.tmrk.cloud.network",
+ :Address => network_ip,
+ :NetworkType => "Dmz",
+ :BroadcastAddress => network_ip,
+ :GatewayAddress => network_ip,
+ :environment_id => environment_id,
+ :Links => {
+ :Link => [
+ Fog::Ecloud.keep(environment, :href, :name, :type),
+ ]
+ },
+ :IpAddresses => {
+ :IpAddress => [],
+ },
+ }
+
+ ip_address = {
+ :id => ip_address_id,
+ :href => "/cloudapi/ecloud/ipaddresses/networks/#{network_id}/#{ip_address_id}",
+ :name => ip_address_id,
+ :type => "application/vnd.tmrk.cloud.ipAddress",
+ :network_id => network_id,
+ :Links => {
+ :Link => [ Fog::Ecloud.keep(network, :href, :name, :type), ],
+ },
+ :Reserved => "false",
+ :Host => nil,
+ :DetectedOn => nil,
+ }
+
+ ip_address2 = ip_address.dup.merge(:id => ip_address2_id, :href => "/cloudapi/ecloud/ipaddresses/networks/#{network_id}/#{ip_address2_id}", :name => ip_address2_id)
+
+ network[:IpAddresses][:IpAddress].push(ip_address).push(ip_address2)
+
+
+ short_name = "solaris10_64guest"
+ operating_system = {
+ :short_name => short_name,
+ :compute_pool_id => compute_pool_id,
+ :href => "/cloudapi/ecloud/operatingsystems/#{short_name}/computepools/#{compute_pool_id}",
+ :name => "Sun Solaris 10 (64-bit)",
+ :type => "application/vnd.tmrk.cloud.operatingSystem",
+ :FamilyName => "Solaris",
+ :Links => {
+ :Link => Fog::Ecloud.keep(compute_pool, :href, :name, :type),
+ },
+ :ConfigurationOptions => {
+ :Processor => {
+ :Minimum => "1",
+ :Maximum => "8",
+ :StepFactor => "1"
+ },
+ :Memory => {
+ :MinimumSize => {
+ :Unit => "MB",
+ :Value => "800"
+ },
+ :MaximumSize => {
+ :Unit => "MB",
+ :Value => "16384"
+ },
+ :StepFactor => {
+ :Unit => "MB",
+ :Value => "4"
+ }
+ },
+ :Disk => {
+ :Minimum => "1",
+ :Maximum => "15",
+ :SystemDisk => {
+ :ResourceCapacityRange => {
+ :MinimumSize => {
+ :Unit => "GB",
+ :Value => "1"
+ },
+ :MaximumSize => {
+ :Unit => "GB",
+ :Value => "512"
+ },
+ :StepFactor => {
+ :Unit => "GB",
+ :Value => "1"}
+ },
+ :MonthlyCost => "0"
+ },
+ :DataDisk => {
+ :ResourceCapacityRange => {
+ :MinimumSize => {
+ :Unit => "GB",
+ :Value => "1"
+ },
+ :MaximumSize => {
+ :Unit => "GB",
+ :Value => "512"
+ },
+ :StepFactor => {
+ :Unit => "GB",
+ :Value => "1"
+ }
+ },
+ :MonthlyCost => "0"
+ }
+ },
+ :NetworkAdapter=> {
+ :Minimum => "1",
+ :Maximum => "4",
+ :StepFactor => "1"
+ }
+ }
+ }
+
+
+ template = {
+ :id => template_id,
+ :href => "/cloudapi/ecloud/templates/#{template_id}/computepools/#{compute_pool_id}",
+ :type => "application/vnd.tmrk.cloud.template",
+ :name => "Sun Solaris 10 (x64)",
+ :compute_pool_id => compute_pool_id,
+ :OperatingSystem => Fog::Ecloud.keep(operating_system, :href, :name, :type),
+ :Memory => {
+ :MinimumSize => {
+ :Unit => "MB",
+ :Value => "800"
+ },
+ :MaximumSize => {
+ :Unit => "MB",
+ :Value => "16384"
+ },
+ :StepFactor => {
+ :Unit => "MB",
+ :Value => "4"
+ }
+ },
+ :Storage => {
+ :Size => {
+ :Unit => "GB",
+ :Value => "7"
+ }
+ },
+ :NetworkAdapters => "1",
+ :Links => {
+ :Link => [
+ Fog::Ecloud.keep(compute_pool, :href, :name, :type),
+ ]
+ }
+ }
+
+ operating_system_family = {
+ :id => operating_system_family_id,
+ :compute_pool_id => compute_pool_id,
+ :OperatingSystemFamily => {
+ :Name => "Linux",
+ :OperatingSystems => {
+ :OperatingSystem => [Fog::Ecloud.keep(operating_system, :href, :name, :type)],
+ }
+ },
+ :Links => {
+ :Link => [
+ Fog::Ecloud.keep(compute_pool, :href, :name, :type),
+ ]
+ }
+ }
+
+ ssh_key = {
+ :id => ssh_key_id,
+ :href => "/cloudapi/ecloud/admin/sshKeys/#{ssh_key_id}",
+ :name => ssh_key_name,
+ :admin_organization_id => organization_id,
+ :Links => {
+ :Link => [
+ Fog::Ecloud.keep(admin_organization, :href, :name, :type),
+ Fog::Ecloud.keep(organization, :href, :name, :type),
+ ]
+ },
+ :Default => "true",
+ :FingerPrint => Fog::Ecloud.mac_address
+ }
+
+ layout = {
+ :id => environment_id,
+ :href => "/cloudapi/ecloud/layout/environments/#{environment_id}",
+ :type => "application/vnd.tmrk.cloud.deviceLayout",
+ :Links => {
+ :Link => [
+ Fog::Ecloud.keep(environment, :name, :href, :type),
+ ],
+ },
+ :Rows => {
+ :Row => [
+ ],
+ },
+ :environment_id => environment_id
+ }
+
+
+ {
+ :compute_pools => {compute_pool_id => compute_pool},
+ :environments => {environment_id => environment},
+ :public_ips => {public_ip_id => public_ip},
+ :internet_services => {internet_service_id => internet_service},
+ :node_services => {node_service_id => node_service},
+ :networks => {network_id => network},
+ :organizations => {organization_id => organization},
+ :admin_organizations => {organization_id => admin_organization},
+ :operating_systems => {operating_system_id => operating_system},
+ :operating_system_families => {operating_system_family_id => operating_system_family},
+ :servers => {},
+ :tasks => {},
+ :templates => {template_id => template},
+ :ssh_keys => {ssh_key_id => ssh_key},
+ :detached_disks => {},
+ :template_href => (Fog.credentials[:ecloud_template_href] || "/cloudapi/ecloud/templates/#{template_id}/computepools/#{compute_pool_id}"),
+ :rows => {},
+ :groups => {},
+ :layouts => {environment_id => layout},
+ }
+ end
+ end
+ end
+
+ def self.reset
+ @data = nil
+ end
+
+ def initialize(options={})
+ @ecloud_api_key = options[:ecloud]
+ end
+
+ def data
+ self.class.data[@ecloud_api_key]
+ end
+
+ def reset_data
+ self.class.data.delete(@ecloud_api_key)
+ end
+
+ def response(params={})
+ body = params[:body]
+ headers = {
+ "Content-Type" => "application/xml"
+ }.merge(params[:headers] || {})
+ status = params[:status] || 200
+
+ response = Excon::Response.new(:body => body, :headers => headers, :status => status)
+ if params.has_key?(:expects) && ![*params[:expects]].include?(response.status)
+ raise(Excon::Errors.status_error(params, response))
+ else response
+ end
+ end
+
+ def deep_copy(o)
+ Marshal.load(Marshal.dump(o))
+ end
+ end
end
end
end
View
24 lib/fog/ecloud/models/compute/admin_organization.rb
@@ -4,34 +4,38 @@ class Ecloud
class AdminOrganization < Fog::Ecloud::Model
identity :href
- attribute :name, :aliases => :Name
- attribute :type, :aliases => :Type
- attribute :other_links, :aliases => :Links
+ attribute :name, :aliases => :Name
+ attribute :type, :aliases => :Type
+ attribute :other_links, :aliases => :Links, :squash => :Link
attribute :multifactor_summary, :aliases => :MultifactorSummary
- attribute :support_access, :aliases => :SupportAccess
+ attribute :support_access, :aliases => :SupportAccess
def ssh_keys
- @ssh_keys = Fog::Compute::Ecloud::SshKeys.new(:connection => connection, :href => "/cloudapi/ecloud/admin/sshKeys/organizations/#{org_id}")
+ @ssh_keys = Fog::Compute::Ecloud::SshKeys.new(:connection => connection, :href => "/cloudapi/ecloud/admin/sshKeys/organizations/#{organization.id}")
end
def password_complexity_rules
- @password_complexity_rules = Fog::Compute::Ecloud::PasswordComplexityRules.new(:connection => connection, :href => "/cloudapi/ecloud/admin/organizations/#{org_id}/passwordComplexityRules")
+ @password_complexity_rules = Fog::Compute::Ecloud::PasswordComplexityRules.new(:connection => connection, :href => "/cloudapi/ecloud/admin/organizations/#{organization.id}/passwordComplexityRules")
end
def login_banner
- @login_banner = Fog::Compute::Ecloud::LoginBanner.new(:connection => connection, :href => "/cloudapi/ecloud/admin/organizations/#{org_id}/loginBanner")
+ @login_banner = Fog::Compute::Ecloud::LoginBanner.new(:connection => connection, :href => "/cloudapi/ecloud/admin/organizations/#{organization.id}/loginBanner")
end
def authentication_levels
- @authentication_levels = Fog::Compute::Ecloud::AuthenticationLevels.new(:connection => connection, :href => "/cloudapi/ecloud/admin/organizations/#{org_id}/authenticationLevels")
+ @authentication_levels = Fog::Compute::Ecloud::AuthenticationLevels.new(:connection => connection, :href => "/cloudapi/ecloud/admin/organizations/#{organization.id}/authenticationLevels")
end
def id
href.scan(/\d+/)[0]
end
- def org_id
- other_links[:Link].detect { |l| l[:type] == "application/vnd.tmrk.cloud.organization" }[:href].scan(/\d+/)[0]
+ def organization
+ @organization ||= begin
+ reload unless other_links
+ organization_link = other_links.find{|l| l[:type] == "application/vnd.tmrk.cloud.organization"}
+ self.connection.organizations.new(organization_link)
+ end
end
end
end
View
5 lib/fog/ecloud/models/compute/admin_organizations.rb
@@ -9,11 +9,6 @@ class AdminOrganizations < Fog::Ecloud::Collection
model Fog::Compute::Ecloud::AdminOrganization
- def all
- data = connection.get_admin_organizations(href).body
- load(data)
- end
-
def get(uri)
if data = connection.get_admin_organization(uri)
new(data.body)
View
28 lib/fog/ecloud/models/compute/compute_pool.rb
@@ -5,13 +5,13 @@ class ComputePool < Fog::Ecloud::Model
identity :href
- attribute :href, :aliases => :Href
- attribute :name, :aliases => :Name
- attribute :type, :aliases => :Type
- attribute :other_links, :aliases => :Links
- attribute :all_servers, :aliases => :VirtualMachines
- attribute :purchased, :aliases => :Purchased
- attribute :cpu_burst, :aliases => :CpuBurst
+ attribute :href, :aliases => :Href
+ attribute :name, :aliases => :Name
+ attribute :type, :aliases => :Type
+ attribute :other_links, :aliases => :Links, :squash => :Link
+ attribute :all_servers, :aliases => :VirtualMachines
+ attribute :purchased, :aliases => :Purchased
+ attribute :cpu_burst, :aliases => :CpuBurst
attribute :memory_burst, :aliases => :MemoryBurst
def servers
@@ -41,7 +41,19 @@ def operating_system_families
end
def templates
- @templates ||= Fog::Compute::Ecloud::Templates.new(:connection => connection, :href => "/cloudapi/ecloud/templates/computePools/#{id}")
+ @templates ||= self.connection.templates(:href => "/cloudapi/ecloud/templates/computePools/#{id}")
+ end
+
+ def detached_disks
+ @detached_disks ||= self.connection.detached_disks(:href => "/cloudapi/ecloud/detacheddisks/computepools/#{id}")
+ end
+
+ def environment
+ @environment ||= begin
+ reload unless other_links
+ environment_link = other_links.find{|l| l[:type] == "application/vnd.tmrk.cloud.environment"}
+ self.connection.environments.get(environment_link[:href])
+ end
end
def edit(options)
View
27 lib/fog/ecloud/models/compute/detached_disk.rb
@@ -0,0 +1,27 @@
+module Fog
+ module Compute
+ class Ecloud
+ class DetachedDisk < Fog::Ecloud::Model
+ identity :href
+
+ attribute :name, :aliases => :Name
+ attribute :type, :aliases => :Type
+ attribute :other_links, :aliases => :Links
+ attribute :status, :aliases => :Status
+ attribute :size, :aliases => :Size
+
+ def ready?
+ unless status =~ /AttachInProgress|DetachInProgress/
+ true
+ else
+ false
+ end
+ end
+
+ def id
+ href.scan(/\d+/)[0]
+ end
+ end
+ end
+ end
+end
View
31 lib/fog/ecloud/models/compute/detached_disks.rb
@@ -0,0 +1,31 @@
+require 'fog/ecloud/models/compute/detached_disk'
+
+module Fog
+ module Compute
+ class Ecloud
+ class DetachedDisks < Fog::Ecloud::Collection
+
+ identity :href
+
+ model Fog::Compute::Ecloud::DetachedDisk
+
+ def all
+ data = connection.get_detached_disks(href).body[:DetachedDisk]
+ data = [] if data.nil?
+ load(data)
+ end
+
+ def get(uri)
+ data = connection.get_detached_disk(uri).body
+ if data == ""
+ new({})
+ else
+ new(data)
+ end
+ rescue Fog::Errors::NotFound
+ nil
+ end
+ end
+ end
+ end
+end
View
19 lib/fog/ecloud/models/compute/environment.rb
@@ -9,7 +9,7 @@ class Environment < Fog::Ecloud::Model
attribute :name
attribute :type
- attribute :other_links, :aliases => :Links
+ attribute :other_links, :aliases => :Links, :squash => :Link
def public_ips
@public_ips ||= Fog::Compute::Ecloud::PublicIps.new(:connection => connection, :href => "/cloudapi/ecloud/publicIps/environments/#{id}")
@@ -28,7 +28,7 @@ def backup_internet_services
end
def networks
- @networks ||= Fog::Compute::Ecloud::Networks.new(:connection => connection, :href => "/cloudapi/ecloud/networks/environments/#{id}")
+ @networks ||= self.connection.networks(:href => "/cloudapi/ecloud/networks/environments/#{id}")
end
def servers
@@ -45,11 +45,11 @@ def servers
end
def layout
- @layout ||= Fog::Compute::Ecloud::Layouts.new(:connection => connection, :href => "/cloudapi/ecloud/layout/environments/#{id}").first
+ @layout ||= self.connection.layouts(:href => "/cloudapi/ecloud/layout/environments/#{id}").first
end
def rows
- layout.rows
+ @rows ||= layout.rows
end
def tasks
@@ -73,8 +73,7 @@ def trusted_network_groups
end
def catalog
- org_href = other_links[:Link].detect { |l| l[:type] == "application/vnd.tmrk.cloud.organization" }[:href]
- @catalog ||= Fog::Compute::Ecloud::Catalog.new(:connection => connection, :href => "/cloudapi/ecloud/admin/catalog/organizations/#{org_href.scan(/\d+/)[0]}")
+ @catalog = connection.catalog(:href => "/cloudapi/ecloud/admin/catalog/organizations/#{organization.id}")
end
def rnats
@@ -98,6 +97,14 @@ def create_firewall_acl(options = {})
def id
href.scan(/\d+/)[0]
end
+
+ def organization
+ @organization ||= begin
+ reload unless other_links
+ organization_link = other_links.find{|l| l[:type] == "application/vnd.tmrk.cloud.organization"}
+ self.connection.organizations.new(organization_link)
+ end
+ end
end
Vdc = Environment
end
View
2  lib/fog/ecloud/models/compute/environments.rb
@@ -14,7 +14,7 @@ class Environments < Fog::Ecloud::Collection
def all
data = []
- connection.get_organization(href).body[:Locations][:Location].each do |d|
+ connection.get_organization(href).body[:Locations][:Location].each do |d|
if d[:Environments][:Environment].is_a?(Array)
d[:Environments][:Environment].each { |e| data << e }
else
View
2  lib/fog/ecloud/models/compute/group.rb
@@ -33,6 +33,8 @@ def delete
def id
href.scan(/\d+/)[0]
end
+
+ alias destroy delete
end
end
end
View
21 lib/fog/ecloud/models/compute/groups.rb
@@ -11,15 +11,26 @@ class Groups < Fog::Ecloud::Collection
def all
data = connection.get_groups(href).body
- data = data[:Groups] ? data[:Groups][:Group] : data
- load(data)
+ data = if data == ""
+ ""
+ else
+ data[:Groups] ? data[:Groups][:Group] : data
+ end
+ if data == "" || !data.is_a?(Array) && data[:type] == "application/vnd.tmrk.cloud.layoutRow"
+ nil
+ else
+ load(data)
+ end
end
def get(uri)
- if data = connection.get_group(uri)
- new(data.body)
+ data = connection.get_group(uri).body
+ if data == ""
+ nil
+ else
+ new(data)
end
- rescue Fog::Errors::NotFound
+ rescue Excon::Errors::NotFound
nil
end
end
View
8 lib/fog/ecloud/models/compute/hardware_configuration.rb
@@ -4,10 +4,10 @@ class Ecloud
class HardwareConfiguration < Fog::Ecloud::Model
identity :href
- attribute :processor_count, :aliases => :ProcessorCount, :type => :integer
- attribute :mem, :aliases => :Memory
- attribute :storage, :aliases => :Disks
- attribute :network_cards, :aliases => :Nics
+ attribute :processor_count, :aliases => :ProcessorCount, :type => :integer
+ attribute :memory, :aliases => :Memory, :squash => :Value # {:Memory => {:Value => 15}}
+ attribute :storage, :aliases => :Disks, :squash => :Disk
+ attribute :network_cards, :aliases => :Nics, :squash => :Nic
def id
href.scan(/\d+/)[0]
View
2  lib/fog/ecloud/models/compute/hardware_configurations.rb
@@ -10,7 +10,7 @@ class HardwareConfigurations < Fog::Ecloud::Collection
model Fog::Compute::Ecloud::HardwareConfiguration
def all
- data = connection.get_hardware_configurations(href).body
+ data = connection.get_server(href).body
load(data)
end
View
32 lib/fog/ecloud/models/compute/internet_service.rb
@@ -4,20 +4,24 @@ class Ecloud
class InternetService < Fog::Ecloud::Model
identity :href
- attribute :name, :aliases => :Name
- attribute :type, :aliases => :Type
- attribute :other_links, :aliases => :Links
- attribute :actions, :aliases => :Actions
- attribute :protocol, :aliases => :Protocol
- attribute :port, :aliases => :Port, :type => :integer
- attribute :enabled, :aliases => :Enabled, :type => :boolean
- attribute :description, :aliases => :Description
- attribute :public_ip, :aliases => :PublicIp
- attribute :persistence, :aliases => :Persistence
- attribute :redirect_url, :aliases => :RedirectUrl
- attribute :trusted_network_group, :aliases => :TrustedNetworkGroup
+ attribute :name, :aliases => :Name
+ attribute :type, :aliases => :Type
+ attribute :other_links, :aliases => :Links
+ attribute :actions, :aliases => :Actions
+ attribute :protocol, :aliases => :Protocol
+ attribute :port, :aliases => :Port, :type => :integer
+ attribute :enabled, :aliases => :Enabled, :type => :boolean
+ attribute :description, :aliases => :Description
+ attribute :public_ip, :aliases => :PublicIp
+ attribute :persistence, :aliases => :Persistence
+ attribute :redirect_url, :aliases => :RedirectUrl
+ attribute :trusted_network_group, :aliases => :TrustedNetworkGroup
attribute :backup_internet_service, :aliases => :BackupInternetService
+ def ready?
+ !self.port.nil?
+ end
+
def nodes
@nodes ||= Fog::Compute::Ecloud::Nodes.new(:connection => connection, :href => href)
end
@@ -43,7 +47,7 @@ def edit(options)
def delete
data = connection.internet_service_delete(href).body
- task = Fog::Compute::Ecloud::Tasks.new(:connection => connection, :href => data[:href])[0]
+ self.connection.tasks.new(data)
end
def create_monitor(options = {})
@@ -85,6 +89,8 @@ def _compose_service_data
service_data.reject! {|k, v| v.nil? }
service_data
end
+
+ alias destroy delete
end
end
end
View
15 lib/fog/ecloud/models/compute/internet_services.rb
@@ -19,8 +19,11 @@ def all
end
def get(uri)
- if data = connection.get_internet_service(uri)
- new(data.body)
+ data = connection.get_internet_service(uri).body
+ if data == ""
+ new({})
+ else
+ new(data)
end
rescue Fog::Errors::NotFound
nil
@@ -28,10 +31,10 @@ def get(uri)
def create(options)
options[:uri] = "/cloudapi/ecloud/internetServices/publicIps/#{public_ip_id}/action/createInternetService"
- options[:protocol] ||= "TCP"
- options[:enabled] ||= true
- options[:description] ||= ""
- options[:persistence] ||= {}
+ options[:protocol] ||= "TCP"
+ options[:enabled] ||= true
+ options[:description] ||= ""
+ options[:persistence] ||= {}
options[:persistence][:type] ||= "None"
data = connection.internet_service_create(options).body
object = new(data)
View
20 lib/fog/ecloud/models/compute/ip_address.rb
@@ -6,7 +6,7 @@ class IpAddress < Fog::Ecloud::Model
attribute :name, :aliases => :Name
attribute :type, :aliases => :Type
- attribute :other_links, :aliases => :Links
+ attribute :other_links, :aliases => :Links, :squash => :Link
attribute :host, :aliases => :Host
attribute :detected_on, :aliases => :DetectedOn
attribute :rnat, :aliases => :RnatAddress
@@ -15,9 +15,23 @@ class IpAddress < Fog::Ecloud::Model
def status
(detected_on || host) ? "Assigned" : "Available"
end
-
+
def id
- href.scan(/\d+/)[0]
+ href.match(/((\d+{1,3}\.){3}(\d+{1,3}))$/)[1]
+ end
+
+ def server
+ @server ||= begin
+ reload unless other_links
+ server_link = other_links.find{|l| l[:type] == "application/vnd.tmrk.cloud.virtualMachine"}
+ self.connection.servers.get(server_link[:href])
+ end
+ end
+
+ def network
+ reload if other_links.nil?
+ network_href = other_links.detect { |l| l[:type] == "application/vnd.tmrk.cloud.network" }[:href]
+ network = self.connection.networks.get(network_href)
end
end
end
View
7 lib/fog/ecloud/models/compute/ip_addresses.rb
@@ -10,7 +10,12 @@ class IpAddresses < Fog::Ecloud::Collection
model Fog::Compute::Ecloud::IpAddress
def all
- data = connection.get_ip_addresses(href).body[:IpAddresses][:IpAddress]
+ data = connection.get_network(href).body
+ data = if data[:IpAddresses]
+ data[:IpAddresses][:IpAddress]
+ else
+ data
+ end
data = data.nil? ? [] : data
load(data)
end
View
2  lib/fog/ecloud/models/compute/layout.rb
@@ -8,7 +8,7 @@ class Layout < Fog::Ecloud::Model
attribute :other_links, :aliases => :Links
def rows
- @rows = Fog::Compute::Ecloud::Rows.new(:connection => connection, :href => href)
+ @rows ||= self.connection.rows(:href => href)
end
def id
View
26 lib/fog/ecloud/models/compute/network.rb
@@ -4,14 +4,14 @@ class Ecloud
class Network < Fog::Ecloud::Model
identity :href
- attribute :name, :aliases => :Name
- attribute :type, :aliases => :Type
- attribute :other_links, :aliases => :Links
- attribute :address, :aliases => :Address
- attribute :network_type, :aliases => :NetworkType
+ attribute :name, :aliases => :Name
+ attribute :type, :aliases => :Type
+ attribute :other_links, :aliases => :Links, :squash => :Link
+ attribute :address, :aliases => :Address
+ attribute :network_type, :aliases => :NetworkType
attribute :broadcast_address, :aliases => :BroadcastAddress
- attribute :gateway_address, :aliases => :GatewayAddress
- attribute :rnat_address, :aliases => :RnatAddress
+ attribute :gateway_address, :aliases => :GatewayAddress
+ attribute :rnat_address, :aliases => :RnatAddress
def rnats
@rnats ||= Fog::Compute::Ecloud::Rnats.new(:connection => connection, :href => "cloudapi/ecloud/rnats/networks/#{id}")
@@ -26,10 +26,20 @@ def edit_rnat_association(options)
data = connection.rnat_associations_edit_network(options).body
task = Fog::Compute::Ecloud::Tasks.new(:connection => connection, :href => data[:href])[0]
end
-
+
def id
href.scan(/\d+/)[0]
end
+
+ def environment
+ reload if other_links.nil?
+ environment_href = other_links.detect { |l| l[:type] == "application/vnd.tmrk.cloud.environment" }[:href]
+ self.connection.environments.get(environment_href)
+ end
+
+ def location
+ environment.id
+ end
end
end
end
View
12 lib/fog/ecloud/models/compute/networks.rb
@@ -5,14 +5,18 @@ module Compute
class Ecloud
class Networks < Fog::Ecloud::Collection
- identity :href
+ attribute :href, :aliases => :Href
model Fog::Compute::Ecloud::Network
def all
- data = connection.get_networks(href).body
- data = data[:Networks] ? data[:Networks][:Network] : data[:Network]
- data = data.nil? ? [] : data
+ body = connection.get_networks(self.href).body
+ body = body[:Networks] ? body[:Networks][:Network] : body[:Network]
+ data = case body
+ when NilClass then []
+ when Array then body
+ when Hash then [body]
+ end
load(data)
end
View
10 lib/fog/ecloud/models/compute/node.rb
@@ -13,13 +13,17 @@ class Node < Fog::Ecloud::Model
attribute :enabled, :aliases => :Enabled, :type => :boolean
attribute :description, :aliases => :Description
+ def ready?
+ !self.name.nil?
+ end
+
def tasks
@tasks ||= Fog::Compute::Ecloud::Tasks.new(:connection => connection, :href => "/cloudapi/ecloud/tasks/virtualMachines/#{id}")
end
def delete
data = connection.node_service_delete(href).body
- task = Fog::Compute::Ecloud::Tasks.new(:connection => connection, :href => data[:href])[0]
+ self.connection.tasks.new(data)
end
def edit(options)
@@ -29,10 +33,12 @@ def edit(options)
data = connection.node_service_edit(options).body
task = Fog::Compute::Ecloud::Tasks.new(:connection => connection, :href => data[:href])[0]
end
-
+
def id
href.scan(/\d+/)[0]
end
+
+ alias destroy delete
end
end
end
View
7 lib/fog/ecloud/models/compute/nodes.rb
@@ -19,8 +19,11 @@ def all
end
def get(uri)
- if data = connection.get_node(uri)
- new(data.body)
+ data = connection.get_node(uri).body
+ if data == ""
+ new({})
+ else
+ new(data)
end
rescue Fog::Errors::NotFound
nil
View
2  lib/fog/ecloud/models/compute/operating_system_family.rb
@@ -9,7 +9,7 @@ class OperatingSystemFamily < Fog::Ecloud::Model
attribute :operating_system_family, :aliases => :OperatingSystems
def operating_systems
- @operating_systems ||= Fog::Compute::Ecloud::OperatingSystems.new(:connection => connection, :data => operating_system_family[:OperatingSystem])
+ @operating_systems ||= self.connection.operating_systems(:data => operating_system_family[:OperatingSystem])
end
def id
View
10 lib/fog/ecloud/models/compute/organization.rb
@@ -9,26 +9,26 @@ class Organization < Fog::Ecloud::Model
attribute :name, :aliases => :Name
attribute :type, :aliases => :Type
- attribute :other_links, :aliases => :Links
+ attribute :other_links, :aliases => :Links, :squash => :Link
def locations
@locations ||= Fog::Compute::Ecloud::Locations.new( :connection => connection, :href => href )
end
def environments
- @environments ||= Fog::Compute::Ecloud::Environments.new(:connection => connection, :href => href)
+ @environments ||= self.connection.environments(:href => href)
end
def tags
- @tags ||= Fog::Compute::Ecloud::Tags.new(:connection => connection, :href => "/cloudapi/ecloud/deviceTags/organizations/#{id}")
+ @tags ||= self.connection.tags(:href => "/cloudapi/ecloud/deviceTags/organizations/#{id}")
end
def admin
- @admin ||= Fog::Compute::Ecloud::AdminOrganizations.new(:connection => connection, :href => "/cloudapi/ecloud/admin/organizations/#{id}").first
+ @admin ||= self.connection.admin_organizations.new(:href => "/cloudapi/ecloud/admin/organizations/#{id}")
end
def users
- @users ||= Fog::Compute::Ecloud::Users.new(:connection => connection, :href => "/cloudapi/ecloud/admin/users/organizations/#{id}")
+ @users ||= self.connection.users(:href => "/cloudapi/ecloud/admin/users/organizations/#{id}")
end
def support_tickets(type = :open)
View
2  lib/fog/ecloud/models/compute/public_ip.rb
@@ -12,7 +12,7 @@ class PublicIp < Fog::Ecloud::Model
def internet_services
@internet_services = Fog::Compute::Ecloud::InternetServices.new(:connection => connection, :href => href)
end
-
+
def environment_id
other_links[:Link].detect { |l| l[:type] == "application/vnd.tmrk.cloud.environment" }[:href].scan(/\d+/)[0]
end
View
7 lib/fog/ecloud/models/compute/public_ips.rb
@@ -16,8 +16,11 @@ def all
end
def get(uri)
- if data = connection.get_public_ip(uri)
- new(data.body)
+ data = connection.get_public_ip(uri).body
+ if data == ""
+ new({})
+ else
+ new(data)
end
rescue Fog::Errors::NotFound
nil
View
7 lib/fog/ecloud/models/compute/row.rb
@@ -10,7 +10,7 @@ class Row < Fog::Ecloud::Model
attribute :index, :aliases => :Index
def groups
- @groups = Fog::Compute::Ecloud::Groups.new(:connection => connection, :href => href)
+ @groups = self.connection.groups(:href => href)
end
def edit(options)
@@ -37,16 +37,19 @@ def create_group(options = {})
options[:row_name] = name
options[:href] = href
data = connection.groups_create(options).body
- group = Fog::Compute::Ecloud::Groups.new(:connection => connection, :href => data[:href])[0]
+ group = self.connection.groups.new(data)
end
def environment_id
+ reload if other_links.nil?
other_links[:Link][:href].scan(/\d+/)[0]
end
def id
href.scan(/\d+/)[0]
end
+
+ alias destroy delete
end
end
end
View
9 lib/fog/ecloud/models/compute/rows.rb
@@ -15,10 +15,13 @@ def all
end
def get(uri)
- if data = connection.get_row(uri)
- new(data.body)
+ data = connection.get_row(uri).body
+ if data == ""
+ nil
+ else
+ new(data)
end
- rescue Fog::Errors::NotFound
+ rescue Excon::Errors::NotFound
nil
end
View
200 lib/fog/ecloud/models/compute/server.rb
@@ -2,80 +2,69 @@ module Fog
module Compute
class Ecloud
class Server < Fog::Ecloud::Model
+ extend Forwardable
+
identity :href
- attribute :name, :aliases => :Name
- attribute :type , :aliases => :Type
- attribute :other_links, :aliases => :Link
- attribute :status, :aliases => :Status
- attribute :storage, :aliases => :Storage
- attribute :ip_addresses, :aliases => :IpAddresses
- attribute :operating_system, :aliases => :OperatingSystem
- attribute :powered_on, :aliases => :PoweredOn, :type => :boolean
- attribute :tools_status, :aliases => :ToolsStatus
- attribute :cpus, :aliases => :ProcessorCount, :type => :integer
- attribute :memory, :aliases => :Memory
- attribute :description, :aliases => :Description
- attribute :tags, :aliases => :Tags
- attribute :layout, :aliases => :Layout
+ attribute :description, :aliases => :Description
+ attribute :hardware_configuration, :aliases => :HardwareConfiguration
+ attribute :ip_addresses, :aliases => :IpAddresses, :squash => :AssignedIpAddresses
+ attribute :layout, :aliases => :Layout
+ attribute :name, :aliases => :Name
+ attribute :operating_system, :aliases => :OperatingSystem
+ attribute :other_links, :aliases => :Links, :squash => :Link
+ attribute :powered_on, :aliases => :PoweredOn, :type => :boolean
+ attribute :status, :aliases => :Status
+ attribute :tags, :aliases => :Tags
+ attribute :tools_status, :aliases => :ToolsStatus
+ attribute :type, :aliases => :Type
+
+ def cpus
+ hardware_configuration.processor_count
+ end
+
+ def memory # always in MB
+ hardware_configuration.memory.to_i
+ end
+
+ def location
+ end
+
+ def flavor_id
+ {:ram => hardware_configuration.memory.to_i, :cpus => hardware_configuration.processor_count}
+ end
+
+ def storage
+ hardware_configuration.storage[:Disk]
+ end
def tasks
- @tasks ||= Fog::Compute::Ecloud::Tasks.new(:connection => connection, :href => "/cloudapi/ecloud/tasks/virtualMachines/#{id}")