mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
working toward more consistent/simpler collection/bin management
This commit is contained in:
parent
c96614a11d
commit
a3af5d7800
22 changed files with 302 additions and 282 deletions
|
@ -23,40 +23,20 @@ module AWS
|
|||
@@connections[service]
|
||||
end
|
||||
|
||||
def addresses
|
||||
self[:ec2].addresses
|
||||
for collection in Fog::AWS::EC2.collections
|
||||
module_eval <<-EOS, __FILE__, __LINE__
|
||||
def #{collection}
|
||||
self[:ec2].#{collection}
|
||||
end
|
||||
EOS
|
||||
end
|
||||
|
||||
def directories
|
||||
self[:s3].directories
|
||||
end
|
||||
|
||||
def flavors
|
||||
self[:ec2].flavors
|
||||
end
|
||||
|
||||
def images
|
||||
self[:ec2].images
|
||||
end
|
||||
|
||||
def servers
|
||||
self[:ec2].servers
|
||||
end
|
||||
|
||||
def key_pairs
|
||||
self[:ec2].key_pairs
|
||||
end
|
||||
|
||||
def security_groups
|
||||
self[:ec2].security_groups
|
||||
end
|
||||
|
||||
def snapshots
|
||||
self[:ec2].snapshots
|
||||
end
|
||||
|
||||
def volumes
|
||||
self[:ec2].volumes
|
||||
for collection in Fog::AWS::S3.collections
|
||||
module_eval <<-EOS, __FILE__, __LINE__
|
||||
def #{collection}
|
||||
self[:s3].#{collection}
|
||||
end
|
||||
EOS
|
||||
end
|
||||
|
||||
else
|
||||
|
@ -67,4 +47,5 @@ module AWS
|
|||
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -6,63 +6,63 @@ module Fog
|
|||
requires :aws_access_key_id, :aws_secret_access_key
|
||||
|
||||
model_path 'fog/aws/models/ec2'
|
||||
model 'address'
|
||||
model 'addresses'
|
||||
model 'flavor'
|
||||
model 'flavors'
|
||||
model 'image'
|
||||
model 'images'
|
||||
model 'key_pair'
|
||||
model 'key_pairs'
|
||||
model 'security_group'
|
||||
model 'security_groups'
|
||||
model 'server'
|
||||
model 'servers'
|
||||
model 'snapshot'
|
||||
model 'snapshots'
|
||||
model 'volume'
|
||||
model 'volumes'
|
||||
model :address
|
||||
collection :addresses
|
||||
model :flavor
|
||||
collection :flavors
|
||||
model :image
|
||||
collection :images
|
||||
model :key_pair
|
||||
collection :key_pairs
|
||||
model :security_group
|
||||
collection :security_groups
|
||||
model :server
|
||||
collection :servers
|
||||
model :snapshot
|
||||
collection :snapshots
|
||||
model :volume
|
||||
collection :volumes
|
||||
|
||||
require 'fog/aws/parsers/ec2/basic'
|
||||
|
||||
request_path 'fog/aws/requests/ec2'
|
||||
request 'allocate_address'
|
||||
request 'associate_address'
|
||||
request 'attach_volume'
|
||||
request 'authorize_security_group_ingress'
|
||||
request 'create_key_pair'
|
||||
request 'create_security_group'
|
||||
request 'create_snapshot'
|
||||
request 'create_image'
|
||||
request 'create_volume'
|
||||
request 'delete_key_pair'
|
||||
request 'delete_security_group'
|
||||
request 'delete_snapshot'
|
||||
request 'delete_volume'
|
||||
request 'deregister_image'
|
||||
request 'describe_addresses'
|
||||
request 'describe_availability_zones'
|
||||
request 'describe_images'
|
||||
request 'describe_instances'
|
||||
request 'describe_reserved_instances'
|
||||
request 'describe_key_pairs'
|
||||
request 'describe_regions'
|
||||
request 'describe_security_groups'
|
||||
request 'describe_snapshots'
|
||||
request 'describe_volumes'
|
||||
request 'detach_volume'
|
||||
request 'disassociate_address'
|
||||
request 'get_console_output'
|
||||
request 'modify_image_attributes'
|
||||
request 'modify_snapshot_attribute'
|
||||
request 'reboot_instances'
|
||||
request 'release_address'
|
||||
request 'register_image'
|
||||
request 'revoke_security_group_ingress'
|
||||
request 'run_instances'
|
||||
request 'terminate_instances'
|
||||
request 'start_instances'
|
||||
request 'stop_instances'
|
||||
request :allocate_address
|
||||
request :associate_address
|
||||
request :attach_volume
|
||||
request :authorize_security_group_ingress
|
||||
request :create_key_pair
|
||||
request :create_security_group
|
||||
request :create_snapshot
|
||||
request :create_image
|
||||
request :create_volume
|
||||
request :delete_key_pair
|
||||
request :delete_security_group
|
||||
request :delete_snapshot
|
||||
request :delete_volume
|
||||
request :deregister_image
|
||||
request :describe_addresses
|
||||
request :describe_availability_zones
|
||||
request :describe_images
|
||||
request :describe_instances
|
||||
request :describe_reserved_instances
|
||||
request :describe_key_pairs
|
||||
request :describe_regions
|
||||
request :describe_security_groups
|
||||
request :describe_snapshots
|
||||
request :describe_volumes
|
||||
request :detach_volume
|
||||
request :disassociate_address
|
||||
request :get_console_output
|
||||
request :modify_image_attributes
|
||||
request :modify_snapshot_attribute
|
||||
request :reboot_instances
|
||||
request :release_address
|
||||
request :register_image
|
||||
request :revoke_security_group_ingress
|
||||
request :run_instances
|
||||
request :terminate_instances
|
||||
request :start_instances
|
||||
request :stop_instances
|
||||
|
||||
class Mock
|
||||
include Collections
|
||||
|
|
|
@ -6,14 +6,14 @@ module Fog
|
|||
requires :aws_access_key_id, :aws_secret_access_key
|
||||
|
||||
request_path 'fog/aws/requests/elb'
|
||||
request 'create_load_balancer'
|
||||
request 'delete_load_balancer'
|
||||
request 'deregister_instances_from_load_balancer'
|
||||
request 'describe_instance_health'
|
||||
request 'describe_load_balancers'
|
||||
request 'disable_availability_zones_for_load_balancer'
|
||||
request 'enable_availability_zones_for_load_balancer'
|
||||
request 'register_instances_with_load_balancer'
|
||||
request :create_load_balancer
|
||||
request :delete_load_balancer
|
||||
request :deregister_instances_from_load_balancer
|
||||
request :describe_instance_health
|
||||
request :describe_load_balancers
|
||||
request :disable_availability_zones_for_load_balancer
|
||||
request :enable_availability_zones_for_load_balancer
|
||||
request :register_instances_with_load_balancer
|
||||
|
||||
class Mock
|
||||
include Collections
|
||||
|
|
|
@ -5,6 +5,12 @@ module Fog
|
|||
module AWS
|
||||
module S3
|
||||
|
||||
module Collections
|
||||
def files
|
||||
Fog::AWS::S3::Files.new(:connection => self)
|
||||
end
|
||||
end
|
||||
|
||||
class Files < Fog::Collection
|
||||
|
||||
attribute :delimiter, 'Delimiter'
|
||||
|
@ -17,6 +23,7 @@ module Fog
|
|||
model Fog::AWS::S3::File
|
||||
|
||||
def all(options = {})
|
||||
requires :directory
|
||||
options = {
|
||||
'delimiter' => @delimiter,
|
||||
'marker' => @marker,
|
||||
|
@ -38,6 +45,7 @@ module Fog
|
|||
end
|
||||
|
||||
def get(key, options = {}, &block)
|
||||
requires :directory
|
||||
data = connection.get_object(directory.key, key, options, &block)
|
||||
file_data = {
|
||||
:body => data.body,
|
||||
|
@ -54,10 +62,12 @@ module Fog
|
|||
end
|
||||
|
||||
def get_url(key, expires)
|
||||
requires :directory
|
||||
connection.get_object_url(directory.key, key, expires)
|
||||
end
|
||||
|
||||
def head(key, options = {})
|
||||
requires :directory
|
||||
data = connection.head_object(directory.key, key, options)
|
||||
file_data = {
|
||||
:key => key
|
||||
|
@ -73,6 +83,7 @@ module Fog
|
|||
end
|
||||
|
||||
def new(attributes = {})
|
||||
requires :directory
|
||||
super({ :directory => directory }.merge!(attributes))
|
||||
end
|
||||
|
||||
|
|
|
@ -6,35 +6,35 @@ module Fog
|
|||
requires :aws_access_key_id, :aws_secret_access_key
|
||||
|
||||
model_path 'fog/aws/models/s3'
|
||||
model 'directories'
|
||||
model 'directory'
|
||||
model 'files'
|
||||
model 'file'
|
||||
collection :directories
|
||||
model :directory
|
||||
collection :files
|
||||
model :file
|
||||
|
||||
request_path 'fog/aws/requests/s3'
|
||||
request 'copy_object'
|
||||
request 'delete_bucket'
|
||||
request 'delete_object'
|
||||
request 'get_bucket'
|
||||
request 'get_bucket_acl'
|
||||
request 'get_bucket_location'
|
||||
request 'get_bucket_logging'
|
||||
request 'get_bucket_object_versions'
|
||||
request 'get_bucket_versioning'
|
||||
request 'get_object'
|
||||
request 'get_object_acl'
|
||||
request 'get_object_torrent'
|
||||
request 'get_object_url'
|
||||
request 'get_request_payment'
|
||||
request 'get_service'
|
||||
request 'head_object'
|
||||
request 'put_bucket'
|
||||
request 'put_bucket_acl'
|
||||
request 'put_bucket_logging'
|
||||
request 'put_bucket_versioning'
|
||||
request 'put_object'
|
||||
request 'put_object_url'
|
||||
request 'put_request_payment'
|
||||
request :copy_object
|
||||
request :delete_bucket
|
||||
request :delete_object
|
||||
request :get_bucket
|
||||
request :get_bucket_acl
|
||||
request :get_bucket_location
|
||||
request :get_bucket_logging
|
||||
request :get_bucket_object_versions
|
||||
request :get_bucket_versioning
|
||||
request :get_object
|
||||
request :get_object_acl
|
||||
request :get_object_torrent
|
||||
request :get_object_url
|
||||
request :get_request_payment
|
||||
request :get_service
|
||||
request :head_object
|
||||
request :put_bucket
|
||||
request :put_bucket_acl
|
||||
request :put_bucket_logging
|
||||
request :put_bucket_versioning
|
||||
request :put_object
|
||||
request :put_object_url
|
||||
request :put_request_payment
|
||||
|
||||
module Utils
|
||||
|
||||
|
|
|
@ -6,15 +6,15 @@ module Fog
|
|||
requires :aws_access_key_id, :aws_secret_access_key
|
||||
|
||||
request_path 'fog/aws/requests/simpledb'
|
||||
request 'batch_put_attributes'
|
||||
request 'create_domain'
|
||||
request 'delete_attributes'
|
||||
request 'delete_domain'
|
||||
request 'domain_metadata'
|
||||
request 'get_attributes'
|
||||
request 'list_domains'
|
||||
request 'put_attributes'
|
||||
request 'select'
|
||||
request :batch_put_attributes
|
||||
request :create_domain
|
||||
request :delete_attributes
|
||||
request :delete_domain
|
||||
request :domain_metadata
|
||||
request :get_attributes
|
||||
request :list_domains
|
||||
request :put_attributes
|
||||
request :select
|
||||
|
||||
class Mock
|
||||
include Collections
|
||||
|
|
|
@ -5,22 +5,23 @@ module Fog
|
|||
requires :bluebox_api_key, :bluebox_customer_id
|
||||
|
||||
model_path 'fog/bluebox/models'
|
||||
model 'flavor'
|
||||
model 'flavors'
|
||||
model 'images'
|
||||
model 'server'
|
||||
model 'servers'
|
||||
model :flavor
|
||||
collection :flavors
|
||||
model :image
|
||||
collection :images
|
||||
model :server
|
||||
collection :servers
|
||||
|
||||
request_path 'fog/bluebox/requests'
|
||||
request 'create_block'
|
||||
request 'destroy_block'
|
||||
request 'get_block'
|
||||
request 'get_blocks'
|
||||
request 'get_product'
|
||||
request 'get_products'
|
||||
request 'get_template'
|
||||
request 'get_templates'
|
||||
request 'reboot_block'
|
||||
request :create_block
|
||||
request :destroy_block
|
||||
request :get_block
|
||||
request :get_blocks
|
||||
request :get_product
|
||||
request :get_products
|
||||
request :get_template
|
||||
request :get_templates
|
||||
request :reboot_block
|
||||
|
||||
class Mock
|
||||
include Collections
|
||||
|
|
|
@ -17,16 +17,12 @@ module Bluebox
|
|||
@@connections[service]
|
||||
end
|
||||
|
||||
def flavors
|
||||
self[:blocks].flavors
|
||||
end
|
||||
|
||||
def images
|
||||
self[:blocks].images
|
||||
end
|
||||
|
||||
def servers
|
||||
self[:blocks].servers
|
||||
for collection in Fog::Bluebox.collections
|
||||
module_eval <<-EOS, __FILE__, __LINE__
|
||||
def #{collection}
|
||||
self[:blocks].#{collection}
|
||||
end
|
||||
EOS
|
||||
end
|
||||
|
||||
else
|
||||
|
|
|
@ -8,15 +8,15 @@ module Fog
|
|||
model_path 'fog/go_grid/models'
|
||||
|
||||
request_path 'fog/go_grid/requests'
|
||||
request 'common_lookup_list'
|
||||
request 'grid_image_list'
|
||||
request 'grid_ip_list'
|
||||
request 'grid_loadbalancer_list'
|
||||
request 'grid_server_add'
|
||||
request 'grid_server_delete'
|
||||
request 'grid_server_get'
|
||||
request 'grid_server_list'
|
||||
request 'grid_server_power'
|
||||
request :common_lookup_list
|
||||
request :grid_image_list
|
||||
request :grid_ip_list
|
||||
request :grid_loadbalancer_list
|
||||
request :grid_server_add
|
||||
request :grid_server_delete
|
||||
request :grid_server_get
|
||||
request :grid_server_list
|
||||
request :grid_server_power
|
||||
|
||||
class Mock
|
||||
include Collections
|
||||
|
|
|
@ -7,15 +7,15 @@ module Fog
|
|||
model_path 'fog/linode/models'
|
||||
|
||||
request_path 'fog/linode/requests'
|
||||
request 'avail_datacenters'
|
||||
request 'avail_distributions'
|
||||
request 'avail_kernels'
|
||||
request 'avail_linodeplans'
|
||||
request 'avail_stackscripts'
|
||||
request 'linode_create'
|
||||
request 'linode_delete'
|
||||
request 'linode_list'
|
||||
request 'linode_reboot'
|
||||
request :avail_datacenters
|
||||
request :avail_distributions
|
||||
request :avail_kernels
|
||||
request :avail_linodeplans
|
||||
request :avail_stackscripts
|
||||
request :linode_create
|
||||
request :linode_delete
|
||||
request :linode_list
|
||||
request :linode_reboot
|
||||
|
||||
class Mock
|
||||
include Collections
|
||||
|
|
|
@ -5,10 +5,10 @@ module Fog
|
|||
requires :local_root
|
||||
|
||||
model_path 'fog/local/models'
|
||||
model 'directories'
|
||||
model 'directory'
|
||||
model 'file'
|
||||
model 'files'
|
||||
collection :directories
|
||||
model :directory
|
||||
model :file
|
||||
collection :files
|
||||
|
||||
class Mock
|
||||
include Collections
|
||||
|
|
|
@ -16,8 +16,12 @@ module Local
|
|||
@@connections[service]
|
||||
end
|
||||
|
||||
def directories
|
||||
self[:files].directories
|
||||
for collection in Fog::Local.collections
|
||||
module_eval <<-EOS, __FILE__, __LINE__
|
||||
def #{collection}
|
||||
self[:files].#{collection}
|
||||
end
|
||||
EOS
|
||||
end
|
||||
|
||||
else
|
||||
|
|
|
@ -4,11 +4,20 @@ require 'fog/local/models/file'
|
|||
module Fog
|
||||
module Local
|
||||
|
||||
module Collections
|
||||
def files
|
||||
Fog::Local::Files.new(:connection => self)
|
||||
end
|
||||
end
|
||||
|
||||
class Files < Fog::Collection
|
||||
|
||||
attribute :directory
|
||||
|
||||
model Fog::Local::File
|
||||
|
||||
def all
|
||||
requires :directory
|
||||
if directory.collection.get(directory.key)
|
||||
data = Dir.entries(connection.path_to(directory.key)).select do |key|
|
||||
key[0...1] != '.' && !::File.directory?(connection.path_to(key))
|
||||
|
@ -26,11 +35,8 @@ module Fog
|
|||
end
|
||||
end
|
||||
|
||||
def directory
|
||||
@directory
|
||||
end
|
||||
|
||||
def get(key, &block)
|
||||
requires :directory
|
||||
path = file_path(key)
|
||||
if ::File.exists?(path)
|
||||
data = {
|
||||
|
@ -56,15 +62,12 @@ module Fog
|
|||
end
|
||||
|
||||
def new(attributes = {})
|
||||
requires :directory
|
||||
super({ :directory => directory }.merge!(attributes))
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def directory=(new_directory)
|
||||
@directory = new_directory
|
||||
end
|
||||
|
||||
def file_path(key)
|
||||
connection.path_to(::File.join(directory.key, key))
|
||||
end
|
||||
|
|
|
@ -10,13 +10,13 @@ module Fog
|
|||
model_path 'fog/new_servers/models'
|
||||
|
||||
request_path 'fog/new_servers/requests'
|
||||
request 'add_server'
|
||||
request 'cancel_server'
|
||||
request 'get_server'
|
||||
request 'list_images'
|
||||
request 'list_plans'
|
||||
request 'list_servers'
|
||||
request 'reboot_server'
|
||||
request :add_server
|
||||
request :cancel_server
|
||||
request :get_server
|
||||
request :list_images
|
||||
request :list_plans
|
||||
request :list_servers
|
||||
request :reboot_server
|
||||
|
||||
class Mock
|
||||
include Collections
|
||||
|
|
|
@ -18,22 +18,22 @@ module Rackspace
|
|||
@@connections[service]
|
||||
end
|
||||
|
||||
def directories
|
||||
self[:files].directories
|
||||
for collection in Fog::Rackspace::Files.collections
|
||||
module_eval <<-EOS, __FILE__, __LINE__
|
||||
def #{collection}
|
||||
self[:files].#{collection}
|
||||
end
|
||||
EOS
|
||||
end
|
||||
|
||||
def flavors
|
||||
self[:servers].flavors
|
||||
for collection in Fog::Rackspace::Servers.collections
|
||||
module_eval <<-EOS, __FILE__, __LINE__
|
||||
def #{collection}
|
||||
self[:servers].#{collection}
|
||||
end
|
||||
EOS
|
||||
end
|
||||
|
||||
def images
|
||||
self[:servers].images
|
||||
end
|
||||
|
||||
def servers
|
||||
self[:servers].servers
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
def initialized?
|
||||
|
|
|
@ -6,22 +6,22 @@ module Fog
|
|||
requires :rackspace_api_key, :rackspace_username
|
||||
|
||||
model_path 'fog/rackspace/models/files'
|
||||
model 'directory'
|
||||
model 'directories'
|
||||
model 'file'
|
||||
model 'files'
|
||||
model :directory
|
||||
collection :directories
|
||||
model :file
|
||||
collection :files
|
||||
|
||||
request_path 'fog/rackspace/requests/files'
|
||||
request 'delete_container'
|
||||
request 'delete_object'
|
||||
request 'get_container'
|
||||
request 'get_containers'
|
||||
request 'get_object'
|
||||
request 'head_container'
|
||||
request 'head_containers'
|
||||
request 'head_object'
|
||||
request 'put_container'
|
||||
request 'put_object'
|
||||
request :delete_container
|
||||
request :delete_object
|
||||
request :get_container
|
||||
request :get_containers
|
||||
request :get_object
|
||||
request :head_container
|
||||
request :head_containers
|
||||
request :head_object
|
||||
request :put_container
|
||||
request :put_object
|
||||
|
||||
module Utils
|
||||
|
||||
|
|
|
@ -5,8 +5,15 @@ module Fog
|
|||
module Rackspace
|
||||
module Files
|
||||
|
||||
module Collections
|
||||
def files
|
||||
Fog::Rackspace::Files::Files.new(:connection => self)
|
||||
end
|
||||
end
|
||||
|
||||
class Files < Fog::Collection
|
||||
|
||||
attribute :directory
|
||||
attribute :limit
|
||||
attribute :marker
|
||||
attribute :path
|
||||
|
@ -15,6 +22,7 @@ module Fog
|
|||
model Fog::Rackspace::Files::File
|
||||
|
||||
def all(options = {})
|
||||
requires :directory
|
||||
merge_attributes(options)
|
||||
parent = directory.collection.get(
|
||||
directory.key,
|
||||
|
@ -27,11 +35,8 @@ module Fog
|
|||
end
|
||||
end
|
||||
|
||||
def directory
|
||||
@directory
|
||||
end
|
||||
|
||||
def get(key, options = {}, &block)
|
||||
requires :directory
|
||||
options = {
|
||||
'limit' => @limit,
|
||||
'marker' => @marker,
|
||||
|
@ -54,10 +59,12 @@ module Fog
|
|||
end
|
||||
|
||||
def get_url(key, expires)
|
||||
requires :directory
|
||||
connection.get_object_url(directory.name, key, expires)
|
||||
end
|
||||
|
||||
def head(key, options = {})
|
||||
requires :directory
|
||||
data = connection.head_object(directory.name, key, options)
|
||||
file_data = { :key => key }
|
||||
for key, value in data.headers
|
||||
|
@ -71,15 +78,10 @@ module Fog
|
|||
end
|
||||
|
||||
def new(attributes = {})
|
||||
requires :directory
|
||||
super({ :directory => directory }.merge!(attributes))
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def directory=(new_directory)
|
||||
@directory = new_directory
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -6,32 +6,32 @@ module Fog
|
|||
requires :rackspace_api_key, :rackspace_username
|
||||
|
||||
model_path 'fog/rackspace/models/servers'
|
||||
model 'flavor'
|
||||
model 'flavors'
|
||||
model 'image'
|
||||
model 'images'
|
||||
model 'server'
|
||||
model 'servers'
|
||||
model :flavor
|
||||
collection :flavors
|
||||
model :image
|
||||
collection :images
|
||||
model :server
|
||||
collection :servers
|
||||
|
||||
request_path 'fog/rackspace/requests/servers'
|
||||
request 'create_image'
|
||||
request 'create_server'
|
||||
request 'delete_image'
|
||||
request 'delete_server'
|
||||
request 'get_flavor_details'
|
||||
request 'get_image_details'
|
||||
request 'get_server_details'
|
||||
request 'list_addresses'
|
||||
request 'list_private_addresses'
|
||||
request 'list_public_addresses'
|
||||
request 'list_flavors'
|
||||
request 'list_flavors_detail'
|
||||
request 'list_images'
|
||||
request 'list_images_detail'
|
||||
request 'list_servers'
|
||||
request 'list_servers_detail'
|
||||
request 'reboot_server'
|
||||
request 'update_server'
|
||||
request :create_image
|
||||
request :create_server
|
||||
request :delete_image
|
||||
request :delete_server
|
||||
request :get_flavor_details
|
||||
request :get_image_details
|
||||
request :get_server_details
|
||||
request :list_addresses
|
||||
request :list_private_addresses
|
||||
request :list_public_addresses
|
||||
request :list_flavors
|
||||
request :list_flavors_detail
|
||||
request :list_images
|
||||
request :list_images_detail
|
||||
request :list_servers
|
||||
request :list_servers_detail
|
||||
request :reboot_server
|
||||
request :update_server
|
||||
|
||||
class Mock
|
||||
include Collections
|
||||
|
|
|
@ -7,8 +7,6 @@ module Fog
|
|||
class Error < Fog::Errors::Error; end
|
||||
class NotFound < Fog::Errors::NotFound; end
|
||||
|
||||
module Collections; end
|
||||
|
||||
def self.new(options={})
|
||||
if Fog.bin
|
||||
default_credentials = Fog.credentials.reject {|key, value| !requirements.include?(key)}
|
||||
|
@ -28,6 +26,9 @@ module Fog
|
|||
end
|
||||
|
||||
unless @required
|
||||
for collection in collections
|
||||
require [@model_path, collection].join('/')
|
||||
end
|
||||
for model in models
|
||||
require [@model_path, model].join('/')
|
||||
end
|
||||
|
@ -48,6 +49,23 @@ module Fog
|
|||
end
|
||||
instance
|
||||
end
|
||||
|
||||
module Collections
|
||||
|
||||
def collections
|
||||
service.collections
|
||||
end
|
||||
|
||||
def requests
|
||||
service.requests
|
||||
end
|
||||
|
||||
def service
|
||||
@service ||= eval(self.class.to_s.split('::')[0...-1].join('::'))
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
EOS
|
||||
end
|
||||
|
||||
|
@ -55,6 +73,14 @@ module Fog
|
|||
@model_path = new_path
|
||||
end
|
||||
|
||||
def collection(new_collection)
|
||||
collections << new_collection
|
||||
end
|
||||
|
||||
def collections
|
||||
@collections ||= []
|
||||
end
|
||||
|
||||
def model(new_model)
|
||||
models << new_model
|
||||
end
|
||||
|
|
|
@ -5,24 +5,24 @@ module Fog
|
|||
requires :slicehost_password
|
||||
|
||||
model_path 'fog/slicehost/models'
|
||||
model 'flavor'
|
||||
model 'flavors'
|
||||
model 'image'
|
||||
model 'images'
|
||||
model 'server'
|
||||
model 'servers'
|
||||
model :flavor
|
||||
collection :flavors
|
||||
model :image
|
||||
collection :images
|
||||
model :server
|
||||
collection :servers
|
||||
|
||||
request_path 'fog/slicehost/requests'
|
||||
request 'create_slice'
|
||||
request 'delete_slice'
|
||||
request 'get_backups'
|
||||
request 'get_flavor'
|
||||
request 'get_flavors'
|
||||
request 'get_image'
|
||||
request 'get_images'
|
||||
request 'get_slice'
|
||||
request 'get_slices'
|
||||
request 'reboot_slice'
|
||||
request :create_slice
|
||||
request :delete_slice
|
||||
request :get_backups
|
||||
request :get_flavor
|
||||
request :get_flavors
|
||||
request :get_image
|
||||
request :get_images
|
||||
request :get_slice
|
||||
request :get_slices
|
||||
request :reboot_slice
|
||||
|
||||
class Mock
|
||||
include Collections
|
||||
|
|
|
@ -16,16 +16,12 @@ module Slicehost
|
|||
@@connections[service]
|
||||
end
|
||||
|
||||
def flavors
|
||||
self[:slices].flavors
|
||||
end
|
||||
|
||||
def images
|
||||
self[:slices].images
|
||||
end
|
||||
|
||||
def servers
|
||||
self[:slices].servers
|
||||
for collection in Fog::Slicehost.collections
|
||||
module_eval <<-EOS, __FILE__, __LINE__
|
||||
def #{collection}
|
||||
self[:slices].#{collection}
|
||||
end
|
||||
EOS
|
||||
end
|
||||
|
||||
else
|
||||
|
|
|
@ -22,8 +22,8 @@ module Fog
|
|||
requires :username, :password, :versions_uri
|
||||
|
||||
model_path 'fog/vcloud/models'
|
||||
model 'vdc'
|
||||
model 'vdcs'
|
||||
model :vdc
|
||||
model :vdcs
|
||||
|
||||
request_path 'fog/vcloud/requests'
|
||||
request :login
|
||||
|
|
Loading…
Reference in a new issue