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

[aws|compute] improve model and tests

This commit is contained in:
Nick Osborn 2011-06-21 22:15:33 +01:00
parent 9afb8c8460
commit 36601e796d
18 changed files with 93 additions and 71 deletions

View file

@ -40,16 +40,12 @@ module Fog
model_path 'fog/aws/models/auto_scaling'
model :activity
collection :activities
model :adjustment_type
collection :adjustment_types
model :configuration
collection :configurations
model :group
collection :groups
model :instance
collection :instances
model :process_type
collection :process_types
class Real

View file

@ -1,8 +1,10 @@
require 'fog/aws/models/auto_scaling/activity'
module Fog
module AWS
class AutoScaling
class Activities < Fog::Collection
model Fog::AWS::AutoScaling::Activity
def all

View file

@ -1,8 +1,8 @@
require 'fog/core/model'
module Fog
module AWS
class AutoScaling
class Activity < Fog::Model
identity :id, :aliases => 'ActivityId'
@ -19,6 +19,10 @@ module Fog
connection.groups.get(attributes['AutoScalingGroupName'])
end
def save
raise "Operation not supported"
end
end
end
end

View file

@ -1,13 +0,0 @@
require 'fog/core/model'
module Fog
module AWS
class AutoScaling
class AdjustmentType < Fog::Model
identity :id, :aliases => 'AdjustmentType'
end
end
end
end

View file

@ -1,15 +0,0 @@
require 'fog/aws/models/auto_scaling/adjustment_type'
module Fog
module AWS
class AutoScaling
class AdjustmentTypes < Fog::Collection
model Fog::AWS::AutoScaling::AdjustmentType
def all
data = connection.describe_adjustment_types.body['DescribeAdjustmentTypesResult']['AdjustmentTypes']
load(data)
end
end
end
end
end

View file

@ -1,8 +1,8 @@
require 'fog/core/model'
module Fog
module AWS
class AutoScaling
class Configuration < Fog::Model
identity :id, :aliases => 'LaunchConfigurationName'

View file

@ -1,8 +1,10 @@
require 'fog/aws/models/auto_scaling/configuration'
module Fog
module AWS
class AutoScaling
class Configurations < Fog::Collection
model Fog::AWS::AutoScaling::Configuration
# Creates a new launch configuration

View file

@ -1,8 +1,8 @@
require 'fog/core/model'
module Fog
module AWS
class AutoScaling
class Group < Fog::Model
identity :id, :aliases => 'AutoScalingGroupName'
@ -37,8 +37,26 @@ module Fog
super
end
def activities
requires :id
data = []
next_token = nil
loop do
result = connection.describe_scaling_activities('AutoScalingGroupName' => id, 'NextToken' => next_token).body['DescribeScalingActivitiesResult']
data += result['Activities']
next_token = result['NextToken']
break if next_token.nil?
end
Fog::AWS::AutoScaling::Activities.new({
:data => data,
:connection => connection,
#:load_balancer => self
})
end
def configuration
connection.configurations.get(attributes['LaunchConfigurationName'])
requires :launch_configuration_name
connection.configurations.get(launch_configuration_name)
end
def disable_metrics_collection(metrics = {})
@ -53,6 +71,21 @@ module Fog
reload
end
def instances
Fog::AWS::AutoScaling::Instances.new({
:data => attributes['Instances'],
:connection => connection
})
end
def instances_in_service
attributes[:instances].select {|hash| hash['LifecycleState'] == 'InService'}.map {|hash| hash['InstanceId']}
end
def instances_out_service
attributes[:instances].select {|hash| hash['LifecycleState'] == 'OutOfService'}.map {|hash| hash['InstanceId']}
end
def resume_processes(processes = [])
requires :id
connection.resume_processes(id, 'ScalingProcesses' => processes)
@ -66,7 +99,9 @@ module Fog
end
def ready?
# AutoScaling requests are synchronous
# Is this useful?
#instances_in_service.length == desired_capacity
#instances_in_service.length >= min_size
true
end
@ -81,11 +116,10 @@ module Fog
reload
end
def reload
super
# @instance_health = nil
self
end
#def reload
# super
# self
#end
def destroy
requires :id

View file

@ -1,8 +1,10 @@
require 'fog/aws/models/auto_scaling/group'
module Fog
module AWS
class AutoScaling
class Groups < Fog::Collection
model Fog::AWS::AutoScaling::Group
# Creates a new auto scaling group.
@ -26,6 +28,7 @@ module Fog
data = connection.describe_auto_scaling_groups('AutoScalingGroupNames' => identity).body['DescribeAutoScalingGroupsResult']['AutoScalingGroups'].first
new(data) unless data.nil?
end
end
end
end

View file

@ -1,8 +1,8 @@
require 'fog/core/model'
module Fog
module AWS
class AutoScaling
class Instance < Fog::Model
identity :id, :aliases => 'InstanceId'

View file

@ -1,8 +1,10 @@
require 'fog/aws/models/auto_scaling/instance'
module Fog
module AWS
class AutoScaling
class Instances < Fog::Collection
model Fog::AWS::AutoScaling::Instance
def all
@ -21,6 +23,7 @@ module Fog
data = connection.describe_auto_scaling_instances('InstanceIds' => identity).body['DescribeAutoScalingInstancesResult']['AutoScalingInstances'].first
new(data) unless data.nil?
end
end
end
end

View file

@ -1,13 +0,0 @@
require 'fog/core/model'
module Fog
module AWS
class AutoScaling
class ProcessType < Fog::Model
identity :id, :aliases => 'ProcessName'
end
end
end
end

View file

@ -1,15 +0,0 @@
require 'fog/aws/models/auto_scaling/process_type'
module Fog
module AWS
class AutoScaling
class ProcessTypes < Fog::Collection
model Fog::AWS::AutoScaling::ProcessType
def all
data = connection.describe_scaling_process_types.body['DescribeScalingProcessTypesResult']['Processes']
load(data)
end
end
end
end
end

View file

@ -0,0 +1,5 @@
Shindo.tests('AWS::AutoScaling | activities', ['aws', 'auto_scaling_m']) do
collection_tests(AWS[:auto_scaling].activities, {}, false)
end

View file

@ -0,0 +1,13 @@
Shindo.tests('AWS::AutoScaling | configuration', ['aws', 'auto_scaling_m']) do
params = {
:id => uniq_id,
:image_id => 'ami-8c1fece5',
:instance_type => 't1.micro'
}
model_tests(AWS[:auto_scaling].configurations, params, false) do
@instance.wait_for { ready? }
end
end

View file

@ -0,0 +1,11 @@
Shindo.tests('AWS::AutoScaling | configurations', ['aws', 'auto_scaling_m']) do
params = {
:id => uniq_id,
:image_id => 'ami-8c1fece5',
:instance_type => 't1.micro'
}
collection_tests(AWS[:auto_scaling].configurations, params, false)
end

View file

View file

@ -0,0 +1,5 @@
Shindo.tests('AWS::AutoScaling | instances', ['aws', 'auto_scaling_m']) do
collection_tests(AWS[:auto_scaling].instances, {}, false)
end