1
0
Fork 0
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:
geemus 2010-09-02 16:01:19 -07:00
parent c96614a11d
commit a3af5d7800
22 changed files with 302 additions and 282 deletions

View file

@ -23,40 +23,20 @@ module AWS
@@connections[service] @@connections[service]
end end
def addresses for collection in Fog::AWS::EC2.collections
self[:ec2].addresses module_eval <<-EOS, __FILE__, __LINE__
def #{collection}
self[:ec2].#{collection}
end
EOS
end end
def directories for collection in Fog::AWS::S3.collections
self[:s3].directories module_eval <<-EOS, __FILE__, __LINE__
end def #{collection}
self[:s3].#{collection}
def flavors end
self[:ec2].flavors EOS
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
end end
else else
@ -67,4 +47,5 @@ module AWS
end end
end end
end end

View file

@ -6,63 +6,63 @@ module Fog
requires :aws_access_key_id, :aws_secret_access_key requires :aws_access_key_id, :aws_secret_access_key
model_path 'fog/aws/models/ec2' model_path 'fog/aws/models/ec2'
model 'address' model :address
model 'addresses' collection :addresses
model 'flavor' model :flavor
model 'flavors' collection :flavors
model 'image' model :image
model 'images' collection :images
model 'key_pair' model :key_pair
model 'key_pairs' collection :key_pairs
model 'security_group' model :security_group
model 'security_groups' collection :security_groups
model 'server' model :server
model 'servers' collection :servers
model 'snapshot' model :snapshot
model 'snapshots' collection :snapshots
model 'volume' model :volume
model 'volumes' collection :volumes
require 'fog/aws/parsers/ec2/basic' require 'fog/aws/parsers/ec2/basic'
request_path 'fog/aws/requests/ec2' request_path 'fog/aws/requests/ec2'
request 'allocate_address' request :allocate_address
request 'associate_address' request :associate_address
request 'attach_volume' request :attach_volume
request 'authorize_security_group_ingress' request :authorize_security_group_ingress
request 'create_key_pair' request :create_key_pair
request 'create_security_group' request :create_security_group
request 'create_snapshot' request :create_snapshot
request 'create_image' request :create_image
request 'create_volume' request :create_volume
request 'delete_key_pair' request :delete_key_pair
request 'delete_security_group' request :delete_security_group
request 'delete_snapshot' request :delete_snapshot
request 'delete_volume' request :delete_volume
request 'deregister_image' request :deregister_image
request 'describe_addresses' request :describe_addresses
request 'describe_availability_zones' request :describe_availability_zones
request 'describe_images' request :describe_images
request 'describe_instances' request :describe_instances
request 'describe_reserved_instances' request :describe_reserved_instances
request 'describe_key_pairs' request :describe_key_pairs
request 'describe_regions' request :describe_regions
request 'describe_security_groups' request :describe_security_groups
request 'describe_snapshots' request :describe_snapshots
request 'describe_volumes' request :describe_volumes
request 'detach_volume' request :detach_volume
request 'disassociate_address' request :disassociate_address
request 'get_console_output' request :get_console_output
request 'modify_image_attributes' request :modify_image_attributes
request 'modify_snapshot_attribute' request :modify_snapshot_attribute
request 'reboot_instances' request :reboot_instances
request 'release_address' request :release_address
request 'register_image' request :register_image
request 'revoke_security_group_ingress' request :revoke_security_group_ingress
request 'run_instances' request :run_instances
request 'terminate_instances' request :terminate_instances
request 'start_instances' request :start_instances
request 'stop_instances' request :stop_instances
class Mock class Mock
include Collections include Collections

View file

@ -6,14 +6,14 @@ module Fog
requires :aws_access_key_id, :aws_secret_access_key requires :aws_access_key_id, :aws_secret_access_key
request_path 'fog/aws/requests/elb' request_path 'fog/aws/requests/elb'
request 'create_load_balancer' request :create_load_balancer
request 'delete_load_balancer' request :delete_load_balancer
request 'deregister_instances_from_load_balancer' request :deregister_instances_from_load_balancer
request 'describe_instance_health' request :describe_instance_health
request 'describe_load_balancers' request :describe_load_balancers
request 'disable_availability_zones_for_load_balancer' request :disable_availability_zones_for_load_balancer
request 'enable_availability_zones_for_load_balancer' request :enable_availability_zones_for_load_balancer
request 'register_instances_with_load_balancer' request :register_instances_with_load_balancer
class Mock class Mock
include Collections include Collections

View file

@ -5,6 +5,12 @@ module Fog
module AWS module AWS
module S3 module S3
module Collections
def files
Fog::AWS::S3::Files.new(:connection => self)
end
end
class Files < Fog::Collection class Files < Fog::Collection
attribute :delimiter, 'Delimiter' attribute :delimiter, 'Delimiter'
@ -17,6 +23,7 @@ module Fog
model Fog::AWS::S3::File model Fog::AWS::S3::File
def all(options = {}) def all(options = {})
requires :directory
options = { options = {
'delimiter' => @delimiter, 'delimiter' => @delimiter,
'marker' => @marker, 'marker' => @marker,
@ -38,6 +45,7 @@ module Fog
end end
def get(key, options = {}, &block) def get(key, options = {}, &block)
requires :directory
data = connection.get_object(directory.key, key, options, &block) data = connection.get_object(directory.key, key, options, &block)
file_data = { file_data = {
:body => data.body, :body => data.body,
@ -54,10 +62,12 @@ module Fog
end end
def get_url(key, expires) def get_url(key, expires)
requires :directory
connection.get_object_url(directory.key, key, expires) connection.get_object_url(directory.key, key, expires)
end end
def head(key, options = {}) def head(key, options = {})
requires :directory
data = connection.head_object(directory.key, key, options) data = connection.head_object(directory.key, key, options)
file_data = { file_data = {
:key => key :key => key
@ -73,6 +83,7 @@ module Fog
end end
def new(attributes = {}) def new(attributes = {})
requires :directory
super({ :directory => directory }.merge!(attributes)) super({ :directory => directory }.merge!(attributes))
end end

View file

@ -6,35 +6,35 @@ module Fog
requires :aws_access_key_id, :aws_secret_access_key requires :aws_access_key_id, :aws_secret_access_key
model_path 'fog/aws/models/s3' model_path 'fog/aws/models/s3'
model 'directories' collection :directories
model 'directory' model :directory
model 'files' collection :files
model 'file' model :file
request_path 'fog/aws/requests/s3' request_path 'fog/aws/requests/s3'
request 'copy_object' request :copy_object
request 'delete_bucket' request :delete_bucket
request 'delete_object' request :delete_object
request 'get_bucket' request :get_bucket
request 'get_bucket_acl' request :get_bucket_acl
request 'get_bucket_location' request :get_bucket_location
request 'get_bucket_logging' request :get_bucket_logging
request 'get_bucket_object_versions' request :get_bucket_object_versions
request 'get_bucket_versioning' request :get_bucket_versioning
request 'get_object' request :get_object
request 'get_object_acl' request :get_object_acl
request 'get_object_torrent' request :get_object_torrent
request 'get_object_url' request :get_object_url
request 'get_request_payment' request :get_request_payment
request 'get_service' request :get_service
request 'head_object' request :head_object
request 'put_bucket' request :put_bucket
request 'put_bucket_acl' request :put_bucket_acl
request 'put_bucket_logging' request :put_bucket_logging
request 'put_bucket_versioning' request :put_bucket_versioning
request 'put_object' request :put_object
request 'put_object_url' request :put_object_url
request 'put_request_payment' request :put_request_payment
module Utils module Utils

View file

@ -6,15 +6,15 @@ module Fog
requires :aws_access_key_id, :aws_secret_access_key requires :aws_access_key_id, :aws_secret_access_key
request_path 'fog/aws/requests/simpledb' request_path 'fog/aws/requests/simpledb'
request 'batch_put_attributes' request :batch_put_attributes
request 'create_domain' request :create_domain
request 'delete_attributes' request :delete_attributes
request 'delete_domain' request :delete_domain
request 'domain_metadata' request :domain_metadata
request 'get_attributes' request :get_attributes
request 'list_domains' request :list_domains
request 'put_attributes' request :put_attributes
request 'select' request :select
class Mock class Mock
include Collections include Collections

View file

@ -5,22 +5,23 @@ module Fog
requires :bluebox_api_key, :bluebox_customer_id requires :bluebox_api_key, :bluebox_customer_id
model_path 'fog/bluebox/models' model_path 'fog/bluebox/models'
model 'flavor' model :flavor
model 'flavors' collection :flavors
model 'images' model :image
model 'server' collection :images
model 'servers' model :server
collection :servers
request_path 'fog/bluebox/requests' request_path 'fog/bluebox/requests'
request 'create_block' request :create_block
request 'destroy_block' request :destroy_block
request 'get_block' request :get_block
request 'get_blocks' request :get_blocks
request 'get_product' request :get_product
request 'get_products' request :get_products
request 'get_template' request :get_template
request 'get_templates' request :get_templates
request 'reboot_block' request :reboot_block
class Mock class Mock
include Collections include Collections

View file

@ -17,16 +17,12 @@ module Bluebox
@@connections[service] @@connections[service]
end end
def flavors for collection in Fog::Bluebox.collections
self[:blocks].flavors module_eval <<-EOS, __FILE__, __LINE__
end def #{collection}
self[:blocks].#{collection}
def images end
self[:blocks].images EOS
end
def servers
self[:blocks].servers
end end
else else

View file

@ -8,15 +8,15 @@ module Fog
model_path 'fog/go_grid/models' model_path 'fog/go_grid/models'
request_path 'fog/go_grid/requests' request_path 'fog/go_grid/requests'
request 'common_lookup_list' request :common_lookup_list
request 'grid_image_list' request :grid_image_list
request 'grid_ip_list' request :grid_ip_list
request 'grid_loadbalancer_list' request :grid_loadbalancer_list
request 'grid_server_add' request :grid_server_add
request 'grid_server_delete' request :grid_server_delete
request 'grid_server_get' request :grid_server_get
request 'grid_server_list' request :grid_server_list
request 'grid_server_power' request :grid_server_power
class Mock class Mock
include Collections include Collections

View file

@ -7,15 +7,15 @@ module Fog
model_path 'fog/linode/models' model_path 'fog/linode/models'
request_path 'fog/linode/requests' request_path 'fog/linode/requests'
request 'avail_datacenters' request :avail_datacenters
request 'avail_distributions' request :avail_distributions
request 'avail_kernels' request :avail_kernels
request 'avail_linodeplans' request :avail_linodeplans
request 'avail_stackscripts' request :avail_stackscripts
request 'linode_create' request :linode_create
request 'linode_delete' request :linode_delete
request 'linode_list' request :linode_list
request 'linode_reboot' request :linode_reboot
class Mock class Mock
include Collections include Collections

View file

@ -5,10 +5,10 @@ module Fog
requires :local_root requires :local_root
model_path 'fog/local/models' model_path 'fog/local/models'
model 'directories' collection :directories
model 'directory' model :directory
model 'file' model :file
model 'files' collection :files
class Mock class Mock
include Collections include Collections

View file

@ -16,8 +16,12 @@ module Local
@@connections[service] @@connections[service]
end end
def directories for collection in Fog::Local.collections
self[:files].directories module_eval <<-EOS, __FILE__, __LINE__
def #{collection}
self[:files].#{collection}
end
EOS
end end
else else

View file

@ -4,11 +4,20 @@ require 'fog/local/models/file'
module Fog module Fog
module Local module Local
module Collections
def files
Fog::Local::Files.new(:connection => self)
end
end
class Files < Fog::Collection class Files < Fog::Collection
attribute :directory
model Fog::Local::File model Fog::Local::File
def all def all
requires :directory
if directory.collection.get(directory.key) if directory.collection.get(directory.key)
data = Dir.entries(connection.path_to(directory.key)).select do |key| data = Dir.entries(connection.path_to(directory.key)).select do |key|
key[0...1] != '.' && !::File.directory?(connection.path_to(key)) key[0...1] != '.' && !::File.directory?(connection.path_to(key))
@ -26,11 +35,8 @@ module Fog
end end
end end
def directory
@directory
end
def get(key, &block) def get(key, &block)
requires :directory
path = file_path(key) path = file_path(key)
if ::File.exists?(path) if ::File.exists?(path)
data = { data = {
@ -56,15 +62,12 @@ module Fog
end end
def new(attributes = {}) def new(attributes = {})
requires :directory
super({ :directory => directory }.merge!(attributes)) super({ :directory => directory }.merge!(attributes))
end end
private private
def directory=(new_directory)
@directory = new_directory
end
def file_path(key) def file_path(key)
connection.path_to(::File.join(directory.key, key)) connection.path_to(::File.join(directory.key, key))
end end

View file

@ -10,13 +10,13 @@ module Fog
model_path 'fog/new_servers/models' model_path 'fog/new_servers/models'
request_path 'fog/new_servers/requests' request_path 'fog/new_servers/requests'
request 'add_server' request :add_server
request 'cancel_server' request :cancel_server
request 'get_server' request :get_server
request 'list_images' request :list_images
request 'list_plans' request :list_plans
request 'list_servers' request :list_servers
request 'reboot_server' request :reboot_server
class Mock class Mock
include Collections include Collections

View file

@ -18,22 +18,22 @@ module Rackspace
@@connections[service] @@connections[service]
end end
def directories for collection in Fog::Rackspace::Files.collections
self[:files].directories module_eval <<-EOS, __FILE__, __LINE__
def #{collection}
self[:files].#{collection}
end
EOS
end end
def flavors for collection in Fog::Rackspace::Servers.collections
self[:servers].flavors module_eval <<-EOS, __FILE__, __LINE__
def #{collection}
self[:servers].#{collection}
end
EOS
end end
def images
self[:servers].images
end
def servers
self[:servers].servers
end
else else
def initialized? def initialized?

View file

@ -6,22 +6,22 @@ module Fog
requires :rackspace_api_key, :rackspace_username requires :rackspace_api_key, :rackspace_username
model_path 'fog/rackspace/models/files' model_path 'fog/rackspace/models/files'
model 'directory' model :directory
model 'directories' collection :directories
model 'file' model :file
model 'files' collection :files
request_path 'fog/rackspace/requests/files' request_path 'fog/rackspace/requests/files'
request 'delete_container' request :delete_container
request 'delete_object' request :delete_object
request 'get_container' request :get_container
request 'get_containers' request :get_containers
request 'get_object' request :get_object
request 'head_container' request :head_container
request 'head_containers' request :head_containers
request 'head_object' request :head_object
request 'put_container' request :put_container
request 'put_object' request :put_object
module Utils module Utils

View file

@ -5,8 +5,15 @@ module Fog
module Rackspace module Rackspace
module Files module Files
module Collections
def files
Fog::Rackspace::Files::Files.new(:connection => self)
end
end
class Files < Fog::Collection class Files < Fog::Collection
attribute :directory
attribute :limit attribute :limit
attribute :marker attribute :marker
attribute :path attribute :path
@ -15,6 +22,7 @@ module Fog
model Fog::Rackspace::Files::File model Fog::Rackspace::Files::File
def all(options = {}) def all(options = {})
requires :directory
merge_attributes(options) merge_attributes(options)
parent = directory.collection.get( parent = directory.collection.get(
directory.key, directory.key,
@ -27,11 +35,8 @@ module Fog
end end
end end
def directory
@directory
end
def get(key, options = {}, &block) def get(key, options = {}, &block)
requires :directory
options = { options = {
'limit' => @limit, 'limit' => @limit,
'marker' => @marker, 'marker' => @marker,
@ -54,10 +59,12 @@ module Fog
end end
def get_url(key, expires) def get_url(key, expires)
requires :directory
connection.get_object_url(directory.name, key, expires) connection.get_object_url(directory.name, key, expires)
end end
def head(key, options = {}) def head(key, options = {})
requires :directory
data = connection.head_object(directory.name, key, options) data = connection.head_object(directory.name, key, options)
file_data = { :key => key } file_data = { :key => key }
for key, value in data.headers for key, value in data.headers
@ -71,15 +78,10 @@ module Fog
end end
def new(attributes = {}) def new(attributes = {})
requires :directory
super({ :directory => directory }.merge!(attributes)) super({ :directory => directory }.merge!(attributes))
end end
private
def directory=(new_directory)
@directory = new_directory
end
end end
end end

View file

@ -6,32 +6,32 @@ module Fog
requires :rackspace_api_key, :rackspace_username requires :rackspace_api_key, :rackspace_username
model_path 'fog/rackspace/models/servers' model_path 'fog/rackspace/models/servers'
model 'flavor' model :flavor
model 'flavors' collection :flavors
model 'image' model :image
model 'images' collection :images
model 'server' model :server
model 'servers' collection :servers
request_path 'fog/rackspace/requests/servers' request_path 'fog/rackspace/requests/servers'
request 'create_image' request :create_image
request 'create_server' request :create_server
request 'delete_image' request :delete_image
request 'delete_server' request :delete_server
request 'get_flavor_details' request :get_flavor_details
request 'get_image_details' request :get_image_details
request 'get_server_details' request :get_server_details
request 'list_addresses' request :list_addresses
request 'list_private_addresses' request :list_private_addresses
request 'list_public_addresses' request :list_public_addresses
request 'list_flavors' request :list_flavors
request 'list_flavors_detail' request :list_flavors_detail
request 'list_images' request :list_images
request 'list_images_detail' request :list_images_detail
request 'list_servers' request :list_servers
request 'list_servers_detail' request :list_servers_detail
request 'reboot_server' request :reboot_server
request 'update_server' request :update_server
class Mock class Mock
include Collections include Collections

View file

@ -7,8 +7,6 @@ module Fog
class Error < Fog::Errors::Error; end class Error < Fog::Errors::Error; end
class NotFound < Fog::Errors::NotFound; end class NotFound < Fog::Errors::NotFound; end
module Collections; end
def self.new(options={}) def self.new(options={})
if Fog.bin if Fog.bin
default_credentials = Fog.credentials.reject {|key, value| !requirements.include?(key)} default_credentials = Fog.credentials.reject {|key, value| !requirements.include?(key)}
@ -28,6 +26,9 @@ module Fog
end end
unless @required unless @required
for collection in collections
require [@model_path, collection].join('/')
end
for model in models for model in models
require [@model_path, model].join('/') require [@model_path, model].join('/')
end end
@ -48,6 +49,23 @@ module Fog
end end
instance instance
end 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 EOS
end end
@ -55,6 +73,14 @@ module Fog
@model_path = new_path @model_path = new_path
end end
def collection(new_collection)
collections << new_collection
end
def collections
@collections ||= []
end
def model(new_model) def model(new_model)
models << new_model models << new_model
end end

View file

@ -5,24 +5,24 @@ module Fog
requires :slicehost_password requires :slicehost_password
model_path 'fog/slicehost/models' model_path 'fog/slicehost/models'
model 'flavor' model :flavor
model 'flavors' collection :flavors
model 'image' model :image
model 'images' collection :images
model 'server' model :server
model 'servers' collection :servers
request_path 'fog/slicehost/requests' request_path 'fog/slicehost/requests'
request 'create_slice' request :create_slice
request 'delete_slice' request :delete_slice
request 'get_backups' request :get_backups
request 'get_flavor' request :get_flavor
request 'get_flavors' request :get_flavors
request 'get_image' request :get_image
request 'get_images' request :get_images
request 'get_slice' request :get_slice
request 'get_slices' request :get_slices
request 'reboot_slice' request :reboot_slice
class Mock class Mock
include Collections include Collections

View file

@ -16,16 +16,12 @@ module Slicehost
@@connections[service] @@connections[service]
end end
def flavors for collection in Fog::Slicehost.collections
self[:slices].flavors module_eval <<-EOS, __FILE__, __LINE__
end def #{collection}
self[:slices].#{collection}
def images end
self[:slices].images EOS
end
def servers
self[:slices].servers
end end
else else

View file

@ -22,8 +22,8 @@ module Fog
requires :username, :password, :versions_uri requires :username, :password, :versions_uri
model_path 'fog/vcloud/models' model_path 'fog/vcloud/models'
model 'vdc' model :vdc
model 'vdcs' model :vdcs
request_path 'fog/vcloud/requests' request_path 'fog/vcloud/requests'
request :login request :login