mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[aws|elasticache] add Cache Cluster model and collection
This commit is contained in:
parent
351fc7c2f5
commit
a6a6c3eb4b
6 changed files with 157 additions and 5 deletions
|
@ -32,8 +32,8 @@ module Fog
|
|||
#request :describe_events
|
||||
|
||||
model_path 'fog/aws/models/elasticache'
|
||||
# model :server
|
||||
# collection :servers
|
||||
model :cluster
|
||||
collection :clusters
|
||||
model :security_group
|
||||
collection :security_groups
|
||||
# model :parameter_group
|
||||
|
|
73
lib/fog/aws/models/elasticache/cluster.rb
Normal file
73
lib/fog/aws/models/elasticache/cluster.rb
Normal file
|
@ -0,0 +1,73 @@
|
|||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module AWS
|
||||
class Elasticache
|
||||
|
||||
class Cluster < Fog::Model
|
||||
# simple attributes
|
||||
identity :id, :aliases => 'CacheClusterId'
|
||||
attribute :auto_upgrade, :aliases => 'AutoMinorVersionUpgrade'
|
||||
attribute :status, :aliases => 'CacheClusterStatus'
|
||||
attribute :node_type, :aliases => 'CacheNodeType'
|
||||
attribute :engine, :aliases => 'Engine'
|
||||
attribute :engine_version, :aliases => 'EngineVersion'
|
||||
attribute :port, :aliases => 'Port'
|
||||
attribute :num_nodes, :aliases => 'NumCacheNodes'
|
||||
attribute :zone, :aliases => 'PreferredAvailabilityZone'
|
||||
attribute :maintenance_window, :aliases => 'PreferredMaintenanceWindow'
|
||||
# complex attributes
|
||||
attribute :nodes, :aliases => 'CacheNodes', :type => :array
|
||||
attribute :parameter_group,
|
||||
:aliases => 'CacheParameterGroup', :type => :hash
|
||||
attribute :pending_values,
|
||||
:aliases => 'PendingModifiedValues', :type => :hash
|
||||
attribute :create_time,
|
||||
:aliases => 'CacheClusterCreateTime', :type => :date_time
|
||||
attribute :security_groups,
|
||||
:aliases => 'CacheSecurityGroupNames', :type => :array
|
||||
attribute :notification_config,
|
||||
:aliases => 'NotificationConfiguration', :type => :hash
|
||||
|
||||
def ready?
|
||||
status == 'available'
|
||||
end
|
||||
|
||||
def destroy
|
||||
requires :id
|
||||
connection.delete_cache_cluster(id)
|
||||
true
|
||||
end
|
||||
|
||||
def save
|
||||
requires :id
|
||||
requires :node_type
|
||||
requires :security_groups
|
||||
requires :engine
|
||||
requires :num_nodes
|
||||
|
||||
parameter_group ||= Hash.new
|
||||
notification_config ||= Hash.new
|
||||
security_groups ||= Array.new
|
||||
|
||||
connection.create_cache_cluster(
|
||||
:cluster_id => id,
|
||||
:node_type => node_type,
|
||||
:security_group_names => security_groups,
|
||||
:num_nodes => num_nodes,
|
||||
:auto_minor_version_upgrade => auto_upgrade,
|
||||
:parameter_group_name => parameter_group['CacheParameterGroupName'],
|
||||
:engine => engine,
|
||||
:engine_version => engine_version,
|
||||
:notification_topic_arn => notification_config['TopicArn'],
|
||||
:port => port,
|
||||
:preferred_availablility_zone => zone,
|
||||
:preferred_maintenance_window => maintenance_window
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
30
lib/fog/aws/models/elasticache/clusters.rb
Normal file
30
lib/fog/aws/models/elasticache/clusters.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/aws/models/elasticache/cluster'
|
||||
|
||||
module Fog
|
||||
module AWS
|
||||
class Elasticache
|
||||
|
||||
class Clusters < Fog::Collection
|
||||
model Fog::AWS::Elasticache::Cluster
|
||||
|
||||
def all
|
||||
load(
|
||||
connection.describe_cache_clusters.body['CacheClusters']
|
||||
)
|
||||
end
|
||||
|
||||
def get(identity)
|
||||
new(
|
||||
connection.describe_cache_security_groups(
|
||||
'CacheSecurityGroupName' => identity
|
||||
).body['CacheSecurityGroups'].first
|
||||
)
|
||||
rescue Fog::AWS::Elasticache::NotFound
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -18,7 +18,6 @@ module Fog
|
|||
# * :engine <~String> - The Cluster's caching software (memcached)
|
||||
# * :engine_version <~String> - The Cluster's caching software version
|
||||
# * :notification_topic_arn <~String> - Amazon SNS Resource Name
|
||||
# * :cluster_id <~String> - The name of the Cache Cluster
|
||||
# * :port <~Integer> - The memcached port number
|
||||
# * :preferred_availablility_zone <~String>
|
||||
# * :preferred_maintenance_window <~String>
|
||||
|
|
38
tests/aws/models/elasticache/cluster_tests.rb
Normal file
38
tests/aws/models/elasticache/cluster_tests.rb
Normal file
|
@ -0,0 +1,38 @@
|
|||
Shindo.tests('AWS::Elasticache | cache clusters', ['aws', 'elasticache']) do
|
||||
cluster_params = {
|
||||
:id => 'fog-test-cluster',
|
||||
:node_type => 'cache.m1.large',
|
||||
:security_groups => ['default'],
|
||||
:engine => 'memcached',
|
||||
:num_nodes => 1
|
||||
}
|
||||
|
||||
pending if Fog.mocking?
|
||||
|
||||
model_tests(AWS[:elasticache].clusters, cluster_params, false) do
|
||||
# Reload to get the cluster info
|
||||
@instance.reload
|
||||
puts "Waiting for cluster #{@instance.id} to become available..."
|
||||
#@instance.wait_for {ready?} # This doesn't work (entity disappears)
|
||||
while (@instance.status != "available") do
|
||||
puts "Waiting for cluster #{@instance.id} (#{@instance.status})"
|
||||
sleep 20
|
||||
#@instance.reload # This doesn't work either! (no changes)
|
||||
@instance = AWS[:elasticache].clusters.find {|c| c.id == @instance.id}
|
||||
end
|
||||
end
|
||||
|
||||
collection_tests(AWS[:elasticache].clusters, cluster_params, false) do
|
||||
# Reload to get the cluster info
|
||||
@instance.reload
|
||||
puts "Waiting for cluster #{@instance.id} to become available..."
|
||||
#@instance.wait_for {ready?} # This doesn't work (entity disappears)
|
||||
while (@instance.status != "available") do
|
||||
puts "Waiting for cluster #{@instance.id} (#{@instance.status})"
|
||||
sleep 20
|
||||
#@instance.reload # This doesn't work either! (no changes)
|
||||
@instance = AWS[:elasticache].clusters.find {|c| c.id == @instance.id}
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -26,6 +26,11 @@ Shindo.tests('AWS::Elasticache | cache cluster requests', ['aws', 'elasticache']
|
|||
cluster['CacheClusterId'] == cluster_id
|
||||
end
|
||||
end
|
||||
# The DESCRIBE_CACHE_CLUSTERS format must include only one cluster
|
||||
# So remove all but the relevant cluster from the response body
|
||||
test_cluster = body['CacheClusters'].delete_if do |cluster|
|
||||
cluster['CacheClusterId'] != cluster_id
|
||||
end
|
||||
body
|
||||
end
|
||||
|
||||
|
@ -42,8 +47,15 @@ Shindo.tests('AWS::Elasticache | cache cluster requests', ['aws', 'elasticache']
|
|||
body
|
||||
end
|
||||
|
||||
#cluster = AWS[:elasticache].clusters.get(cluster_id)
|
||||
#cluster.wait_for {ready?}
|
||||
puts "Waiting for cluster #{cluster_id} to become available..."
|
||||
cluster = AWS[:elasticache].clusters.find {|c| c.id == cluster_id}
|
||||
#cluster.wait_for {ready?} # This doesn't work (entity disappears)
|
||||
while (cluster.status != "available") do
|
||||
puts "Waiting for cluster #{cluster.id} (#{cluster.status})"
|
||||
sleep 20
|
||||
#cluster.reload # This doesn't work either! (no changes)
|
||||
cluster = AWS[:elasticache].clusters.find {|c| c.id == cluster_id}
|
||||
end
|
||||
|
||||
tests(
|
||||
'#delete_cache_security_group'
|
||||
|
|
Loading…
Reference in a new issue