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

[aws|elasticache] refactor acs->elasticache

This commit is contained in:
Benton Roberts 2011-09-27 11:03:11 -04:00 committed by geemus
parent 8b1e2f5199
commit 5b66328a70
17 changed files with 116 additions and 50 deletions

View file

@ -7,7 +7,7 @@ module Fog
requires :aws_access_key_id, :aws_secret_access_key
recognizes :region, :host, :path, :port, :scheme, :persistent
request_path 'fog/aws/requests/acs'
request_path 'fog/aws/requests/elasticache'
#request :create_cache_cluster
#request :delete_cache_cluster
@ -31,7 +31,7 @@ module Fog
#request :describe_events
model_path 'fog/aws/models/acs'
model_path 'fog/aws/models/elasticache'
# model :server
# collection :servers
model :security_group

View file

@ -1,12 +1,12 @@
require 'fog/core/collection'
require 'fog/aws/models/acs/security_group'
require 'fog/aws/models/elasticache/security_group'
module Fog
module AWS
class ACS
class Elasticache
class SecurityGroups < Fog::Collection
model Fog::AWS::ACS::SecurityGroup
model Fog::AWS::Elasticache::SecurityGroup
def all
data = connection.describe_cache_security_groups.body['CacheSecurityGroups']
@ -16,7 +16,7 @@ module Fog
def get(identity)
data = connection.describe_cache_security_groups('CacheSecurityGroupName' => identity).body['CacheSecurityGroups'].first
new(data)
rescue Fog::AWS::ACS::NotFound
rescue Fog::AWS::Elasticache::NotFound
nil
end
end

View file

@ -1,11 +1,11 @@
module Fog
module Parsers
module AWS
module ACS
module Elasticache
require 'fog/aws/parsers/acs/security_group_parser'
require 'fog/aws/parsers/elasticache/security_group_parser'
class AuthorizeCacheSecurityGroupIngress < Fog::Parsers::AWS::ACS::SecurityGroupParser
class AuthorizeCacheSecurityGroupIngress < Fog::Parsers::AWS::Elasticache::SecurityGroupParser
def end_element(name)
case name

View file

@ -0,0 +1,34 @@
module Fog
module Parsers
module AWS
module Elasticache
require 'fog/aws/parsers/elasticache/base'
# Base parser for ResponseMetadata, RequestId
class Base < Fog::Parsers::Base
def reset
super
@response = { 'ResponseMetadata' => {} }
end
def start_element(name, attrs = [])
super
end
def end_element(name)
case name
when 'RequestId'
@response['ResponseMetadata'][name] = value
else
super
end
end
end
end
end
end
end

View file

@ -1,8 +1,8 @@
module Fog
module Parsers
module AWS
module ACS
require 'fog/aws/parsers/acs/security_group_parser'
module Elasticache
require 'fog/aws/parsers/elasticache/security_group_parser'
class DescribeSecurityGroups < SecurityGroupParser

View file

@ -1,7 +1,8 @@
module Fog
module Parsers
module AWS
module ACS
module Elasticache
require 'fog/aws/parsers/elasticache/base'
class SecurityGroupParser < Fog::Parsers::Base

View file

@ -1,8 +1,8 @@
module Fog
module Parsers
module AWS
module ACS
require 'fog/aws/parsers/acs/security_group_parser'
module Elasticache
require 'fog/aws/parsers/elasticache/security_group_parser'
class SingleSecurityGroup < SecurityGroupParser

View file

@ -1,9 +1,9 @@
module Fog
module AWS
class ACS
class Elasticache
class Real
require 'fog/aws/parsers/acs/single_security_group'
require 'fog/aws/parsers/elasticache/single_security_group'
# Authorize ingress to a CacheSecurityGroup using EC2 Security Groups
#
@ -20,7 +20,7 @@ module Fog
'CacheSecurityGroupName' => name,
'EC2SecurityGroupName' => ec2_name,
'EC2SecurityGroupOwnerId' => ec2_owner_id,
:parser => Fog::Parsers::AWS::ACS::SingleSecurityGroup.new
:parser => Fog::Parsers::AWS::Elasticache::SingleSecurityGroup.new
})
end

View file

@ -1,9 +1,9 @@
module Fog
module AWS
class ACS
class Elasticache
class Real
require 'fog/aws/parsers/acs/single_security_group'
require 'fog/aws/parsers/elasticache/single_security_group'
# creates a cache security group
#
@ -18,7 +18,7 @@ module Fog
'Action' => 'CreateCacheSecurityGroup',
'CacheSecurityGroupName' => name,
'Description' => description,
:parser => Fog::Parsers::AWS::ACS::SingleSecurityGroup.new
:parser => Fog::Parsers::AWS::Elasticache::SingleSecurityGroup.new
})
end
end

View file

@ -0,0 +1,31 @@
module Fog
module AWS
class Elasticache
class Real
require 'fog/aws/parsers/elasticache/base'
# deletes a cache security group
#
# === Parameters
# * name <~String> - The name for the Cache Security Group
# === Returns
# * response <~Excon::Response>:
# * body <~Hash>
def delete_cache_security_group(name)
request({
'Action' => 'DeleteCacheSecurityGroup',
'CacheSecurityGroupName' => name,
:parser => Fog::Parsers::AWS::Elasticache::Base.new
})
end
end
class Mock
def delete_cache_security_group(name)
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -1,9 +1,9 @@
module Fog
module AWS
class ACS
class Elasticache
class Real
require 'fog/aws/parsers/acs/describe_security_groups'
require 'fog/aws/parsers/elasticache/describe_security_groups'
# Returns a list of CacheSecurityGroup descriptions
#
@ -18,7 +18,7 @@ module Fog
def describe_cache_security_groups(options = {})
request({
'Action' => 'DescribeCacheSecurityGroups',
:parser => Fog::Parsers::AWS::ACS::DescribeSecurityGroups.new
:parser => Fog::Parsers::AWS::Elasticache::DescribeSecurityGroups.new
}.merge(options))
end

View file

@ -1,10 +1,10 @@
module Fog
module AWS
class ACS
class Elasticache
class Real
require 'fog/aws/parsers/acs/single_security_group'
require 'fog/aws/parsers/elasticache/single_security_group'
# Revoke ingress to a CacheSecurityGroup using EC2 Security Groups
#
@ -21,7 +21,7 @@ module Fog
'CacheSecurityGroupName' => name,
'EC2SecurityGroupName' => ec2_name,
'EC2SecurityGroupOwnerId' => ec2_owner_id,
:parser => Fog::Parsers::AWS::ACS::SingleSecurityGroup.new
:parser => Fog::Parsers::AWS::Elasticache::SingleSecurityGroup.new
})
end

View file

@ -3,8 +3,8 @@ class AWS < Fog::Bin
def class_for(key)
case key
when :acs
Fog::AWS::ACS
when :elasticache
Fog::AWS::Elasticache
when :auto_scaling
Fog::AWS::AutoScaling
when :cdn
@ -44,8 +44,8 @@ class AWS < Fog::Bin
def [](service)
@@connections ||= Hash.new do |hash, key|
hash[key] = case key
when :acs
Fog::AWS::ACS.new
when :elasticache
Fog::AWS::Elasticache.new
when :auto_scaling
Fog::AWS::AutoScaling.new
when :cdn

View file

@ -1,13 +1,13 @@
Shindo.tests('AWS::ACS | security groups', ['aws', 'acs']) do
Shindo.tests('AWS::Elasticache | security groups', ['aws', 'elasticache']) do
group_name = 'fog-test'
description = 'Fog Test'
pending if Fog.mocking?
model_tests(AWS[:acs].security_groups, {:id => group_name, :description => description}, false) do
model_tests(AWS[:elasticache].security_groups, {:id => group_name, :description => description}, false) do
# An EC2 group to authorize
ec2_group = Fog::Compute.new(:provider => 'AWS').security_groups.create(:name => 'fog-test-acs', :description => 'fog test')
ec2_group = Fog::Compute.new(:provider => 'AWS').security_groups.create(:name => 'fog-test-elasticache', :description => 'fog test')
# Reload to get the instance owner_id
@instance.reload
@ -29,5 +29,5 @@ Shindo.tests('AWS::ACS | security groups', ['aws', 'acs']) do
ec2_group.destroy
end
collection_tests(AWS[:acs].security_groups, {:id => group_name, :description => description}, false)
collection_tests(AWS[:elasticache].security_groups, {:id => group_name, :description => description}, false)
end

View file

@ -1,5 +1,5 @@
class AWS
module ACS
module Elasticache
module Formats
BASIC = {

View file

@ -1,4 +1,4 @@
Shindo.tests('AWS::ACS | security group requests', ['aws', 'acs']) do
Shindo.tests('AWS::Elasticache | security group requests', ['aws', 'elasticache']) do
tests('success') do
pending if Fog.mocking?
@ -6,8 +6,8 @@ Shindo.tests('AWS::ACS | security group requests', ['aws', 'acs']) do
name = 'fog-test'
description = 'Fog Test Group'
tests('#create_cache_security_group').formats(AWS::ACS::Formats::SINGLE_SECURITY_GROUP) do
body = AWS[:acs].create_cache_security_group(name, description).body
tests('#create_cache_security_group').formats(AWS::Elasticache::Formats::SINGLE_SECURITY_GROUP) do
body = AWS[:elasticache].create_cache_security_group(name, description).body
group = body['CacheSecurityGroup']
returns(name) { group['CacheSecurityGroupName'] }
returns(description) { group['Description'] }
@ -15,28 +15,28 @@ Shindo.tests('AWS::ACS | security group requests', ['aws', 'acs']) do
body
end
tests('#describe_cache_security_groups without options').formats(AWS::ACS::Formats::DESCRIBE_SECURITY_GROUPS) do
body = AWS[:acs].describe_cache_security_groups.body
tests('#describe_cache_security_groups without options').formats(AWS::Elasticache::Formats::DESCRIBE_SECURITY_GROUPS) do
body = AWS[:elasticache].describe_cache_security_groups.body
returns(true, "has #{name}") do
body['CacheSecurityGroups'].any? {|group| group['CacheSecurityGroupName'] == name }
end
body
end
tests('#describe_cache_security_groups with name').formats(AWS::ACS::Formats::DESCRIBE_SECURITY_GROUPS) do
body = AWS[:acs].describe_cache_security_groups('CacheSecurityGroupName' => name).body
tests('#describe_cache_security_groups with name').formats(AWS::Elasticache::Formats::DESCRIBE_SECURITY_GROUPS) do
body = AWS[:elasticache].describe_cache_security_groups('CacheSecurityGroupName' => name).body
returns(1, "size of 1") { body['CacheSecurityGroups'].size }
returns(name, "has #{name}") { body['CacheSecurityGroups'].first['CacheSecurityGroupName'] }
body
end
tests('authorization') do
ec2_group = Fog::Compute.new(:provider => 'AWS').security_groups.create(:name => 'fog-test-acs', :description => 'Fog Test ACS')
ec2_group = Fog::Compute.new(:provider => 'AWS').security_groups.create(:name => 'fog-test-elasticache', :description => 'Fog Test Elasticache')
# Reload to get the owner_id
ec2_group.reload
tests('#authorize_cache_security_group_ingress').formats(AWS::ACS::Formats::SINGLE_SECURITY_GROUP) do
body = AWS[:acs].authorize_cache_security_group_ingress(name, ec2_group.name, ec2_group.owner_id).body
tests('#authorize_cache_security_group_ingress').formats(AWS::Elasticache::Formats::SINGLE_SECURITY_GROUP) do
body = AWS[:elasticache].authorize_cache_security_group_ingress(name, ec2_group.name, ec2_group.owner_id).body
group = body['CacheSecurityGroup']
expected_ec2_groups = [{'Status' => 'authorizing', 'EC2SecurityGroupName' => ec2_group.name, 'EC2SecurityGroupOwnerId' => ec2_group.owner_id}]
returns(expected_ec2_groups, 'has correct EC2 groups') { group['EC2SecurityGroups'] }
@ -45,12 +45,12 @@ Shindo.tests('AWS::ACS | security group requests', ['aws', 'acs']) do
# Wait for the state to be active
Fog.wait_for do
group = AWS[:acs].describe_cache_security_groups('CacheSecurityGroupName' => name).body['CacheSecurityGroups'].first
group = AWS[:elasticache].describe_cache_security_groups('CacheSecurityGroupName' => name).body['CacheSecurityGroups'].first
group['EC2SecurityGroups'].all? {|ec2| ec2['Status'] == 'authorized'}
end
tests('#revoke_cache_security_group_ingress').formats(AWS::ACS::Formats::SINGLE_SECURITY_GROUP) do
body = AWS[:acs].revoke_cache_security_group_ingress(name, ec2_group.name, ec2_group.owner_id).body
tests('#revoke_cache_security_group_ingress').formats(AWS::Elasticache::Formats::SINGLE_SECURITY_GROUP) do
body = AWS[:elasticache].revoke_cache_security_group_ingress(name, ec2_group.name, ec2_group.owner_id).body
group = body['CacheSecurityGroup']
expected_ec2_groups = [{'Status' => 'revoking', 'EC2SecurityGroupName' => ec2_group.name, 'EC2SecurityGroupOwnerId' => ec2_group.owner_id}]
returns(expected_ec2_groups, 'has correct EC2 groups') { group['EC2SecurityGroups'] }
@ -61,8 +61,8 @@ Shindo.tests('AWS::ACS | security group requests', ['aws', 'acs']) do
ec2_group.destroy
end
tests('#delete_cache_security_group').formats(AWS::ACS::Formats::BASIC) do
body = AWS[:acs].delete_cache_security_group(name).body
tests('#delete_cache_security_group').formats(AWS::Elasticache::Formats::BASIC) do
body = AWS[:elasticache].delete_cache_security_group(name).body
end
end