1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Removed non-functioning Mock classes

This commit is contained in:
Eugene Howe 2012-06-07 12:50:11 -04:00
parent 5fd4f95ab1
commit 825d7996aa
301 changed files with 6254 additions and 6470 deletions

View file

@ -1,4 +1,4 @@
require 'fog/core'
require(File.expand_path(File.join(File.dirname(__FILE__), 'core')))
module Fog
module Ecloud

View file

@ -0,0 +1,26 @@
module Fog
module Ecloud
class Collection < Fog::Collection
def load(objects)
objects = [ objects ] if objects.is_a?(Hash)
super
end
def check_href!(opts = {})
unless href
opts = { :parent => opts } if opts.is_a?(String)
msg = ":href missing, call with a :href pointing to #{if opts[:message]
opts[:message]
elsif opts[:parent]
"the #{opts[:parent]} whos #{self.class.to_s.split('::').last.downcase} you want to enumerate"
else
"the resource"
end}"
raise Fog::Errors::Error.new(msg)
end
end
end
end
end

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,130 @@
require 'optparse'
class String
def camelize
self.split('_').map {|w| w.capitalize}.join
end
end
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: #{__FILE__} [options]"
opts.on("-m", "--model-name NAME", "Model Name") { |v| options[:model] = v }
opts.on("-c", "--collection-name NAME", "Collection Name") { |v| options[:collection] = v }
opts.on("-M", "--methods a:href,b:href,c:href", Array, "List of methods to be defined and href to the method") { |v| options[:methods] = v.map { |a| a.split(':') } }
opts.on("-a", "--attributes name:alias,other_name:other_alias", Array, "List of attributes to be defined") { |v| options[:attributes] = v.map { |a| a.split(':') } }
end.parse!
if options[:methods]
methods = options[:methods].map do |m|
m = <<METHOD
def #{m[0]}
@#{m[0]} = Fog::Compute::Ecloud::#{m[0].camelize}.new(:connection => connection, :href => "#{m[1]}")
end
METHOD
end.join("\n ")
end
if options[:attributes]
attributes = options[:attributes].map do |a|
a = "attribute :#{a[0]}, :aliases => :#{a[1] || a[0].camelize}"
end.join("\n ")
end
collection_file = "#{File.expand_path(File.dirname(__FILE__))}/models/compute/#{options[:collection]}.rb"
model_file = "#{File.expand_path(File.dirname(__FILE__))}/models/compute/#{options[:model]}.rb"
collection_request_file = "#{File.expand_path(File.dirname(__FILE__))}/requests/compute/get_#{options[:collection]}.rb"
model_request_file = "#{File.expand_path(File.dirname(__FILE__))}/requests/compute/get_#{options[:model]}.rb"
collection = <<COLLECTION
require 'fog/ecloud/models/compute/#{options[:model]}'
module Fog
module Compute
class Ecloud
class #{options[:collection].camelize} < Fog::Ecloud::Collection
identity :href
model Fog::Compute::Ecloud::#{options[:model].camelize}
def all
data = connection.get_#{options[:collection]}(href).body
load(data)
end
def get(uri)
if data = connection.get_#{options[:model]}(uri)
new(data.body)
end
rescue Fog::Errors::NotFound
nil
end
end
end
end
end
COLLECTION
model = <<MODEL
module Fog
module Compute
class Ecloud
class #{options[:model].camelize} < Fog::Model
identity :href
#{attributes}
#{methods}
def id
href.scan(/\\d+/)[0]
end
end
end
end
end
MODEL
collection_request = <<COLLECTION
module Fog
module Compute
class Ecloud
class Real
basic_request :get_#{options[:collection]}
end
class Mock
def get_#{options[:collection]}(uri)
end
end
end
end
end
COLLECTION
model_request = <<MODEL
module Fog
module Compute
class Ecloud
class Real
basic_request :get_#{options[:model]}
end
class Mock
def get_#{options[:model]}(uri)
end
end
end
end
end
MODEL
File.open(collection_file, 'w') { |f| f.write(collection) }
File.open(model_file, 'w') { |f| f.write(model) }
File.open(collection_request_file, 'w') { |f| f.write(collection_request) }
File.open(model_request_file, 'w') { |f| f.write(model_request) }

5
lib/fog/ecloud/ipaddr.rb Normal file
View file

@ -0,0 +1,5 @@
class IPAddr
def mask
_to_string(@mask_addr)
end
end

View file

@ -0,0 +1,768 @@
module Fog
module Ecloud
module MockDataClasses
class Base < Hash
def self.base_url=(url)
@base_url = url
end
self.base_url = "http://vcloud.example.com"
def self.base_url
@base_url
end
def first
raise "Don't do this"
end
def last
raise "Don't do this"
end
def initialize(data = {}, parent = nil)
@parent = parent
replace(data)
end
def _parent
@parent
end
def base_url
Base.base_url
end
def href
[base_url, self.class.name.split("::").last, object_id].join("/")
end
def inspect
"<#{self.class.name} #{object_id} data=#{super}>"
end
end
class MockData < Base
def versions
@versions ||= []
end
def organizations
@organizations ||= []
end
def organization_collection_from_href(href)
find_href_in(href, all_organizations)
end
def all_organizations
organizations.map(&:environments).flatten
end
def organization_from_href(href)
find_href_in(href, all_organizations)
end
def all_vdcs
organizations.map(&:environments).flatten
end
def vdc_from_href(href)
find_href_in(href, all_vdcs)
end
def all_catalogs
all_vdcs.map(&:catalog).flatten
end
def catalog_from_href(href)
find_href_in(href, all_catalogs)
end
def all_catalog_items
all_catalogs.map(&:items).flatten
end
def catalog_item_from_href(href)
find_href_in(href, all_catalog_items)
end
def all_virtual_machines
all_vdcs.map(&:virtual_machines).flatten
end
def virtual_machine_from_href(href)
find_href_prefixed_in(href, all_virtual_machines)
end
def all_networks
all_vdcs.map(&:networks).flatten
end
def network_from_href(href)
find_href_in(href, all_networks)
end
def all_network_extensions
all_networks.map(&:extensions).flatten
end
def network_extension_from_href(href)
find_href_in(href, all_network_extensions)
end
def all_vdc_internet_service_collections
all_vdcs.map(&:internet_service_collection).flatten
end
def vdc_internet_service_collection_from_href(href)
find_href_in(href, all_vdc_internet_service_collections)
end
def all_backup_internet_services
all_vdc_internet_service_collections.map(&:backup_internet_services).flatten
end
def backup_internet_service_from_href(href)
find_href_in(href, all_backup_internet_services)
end
def all_public_ip_collections
all_vdcs.map {|v| v.public_ip_collection }.flatten
end
def public_ip_collection_from_href(href)
find_href_in(href, all_public_ip_collections)
end
def all_public_ips
all_public_ip_collections.map(&:items).flatten
end
def public_ip_from_href(href)
find_href_in(href, all_public_ips)
end
def all_public_ip_internet_service_collections
all_public_ips.map(&:internet_service_collection).flatten
end
def public_ip_internet_service_collection_from_href(href)
find_href_in(href, all_public_ip_internet_service_collections)
end
def all_public_ip_internet_services
all_public_ip_internet_service_collections.map(&:items).flatten
end
def public_ip_internet_service_from_href(href)
find_href_in(href, all_public_ip_internet_services)
end
def all_public_ip_internet_service_node_collections
all_public_ip_internet_services.map(&:node_collection).flatten
end
def public_ip_internet_service_node_collection_from_href(href)
find_href_in(href, all_public_ip_internet_service_node_collections)
end
def all_public_ip_internet_service_nodes
all_public_ip_internet_service_node_collections.map(&:items).flatten
end
def public_ip_internet_service_node_from_href(href)
find_href_in(href, all_public_ip_internet_service_nodes)
end
def all_network_ip_collections
all_networks.map(&:ip_collection)
end
def network_ip_collection_from_href(href)
find_href_in(href, all_network_ip_collections)
end
def all_network_ips
all_network_ip_collections.map {|c| c.items.values }.flatten
end
def network_ip_from_href(href)
find_href_in(href, all_network_ips)
end
private
def find_href_in(href, objects)
objects.detect {|o| o.href == href }
end
def find_href_prefixed_in(href, objects)
objects.detect {|o| href =~ %r{^#{o.href}($|/)} }
end
end
class MockVersion < Base
def version
self[:version]
end
def supported
!!self[:supported]
end
def login_url
href
end
end
class MockOrganization < Base
def name
self[:name]
end
def environments
@vdcs ||= []
end
end
class MockVdc < Base
def name
self[:name]
end
def storage_allocated
self[:storage_allocated] || 200
end
def storage_used
self[:storage_used] || 105
end
def cpu_allocated
self[:cpu_allocated] || 10000
end
def memory_allocated
self[:memory_allocated] || 20480
end
def catalog
@catalog ||= MockCatalog.new({}, self)
end
def networks
@networks ||= []
end
def virtual_machines
@virtual_machines ||= []
end
def task_list
@task_list ||= MockTaskList.new({}, self)
end
# for TM eCloud, should probably be subclassed
def public_ip_collection
@public_ip_collection ||= MockPublicIps.new({}, self)
end
def internet_service_collection
@internet_service_collection ||= MockVdcInternetServices.new({}, self)
end
def firewall_acls
@firewall_acls ||= MockFirewallAcls.new({}, self)
end
end
class MockTaskList < Base
def name
self[:name] || "Tasks List"
end
end
class MockCatalog < Base
def name
self[:name] || "Catalog"
end
def items
@items ||= []
end
end
class MockCatalogItem < Base
def name
self[:name]
end
def disks
@disks ||= MockVirtualMachineDisks.new(self)
end
def customization
@customization ||= MockCatalogItemCustomization.new({}, self)
end
def vapp_template
@vapp_template ||= MockCatalogItemVappTemplate.new({ :name => name }, self)
end
end
class MockCatalogItemCustomization < Base
def name
self[:name] || "Customization Options"
end
end
class MockCatalogItemVappTemplate < Base
def name
self[:name]
end
end
class MockNetwork < Base
def name
self[:name] || subnet
end
def subnet
self[:subnet]
end
def gateway
self[:gateway] || subnet_ips[1]
end
def netmask
self[:netmask] || subnet_ipaddr.mask
end
def dns
"8.8.8.8"
end
def features
[
{ :type => :FenceMode, :value => "isolated" }
]
end
def ip_collection
@ip_collection ||= MockNetworkIps.new({}, self)
end
def extensions
@extensions ||= MockNetworkExtensions.new({}, self)
end
def random_ip
usable_subnet_ips[rand(usable_subnet_ips.length)]
end
# for TM eCloud. should probably be a subclass
def rnat
self[:rnat]
end
def usable_subnet_ips
subnet_ips[3..-2]
end
def address
subnet_ips.first
end
def broadcast
subnet_ips.last
end
private
def subnet_ipaddr
@ipaddr ||= IPAddr.new(subnet)
end
def subnet_ips
subnet_ipaddr.to_range.to_a.map(&:to_s)
end
end
class MockNetworkIps < Base
def items
@items ||= _parent.usable_subnet_ips.inject({}) do |out, subnet_ip|
out.update(subnet_ip => MockNetworkIp.new({ :ip => subnet_ip }, self))
end
end
def ordered_ips
items.values.sort_by {|i| i.ip.split(".").map(&:to_i) }
end
def name
"IP Addresses"
end
end
class MockNetworkIp < Base
def name
self[:name] || ip
end
def ip
self[:ip]
end
def used_by
self[:used_by] || _parent._parent._parent.virtual_machines.detect {|v| v.ip == ip }
end
def status
if used_by
"Assigned"
else
"Available"
end
end
def rnat
self[:rnat] || _parent._parent.rnat
end
def rnat_set?
!!self[:rnat]
end
end
class MockNetworkExtensions < Base
def name
_parent.name
end
def gateway
_parent.gateway
end
def broadcast
_parent.broadcast
end
def address
_parent.address
end
def rnat
_parent.rnat
end
def type
self[:type] || "DMZ"
end
def vlan
object_id.to_s
end
def friendly_name
"#{name} (#{type}_#{object_id})"
end
end
class MockVirtualMachine < Base
def name
self[:name]
end
def ip
self[:ip]
end
def cpus
self[:cpus] || 1
end
def memory
self[:memory] || 1024
end
def disks
@disks ||= MockVirtualMachineDisks.new(self)
end
def status
self[:status] || 2
end
def power_off!
self[:status] = 2
end
def power_on!
self[:status] = 4
end
def size
disks.inject(0) {|s, d| s + d.vcloud_size }
end
def network_ip
if network = _parent.networks.detect {|n| n.ip_collection.items[ip] }
network.ip_collection.items[ip]
end
end
# from fog ecloud server's _compose_vapp_data
def to_configure_vapp_hash
{
:name => name,
:cpus => cpus,
:memory => memory,
:disks => disks.map {|d| { :number => d.address.to_s, :size => d.vcloud_size, :resource => d.vcloud_size.to_s } }
}
end
def href(purpose = :base)
case purpose
when :base
super()
when :power_on
super() + "/power/action/powerOn"
when :power_off
super() + "/power/action/powerOff"
end
end
end
class MockVirtualMachineDisks < Array
def initialize(parent = nil)
@parent = parent
end
def _parent
@parent
end
def <<(disk)
next_address = 0
disk_with_max_address = max {|a, b| a[:address] <=> b[:address] }
disk_with_max_address && next_address = disk_with_max_address.address + 1
disk[:address] ||= next_address
super(disk)
if (addresses = map {|d| d.address }).uniq.size != size
raise "Duplicate disk address in: #{addresses.inspect} (#{size})"
end
sort! {|a, b| a.address <=> b.address }
self
end
def at_address(address)
detect {|d| d.address == address }
end
end
class MockVirtualMachineDisk < Base
def size
self[:size].to_i
end
def vcloud_size
# kilobytes
size * 1024
end
def address
self[:address].to_i
end
end
# for Terremark eCloud
class MockVdcInternetServices < Base
def href
_parent.href + "/internetServices"
end
def name
"Internet Services"
end
def items
public_ip_internet_services + backup_internet_services
end
def public_ip_internet_services
_parent.public_ip_collection.items.inject([]) do |services, public_ip|
services + public_ip.internet_service_collection.items
end
end
def backup_internet_services
@backup_internet_services ||= []
end
end
class MockBackupInternetService < Base
def name
self[:name] || "Backup Internet Service #{object_id}"
end
def protocol
self[:protocol]
end
def port
0
end
def enabled
self[:enabled].to_s.downcase != "false"
end
def timeout
self[:timeout] || 2
end
def description
self[:description] || "Description for Backup Service #{name}"
end
def redirect_url
nil
end
def node_collection
@node_collection ||= MockPublicIpInternetServiceNodes.new({}, self)
end
end
class MockFirewallAcls < Base
def name
"Firewall Access List"
end
end
class MockPublicIps < Base
def name
self[:name] || "Public IPs"
end
def items
@items ||= []
end
end
class MockPublicIp < Base
def name
self[:name]
end
def internet_service_collection
@internet_service_collection ||= MockPublicIpInternetServices.new({}, self)
end
end
class MockPublicIpInternetServices < Base
def href
_parent.href + "/internetServices"
end
def items
@items ||= []
end
end
class MockPublicIpInternetService < Base
def name
self[:name] || "Public IP Service #{object_id}"
end
def description
self[:description] || "Description for Public IP Service #{name}"
end
def protocol
self[:protocol]
end
def port
self[:port]
end
def enabled
!!self[:enabled]
end
def redirect_url
self[:redirect_url]
end
def timeout
self[:timeout] || 2
end
def node_collection
@node_collection ||= MockPublicIpInternetServiceNodes.new({}, self)
end
def monitor
nil
end
def backup_service
self[:backup_service]
end
end
class MockPublicIpInternetServiceNodes < Base
def href
_parent.href + "/nodeServices"
end
def items
@items ||= [].tap do |node_array|
node_array.instance_variable_set("@default_port", _parent.port)
def node_array.<<(node)
node[:port] ||= @default_port
super
end
end
end
end
class MockPublicIpInternetServiceNode < Base
def ip_address
self[:ip_address]
end
def name
self[:name] || "Public IP Service Node #{object_id}"
end
def description
self[:description] || "Description for Public IP Service Node #{name}"
end
def port
self[:port]
end
def enabled
self[:enabled].to_s.downcase != "false"
end
def enabled=(new_value)
self[:enabled] = new_value
end
end
end
end
end

22
lib/fog/ecloud/model.rb Normal file
View file

@ -0,0 +1,22 @@
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
end
end
end

View file

@ -0,0 +1,39 @@
module Fog
module Compute
class Ecloud
class AdminOrganization < Fog::Ecloud::Model
identity :href
attribute :name, :aliases => :Name
attribute :type, :aliases => :Type
attribute :other_links, :aliases => :Links
attribute :multifactor_summary, :aliases => :MultifactorSummary
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}")
end
def password_complexity_rules
@password_complexity_rules = Fog::Compute::Ecloud::PasswordComplexityRules.new(:connection => connection, :href => "/cloudapi/ecloud/admin/organizations/#{org_id}/passwordComplexityRules")
end
def login_banner
@login_banner = Fog::Compute::Ecloud::LoginBanner.new(:connection => connection, :href => "/cloudapi/ecloud/admin/organizations/#{org_id}/loginBanner")
end
def authentication_levels
@authentication_levels = Fog::Compute::Ecloud::AuthenticationLevels.new(:connection => connection, :href => "/cloudapi/ecloud/admin/organizations/#{org_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]
end
end
end
end
end

View file

@ -0,0 +1,27 @@
require 'fog/ecloud/models/compute/admin_organization'
module Fog
module Compute
class Ecloud
class AdminOrganizations < Fog::Ecloud::Collection
identity :href
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)
end
rescue Fog::Errors::NotFound
nil
end
end
end
end
end

View file

@ -0,0 +1,21 @@
module Fog
module Compute
class Ecloud
class ApiKey < Fog::Ecloud::Model
identity :href
attribute :name, :aliases => :Name
attribute :type, :aliases => :Type
attribute :other_links, :aliases => :Links
attribute :access_key, :aliases => :AccessKey
attribute :status, :aliases => :Status
attribute :private_key, :aliases => :PrivateKey
def id
href.scan(/\d+/)[0]
end
end
end
end
end

View file

@ -0,0 +1,27 @@
require 'fog/ecloud/models/compute/api_key'
module Fog
module Compute
class Ecloud
class ApiKeys < Fog::Ecloud::Collection
identity :href
model Fog::Compute::Ecloud::ApiKey
def all
data = connection.get_api_keys(href).body
load(data)
end
def get(uri)
if data = connection.get_api_key(uri)
new(data.body)
end
rescue Fog::Errors::NotFound
nil
end
end
end
end
end

View file

@ -0,0 +1,23 @@
module Fog
module Compute
class Ecloud
class Association < Fog::Ecloud::Model
identity :href
attribute :name, :aliases => :Name
attribute :type, :aliases => :Type
attribute :other_links, :aliases => :Links
attribute :ip_address, :aliases => :IpAddress
def delete
data = connection.rnat_associations_delete(href).body
task = Fog::Compute::Ecloud::Tasks.new(:connection => connection, :href => href)[0]
end
def id
href.scan(/\d+/)[0]
end
end
end
end
end

View file

@ -0,0 +1,35 @@
require 'fog/ecloud/models/compute/association'
module Fog
module Compute
class Ecloud
class Associations < Fog::Ecloud::Collection
identity :href
model Fog::Compute::Ecloud::Association
def all
data = connection.get_associations(href).body
if data[:Associations]
data = data[:Associations]
if data.is_a?(String) && data.empty?
data = []
elsif data.is_a?(Hash)
data = data[:Association]
end
end
load(data)
end
def get(uri)
if data = connection.get_association(uri)
new(data.body)
end
rescue Fog::Errors::NotFound
nil
end
end
end
end
end

View file

@ -0,0 +1,22 @@
module Fog
module Compute
class Ecloud
class AuthenticationLevel < Fog::Ecloud::Model
identity :href
attribute :basic_enabled, :aliases => :BasicEnabled, :type => :boolean
attribute :sha1_enabled, :aliases => :SHA1Enabled, :type => :boolean
attribute :Sha256_enabled, :aliases => :SHA256Enabled, :type => :boolean
attribute :Sha512_enabled, :aliases => :SHA512Enabled, :type => :boolean
attribute :hmacsha1_enabled, :aliases => :HMACSHA1Enabled, :type => :boolean
attribute :hmacsha256_enabled, :aliases => :HMACSHA256Enabled, :type => :boolean
attribute :hmacsha512_enabled, :aliases => :HMACSHA512Enabled, :type => :boolean
def id
href.scan(/\d+/)[0]
end
end
end
end
end

View file

@ -0,0 +1,27 @@
require 'fog/ecloud/models/compute/authentication_level'
module Fog
module Compute
class Ecloud
class AuthenticationLevels < Fog::Ecloud::Collection
identity :href
model Fog::Compute::Ecloud::AuthenticationLevel
def all
data = connection.get_authentication_levels(href).body
load(data)
end
def get(uri)
if data = connection.get_authentication_level(uri)
new(data.body)
end
rescue Fog::Errors::NotFound
nil
end
end
end
end
end

View file

@ -2,54 +2,43 @@ module Fog
module Compute
class Ecloud
class BackupInternetService < Fog::Ecloud::Model
identity :href, :aliases => :Href
ignore_attributes :xmlns, :xmlns_i
identity :href
attribute :name, :aliases => :Name
attribute :id, :aliases => :Id
attribute :type, :aliases => :Type
attribute :other_links, :aliases => :Links
attribute :protocol, :aliases => :Protocol
attribute :enabled, :aliases => :Enabled
attribute :enabled, :aliases => :Enabled, :type => :boolean
attribute :description, :aliases => :Description
attribute :timeout, :aliases => :Timeout
attribute :redirect_url, :aliases => :RedirectURL
attribute :monitor, :aliases => :Monitor
attribute :persistence, :aliases => :Persistence
attribute :redirect_url, :aliases => :RedirectUrl
def tasks
@tasks = Fog::Compute::Ecloud::Tasks.new(:connection => connection, :href => href)
end
def internet_services
@internet_services = Fog::Compute::Ecloud::InternetServices.new(:connection => connection, :href => href)
end
def node_services
@node_services = Fog::Compute::Ecloud::NodeServices.new(:connection => connection, :href => href)
end
def edit(options)
options[:uri] = href
data = connection.backup_internet_service_edit(options).body
object = collection.from_data(data)
end
def delete
requires :href
connection.delete_internet_service( href )
data = connection.backup_internet_service_delete(href).body
task = Fog::Compute::Ecloud::Tasks.new(:connection => connection, :href => data[:href])[0]
end
def monitor=(new_monitor = {})
if new_monitor.nil? || new_monitor.empty?
attributes[:monitor] = nil
end
def id
href.scan(/\d+/)[0]
end
def save
if new_record?
result = connection.add_backup_internet_service( collection.href, _compose_service_data )
merge_attributes(result.body)
else
connection.configure_backup_internet_service( href, _compose_service_data )
end
end
def nodes
@nodes ||= Fog::Compute::Ecloud::Nodes.new( :connection => connection, :href => href + "/nodeServices" )
end
private
def _compose_service_data
#For some reason inject didn't work
service_data = {}
self.class.attributes.select{ |attribute| !send(attribute).nil? }.each { |attribute| service_data[attribute] = send(attribute) }
service_data
end
end
end
end

View file

@ -5,28 +5,37 @@ module Fog
class Ecloud
class BackupInternetServices < Fog::Ecloud::Collection
identity :href
model Fog::Compute::Ecloud::BackupInternetService
attribute :href, :aliases => :Href
def all
check_href! :message => "the Internet Services for the Vdc you want to enumerate"
if data = connection.get_internet_services(href).body[:InternetService].find_all {|i| i[:IsBackupService] == "true" }
load(data)
end
data = connection.get_backup_internet_services(href).body
load(data)
end
# Optimize later, no need to get_internet_services again?
def get(uri)
internet_services = connection.get_internet_services(href).body[:InternetService]
internet_services = [ internet_services ] if internet_services.is_a?(Hash)
if data = internet_services.detect { |service| service[:Href] == uri }
new(data)
if data = connection.get_backup_internet_service(uri)
new(data.body)
end
rescue Fog::Errors::NotFound
nil
end
def from_data(data)
new(data)
end
def create(options)
options[:uri] = href + "/action/createBackupInternetService"
options[:enabled] ||= true
data = connection.backup_internet_service_create(options)
new(data)
end
def internet_service_id
href.scan(/\d+/)[0]
end
end
end
end

View file

@ -1,16 +1,29 @@
require 'fog/ecloud/models/compute/catalog_item'
module Fog
module Compute
class Ecloud
class Catalog < Fog::Ecloud::Collection
identity :href
model Fog::Compute::Ecloud::CatalogItem
attribute :href, :aliases => :Href
def all
check_href!
if data = connection.get_catalog(href).body[:CatalogItems][:CatalogItem]
data = connection.get_catalog(href).body#[:Locations][:Location][:Catalog][:CatalogEntry]
if data[:Locations][:Location].is_a?(Hash)
data = [] if data[:Locations][:Location][:Catalog].is_a?(String) && data[:Locations][:Location][:Catalog].empty?
load(data)
elsif data[:Locations][:Location].is_a?(Array)
r_data = []
data[:Locations][:Location].each do |d|
unless d[:Catalog].is_a?(String) && d[:Catalog].empty?
d[:Catalog][:CatalogEntry].each do |c|
r_data << c
end
end
end
load(r_data)
end
end
@ -21,7 +34,6 @@ module Fog
rescue Fog::Errors::NotFound
nil
end
end
end
end

View file

@ -0,0 +1,23 @@
module Fog
module Compute
class Ecloud
class CatalogConfiguration < Fog::Ecloud::Model
identity :href
attribute :type, :aliases => :Type
attribute :other_links, :aliases => :Links
attribute :processor_count, :aliases => :ProcessorCount, :type => :integer
attribute :memory, :aliases => :Memory
attribute :operating_system, :aliases => :OperatingSystem
attribute :disks, :aliases => :Disks
attribute :network_adapters, :aliases => :NetworkAdapters, :type => :integer
attribute :network_mappings, :aliases => :NetworkMappings
def id
href.scan(/\d+/)[0]
end
end
end
end
end

View file

@ -0,0 +1,27 @@
require 'fog/ecloud/models/compute/catalog_configuration'
module Fog
module Compute
class Ecloud
class CatalogConfigurations < Fog::Ecloud::Collection
identity :href
model Fog::Compute::Ecloud::CatalogConfiguration
def all
data = connection.get_catalog_configurations(href).body
load(data)
end
def get(uri)
if data = connection.get_catalog_configuration(uri)
new(data.body)
end
rescue Fog::Errors::NotFound
nil
end
end
end
end
end

View file

@ -2,27 +2,22 @@ module Fog
module Compute
class Ecloud
class CatalogItem < Fog::Ecloud::Model
identity :href
identity :href, :aliases => :Href
attribute :name, :aliases => :Name
attribute :type, :aliases => :Type
attribute :other_links, :aliases => :Links
attribute :status, :aliases => :Status
attribute :alerts, :aliases => :Alerts
attribute :files, :aliases => :Files
ignore_attributes :xmlns, :xmlns_i, :xmlns_xsi, :xmlns_xsd
attribute :type
attribute :name
attribute :entity, :aliases => :Entity
attribute :link, :aliases => :Link
attribute :property, :aliases => :Property
def customization_options
load_unless_loaded!
if data = connection.get_customization_options( link[:href] ).body
data.delete_if { |key, value| [:xmlns_i, :xmlns].include?(key) }
data
else
nil
end
def configuration
@configuration = Fog::Compute::Ecloud::CatalogConfigurations.new(:connection => connection, :href => "/cloudapi/ecloud/admin/catalog/#{id}/configuration")
end
def id
href.scan(/\d+/)[0]
end
end
end
end

View file

@ -3,16 +3,56 @@ module Fog
class Ecloud
class ComputePool < Fog::Ecloud::Model
identity :href, :aliases => :Href
identity :href
ignore_attributes :xmlns, :xmlns_i
attribute :name, :aliases => :Name
attribute :id, :aliases => :Id
attribute :href, :aliases => :Href
attribute :state, :aliases => :State
attribute :is_default, :aliases => :IsDefault
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 :memory_burst, :aliases => :MemoryBurst
def servers
@servers ||= Fog::Compute::Ecloud::Servers.new( :connection => connection, :href => "/cloudapi/ecloud/virtualMachines/computePools/#{id}" )
end
def layout
@layout ||= Fog::Compute::Ecloud::Layouts.new(:connection => connection, :href => "/cloudapi/ecloud/layout/computePools/#{id}").first
end
def cpu_usage
# time ? query = "/details?time=#{Time.parse(time).utc.strftime('%Y-%m-%dT%H:%M:%SZ')}" : query = ""
@cpu_usage ||= Fog::Compute::Ecloud::CpuUsageDetailSummary.new(:connection => connection, :href => "/cloudapi/ecloud/computePools/#{id}/usage/cpu")
end
def memory_usage
# time ? query = "/details?time=#{Time.parse(time).utc.strftime('%Y-%m-%dT%H:%M:%SZ')}" : query = ""
@memory_usage ||= Fog::Compute::Ecloud::MemoryUsageDetailSummary.new(:connection => connection, :href => "/cloudapi/ecloud/computePools/#{id}/usage/memory")
end
def storage_usage
@storage_usage ||= Fog::Compute::Ecloud::StorageUsageDetailSummary.new(:connection => connection, :href => "/cloudapi/ecloud/computePools/#{id}/usage/storage")
end
def operating_system_families
@operating_system_families ||= Fog::Compute::Ecloud::OperatingSystemFamilies.new(:connection => connection, :href => "/cloudapi/ecloud/operatingSystemFamilies/computePools/#{id}")
end
def templates
@templates ||= Fog::Compute::Ecloud::Templates.new(:connection => connection, :href => "/cloudapi/ecloud/templates/computePools/#{id}")
end
def edit(options)
options[:uri] = href
data = connection.compute_pool_edit(options).body
pool = collection.from_data(data)
end
def id
href.scan(/\d+/)[0]
end
end
end
end

View file

@ -11,15 +11,10 @@ module Fog
model Fog::Compute::Ecloud::ComputePool
#get_request :get_compute_pool
#vcloud_type "application/vnd.tmrk.ecloud.publicIp+xml"
#all_request lambda { |compute_pools| public_ips.connection.get_public_ips(public_ips.href) }
def all
check_href!(:message => "the Compute Pool href of the Vdc you want to enumerate")
if data = connection.get_compute_pools(href).body[:ComputePool]
load(data)
end
check_href!(:message => "the Compute Pool href of the Environment you want to enumerate")
data = connection.get_compute_pools(href).body[:ComputePool]
load(data)
end
def get(uri)
@ -30,6 +25,9 @@ module Fog
nil
end
def from_data(data)
new(data)
end
end
end
end

View file

@ -0,0 +1,17 @@
module Fog
module Compute
class Ecloud
class CpuUsageDetail < Fog::Ecloud::Model
identity :href
attribute :time, :aliases => :Time
attribute :value, :aliases => :Value
def id
href.scan(/\d+/)[0]
end
end
end
end
end

View file

@ -0,0 +1,27 @@
require 'fog/ecloud/models/compute/cpu_usage_detail'
module Fog
module Compute
class Ecloud
class CpuUsageDetailSummary < Fog::Ecloud::Collection
identity :href
model Fog::Compute::Ecloud::CpuUsageDetail
def all
data = connection.get_cpu_usage_detail_summary(href).body[:CpuUsageDetailSummary][:CpuUsageDetail]
load(data)
end
def get(uri)
if data = connection.get_cpu_usage_detail(uri)
new(data.body)
end
rescue Fog::Errors::NotFound
nil
end
end
end
end
end

View file

@ -0,0 +1,105 @@
module Fog
module Compute
class Ecloud
class Environment < Fog::Ecloud::Model
identity :href
ignore_attributes :xmlns, :xmlns_xsi, :xmlns_xsd
attribute :name
attribute :type
attribute :other_links, :aliases => :Links
def public_ips
@public_ips ||= Fog::Compute::Ecloud::PublicIps.new(:connection => connection, :href => "/cloudapi/ecloud/publicIps/environments/#{id}")
end
def internet_services
@internet_services ||= Fog::Compute::Ecloud::InternetServices.new(:connection => connection, :href => "/cloudapi/ecloud/networkSummary/environments/#{id}")
end
def node_services
@node_services ||= Fog::Compute::Ecloud::Nodes.new(:connection => connection, :href => "/cloudapi/ecloud/networkSummary/environments/#{id}")
end
def backup_internet_services
@backup_internet_services ||= Fog::Compute::Ecloud::BackupInternetServices.new(:connection, :href => "/cloudapi/ecloud/backupInternetServices/environments/#{id}")
end
def networks
@networks ||= Fog::Compute::Ecloud::Networks.new(:connection => connection, :href => "/cloudapi/ecloud/networks/environments/#{id}")
end
def servers
@servers = nil
pools = compute_pools
pools.each do |c|
if pools.index(c) == 0
@servers = c.servers
else
c.servers.each { |s| @servers << s }
end
end
@servers
end
def layout
@layout ||= Fog::Compute::Ecloud::Layouts.new(:connection => connection, :href => "/cloudapi/ecloud/layout/environments/#{id}").first
end
def rows
layout.rows
end
def tasks
@tasks ||= Fog::Compute::Ecloud::Tasks.new(:connection => connection, :href => "/cloudapi/ecloud/tasks/environments/#{id}")
end
def firewall_acls
@firewall_acls ||= Fog::Compute::Ecloud::FirewallAcls.new(:connection => connection, :href => "/cloudapi/ecloud/firewallAcls/environments/#{id}")
end
def compute_pools
@compute_pools ||= Fog::Compute::Ecloud::ComputePools.new(:connection => connection, :href => "/cloudapi/ecloud/computePools/environments/#{id}")
end
def physical_devices
@physical_devices ||= Fog::Compute::Ecloud::PhysicalDevices.new(:connection => connection, :href => "/cloudapi/ecloud/physicalDevices/environments/#{id}")
end
def trusted_network_groups
@trusted_network_groups ||= Fog::Compute::Ecloud::TrustedNetworkGroups.new(:connection => connection, :href => "/cloudapi/ecloud/trustedNetworkGroups/environments/#{id}")
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]}")
end
def rnats
@rnats ||= Fog::Compute::Ecloud::Rnats.new(:connection => connection, :href => "/cloudapi/ecloud/rnats/environments/#{id}")
end
def create_trusted_network_group(options = {})
options[:uri] = "/cloudapi/ecloud/trustedNetworkGroups/environments/#{id}/action/createTrustedNetworkGroup"
data = connection.trusted_network_groups_create(options).body
tng = Fog::Compute::Ecloud::TrustedNetworkGroups.new(:connection => connection, :href => data[:href])[0]
end
def create_firewall_acl(options = {})
options[:uri] = "/cloudapi/ecloud/firewallAcls/environments/#{id}/action/createFirewallAcl"
options[:permission] ||= "deny"
options[:protocol] ||= "any"
data = connection.firewall_acls_create(options).body
acl = Fog::Compute::Ecloud::FirewallAcls.new(:connection => connection, :href => data[:href])[0]
end
def id
href.scan(/\d+/)[0]
end
end
Vdc = Environment
end
end
end

View file

@ -0,0 +1,40 @@
require 'fog/ecloud/models/compute/environment'
module Fog
module Compute
class Ecloud
class Environments < Fog::Ecloud::Collection
model Fog::Compute::Ecloud::Environment
undef_method :create
identity :href
def all
data = []
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
data << d[:Environments][:Environment]
end
end
load(data)
end
def get(uri)
if data = connection.get_environment(uri)
new(data.body)
end
rescue Fog::Errors::NotFound
nil
end
Vdcs = Environments
end
end
end
end

View file

@ -2,22 +2,25 @@ module Fog
module Compute
class Ecloud
class FirewallAcl < Fog::Ecloud::Model
identity :href
identity :href, :aliases => :Href
ignore_attributes :xmlns, :xmlns_i
attribute :name, :aliases => :Name
attribute :id, :aliases => :Id
attribute :type, :aliases => :Type
attribute :links, :aliases => :Links
attribute :permission, :aliases => :Permission
attribute :acl_type, :aliases => :AclType
attribute :port_type, :aliases => :PortType
attribute :protocol, :aliases => :Protocol
attribute :source, :aliases => :Source
attribute :destination, :aliases => :Destination
attribute :permission, :aliases => :Permission
attribute :port_start, :aliases => :PortStart
attribute :port_end, :aliases => :PortEnd
attribute :port_type, :aliases => :PortType
attribute :type, :aliases => :Type
attribute :port_range, :aliases => :PortRange
def tasks
@tasks = Fog::Compute::Ecloud::Tasks.new(:connection => connection, :href => "/cloudapi/ecloud/tasks/virtualMachines/#{id}")
end
def id
href.scan(/\d+/)[0]
end
end
end
end

View file

@ -5,26 +5,23 @@ module Fog
class Ecloud
class FirewallAcls < Fog::Ecloud::Collection
identity :href
model Fog::Compute::Ecloud::FirewallAcl
attribute :href, :aliases => :Href
def all
check_href! :message => "the Firewall ACL href for the network you want to enumerate"
if data = connection.get_firewall_acls(href).body[:FirewallAcl]
data = [ data ] if data.is_a?(Hash)
load(data)
end
data = connection.get_firewall_acls(href).body
data = data[:FirewallAcl] ? data[:FirewallAcl] : data
load(data)
end
def get(uri)
if data = connection.get_firewall_acl(uri).body
new(data)
if data = connection.get_firewall_acl(uri)
new(data.body)
end
rescue Fog::Errors::NotFound
nil
end
end
end
end

View file

@ -0,0 +1,39 @@
module Fog
module Compute
class Ecloud
class Group < Fog::Ecloud::Model
identity :href
attribute :name, :aliases => :Name
attribute :type, :aliases => :Type
attribute :other_links, :aliases => :Links
attribute :index, :aliases => :Index
def servers
@servers = Fog::Compute::Ecloud::Servers.new(:connection => connection, :href => href)
end
def edit(options = {})
options[:uri] = href
data = connection.groups_edit(options).body
end
def move_up
connection.groups_moveup(href).body
end
def move_down
connection.groups_movedown(href).body
end
def delete
connection.groups_delete(href).body
end
def id
href.scan(/\d+/)[0]
end
end
end
end
end

View file

@ -0,0 +1,28 @@
require 'fog/ecloud/models/compute/group'
module Fog
module Compute
class Ecloud
class Groups < Fog::Ecloud::Collection
identity :href
model Fog::Compute::Ecloud::Group
def all
data = connection.get_groups(href).body
data = data[:Groups] ? data[:Groups][:Group] : data
load(data)
end
def get(uri)
if data = connection.get_group(uri)
new(data.body)
end
rescue Fog::Errors::NotFound
nil
end
end
end
end
end

View file

@ -0,0 +1,15 @@
module Fog
module Compute
class Ecloud
class GuestProcess < Fog::Ecloud::Model
identity :name
attribute :process_id, :aliases => :ProcessId
def id
href.scan(/\d+/)[0]
end
end
end
end
end

View file

@ -0,0 +1,27 @@
require 'fog/ecloud/models/compute/guest_process'
module Fog
module Compute
class Ecloud
class GuestProcesses < Fog::Ecloud::Collection
identity :href
model Fog::Compute::Ecloud::GuestProcess
def all
data = connection.get_guest_processes(href).body[:GuestProcess]
load(data)
end
def get(uri)
if data = connection.get_guest_process(uri)
new(data.body)
end
rescue Fog::Errors::NotFound
nil
end
end
end
end
end

View file

@ -0,0 +1,18 @@
module Fog
module Compute
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
def id
href.scan(/\d+/)[0]
end
end
end
end
end

View file

@ -0,0 +1,27 @@
require 'fog/ecloud/models/compute/hardware_configuration'
module Fog
module Compute
class Ecloud
class HardwareConfigurations < Fog::Ecloud::Collection
identity :href
model Fog::Compute::Ecloud::HardwareConfiguration
def all
data = connection.get_hardware_configurations(href).body
load(data)
end
def get(uri)
if data = connection.get_hardware_configuration(uri)
new(data.body)
end
rescue Fog::Errors::NotFound
nil
end
end
end
end
end

View file

@ -2,94 +2,78 @@ module Fog
module Compute
class Ecloud
class InternetService < Fog::Ecloud::Model
identity :href, :aliases => :Href
ignore_attributes :xmlns, :xmlns_i
identity :href
attribute :name, :aliases => :Name
attribute :id, :aliases => :Id
attribute :type, :aliases => :Type
attribute :other_links, :aliases => :Links
attribute :actions, :aliases => :Actions
attribute :protocol, :aliases => :Protocol
attribute :port, :aliases => :Port
attribute :enabled, :aliases => :Enabled
attribute :port, :aliases => :Port, :type => :integer
attribute :enabled, :aliases => :Enabled, :type => :boolean
attribute :description, :aliases => :Description
attribute :public_ip, :aliases => :PublicIpAddress
attribute :timeout, :aliases => :Timeout
attribute :redirect_url, :aliases => :RedirectURL
attribute :monitor, :aliases => :Monitor
attribute :backup_service_data, :aliases => :BackupService
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 delete
requires :href
def nodes
@nodes ||= Fog::Compute::Ecloud::Nodes.new(:connection => connection, :href => href)
end
connection.delete_internet_service( href )
def monitors
@monitors ||= Fog::Compute::Ecloud::Monitors.new(:connection => connection, :href => "/cloudapi/ecloud/internetServices/#{id}/monitor")
end
def save
if new_record?
result = connection.add_internet_service( collection.href, _compose_service_data )
result = connection.internet_service_create( collection.href, _compose_service_data )
merge_attributes(result.body)
else
connection.configure_internet_service( href, _compose_service_data, _compose_ip_data )
end
end
# disables monitoring for this service
def edit(options)
options[:uri] = href
data = connection.internet_service_edit(options).body
task = Fog::Compute::Ecloud::Tasks.new(:connection => connection, :href => data[:href])[0]
end
def delete
data = connection.internet_service_delete(href).body
task = Fog::Compute::Ecloud::Tasks.new(:connection => connection, :href => data[:href])[0]
end
def create_monitor(options = {})
options = {:type => :default}.merge(options)
case options[:type]
when :default
data = connection.monitors_create_default(href + "/action/createDefaultMonitor").body
when :ping
options[:enabled] ||= true
options[:uri] = href + "/action/createPingMonitor"
data = connection.monitors_create_ping(options).body
when :http
options[:uri] = href + "/action/createHttpMonitor"
data = connection.monitors_create_http(options).body
when :ecv
options[:uri] = href + "/action/createEcvMonitor"
data = connection.monitors_create_ecv(options).body
when :loopback
data = connection.monitors_create_loopback(href).body
end
monitor = Fog::Compute::Ecloud::Monitors.new(:connection => connection, :href => data[:href])
end
def disable_monitor
if self.monitor and self.monitor[:type] == "Disabled"
raise RuntimeError.new("Monitoring already disabled")
else
self.monitor = {:type => "Disabled", :is_enabled => "true"}
self.save
end
data = connection.monitors_disable(href + "/action/disableMonitor").body
task = Fog::Compute::Ecloud::Tasks.new(:connection => connection, :href => data[:href])
end
# enable default ping monitoring, use monitor= for more exotic forms (ECV & HTTP)
def enable_ping_monitor
self.monitor = nil
self.save
end
def monitor=(new_monitor = {})
if new_monitor.nil? || new_monitor.empty?
attributes[:monitor] = nil
elsif new_monitor.is_a?(Hash)
attributes[:monitor] = {}
attributes[:monitor][:type] = new_monitor[:MonitorType] || new_monitor[:type]
attributes[:monitor][:url_send_string] = new_monitor[:UrlSendString] || new_monitor[:url_send_string]
attributes[:monitor][:http_headers] = new_monitor[:HttpHeader] || new_monitor[:http_headers]
if attributes[:monitor][:http_headers]
if attributes[:monitor][:http_headers].is_a?(String)
attributes[:monitor][:http_headers] = attributes[:monitor][:http_headers].split("\n")
else
attributes[:monitor][:http_headers] = attributes[:monitor][:http_headers]
end
end
attributes[:monitor][:receive_string] = new_monitor[:ReceiveString] || new_monitor[:receive_string]
attributes[:monitor][:interval] = new_monitor[:Interval] || new_monitor[:interval]
attributes[:monitor][:response_timeout] = new_monitor[:ResponseTimeOut] || new_monitor[:response_timeout]
attributes[:monitor][:downtime] = new_monitor[:DownTime] || new_monitor[:downtime]
attributes[:monitor][:retries] = new_monitor[:Retries] || new_monitor[:retries]
attributes[:monitor][:is_enabled] = new_monitor[:IsEnabled] || new_monitor[:is_enabled]
else
raise RuntimeError.new("monitor needs to either be nil or a Hash")
end
end
def nodes
@nodes ||= Fog::Compute::Ecloud::Nodes.new( :connection => connection, :href => href + "/nodeServices" )
end
def backup_service_uri
if backup_service_data
backup_service_data[:Href]
end
end
def backup_service_uri=(new_value)
self.backup_service_data = {
:Href => new_value
}
def id
href.scan(/\d+/)[0]
end
private
@ -98,19 +82,9 @@ module Fog
#For some reason inject didn't work
service_data = {}
self.class.attributes.select{ |attribute| attribute != :backup_service_data }.each { |attribute| service_data[attribute] = send(attribute) }
service_data[:backup_service_uri] = backup_service_uri
service_data.reject! {|k, v| v.nil? }
service_data
end
def _compose_ip_data
if public_ip.nil?
{}
else
{ :id => public_ip[:Id], :href => public_ip[:Href], :name => public_ip[:Name] }
end
end
end
end
end

View file

@ -5,28 +5,41 @@ module Fog
class Ecloud
class InternetServices < Fog::Ecloud::Collection
identity :href
model Fog::Compute::Ecloud::InternetService
attribute :href, :aliases => :Href
def all
check_href! :message => "the Internet Services for the Vdc you want to enumerate"
if internet_service_data = connection.get_internet_services(href).body[:InternetService]
load(Array[internet_service_data].flatten.find_all {|i| i[:IsBackupService] == "false" })
data = connection.get_internet_services(href).body[:InternetServices]
if data.is_a?(Hash)
load(data[:InternetService])
elsif data.is_a?(String) && data.empty?
load([])
end
end
# Optimize later, no need to get_internet_services again?
def get(uri)
internet_services = connection.get_internet_services(href).body[:InternetService]
internet_services = [ internet_services ] if internet_services.is_a?(Hash)
if data = internet_services.detect { |service| service[:Href] == uri }
new(data)
if data = connection.get_internet_service(uri)
new(data.body)
end
rescue Fog::Errors::NotFound
nil
end
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[:persistence][:type] ||= "None"
data = connection.internet_service_create(options).body
object = new(data)
end
def public_ip_id
href.scan(/\d+/)[0]
end
end
end
end

View file

@ -1,49 +0,0 @@
module Fog
module Compute
class Ecloud
class Ip < Fog::Ecloud::Model
ignore_attributes :xmlns_i, :xmlns
identity :href, :aliases => :Href
attribute :name, :aliases => :Name
attribute :status, :aliases => :Status
attribute :server, :aliases => :Server
attribute :rnat, :aliases => :RnatAddress
attribute :id, :aliases => :Id, :type => :integer
def rnat=(new_rnat)
attributes[:rnat] = new_rnat
@changed = true
end
def save
if @changed
connection.configure_network_ip( href, _compose_network_ip_data )
end
true
end
def reload
super
@changed = false
self
end
private
def _compose_network_ip_data
{
:id => id,
:href => href,
:name => name,
:status => status,
:server => server,
:rnat => rnat
}
end
end
end
end
end

View file

@ -0,0 +1,25 @@
module Fog
module Compute
class Ecloud
class IpAddress < Fog::Ecloud::Model
identity :href
attribute :name, :aliases => :Name
attribute :type, :aliases => :Type
attribute :other_links, :aliases => :Links
attribute :host, :aliases => :Host
attribute :detected_on, :aliases => :DetectedOn
attribute :rnat, :aliases => :RnatAddress
attribute :reserved, :aliases => :Reserved, :type => :boolean
def status
(detected_on || host) ? "Assigned" : "Available"
end
def id
href.scan(/\d+/)[0]
end
end
end
end
end

View file

@ -0,0 +1,27 @@
require 'fog/ecloud/models/compute/ip_address'
module Fog
module Compute
class Ecloud
class IpAddresses < Fog::Ecloud::Collection
identity :href
model Fog::Compute::Ecloud::IpAddress
def all
data = connection.get_ip_addresses(href).body[:IpAddresses][:IpAddress]
load(data)
end
def get(uri)
if data = connection.get_ip_address(uri)
new(data.body)
end
rescue Fog::Errors::NotFound
nil
end
end
end
end
end

View file

@ -1,32 +0,0 @@
require 'fog/ecloud/models/compute/ip'
module Fog
module Compute
class Ecloud
class Ips < Fog::Ecloud::Collection
model Fog::Compute::Ecloud::Ip
undef_method :create
attribute :href
def all
check_href!( :messages => "Ips href of a Network you want to enumerate" )
if data = connection.get_network_ips(href).body[:IpAddress]
load(data)
end
end
def get(uri)
if data = connection.get_network_ip(uri).body
new(data)
end
rescue Fog::Errors::NotFound
nil
end
end
end
end
end

View file

@ -0,0 +1,20 @@
module Fog
module Compute
class Ecloud
class Layout < Fog::Ecloud::Model
identity :href
attribute :type, :aliases => :Type
attribute :other_links, :aliases => :Links
def rows
@rows = Fog::Compute::Ecloud::Rows.new(:connection => connection, :href => href)
end
def id
href.scan(/\d+/)[0]
end
end
end
end
end

View file

@ -0,0 +1,27 @@
require 'fog/ecloud/models/compute/layout'
module Fog
module Compute
class Ecloud
class Layouts < Fog::Ecloud::Collection
identity :href
model Fog::Compute::Ecloud::Layout
def all
data = connection.get_layouts(href).body
load(data)
end
def get(uri)
if data = connection.get_layout(uri)
new(data.body)
end
rescue Fog::Errors::NotFound
nil
end
end
end
end
end

View file

@ -0,0 +1,23 @@
module Fog
module Compute
class Ecloud
class Location < Fog::Ecloud::Model
identity :href
ignore_attributes :xmlns, :xmlns_xsi, :xmlns_xsd, :xmlns_i
attribute :name, :aliases => :Name
attribute :type, :aliases => :Type
def catalog(org_href)
@catalog ||= Fog::Compute::Ecloud::Catalog.new(:connection => connection, :href => "/cloudapi/ecloud/admin/catalog/organizations/#{org_href.scan(/\d+/)[0]}/locations/#{id}")
end
def id
href.scan(/\d+/)[0]
end
end
end
end
end

View file

@ -0,0 +1,31 @@
require 'fog/ecloud/models/compute/location'
module Fog
module Compute
class Ecloud
class Locations < Fog::Ecloud::Collection
model Fog::Compute::Ecloud::Location
undef_method :create
identity :href
def all
data = connection.get_organization(href).body[:Locations][:Location]
load(data)
end
def get(uri)
if data = connection.get_location(uri)
new(data.body)
end
rescue Fog::Errors::NotFound
nil
end
end
end
end
end

View file

@ -0,0 +1,16 @@
module Fog
module Compute
class Ecloud
class LoginBanner < Fog::Ecloud::Model
identity :href
attribute :display, :aliases => :Display, :type => :boolean
attribute :text, :aliases => :Text
def id
href.scan(/\d+/)[0]
end
end
end
end
end

View file

@ -0,0 +1,27 @@
require 'fog/ecloud/models/compute/login_banner'
module Fog
module Compute
class Ecloud
class LoginBanners < Fog::Ecloud::Collection
identity :href
model Fog::Compute::Ecloud::LoginBanner
def all
data = connection.get_login_banners(href).body
load(data)
end
def get(uri)
if data = connection.get_login_banner(uri)
new(data.body)
end
rescue Fog::Errors::NotFound
nil
end
end
end
end
end

View file

@ -0,0 +1,16 @@
module Fog
module Compute
class Ecloud
class MemoryUsageDetail < Fog::Ecloud::Model
identity :href
attribute :time, :aliases => :Time
attribute :value, :aliases => :Value
def id
href.scan(/\d+/)[0]
end
end
end
end
end

View file

@ -0,0 +1,27 @@
require 'fog/ecloud/models/compute/memory_usage_detail'
module Fog
module Compute
class Ecloud
class MemoryUsageDetailSummary < Fog::Ecloud::Collection
identity :href
model Fog::Compute::Ecloud::MemoryUsageDetail
def all
data = connection.get_memory_usage_detail_summary(href).body[:MemoryUsageDetailSummary][:MemoryUsageDetail]
load(data)
end
def get(uri)
if data = connection.get_memory_usage_detail(uri)
new(data.body)
end
rescue Fog::Errors::NotFound
nil
end
end
end
end
end

View file

@ -0,0 +1,46 @@
module Fog
module Compute
class Ecloud
class Monitor < Fog::Ecloud::Model
identity :href
attribute :type, :aliases => :Type
attribute :other_links, :aliases => :Links
attribute :interval, :aliases => :Interval, :type => :integer
attribute :response_timeout, :aliases => :ResponseTimeout, :type => :integer
attribute :retries, :aliases => :Retries, :type => :integer
attribute :downtime, :aliases => :Downtime, :type => :integer
attribute :enabled, :aliases => :Enabled, :type => :boolean
attribute :request_uri, :aliases => :RequestUri
attribute :http_headers, :aliases => :HttpHeaders
attribute :response_codes, :aliases => :ResponseCodes
attribute :send_string, :aliases => :SendString
attribute :receive_string, :aliases => :ReceiveString
def edit(options = {})
href = "/cloudapi/ecloud/internetServices/#{internet_service_id}/monitor?type="
case type
when "application/vnd.tmrk.cloud.pingMonitor"
options[:uri] = href + "ping"
data = connection.monitors_edit_ping(options).body
when "application/vnd.tmrk.cloud.httpMonitor"
options[:uri] = href + "http"
data = connection.monitors_edit_http(options).body
when "application/vnd.tmrk.cloud.ecvMonitor"
options[:uri] = href + "ecv"
data = connection.monitors_edit_ecv(options).body
end
object = collection.from_data(data)
end
def internet_service_id
other_links[:Link][:href].scan(/\d+/)[0]
end
def id
href.scan(/\d+/)[0]
end
end
end
end
end

View file

@ -0,0 +1,31 @@
require 'fog/ecloud/models/compute/monitor'
module Fog
module Compute
class Ecloud
class Monitors < Fog::Ecloud::Collection
identity :href
model Fog::Compute::Ecloud::Monitor
def all
data = connection.get_monitors(href).body
load(data)
end
def get(uri)
if data = connection.get_monitor(uri)
new(data.body)
end
rescue Fog::Errors::NotFound
nil
end
def from_data(data)
new(data)
end
end
end
end
end

View file

@ -2,72 +2,33 @@ module Fog
module Compute
class Ecloud
class Network < Fog::Ecloud::Model
identity :href
ignore_attributes :xmlns, :xmlns_xsi, :xmlns_xsd, :xmlns_i, :Configuration, :Id
attribute :name, :aliases => :Name
#attribute :id, :aliases => :Id
attribute :features, :aliases => :Features, :type => :array
attribute :links, :aliases => :Link, :type => :array
attribute :type
attribute :gateway, :aliases => :GatewayAddress
attribute :broadcast, :aliases => :BroadcastAddress
attribute :type, :aliases => :Type
attribute :other_links, :aliases => :Links
attribute :address, :aliases => :Address
attribute :rnat, :aliases => :RnatAddress
attribute :extension_href, :aliases => :Href
attribute :network_type, :aliases => :NetworkType
attribute :vlan, :aliases => :Vlan
attribute :friendly_name, :aliases => :FriendlyName
attribute :broadcast_address, :aliases => :BroadcastAddress
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}")
end
def ips
load_unless_loaded!
connection.ips.new
Fog::Compute::Ecloud::Ips.new(
:connection => connection,
:href => links.detect { |link| link[:name] == "IP Addresses" }[:href]
)
@ips ||= Fog::Compute::Ecloud::IpAddresses.new(:connection => connection, :href => href)
end
def rnat=(new_rnat)
attributes[:rnat] = new_rnat
@changed = true
def edit_rnat_association(options)
options[:uri] = href
data = connection.rnat_associations_edit_network(options).body
task = Fog::Compute::Ecloud::Tasks.new(:connection => connection, :href => data[:href])[0]
end
def save
if @changed
connection.configure_network( extension_href, _compose_network_data )
end
true
end
def reload
super
merge_attributes(extension_data.body)
self
end
private
def extension_data
connection.get_network_extensions( extensions_link[:href] )
end
def extensions_link
links.detect { |link| link[:name] == name }
end
def _compose_network_data
{
:id => id,
:href => extension_href,
:name => name,
:rnat => rnat,
:address => address,
:broadcast => broadcast,
:gateway => gateway
}
def id
href.scan(/\d+/)[0]
end
end
end

View file

@ -3,30 +3,25 @@ require 'fog/ecloud/models/compute/network'
module Fog
module Compute
class Ecloud
class Networks < Fog::Ecloud::Collection
undef_method :create
identity :href
model Fog::Compute::Ecloud::Network
attribute :href
def all
check_href!("Vdc")
if data = connection.get_vdc(href).body[:AvailableNetworks][:Network]
load(data)
end
data = connection.get_networks(href).body
data = data[:Networks] ? data[:Networks][:Network] : data[:Network]
load(data)
end
def get(uri)
if data = connection.get_network(uri)
new(data.body)
end
rescue Fog::Errors::NotFound
rescue Fog::Errors::NotFound
nil
end
end
end
end

View file

@ -2,41 +2,37 @@ module Fog
module Compute
class Ecloud
class Node < Fog::Ecloud::Model
identity :href
identity :href, :aliases => :Href
ignore_attributes :xmlns, :xmlns_i
attribute :ip_address, :aliases => :IpAddress
attribute :description, :aliases => :Description
attribute :name, :aliases => :Name
attribute :port, :aliases => :Port
attribute :enabled, :aliases => :Enabled
attribute :id, :aliases => :Id
attribute :type, :aliases => :Type
attribute :other_links, :aliases => :Links
attribute :ip_address, :aliases => :IpAddress
attribute :protocol, :aliases => :Protocol
attribute :port, :aliases => :Port, :type => :integer
attribute :enabled, :aliases => :Enabled, :type => :boolean
attribute :description, :aliases => :Description
def tasks
@tasks ||= Fog::Compute::Ecloud::Tasks.new(:connection => connection, :href => "/cloudapi/ecloud/tasks/virtualMachines/#{id}")
end
def delete
requires :href
connection.delete_node( href )
data = connection.node_service_delete(href).body
task = Fog::Compute::Ecloud::Tasks.new(:connection => connection, :href => data[:href])[0]
end
def save
if new_record?
result = connection.add_node( collection.href, _compose_node_data )
merge_attributes(result.body)
else
connection.configure_node( href, _compose_node_data )
end
def edit(options)
options[:uri] = href
options[:description] ||= ""
options = {:name => name}.merge(options)
data = connection.node_service_edit(options).body
task = Fog::Compute::Ecloud::Tasks.new(:connection => connection, :href => data[:href])[0]
end
private
def _compose_node_data
node_data = {}
self.class.attributes.select{ |attribute| !send(attribute).nil? }.each { |attribute| node_data[attribute] = send(attribute).to_s }
node_data
def id
href.scan(/\d+/)[0]
end
end
end
end

View file

@ -3,17 +3,18 @@ require 'fog/ecloud/models/compute/node'
module Fog
module Compute
class Ecloud
class Nodes < Fog::Ecloud::Collection
identity :href
model Fog::Compute::Ecloud::Node
attribute :href, :aliases => :Href
def all
check_href!( :messages => "the Nodes href of the Internet Service you want to enumerate" )
if data = connection.get_nodes(href).body[:NodeService]
load(data)
data = connection.get_nodes(href).body
if data[:NodeServices]
load(data[:NodeServices][:NodeService])
else
load([])
end
end
@ -25,6 +26,18 @@ module Fog
nil
end
def create(options)
options[:uri] = "/cloudapi/ecloud/nodeServices/internetServices/#{internet_service_id}/action/createNodeService"
options[:protocol] ||= "TCP"
options[:enabled] ||= true
options[:description] ||= ""
data = connection.node_service_create(options).body
object = new(data)
end
def internet_service_id
href.scan(/\d+/)[0]
end
end
end
end

View file

@ -0,0 +1,17 @@
module Fog
module Compute
class Ecloud
class OperatingSystem < Fog::Ecloud::Model
identity :href
attribute :name, :aliases => :Name
attribute :type, :aliases => :Type
def id
href.scan(/\d+/)[0]
end
end
end
end
end

View file

@ -0,0 +1,27 @@
require 'fog/ecloud/models/compute/operating_system_family'
module Fog
module Compute
class Ecloud
class OperatingSystemFamilies < Fog::Ecloud::Collection
identity :href
model Fog::Compute::Ecloud::OperatingSystemFamily
def all
data = connection.get_operating_system_families(href).body[:OperatingSystemFamily]
load(data)
end
def get(uri)
if data = connection.get_operating_system(uri)
new(data.body)
end
rescue Fog::Errors::NotFound
nil
end
end
end
end
end

View file

@ -0,0 +1,21 @@
module Fog
module Compute
class Ecloud
class OperatingSystemFamily < Fog::Ecloud::Model
identity :href
attribute :name, :aliases => :Name
attribute :type, :aliases => :Type
attribute :operating_system_family, :aliases => :OperatingSystems
def operating_systems
@operating_systems ||= Fog::Compute::Ecloud::OperatingSystems.new(:connection => connection, :data => operating_system_family[:OperatingSystem])
end
def id
href.scan(/\d+/)[0]
end
end
end
end
end

View file

@ -0,0 +1,26 @@
require 'fog/ecloud/models/compute/operating_system'
module Fog
module Compute
class Ecloud
class OperatingSystems < Fog::Ecloud::Collection
model Fog::Compute::Ecloud::OperatingSystem
identity :data
def all
load(data)
end
def get(uri)
if data = connection.get_operating_system(uri)
new(data.body)
end
rescue Fog::Errors::NotFound
nil
end
end
end
end
end

View file

@ -0,0 +1,79 @@
module Fog
module Compute
class Ecloud
class Organization < Fog::Ecloud::Model
identity :href
ignore_attributes :xmlns, :xmlns_xsi, :xmlns_xsd, :xmlns_i
attribute :name, :aliases => :Name
attribute :type, :aliases => :Type
attribute :other_links, :aliases => :Links
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)
end
def tags
@tags ||= Fog::Compute::Ecloud::Tags.new(:connection => connection, :href => "/cloudapi/ecloud/deviceTags/organizations/#{id}")
end
def admin
@admin ||= Fog::Compute::Ecloud::AdminOrganizations.new(:connection => connection, :href => "/cloudapi/ecloud/admin/organizations/#{id}").first
end
def users
@users ||= Fog::Compute::Ecloud::Users.new(:connection => connection, :href => "/cloudapi/ecloud/admin/users/organizations/#{id}")
end
def support_tickets(type = :open)
case type
when :open
@support_tickets ||= Fog::Compute::Ecloud::SupportTickets.new(:connection => connection, :href => "/cloudapi/ecloud/admin/tickets/organizations/#{id}/active")
when :closed
@support_tickets ||= Fog::Compute::Ecloud::SupportTickets.new(:connection => connection, :href => "/cloudapi/ecloud/admin/tickets/organizations/#{id}/closed")
end
end
def edit_authentication_levels(options = {})
options[:uri] = "/cloudapi/ecloud/admin/organizations/#{id}/authenticationLevels"
data = connection.admin_edit_authentication_levels(options).body
level = Fog::Compute::Ecloud::AdminOrganizations.new(:connection => connection, :href => data[:href])[0]
end
def edit_password_complexity_rules(options = {})
options[:uri] = "/cloudapi/ecloud/admin/organizations/#{id}/passwordComplexityRules"
data = connection.admin_edit_password_complexity_rules(options).body
level = Fog::Compute::Ecloud::PasswordComplexityRules.new(:connection => connection, :href => data[:href])[0]
end
def edit_login_banner(options = {})
options[:uri] = "/cloudapi/ecloud/admin/organizations/#{id}/loginBanner"
data = connection.admin_edit_login_banner(options).body
banner = Fog::Compute::Ecloud::LoginBanners.new(:connection => connection, :href => data[:href])[0]
end
def enable_support_access(options = {})
options[:uri] = "/cloudapi/ecloud/admin/organizations/#{id}/action/enableSupportAccess"
connection.admin_enable_support_access(options[:uri])
end
def disable_support_access(options = {})
options[:uri] = "/cloudapi/ecloud/admin/organizations/#{id}/action/disableSupportAccess"
connection.admin_disable_support_access(options[:uri])
end
def id
href.scan(/\d+/)[0]
end
alias :vdcs :environments
end
end
end
end

View file

@ -0,0 +1,39 @@
require 'fog/ecloud/models/compute/organization'
module Fog
module Compute
class Ecloud
class Organizations < Fog::Ecloud::Collection
model Fog::Compute::Ecloud::Organization
undef_method :create
identity :href
def all
data = connection.get_organizations(organization_uri).body
load(data[:Organization])
end
def get(uri)
if data = connection.get_organization(uri)
new(data.body)
end
rescue Fog::Errors::NotFound
nil
end
def organization_uri
@organization_uri ||= connection.default_organization_uri
end
private
def organization_uri=(new_organization_uri)
@organization_uri = new_organization_uri
end
end
end
end
end

View file

@ -0,0 +1,49 @@
module Fog
module Compute
class Ecloud
class PasswordComplexityRule < Fog::Ecloud::Model
identity :href
attribute :rule_type, :aliases => :RuleType
attribute :custom_rules, :aliases => :CustomRules
attribute :description, :aliases => :Description
def minimum_characters
custom_rules[:MinimumCharacters]
end
def minimum_upper_case_characters
custom_rules[:MinimumUpperCaseCharacters]
end
def minimum_lower_case_characters
custom_rules[:MinimumLowerCaseCharacters]
end
def minimum_numeric_characters
custom_rules[:MinimumNumericCharacters]
end
def minimum_special_characters
custom_rules[:MinimumSpecialCharacters]
end
def maximum_consecutive_characters_from_prior_password
custom_rules[:MaximumConsecutiveCharactersFromPriorPassword]
end
def minimum_lifetime_restriction
custom_rules[:MinimumLifetimeRestriction]
end
def minimum_generations_before_reuse
custom_rules[:MinimumGenerationsBeforeReuse]
end
def id
href.scan(/\d+/)[0]
end
end
end
end
end

View file

@ -0,0 +1,27 @@
require 'fog/ecloud/models/compute/password_complexity_rule'
module Fog
module Compute
class Ecloud
class PasswordComplexityRules < Fog::Ecloud::Collection
identity :href
model Fog::Compute::Ecloud::PasswordComplexityRule
def all
data = connection.get_password_complexity_rules(href).body
load(data)
end
def get(uri)
if data = connection.get_password_complexity_rule(uri)
new(data.body)
end
rescue Fog::Errors::NotFound
nil
end
end
end
end
end

View file

@ -0,0 +1,22 @@
module Fog
module Compute
class Ecloud
class PhysicalDevice < Fog::Ecloud::Model
identity :href
attribute :name, :aliases => :Name
attribute :type, :aliases => :Type
attribute :tags, :aliases => :Tags
attribute :layout, :aliases => :Layout
attribute :network_host, :aliases => :NetworkHost
attribute :classification, :aliases => :Classification
attribute :model, :aliases => :Model
def id
href.scan(/\d+/)[0]
end
end
end
end
end

View file

@ -0,0 +1,27 @@
require 'fog/ecloud/models/compute/physical_device'
module Fog
module Compute
class Ecloud
class PhysicalDevices < Fog::Ecloud::Collection
identity :href
model Fog::Compute::Ecloud::PhysicalDevice
def all
data = connection.get_physical_devices(href).body[:PhysicalDevice] || []
load(data)
end
def get(uri)
if data = connection.get_physical_device(uri)
new(data.body)
end
rescue Fog::Errors::NotFound
nil
end
end
end
end
end

View file

@ -2,21 +2,25 @@ module Fog
module Compute
class Ecloud
class PublicIp < Fog::Ecloud::Model
identity :href, :aliases => :Href
ignore_attributes :xmlns, :xmlns_i
identity :href
attribute :name, :aliases => :Name
attribute :id, :aliases => :Id
attribute :type, :aliases => :Type
attribute :other_links, :aliases => :Links
attribute :ip_type, :aliases => :IpType
def internet_services
load_unless_loaded!
@internet_services ||= Fog::Compute::Ecloud::InternetServices.
new( :connection => connection,
:href => href.to_s + "/internetServices" )
@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
def id
href.scan(/\d+/)[0]
end
end
end
end
end
end

View file

@ -5,21 +5,14 @@ module Fog
class Ecloud
class PublicIps < Fog::Ecloud::Collection
undef_method :create
attribute :href, :aliases => :Href
identity :href
model Fog::Compute::Ecloud::PublicIp
#get_request :get_public_ip
#vcloud_type "application/vnd.tmrk.ecloud.publicIp+xml"
#all_request lambda { |public_ips| public_ips.connection.get_public_ips(public_ips.href) }
def all
check_href!(:message => "the Public Ips href of the Vdc you want to enumerate")
if data = connection.get_public_ips(href).body[:PublicIPAddress]
load(data)
end
data = connection.get_public_ips(href).body
data = data[:PublicIp] ? data[:PublicIp] : data
load(data)
end
def get(uri)
@ -30,6 +23,10 @@ module Fog
nil
end
def activate
data = connection.public_ip_activate(href + "/action/activatePublicIp").body
ip = Fog::Compute::Ecloud::PublicIps.new(:connection => connection, :href => data[:href])[0]
end
end
end
end

View file

@ -0,0 +1,27 @@
module Fog
module Compute
class Ecloud
class Rnat < Fog::Ecloud::Model
identity :href
attribute :name, :aliases => :Name
attribute :type, :aliases => :Type
attribute :other_links, :aliases => :Links
attribute :default, :aliases => :Default, :type => :boolean
attribute :public_ip, :aliases => :PublicIp
def networks
@networks = Fog::Compute::Ecloud::Networks.new(:connection => connection, :href => href)
end
def associations
@associations = Fog::Compute::Ecloud::Associations.new(:connection => connection, :href => href)
end
def id
href.scan(/\d+/)[0]
end
end
end
end
end

View file

@ -0,0 +1,27 @@
require 'fog/ecloud/models/compute/rnat'
module Fog
module Compute
class Ecloud
class Rnats < Fog::Ecloud::Collection
identity :href
model Fog::Compute::Ecloud::Rnat
def all
data = connection.get_rnats(href).body[:Rnats][:Rnat]
load(data)
end
def get(uri)
if data = connection.get_rnat(uri)
new(data.body)
end
rescue Fog::Errors::NotFound
nil
end
end
end
end
end

View file

@ -0,0 +1,24 @@
module Fog
module Compute
class Ecloud
class Role < Fog::Ecloud::Model
identity :href
attribute :name, :aliases => :Name
attribute :environment_name, :aliases => :EnvironmentName
attribute :type, :aliases => :Type
attribute :other_links, :aliases => :Links
attribute :role_type, :aliases => :RoleType
attribute :active, :aliases => :Active, :type => :boolean
attribute :category, :aliases => :Category
attribute :is_admin, :aliases => :IsAdmin, :type => :boolean
attribute :business_operations, :aliases => :BusinessOperations
def id
href.scan(/\d+/)[0]
end
end
end
end
end

View file

@ -0,0 +1,37 @@
require 'fog/ecloud/models/compute/role'
module Fog
module Compute
class Ecloud
class Roles < Fog::Ecloud::Collection
identity :href
model Fog::Compute::Ecloud::Role
def all
data = connection.get_roles(href).body
if data[:OrganizationRole]
load(data[:OrganizationRole])
else
r_data = []
data[:EnvironmentRoles][:EnvironmentRole].each do |d|
d[:Environment][:EnvironmentName] = d[:Environment][:name]
d[:Environment] = d[:Environment].merge(d[:Role]) if d[:Role]
r_data << d[:Environment]
end
load(r_data)
end
end
def get(uri)
if data = connection.get_role(uri)
new(data.body)
end
rescue Fog::Errors::NotFound
nil
end
end
end
end
end

View file

@ -0,0 +1,53 @@
module Fog
module Compute
class Ecloud
class Row < Fog::Ecloud::Model
identity :href
attribute :name, :aliases => :Name
attribute :type, :aliases => :Type
attribute :other_links, :aliases => :Links
attribute :index, :aliases => :Index
def groups
@groups = Fog::Compute::Ecloud::Groups.new(:connection => connection, :href => href)
end
def edit(options)
options[:uri] = href
connection.rows_edit(options).body
end
def move_up(options)
options[:uri] = href + "/action/moveup"
connection.rows_moveup(options).body
end
def move_down(options)
options[:uri] = href + "/action/movedown"
connection.rows_movedown(options).body
end
def delete
connection.rows_delete(href).body
end
def create_group(options = {})
options[:uri] = "/cloudapi/ecloud/layoutGroups/environments/#{environment_id}/action/createLayoutGroup"
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]
end
def environment_id
other_links[:Link][:href].scan(/\d+/)[0]
end
def id
href.scan(/\d+/)[0]
end
end
end
end
end

View file

@ -0,0 +1,37 @@
require 'fog/ecloud/models/compute/row'
module Fog
module Compute
class Ecloud
class Rows < Fog::Ecloud::Collection
identity :href
model Fog::Compute::Ecloud::Row
def all
data = connection.get_layout(href).body[:Rows][:Row]
load(data)
end
def get(uri)
if data = connection.get_row(uri)
new(data.body)
end
rescue Fog::Errors::NotFound
nil
end
def create(options = {})
options[:uri] = "/cloudapi/ecloud/layoutRows/environments/#{environment_id}/action/createLayoutRow"
data = connection.rows_create(options).body
new(data)
end
def environment_id
href.scan(/\d+/)[0]
end
end
end
end
end

View file

@ -2,47 +2,80 @@ module Fog
module Compute
class Ecloud
class Server < Fog::Ecloud::Model
identity :href
identity :href, :aliases => :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
ignore_attributes :xmlns, :xmlns_i, :xmlns_xsi, :xmlns_xsd
def tasks
@tasks ||= Fog::Compute::Ecloud::Tasks.new(:connection => connection, :href => "/cloudapi/ecloud/tasks/virtualMachines/#{id}")
end
attribute :type
attribute :name
attribute :status
attribute :network_connections, :aliases => :NetworkConnectionSection, :squash => :NetworkConnection
attribute :os, :aliases => :OperatingSystemSection
attribute :virtual_hardware, :aliases => :VirtualHardwareSection
attribute :storage_size, :aliases => :size
attribute :links, :aliases => :Link, :type => :array
def processes
@processes ||= Fog::Compute::Ecloud::GuestProcesses.new(:connection, connection, :href => "/cloudapi/ecloud/virtualMachines/#{id}/guest/processes")
end
def friendly_status
load_unless_loaded!
case status
when '0'
'creating'
when '2'
'off'
when '4'
'on'
else
'unkown'
def hardware_configuration
@hardware_configuration ||= Fog::Compute::Ecloud::HardwareConfigurations.new(:connection => connection, :href => "/cloudapi/ecloud/virtualMachines/#{id}/hardwareConfiguration")[0]
end
def configuration
@configuration ||= Fog::Compute::Ecloud::ServerConfigurationOptions.new(:connection => connection, :href => "/cloudapi/ecloud/virtualMachines/#{id}/configurationOptions")[0]
end
def ips
network_hash = ip_addresses[:AssignedIpAddresses][:Networks]
network_hash[:Network] = network_hash[:Network].is_a?(Hash) ? [network_hash[:Network]] : network_hash[:Network]
network_hash[:Network].each do |network|
network[:IpAddresses][:IpAddress] = network[:IpAddresses][:IpAddress].is_a?(String) ? [network[:IpAddresses][:IpAddress]] : network[:IpAddresses][:IpAddress]
end
@ips = nil
networks = Fog::Compute::Ecloud::Networks.new(:connection => connection, :href => "/cloudapi/ecloud/virtualMachines/#{id}/assignedIps")
networks.each do |network|
if networks.index(network) == 0
if @ips.nil?
@ips = network.ips.select do |ip|
network_hash[:Network].any? do |network|
network[:IpAddresses][:IpAddress].include?(ip.name)
end
end
else
network.ips.each do |ip|
network_hash[:Network].any? do |network|
network[:IpAddresses][:IpAddress].each do |i|
@ips << ip if i == ip.name
end
end
end
end
else
network.ips.each do |ip|
network_hash[:Network].each do |network|
network[:IpAddresses][:IpAddress].each do |i|
@ips << ip if i == ip.name
end
end
end
end
end
@ips
end
def ready?
load_unless_loaded!
status == '2'
end
def on?
load_unless_loaded!
status == '4'
end
def off?
load_unless_loaded!
status == '2'
def networks
@networks ||= Fog::Compute::Ecloud::Networks.new(:connection => connection, :href => "/cloudapi/ecloud/virtualMachines/#{id}/assignedIps")
end
def power_on
@ -58,145 +91,150 @@ module Fog
end
def power_reset
power_operation( :power_reset => :reset )
end
def graceful_restart
requires :href
shutdown
wait_for { off? }
power_on
power_operation( :power_reset => :reboot )
end
def delete
requires :href
connection.delete_vapp( href)
data = connection.virtual_machine_delete(href).body
task = Fog::Compute::Ecloud::Tasks.new(:connection => connection, :href => data[:href])[0]
end
def name=(new_name)
attributes[:name] = new_name
@changed = true
def copy(options = {})
options = {:type => :copy}.merge(options)
options[:source] ||= href
if options[:type] == :copy
options[:cpus] ||= 1
options[:memory] ||= 512
options[:customization] ||= :linux
options[:tags] ||= []
options[:powered_on] ||= false
if options[:ips]
options[:ips] = options[:ips].is_a?(String) ? [options[:ips]] : options[:ips]
else
options[:network_uri] = options[:network_uri].is_a?(String) ? [options[:network_uri]] : options[:network_uri]
options[:network_uri].each do |uri|
index = options[:network_uri].index(uri)
ip = Fog::Compute::Ecloud::IpAddresses.new(:connection => connection, :href => uri).detect { |i| i.host == nil }.name
options[:ips] ||= []
options[:ips][index] = ip
end
end
data = connection.virtual_machine_copy("/cloudapi/ecloud/virtualMachines/computePools/#{compute_pool_id}/action/copyVirtualMachine", options).body
elsif options[:type] == :identical
data = connection.virtual_machine_copy_identical("/cloudapi/ecloud/virtualMachines/computePools/#{compute_pool_id}/action/copyIdenticalVirtualMachine", options).body
end
vm = collection.from_data(data)
vm
end
def cpus
if cpu_mess
{ :count => cpu_mess[:VirtualQuantity].to_i,
:units => cpu_mess[:AllocationUnits] }
def rnats
rnats = Fog::Compute::Ecloud::Rnats.new(:connection => connection, :href => "/cloudapi/ecloud/rnats/environments/#{environment_id}")
associations = nil
rnats.each do |rnat|
if rnats.index(rnat) == 0
associations = rnat.associations.select do |association|
ips.any? do |ip|
association.name == ip.name
end
end
else
rnat.associations.select do |association|
ips.each do |ip|
if ip.name == association.name
associations << association
end
end
end
end
end
associations
end
def edit(options = {})
data = connection.virtual_machine_edit(href, options).body
if data[:type] == "application/vnd.tmrk.cloud.task"
task = Fog::Compute::Ecloud::Tasks.new(:connection => connection, :href => data[:href])[0]
end
end
def cpus=(qty)
@changed = true
cpu_mess[:VirtualQuantity] = qty.to_s
def create_rnat(options)
options[:host_ip_href] ||= ips.first.href
options[:uri] = "/cloudapi/ecloud/rnats/environments/#{environment_id}/action/createAssociation"
data = connection.rnat_associations_create_device(options).body
rnat = Fog::Compute::Ecloud::Associations.new(:connection => connection, :href => data[:href])[0]
end
def memory
if memory_mess
{ :amount => memory_mess[:VirtualQuantity].to_i,
:units => memory_mess[:AllocationUnits] }
end
end
def memory=(amount)
@changed = true
memory_mess[:VirtualQuantity] = amount.to_s
end
def disks
disk_mess.map do |dm|
{ :number => dm[:AddressOnParent], :size => dm[:VirtualQuantity].to_i, :resource => dm[:HostResource] }
end
c = hardware_configuration.storage[:Disk]
c = c.is_a?(Hash) ? [c] : c
@disks = c
end
def add_disk(size)
if @disk_change == :deleted
raise RuntimeError, "Can't add a disk w/o saving changes or reloading"
else
@disk_change = :added
load_unless_loaded!
virtual_hardware[:Item] << { :ResourceType => '17',
:AddressOnParent => (disk_mess.map { |dm| dm[:AddressOnParent] }.sort.last.to_i + 1).to_s,
:VirtualQuantity => size.to_s }
end
true
index = disks.map { |d| d[:Index].to_i }.sort[-1] + 1
vm_disks = disks << {:Index => index, :Size=>{:Unit => "GB", :Value => size}}
data = connection.virtual_machine_edit_hardware_configuration(href + "/hardwareConfiguration", _configuration_data(:disks => vm_disks)).body
task = Fog::Compute::Ecloud::Tasks.new(:connection => connection, :href => data[:href])[0]
end
def delete_disk(number)
if @disk_change == :added
raise RuntimeError, "Can't delete a disk w/o saving changes or reloading"
else
@disk_change = :deleted
load_unless_loaded!
unless number == 0
virtual_hardware[:Item].delete_if { |vh| vh[:ResourceType] == '17' && vh[:AddressOnParent].to_i == number }
end
end
true
def nics
c = hardware_configuration.network_cards[:Nic]
c = c.is_a?(Hash) ? [c] : c
@nics = c
end
def reload
reset_tracking
super
def add_nic(network)
unit_number = nics.map { |n| n[:UnitNumber].to_i }.sort[-1] + 1
vm_nics = nics << {:UnitNumber => unit_number, :Network => {:href => network.href, :name => network.name, :type => "application/vnd.tmrk.cloud.network"}}
data = connection.virtual_machine_edit_hardware_configuration(href + "/hardwareConfiguration", _configuration_data(:nics => vm_nics)).body
task = Fog::Compute::Ecloud::Tasks.new(:connection => connection, :href => data[:href])[0]
end
def save
if new_record?
#Lame ...
raise RuntimeError, "Should not be here"
def storage_size
vm_disks = disks
disks.map! { |d| d[:Size][:Value].to_i }.inject(0){|sum,item| sum + item} * 1024 * 1024
end
def ready?
load_unless_loaded!
unless status =~ /NotDeployed|Orphaned|TaskInProgress|CopyInProgress/
true
else
if on?
if @changed
raise RuntimeError, "Can't save cpu, name or memory changes while the VM is on."
end
end
connection.configure_vapp( href, _compose_vapp_data )
false
end
reset_tracking
end
def on?
powered_on == true
end
def off?
powered_on == false
end
def compute_pool_id
other_links[:Link].detect { |l| l[:type] == "application/vnd.tmrk.cloud.computePool" }[:href].scan(/\d+/)[0]
end
def environment_id
other_links[:Link].detect { |l| l[:type] == "application/vnd.tmrk.cloud.environment" }[:href].scan(/\d+/)[0]
end
def id
href.scan(/\d+/)[0]
end
private
def reset_tracking
@disk_change = false
@changed = false
end
def _compose_vapp_data
{ :name => name,
:cpus => cpus[:count],
:memory => memory[:amount],
:disks => disks
}
end
def memory_mess
load_unless_loaded!
if virtual_hardware && virtual_hardware[:Item]
virtual_hardware[:Item].detect { |item| item[:ResourceType] == "4" }
end
end
def cpu_mess
load_unless_loaded!
if virtual_hardware && virtual_hardware[:Item]
virtual_hardware[:Item].detect { |item| item[:ResourceType] == "3" }
end
end
def disk_mess
load_unless_loaded!
if virtual_hardware && virtual_hardware[:Item]
virtual_hardware[:Item].select { |item| item[:ResourceType] == "17" }
else
[]
end
def _configuration_data(options = {})
{:cpus => (options[:cpus] || hardware_configuration.processor_count), :memory => (options[:memory] || hardware_configuration.mem), :disks => (options[:disks] || disks), :nics => (options[:nics] || nics)}
end
def power_operation(op)
requires :href
begin
connection.send(op.keys.first, href + "/power/action/#{op.values.first}" )
rescue Excon::Errors::InternalServerError => e
connection.send(op.keys.first, href + "/action/#{op.values.first}" )
rescue Excon::Errors::Conflict => e
#Frankly we shouldn't get here ...
raise e unless e.to_s =~ /because it is already powered o(n|ff)/
end

View file

@ -0,0 +1,17 @@
module Fog
module Compute
class Ecloud
class ServerConfigurationOption < Fog::Ecloud::Model
identity :href
attribute :disk, :aliases => :Disk
attribute :customization, :aliases => :Customization
def id
href.scan(/\d+/)[0]
end
end
end
end
end

View file

@ -0,0 +1,27 @@
require 'fog/ecloud/models/compute/server_configuration_option'
module Fog
module Compute
class Ecloud
class ServerConfigurationOptions < Fog::Ecloud::Collection
identity :href
model Fog::Compute::Ecloud::ServerConfigurationOption
def all
data = connection.get_server_configuration_options(href).body
load(data)
end
def get(uri)
if data = connection.get_server_configuration_option(uri)
new(data.body)
end
rescue Fog::Errors::NotFound
nil
end
end
end
end
end

View file

@ -3,56 +3,65 @@ require 'fog/ecloud/models/compute/server'
module Fog
module Compute
class Ecloud
class Servers < Fog::Ecloud::Collection
undef_method :create
model Fog::Compute::Ecloud::Server
attribute :href, :aliases => :Href
identity :href
def all
check_href!(:parent => "Vdc")
load(_vapps)
data = connection.get_servers(href).body
if data.keys.include?(:VirtualMachines)
data = data[:VirtualMachines][:VirtualMachine]
else
data = data[:VirtualMachine]
end
load(data)
end
def get(uri)
if data = connection.get_vapp(uri)
if data = connection.get_server(uri)
new(data.body)
end
rescue Fog::Errors::NotFound
nil
end
def create( catalog_item_uri, options )
options[:vdc_uri] = href
def from_data(data)
new(data)
end
def create( template_uri, options )
options[:cpus] ||= 1
options[:memory] ||= 512
options[:computePool] ||= ""
data = connection.instantiate_vapp_template( catalog_item_uri, options ).body
options[:description] ||= ""
options[:tags] ||= []
if template_uri =~ /\/templates\/\d+/
options[:uri] = href + "/action/createVirtualMachine"
options[:customization] ||= :linux
options[:powered_on] ||= false
if options[:ips]
options[:ips] = options[:ips].is_a?(String) ? [options[:ips]] : options[:ips]
else
options[:network_uri] = options[:network_uri].is_a?(String) ? [options[:network_uri]] : options[:network_uri]
options[:network_uri].each do |uri|
index = options[:network_uri].index(uri)
ip = Fog::Compute::Ecloud::IpAddresses.new(:connection => connection, :href => uri).detect { |i| i.host == nil }.name
options[:ips] ||= []
options[:ips][index] = ip
end
end
data = connection.virtual_machine_create_from_template( template_uri, options ).body
else
options[:uri] = href + "/action/importVirtualMachine"
data = connection.virtual_machine_import( template_uri, options ).body
end
object = new(data)
object
end
private
def _resource_entities
if Hash === resource_entities = connection.get_vdc(href).body[:ResourceEntities]
resource_entities[:ResourceEntity]
end
end
def _vapps
resource_entities = _resource_entities
if resource_entities.nil?
[]
else
resource_entities
end
end
end
end
end
end

View file

@ -0,0 +1,20 @@
module Fog
module Compute
class Ecloud
class SshKey < Fog::Ecloud::Model
identity :href
attribute :name, :aliases => :Name
attribute :type, :aliases => :Type
attribute :other_links, :aliases => :Links
attribute :default, :aliases => :Default, :type => :boolean
attribute :finger_print, :aliases => :FingerPrint
def id
href.scan(/\d+/)[0]
end
end
end
end
end

View file

@ -0,0 +1,27 @@
require 'fog/ecloud/models/compute/ssh_key'
module Fog
module Compute
class Ecloud
class SshKeys < Fog::Ecloud::Collection
identity :href
model Fog::Compute::Ecloud::SshKey
def all
data = connection.get_ssh_keys(href).body[:SshKey]
load(data)
end
def get(uri)
if data = connection.get_ssh_key(uri)
new(data.body)
end
rescue Fog::Errors::NotFound
nil
end
end
end
end
end

View file

@ -0,0 +1,16 @@
module Fog
module Compute
class Ecloud
class StorageUsageDetail < Fog::Ecloud::Model
identity :href
attribute :disk_count, :aliases => :DiskCount
attribute :allocated, :aliases => :Allocated
def id
href.scan(/\d+/)[0]
end
end
end
end
end

View file

@ -0,0 +1,27 @@
require 'fog/ecloud/models/compute/storage_usage_detail'
module Fog
module Compute
class Ecloud
class StorageUsageDetailSummary < Fog::Ecloud::Collection
identity :href
model Fog::Compute::Ecloud::StorageUsageDetail
def all
data = connection.get_storage_usage_detail_summary(href).body[:VirtualMachines][:VirtualMachine]
load(data)
end
def get(uri)
if data = connection.get_storage_usage_detail(uri)
new(data.body)
end
rescue Fog::Errors::NotFound
nil
end
end
end
end
end

View file

@ -0,0 +1,29 @@
module Fog
module Compute
class Ecloud
class SupportTicket < Fog::Ecloud::Model
identity :href
attribute :type, :aliases => :Type
attribute :other_links, :aliases => :Links
attribute :date, :aliases => :Date
attribute :status, :aliases => :Status
attribute :category, :aliases => :Category
attribute :detected_by, :aliases => :DetectedBy
attribute :severity, :aliases => :Severity
attribute :device, :aliases => :Device
attribute :classification, :aliases => :Classification
attribute :owner, :aliases => :Owner
attribute :description, :aliases => :Description
attribute :information, :aliases => :Information
attribute :solution, :aliases => :Solution
attribute :history, :aliases => :History
def id
href.scan(/\d+/)[0]
end
end
end
end
end

View file

@ -0,0 +1,27 @@
require 'fog/ecloud/models/compute/support_ticket'
module Fog
module Compute
class Ecloud
class SupportTickets < Fog::Ecloud::Collection
identity :href
model Fog::Compute::Ecloud::SupportTicket
def all
data = connection.get_support_tickets(href).body[:TicketReference]
load(data)
end
def get(uri)
if data = connection.get_support_ticket(uri)
new(data.body)
end
rescue Fog::Errors::NotFound
nil
end
end
end
end
end

View file

@ -0,0 +1,13 @@
module Fog
module Compute
class Ecloud
class Tag < Fog::Ecloud::Model
identity :name
def id
href.scan(/\d+/)[0]
end
end
end
end
end

View file

@ -0,0 +1,27 @@
require 'fog/ecloud/models/compute/tag'
module Fog
module Compute
class Ecloud
class Tags < Fog::Ecloud::Collection
identity :href
model Fog::Compute::Ecloud::Tag
def all
data = connection.get_tags(href).body[:DeviceTag]
load(data)
end
def get(uri)
if data = connection.get_tag(uri)
new(data.body)
end
rescue Fog::Errors::NotFound
nil
end
end
end
end
end

View file

@ -2,18 +2,17 @@ module Fog
module Compute
class Ecloud
class Task < Fog::Ecloud::Model
identity :href
identity :href, :aliases => :Href
ignore_attributes :xmlns, :xmlns_i, :xmlns_xsi, :xmlns_xsd
attribute :status
attribute :type
attribute :result, :aliases => :Result
attribute :owner, :aliases => :Owner
attribute :start_time, :aliases => :startTime, :type => :time
attribute :end_time, :aliases => :endTime, :type => :time
attribute :error, :aliases => :Error
attribute :type , :aliases => :Type
attribute :operation, :aliases => :Operation
attribute :status, :aliases => :Status
attribute :impacted_item, :aliases => :ImpactedItem
attribute :start_time, :aliases => :StartTime
attribute :completed_time, :aliases => :CompletedTime
attribute :notes, :aliases => :Notes
attribute :error_message, :aliases => :ErrorMessage
attribute :initiated_by, :aliases => :InitiatedBy
end
end

View file

@ -3,18 +3,18 @@ require 'fog/ecloud/models/compute/task'
module Fog
module Compute
class Ecloud
class Tasks < Fog::Ecloud::Collection
model Fog::Compute::Ecloud::Task
attribute :href, :aliases => :Href
identity :href
attribute :other_links, :aliases => :Links
attribute :total_count, :aliases => :TotalCount
def all
check_href!
if data = connection.get_task_list(href).body[:Task]
load(data)
end
data = connection.get_tasks(href).body
data = data[:Task] ? data[:Task] : data
load(data)
end
def get(uri)
@ -24,8 +24,8 @@ module Fog
rescue Fog::Errors::NotFound
nil
end
end
end
end
end

View file

@ -0,0 +1,24 @@
module Fog
module Compute
class Ecloud
class Template < Fog::Ecloud::Model
identity :href
attribute :name, :aliases => :Name
attribute :type, :aliases => :Type
attribute :other_links, :aliases => :Links
attribute :operating_system, :aliases => :OperatingSystem
attribute :description, :aliases => :Description
attribute :storage, :aliases => :Storage
attribute :network_adapters, :aliases => :NetworkAdapters
attribute :customization, :aliases => :Customization
attribute :licensed_software, :aliases => :LicensedSoftware
def id
href.scan(/\d+/)[0]
end
end
end
end
end

View file

@ -0,0 +1,40 @@
require 'fog/ecloud/models/compute/template'
module Fog
module Compute
class Ecloud
class Templates < Fog::Ecloud::Collection
identity :href
model Fog::Compute::Ecloud::Template
def all
r_data = []
data = connection.get_templates(href).body[:Families]
data[:Family].is_a?(Hash) ? data = [data[:Family]] : data = data[:Family]
data.each do |d|
d[:Categories][:Category].each do |cat|
cat[:OperatingSystems][:OperatingSystem].is_a?(Hash) ? cat = [cat[:OperatingSystems][:OperatingSystem]] : cat = cat[:OperatingSystems][:OperatingSystem]
cat.each do |os|
os[:Templates][:Template].is_a?(Hash) ? os = [os[:Templates][:Template]] : os = os[:Templates][:Template]
os.each do |template|
r_data << template
end
end
end
end
load(r_data)
end
def get(uri)
if data = connection.get_template(uri)
new(data.body)
end
rescue Fog::Errors::NotFound
nil
end
end
end
end
end

View file

@ -0,0 +1,33 @@
module Fog
module Compute
class Ecloud
class TrustedNetworkGroup < Fog::Ecloud::Model
identity :href
attribute :name, :aliases => :Name
attribute :type, :aliases => :Type
attribute :other_links, :aliases => :Links
attribute :hosts, :aliases => :Hosts
def internet_services
@internet_services ||= Fog::Compute::Ecloud::InternetServices.new(:connection => connection, :href => href)
end
def edit(options)
options[:uri] = href
data = connection.trusted_network_groups_edit(options).body
task = Fog::Compute::Ecloud::Tasks.new(:connection => connection, :href => data[:href])[0]
end
def delete
data = connection.trusted_network_groups_delete(href).body
task = Fog::Compute::Ecloud::Tasks.new(:connection => connection, :href => data[:href])[0]
end
def id
href.scan(/\d+/)[0]
end
end
end
end
end

View file

@ -0,0 +1,28 @@
require 'fog/ecloud/models/compute/trusted_network_group'
module Fog
module Compute
class Ecloud
class TrustedNetworkGroups < Fog::Ecloud::Collection
identity :href
model Fog::Compute::Ecloud::TrustedNetworkGroup
def all
data = connection.get_trusted_network_groups(href).body
data = data[:TrustedNetworkGroup] ? data[:TrustedNetworkGroup] : data
load(data)
end
def get(uri)
if data = connection.get_trusted_network_group(uri)
new(data.body)
end
rescue Fog::Errors::NotFound
nil
end
end
end
end
end

View file

@ -0,0 +1,35 @@
module Fog
module Compute
class Ecloud
class User < Fog::Ecloud::Model
identity :href
attribute :name, :aliases => :Name
attribute :type, :aliases => :Type
attribute :other_links, :aliases => :Links
attribute :first_name, :aliases => :FirstName
attribute :last_name, :aliases => :LastName
attribute :email, :aliases => :Email
attribute :status, :aliases => :Status
attribute :last_login, :aliases => :LastLogin
attribute :multifactor_authentication, :aliases => :MultifactorAuthentication
attribute :is_administrator, :aliases => :IsAdministrator, :type => :boolean
attribute :is_api_user, :aliases => :IsApiUser, :type => :boolean
attribute :is_alert_notification_enabled, :aliases => :IsAlertNotificationEnabled, :type => :boolean
attribute :is_multifactor_authentication_enabled, :aliases => :IsMultifactorAuthenticationEnabled, :type => :boolean
def roles
@roles = Fog::Compute::Ecloud::Roles.new(:connection => connection, :href => "/cloudapi/ecloud/admin/roles/users/#{id}")
end
def api_keys
@api_keys = Fog::Compute::Ecloud::ApiKeys.new(:connection => connection, :href => "/cloudapi/ecloud/admin/apiKeys/users/#{id}")
end
def id
href.scan(/\d+/)[0]
end
end
end
end
end

View file

@ -0,0 +1,27 @@
require 'fog/ecloud/models/compute/user'
module Fog
module Compute
class Ecloud
class Users < Fog::Ecloud::Collection
identity :href
model Fog::Compute::Ecloud::User
def all
data = connection.get_users(href).body[:User]
load(data)
end
def get(uri)
if data = connection.get_user(uri)
new(data.body)
end
rescue Fog::Errors::NotFound
nil
end
end
end
end
end

View file

@ -1,87 +0,0 @@
module Fog
module Compute
class Ecloud
class Vdc < Fog::Ecloud::Model
identity :href
ignore_attributes :xmlns, :xmlns_xsi, :xmlns_xsd
attribute :name
attribute :type
attribute :description, :aliases => :Description
attribute :other_links, :aliases => :Link
attribute :compute_capacity, :aliases => :ComputeCapacity
attribute :storage_capacity, :aliases => :StorageCapacity
attribute :available_networks, :aliases => :AvailableNetworks, :squash => :Network
attribute :resource_entities, :aliases => :ResourceEntities, :squash => :ResourceEntity
attribute :deployed_vm_quota
attribute :instantiated_vm_quota
def public_ips
@public_ips ||= collection_based_on_type("application/vnd.tmrk.ecloud.publicIpsList+xml")
end
def internet_services
@internet_services ||= collection_based_on_type("application/vnd.tmrk.ecloud.internetServicesList+xml")
end
def backup_internet_services
@backup_internet_services ||= collection_based_on_type("application/vnd.tmrk.ecloud.internetServicesList+xml", BackupInternetServices)
end
def networks
@networks ||= Fog::Compute::Ecloud::Networks.
new( :connection => connection,
:href => href )
end
def servers
@servers ||= Fog::Compute::Ecloud::Servers.
new( :connection => connection,
:href => href )
end
def tasks
@tasks ||= Fog::Compute::Ecloud::Tasks.
new( :connection => connection,
:href => href + "/tasksList" )
end
def catalog
@catalog ||= collection_based_on_type("application/vnd.vmware.vcloud.catalog+xml")
end
def firewall_acls
@firewall_acls ||= collection_based_on_type("application/vnd.tmrk.ecloud.firewallAclsList+xml")
end
def compute_pools
@compute_pools ||= Fog::Compute::Ecloud::ComputePools.
new( :connection => connection,
:href => href + "/computePools" )
end
private
def collection_based_on_type(type, klass = nil)
load_unless_loaded!
if link = other_links.detect { |link| link[:type] == type }
case type
when "application/vnd.tmrk.ecloud.publicIpsList+xml"
Fog::Compute::Ecloud::PublicIps
when "application/vnd.tmrk.ecloud.internetServicesList+xml"
klass || Fog::Compute::Ecloud::InternetServices
when "application/vnd.vmware.vcloud.catalog+xml"
Fog::Compute::Ecloud::Catalog
when "application/vnd.tmrk.ecloud.firewallAclsList+xml"
Fog::Compute::Ecloud::FirewallAcls
end.new( :connection => connection, :href => link[:href] )
else
[ ]
end
end
end
end
end
end

View file

@ -1,40 +0,0 @@
require 'fog/ecloud/models/compute/vdc'
module Fog
module Compute
class Ecloud
class Vdcs < Collection
model Fog::Compute::Ecloud::Vdc
undef_method :create
def all
data = connection.get_organization(organization_uri).body[:Link].select { |link| link[:type] == "application/vnd.vmware.vcloud.vdc+xml" }
data.each { |link| link.delete_if { |key, value| [:rel].include?(key) } }
load(data)
end
def get(uri)
if data = connection.get_vdc(uri)
new(data.body)
end
rescue Fog::Errors::NotFound
nil
end
def organization_uri
@organizatio_uri ||= connection.default_organization_uri
end
private
def organization_uri=(new_organization_uri)
@organization_uri = new_organization_uri
end
end
end
end
end

View file

@ -1,109 +0,0 @@
module Fog
module Compute
class Ecloud
module Shared
def validate_backup_internet_service_data(service_data, configure=false)
required_opts = [:name, :protocol, :description, :enabled]
if configure
required_opts + [ :id, :href, :timeout ]
end
unless required_opts.all? { |opt| service_data.has_key?(opt) }
raise ArgumentError.new("Required Backup Internet Service data missing: #{(required_opts - service_data.keys).map(&:inspect).join(", ")}")
end
end
end
class Real
include Shared
def add_backup_internet_service(internet_services_uri, service_data)
validate_backup_internet_service_data(service_data)
if monitor = service_data[:monitor]
validate_internet_service_monitor(monitor)
ensure_monitor_defaults!(monitor)
end
request(
:body => generate_backup_internet_service_request(service_data),
:expects => 200,
:headers => {'Content-Type' => 'application/xml'},
:method => 'POST',
:uri => internet_services_uri,
:parse => true
)
end
private
def generate_backup_internet_service_request(service_data)
builder = Builder::XmlMarkup.new
builder.CreateBackupInternetServiceRequest("xmlns" => "urn:tmrk:eCloudExtensions-2.5") {
builder.Name(service_data[:name])
builder.Protocol(service_data[:protocol])
builder.Enabled(service_data[:enabled])
builder.Description(service_data[:description])
builder.RedirectURL(service_data[:redirect_url])
if monitor = service_data[:monitor]
generate_monitor_section(builder,monitor)
end
}
end
end
class Mock
include Shared
#
# Based on
# http://support.theenterprisecloud.com/kb/default.asp?id=729&Lang=1&SID=
# and many tears shed.
#
def add_backup_internet_service(internet_services_uri, service_data)
validate_backup_internet_service_data(service_data)
internet_services_uri = ensure_unparsed(internet_services_uri)
if vdc_internet_service_collection = mock_data.vdc_internet_service_collection_from_href(internet_services_uri)
new_backup_internet_service = MockBackupInternetService.new(service_data, vdc_internet_service_collection.backup_internet_services)
vdc_internet_service_collection.backup_internet_services << new_backup_internet_service
xml = generate_backup_internet_service_added_response(new_backup_internet_service)
mock_it 200, xml, {'Content-Type' => 'application/vnd.tmrk.ecloud.internetService+xml'}
else
mock_error 200, "401 Unauthorized"
end
end
private
def generate_backup_internet_service_added_response(new_backup_internet_service)
builder = Builder::XmlMarkup.new
builder.InternetService("xmlns" => "urn:tmrk:eCloudExtensions-2.5", "xmlns:i" => "http://www.w3.org/2001/XMLSchema-instance") {
builder.Id new_backup_internet_service.object_id
builder.Href new_backup_internet_service.href
builder.Name new_backup_internet_service.name
# so broken
builder.PublicIpAddress do
builder.Id -2147483648
builder.Id "http://totally.invalid/1234"
builder.Name
end
builder.Port new_backup_internet_service.port
builder.Protocol new_backup_internet_service.protocol
builder.Enabled new_backup_internet_service.enabled
builder.Timeout new_backup_internet_service.timeout
builder.Description new_backup_internet_service.description
builder.RedirectURL new_backup_internet_service.redirect_url
builder.Monitor "i:nil" => true
# so broken
builder.IsBackupService false
builder.BackupService "i:nil" => true
builder.BackupOf "i:nil" => true
}
end
end
end
end
end

View file

@ -1,149 +0,0 @@
module Fog
module Compute
class Ecloud
module Shared
def validate_internet_service_monitor(monitor)
#FIXME: Refactor this type of function into something generic
unless ['Disabled','HTTP','ECV'].include?(monitor[:type])
raise ArgumentError.new("Supported monitor types are: ECV & HTTP")
end
required_opts = case monitor[:type]
when "Disabled"
[:type, :is_enabled]
else
[:type, :url_send_string, :http_headers, :receive_string, :is_enabled]
end
unless required_opts.all? { |opt| monitor.has_key?(opt) && monitor[opt] }
raise ArgumentError.new("Required Monitor data missing: #{(required_opts - monitor.keys).map(&:inspect).join(", ")}")
end
case monitor[:type]
when "HTTP", "ECV"
unless monitor[:http_headers].is_a?(Array) || monitor[:http_headers].is_a?(String)
raise ArgumentError.new("Monitor :http_headers must be a String or Array")
end
end
unless [true, false, "true", "false"].include?(monitor[:is_enabled])
raise ArgumentError.new("Monitor :is_enabled must be true or false")
end
end
def validate_internet_service_data(service_data, configure=false)
required_opts = [:name, :protocol, :port, :description, :enabled]
if configure
required_opts + [ :id, :href, :timeout ]
end
unless required_opts.all? { |opt| service_data.has_key?(opt) }
raise ArgumentError.new("Required Internet Service data missing: #{(required_opts - service_data.keys).map(&:inspect).join(", ")}")
end
end
def ensure_monitor_defaults!(monitor)
if monitor[:http_headers].is_a?(String)
monitor[:http_headers] = [ monitor[:http_headers] ]
end
unless monitor[:retries]
monitor[:retries] = 3
end
unless monitor[:response_timeout]
monitor[:response_timeout] = 2
end
unless monitor[:down_time]
monitor[:down_time] = 30
end
unless monitor[:interval]
monitor[:interval] = 5
end
end
end
class Real
include Shared
def add_internet_service(internet_services_uri, service_data)
validate_internet_service_data(service_data)
if monitor = service_data[:monitor]
validate_internet_service_monitor(monitor)
ensure_monitor_defaults!(monitor)
end
request(
:body => generate_internet_service_request(service_data),
:expects => 200,
:headers => {'Content-Type' => 'application/vnd.tmrk.ecloud.internetService+xml'},
:method => 'POST',
:uri => internet_services_uri,
:parse => true
)
end
private
def generate_internet_service_request(service_data)
builder = Builder::XmlMarkup.new
builder.CreateInternetServiceRequest(ecloud_xmlns) {
builder.Name(service_data[:name])
builder.Protocol(service_data[:protocol])
builder.Port(service_data[:port])
builder.Enabled(service_data[:enabled])
builder.Description(service_data[:description])
builder.RedirectURL(service_data[:redirect_url])
if monitor = service_data[:monitor]
generate_monitor_section(builder,monitor)
end
}
end
def generate_monitor_section(builder, monitor)
builder.Monitor {
builder.MonitorType(monitor[:type])
case monitor[:type]
when "ECV","HTTP"
builder.UrlSendString(monitor[:url_send_string])
builder.HttpHeader(monitor[:http_headers].join("\n"))
builder.ReceiveString(monitor[:receive_string])
builder.Interval(monitor[:interval])
builder.ResponseTimeOut(monitor[:response_timeout])
builder.DownTime(monitor[:downtime])
builder.Retries(monitor[:retries])
end
builder.IsEnabled(monitor[:is_enabled])
}
end
end
class Mock
include Shared
#
# Based on
# http://support.theenterprisecloud.com/kb/default.asp?id=561&Lang=1&SID=
#
def add_internet_service(internet_services_uri, service_data)
validate_internet_service_data(service_data)
internet_services_uri = ensure_unparsed(internet_services_uri)
if public_ip_internet_service_collection = mock_data.public_ip_internet_service_collection_from_href(internet_services_uri)
new_public_ip_internet_service = MockPublicIpInternetService.new(service_data, public_ip_internet_service_collection)
public_ip_internet_service_collection.items << new_public_ip_internet_service
xml = generate_internet_service(Builder::XmlMarkup.new, new_public_ip_internet_service, true)
mock_it 200, xml, {'Content-Type' => 'application/vnd.tmrk.ecloud.internetService+xml'}
else
mock_error 200, "401 Unauthorized"
end
end
end
end
end
end

View file

@ -1,62 +0,0 @@
module Fog
module Compute
class Ecloud
module Shared
private
def generate_node_request(node_data)
builder = Builder::XmlMarkup.new
builder.CreateNodeServiceRequest(ecloud_xmlns) {
builder.IpAddress(node_data[:ip_address])
builder.Name(node_data[:name])
builder.Port(node_data[:port])
builder.Enabled(node_data[:enabled])
builder.Description(node_data[:description])
}
end
def validate_node_data(node_data, configure=false)
valid_opts = [:name, :port, :enabled, :description, :ip_address]
if configure
valid_opts.delete_if { |opt| ![:name, :enabled, :description].include?(opt) }
end
unless valid_opts.all? { |opt| node_data.has_key?(opt) }
raise ArgumentError.new("Required data missing: #{(valid_opts - node_data.keys).map(&:inspect).join(", ")}")
end
end
end
class Real
include Shared
def add_node(nodes_uri, node_data)
validate_node_data(node_data)
request(
:body => generate_node_request(node_data),
:expects => 200,
:headers => {'Content-Type' => 'application/vnd.tmrk.ecloud.nodeService+xml'},
:method => 'POST',
:uri => nodes_uri,
:parse => true
)
end
end
class Mock
include Shared
def add_node(nodes_uri, node_data)
validate_node_data(node_data)
if node_collection = mock_data.public_ip_internet_service_node_collection_from_href(ensure_unparsed(nodes_uri))
new_node = MockPublicIpInternetServiceNode.new(node_data, node_collection)
node_collection.items << new_node
mock_it 200, mock_node_service_response(new_node), { 'Content-Type' => 'application/vnd.tmrk.ecloud.nodeService+xml' }
else
mock_error 200, "401 Unauthorized"
end
end
end
end
end
end

View file

@ -0,0 +1,9 @@
module Fog
module Compute
class Ecloud
class Real
basic_request :admin_disable_support_access, 204, 'POST'
end
end
end
end

View file

@ -0,0 +1,34 @@
module Fog
module Compute
class Ecloud
class Real
def authentication_levels_edit(data)
validate_data([:basic, :sha1, :sha256, :sha512], data)
body = build_authentication_levels_edit(data)
request(
:expects => 202,
:method => 'PUT',
:headers => {},
:body => body,
:uri => data[:uri],
:parse => true
)
end
private
def build_authentication_levels_edit(data)
xml = Builder::XmlMarkup.new
xml.AuthenticationLevels do
xml.BasicEnabled data[:basic]
xml.SHA1Enabled data[:sha1]
xml.SHA256Enabled data[:sha256]
xml.SHA512Enabled data[:sha512]
end
end
end
end
end
end

Some files were not shown because too many files have changed in this diff Show more