mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
consolidate lazy_load code into collection
This commit is contained in:
parent
56caf10c3e
commit
ee5242ba48
20 changed files with 46 additions and 190 deletions
36
Rakefile
36
Rakefile
|
@ -20,42 +20,6 @@ begin
|
|||
gem.homepage = "http://github.com/geemus/fog"
|
||||
gem.authors = ["geemus (Wesley Beary)"]
|
||||
gem.rubyforge_project = "fog"
|
||||
|
||||
gem.post_install_message = <<MESSAGE
|
||||
#{'=' * 50}
|
||||
|
||||
fog 0.0.41 has a minor change to the API for ec2 servers:
|
||||
|
||||
# what_it_was => what_it_is
|
||||
|
||||
ec2.servers.new(:group_id => 'foo') => ec2.servers.new(:groups => ['foo'])
|
||||
|
||||
Updating to the newest api version also means you can now assign multiple groups:
|
||||
|
||||
ec2.servers.new(:groups => ['foo', 'bar'])
|
||||
|
||||
#{'=' * 50}
|
||||
|
||||
fog 0.0.40 has API changes you should know about.
|
||||
|
||||
Some changes you might care about happened in the models:
|
||||
|
||||
# what_it_was => what_it_is
|
||||
|
||||
ec2.instances => ec2.servers
|
||||
ec2.instance => ec2.server
|
||||
|
||||
s3.buckets => s3.directories
|
||||
s3.bucket => s3.directory
|
||||
|
||||
s3.objects => s3.files
|
||||
s3.object => s3.file
|
||||
|
||||
Sorry for the bother, but it will allow for a more consistent API as fog continues to expand.
|
||||
|
||||
#{'=' * 50}
|
||||
MESSAGE
|
||||
|
||||
end
|
||||
rescue LoadError
|
||||
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
||||
|
|
|
@ -22,19 +22,15 @@ module Fog
|
|||
|
||||
def all(public_ip = @public_ip)
|
||||
@public_ip = public_ip
|
||||
if @loaded
|
||||
clear
|
||||
end
|
||||
@loaded = true
|
||||
data = connection.describe_addresses(public_ip).body
|
||||
addresses = []
|
||||
data['addressesSet'].each do |address|
|
||||
addresses << new(address.reject {|key, value| value.nil? || value.empty? })
|
||||
end
|
||||
load(
|
||||
data['addressesSet'].map do |address|
|
||||
address.reject {|key, value| value.nil? || value.empty? }
|
||||
end
|
||||
)
|
||||
if server
|
||||
addresses = addresses.select {|address| address.instance_id == server.id}
|
||||
self.replace(self.select {|address| address.instance_id == server.id})
|
||||
end
|
||||
self.replace(addresses)
|
||||
end
|
||||
|
||||
def get(public_ip)
|
||||
|
|
|
@ -11,10 +11,6 @@ module Fog
|
|||
model Fog::AWS::EC2::Flavor
|
||||
|
||||
def all
|
||||
if @loaded
|
||||
clear
|
||||
end
|
||||
@loaded = true
|
||||
data = [
|
||||
{ :bits => 32, :cores => 1, :disk => 160, :id => 'm1.small', :name => 'Small Instance', :ram => 1740.8},
|
||||
{ :bits => 64, :cores => 4, :disk => 850, :id => 'm1.large', :name => 'Large Instance', :ram => 7680},
|
||||
|
@ -26,9 +22,7 @@ module Fog
|
|||
{ :bits => 64, :cores => 13, :disk => 850, :id => 'm2.2xlarge', :name => 'High Memory Double Extra Large', :ram => 35020.8},
|
||||
{ :bits => 64, :cores => 26, :disk => 1690, :id => 'm2.4xlarge', :name => 'High Memory Quadruple Extra Large', :ram => 70041.6},
|
||||
]
|
||||
for flavor in data
|
||||
self << new(flavor)
|
||||
end
|
||||
load(data)
|
||||
self
|
||||
end
|
||||
|
||||
|
|
|
@ -19,15 +19,8 @@ module Fog
|
|||
|
||||
def all(image_id = @image_id)
|
||||
@image_id = image_id
|
||||
if @loaded
|
||||
clear
|
||||
end
|
||||
@loaded = true
|
||||
data = connection.describe_images('ImageId' => image_id).body
|
||||
data['imagesSet'].each do |image|
|
||||
self << new(image)
|
||||
end
|
||||
self
|
||||
load(data['imagesSet'])
|
||||
end
|
||||
|
||||
def get(image_id)
|
||||
|
|
|
@ -19,15 +19,8 @@ module Fog
|
|||
|
||||
def all(key_name = @key_name)
|
||||
@key_name = key_name
|
||||
if @loaded
|
||||
clear
|
||||
end
|
||||
@loaded = true
|
||||
data = connection.describe_key_pairs(key_name).body
|
||||
data['keySet'].each do |key|
|
||||
self << new(key)
|
||||
end
|
||||
self
|
||||
load(data['keySet'])
|
||||
end
|
||||
|
||||
def get(key_name)
|
||||
|
|
|
@ -19,15 +19,8 @@ module Fog
|
|||
|
||||
def all(group_name = @group_name)
|
||||
@group_name = group_name
|
||||
if @loaded
|
||||
clear
|
||||
end
|
||||
@loaded = true
|
||||
data = connection.describe_security_groups(group_name).body
|
||||
data['securityGroupInfo'].each do |security_group|
|
||||
self << new(security_group)
|
||||
end
|
||||
self
|
||||
load(data['securityGroupInfo'])
|
||||
end
|
||||
|
||||
def get(group_name)
|
||||
|
|
|
@ -19,17 +19,14 @@ module Fog
|
|||
|
||||
def all(server_id = @server_id)
|
||||
@server_id = server_id
|
||||
if @loaded
|
||||
clear
|
||||
end
|
||||
@loaded = true
|
||||
data = connection.describe_instances(server_id).body
|
||||
data['reservationSet'].each do |reservation|
|
||||
reservation['instancesSet'].each do |instance|
|
||||
self << new(instance.merge(:groups => reservation['groupSet']))
|
||||
load(
|
||||
data['reservationSet'].map do |reservation|
|
||||
reservation['instancesSet'].map do |instance|
|
||||
instance.merge(:groups => reservation['groupSet'])
|
||||
end
|
||||
end
|
||||
end
|
||||
self
|
||||
)
|
||||
end
|
||||
|
||||
def get(server_id)
|
||||
|
|
|
@ -22,19 +22,12 @@ module Fog
|
|||
|
||||
def all(snapshot_id = @snapshot_id)
|
||||
@snapshot_id = snapshot_id
|
||||
if @loaded
|
||||
clear
|
||||
end
|
||||
@loaded = true
|
||||
data = connection.describe_snapshots(snapshot_id).body
|
||||
snapshots = []
|
||||
data['snapshotSet'].each do |snapshot|
|
||||
snapshots << new(snapshot)
|
||||
end
|
||||
load(data['snapshotSet'])
|
||||
if volume
|
||||
snapshots = snapshots.select {|snapshot| snapshot.volume_id == volume.id}
|
||||
self.replace(self.select {|snapshot| snapshot.volume_id == volume.id})
|
||||
end
|
||||
self.replace(snapshots)
|
||||
self
|
||||
end
|
||||
|
||||
def get(snapshot_id)
|
||||
|
|
|
@ -22,19 +22,11 @@ module Fog
|
|||
|
||||
def all(volume_id = @volume_id)
|
||||
@volume_id = volume_id
|
||||
if @loaded
|
||||
clear
|
||||
end
|
||||
@loaded = true
|
||||
data = connection.describe_volumes(volume_id).body
|
||||
volumes = []
|
||||
data['volumeSet'].each do |volume|
|
||||
volumes << new(volume)
|
||||
end
|
||||
load(data['volumeSet'])
|
||||
if server
|
||||
volumes = volumes.select {|volume| volume.server_id == server.id}
|
||||
self.replace(self.select {|volume| volume.server_id == server.id})
|
||||
end
|
||||
self.replace(volumes)
|
||||
end
|
||||
|
||||
def get(volume_id)
|
||||
|
|
|
@ -11,15 +11,8 @@ module Fog
|
|||
model Fog::AWS::S3::Directory
|
||||
|
||||
def all
|
||||
if @loaded
|
||||
clear
|
||||
end
|
||||
@loaded = true
|
||||
data = connection.get_service.body
|
||||
data['Buckets'].each do |directory|
|
||||
self << new(directory)
|
||||
end
|
||||
self
|
||||
data = connection.get_service.body['Buckets']
|
||||
load(data)
|
||||
end
|
||||
|
||||
def get(name, options = {})
|
||||
|
|
|
@ -14,16 +14,12 @@ module Fog
|
|||
|
||||
def all(options = {})
|
||||
merge_attributes(options)
|
||||
if @loaded
|
||||
clear
|
||||
end
|
||||
@loaded = true
|
||||
collection = directory.collection.get(
|
||||
directory.name,
|
||||
options
|
||||
)
|
||||
if collection
|
||||
self.replace(collection.files)
|
||||
load(collection.files {|file| file.attributes})
|
||||
else
|
||||
nil
|
||||
end
|
||||
|
|
|
@ -101,9 +101,15 @@ module Fog
|
|||
data
|
||||
end
|
||||
|
||||
def load(array)
|
||||
def load(objects)
|
||||
if @loaded
|
||||
clear
|
||||
end
|
||||
@loaded = true
|
||||
self.clear.concat(array)
|
||||
for object in objects
|
||||
self << new(object)
|
||||
end
|
||||
self
|
||||
end
|
||||
|
||||
def model
|
||||
|
|
|
@ -11,15 +11,8 @@ module Fog
|
|||
model Fog::Rackspace::Files::Directory
|
||||
|
||||
def all
|
||||
if @loaded
|
||||
clear
|
||||
end
|
||||
@loaded = true
|
||||
data = connection.get_containers.body
|
||||
data.each do |directory|
|
||||
self << new(directory)
|
||||
end
|
||||
self
|
||||
load(data)
|
||||
end
|
||||
|
||||
def get(name, options = {})
|
||||
|
|
|
@ -13,16 +13,12 @@ module Fog
|
|||
|
||||
def all(options = {})
|
||||
merge_attributes(options)
|
||||
if @loaded
|
||||
clear
|
||||
end
|
||||
@loaded = true
|
||||
collection = directory.collection.get(
|
||||
directory.name,
|
||||
options
|
||||
)
|
||||
if collection
|
||||
self.replace(collection.files)
|
||||
load(collection.files.map {|file| file.attributes})
|
||||
else
|
||||
nil
|
||||
end
|
||||
|
|
|
@ -11,15 +11,8 @@ module Fog
|
|||
model Fog::Rackspace::Servers::Flavor
|
||||
|
||||
def all
|
||||
if @loaded
|
||||
clear
|
||||
end
|
||||
@loaded = true
|
||||
data = connection.list_flavors_detail.body
|
||||
for flavor in data['flavors']
|
||||
self << new(flavor)
|
||||
end
|
||||
self
|
||||
data = connection.list_flavors_detail.body['flavors']
|
||||
load(data)
|
||||
end
|
||||
|
||||
def get(flavor_id)
|
||||
|
|
|
@ -15,19 +15,11 @@ module Fog
|
|||
attribute :server
|
||||
|
||||
def all
|
||||
if @loaded
|
||||
clear
|
||||
end
|
||||
@loaded = true
|
||||
data = connection.list_images_detail.body
|
||||
images = []
|
||||
for image in data['images']
|
||||
images << new(image)
|
||||
end
|
||||
data = connection.list_images_detail.body['images']
|
||||
load(images)
|
||||
if server
|
||||
images = images.select {|image| image.server_id == server.id}
|
||||
self.replace(self.select {|image| image.server_id == server.id})
|
||||
end
|
||||
self.replace(images)
|
||||
end
|
||||
|
||||
def get(image_id)
|
||||
|
|
|
@ -11,15 +11,8 @@ module Fog
|
|||
model Fog::Rackspace::Servers::Server
|
||||
|
||||
def all
|
||||
if @loaded
|
||||
clear
|
||||
end
|
||||
@loaded = true
|
||||
data = connection.list_servers_detail.body
|
||||
for server in data['servers']
|
||||
self << new(server)
|
||||
end
|
||||
self
|
||||
data = connection.list_servers_detail.body['servers']
|
||||
load(data)
|
||||
end
|
||||
|
||||
def get(server_id)
|
||||
|
|
|
@ -10,15 +10,8 @@ module Fog
|
|||
model Fog::Slicehost::Flavor
|
||||
|
||||
def all
|
||||
if @loaded
|
||||
clear
|
||||
end
|
||||
@loaded = true
|
||||
data = connection.get_flavors.body
|
||||
for flavor in data['flavors']
|
||||
self << new(flavor)
|
||||
end
|
||||
self
|
||||
data = connection.get_flavors.body['flavors']
|
||||
load(self)
|
||||
end
|
||||
|
||||
def get(flavor_id)
|
||||
|
|
|
@ -12,15 +12,8 @@ module Fog
|
|||
model Fog::Slicehost::Image
|
||||
|
||||
def all
|
||||
if @loaded
|
||||
clear
|
||||
end
|
||||
@loaded = true
|
||||
data = connection.get_images.body
|
||||
for image in data['images']
|
||||
self << new(image)
|
||||
end
|
||||
self
|
||||
data = connection.get_images.body['images']
|
||||
load(data)
|
||||
end
|
||||
|
||||
def get(image_id)
|
||||
|
|
|
@ -10,15 +10,8 @@ module Fog
|
|||
model Fog::Slicehost::Server
|
||||
|
||||
def all
|
||||
if @loaded
|
||||
clear
|
||||
end
|
||||
@loaded = true
|
||||
data = connection.get_slices.body['slices']
|
||||
for server in data
|
||||
self << new(server)
|
||||
end
|
||||
self
|
||||
load(data)
|
||||
end
|
||||
|
||||
def get(server_id)
|
||||
|
|
Loading…
Add table
Reference in a new issue