-
-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from k1LoW/add-type-elasticache
Add elasticache type
- Loading branch information
Showing
11 changed files
with
210 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module Awspec::Generator | ||
module Doc | ||
module Type | ||
class Elasticache < Base | ||
def initialize | ||
super | ||
@type_name = 'Elasticache' | ||
@type = Awspec::Type::Elasticache.new('my-rep-group-001') | ||
@ret = @type.resource | ||
@matchers = %w(belong_to_vpc belong_to_replication_group belong_to_cache_subnet_group) | ||
@ignore_matchers = [] | ||
@describes = [] | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module Awspec::Helper | ||
module Finder | ||
module Elasticache | ||
def find_cache_cluster(id) | ||
res = @elasticache_client.describe_cache_clusters({ | ||
cache_cluster_id: id | ||
}) | ||
res[:cache_clusters].first if res[:cache_clusters].count == 1 | ||
rescue | ||
nil | ||
end | ||
|
||
def find_cache_subnet_group(group_name) | ||
res = @elasticache_client.describe_cache_subnet_groups({ | ||
cache_subnet_group_name: group_name | ||
}) | ||
res[:cache_subnet_groups].first if res[:cache_subnet_groups].count == 1 | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
RSpec::Matchers.define :belong_to_cache_subnet_group do |cache_subnet_group_name| | ||
match do |resource| | ||
return true if resource.resource[:cache_subnet_group_name] == cache_subnet_group_name | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
RSpec::Matchers.define :belong_to_replication_group do |group_id| | ||
match do |resource| | ||
# ElastiCache | ||
resource.resource[:replication_group_id] == group_id | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
Aws.config[:elasticache] = { | ||
stub_responses: { | ||
describe_cache_clusters: { | ||
cache_clusters: | ||
[ | ||
{ | ||
cache_cluster_id: 'my-rep-group-001', | ||
configuration_endpoint: nil, | ||
client_download_landing_page: | ||
'https://console.aws.amazon.com/elasticache/home#client-download:', | ||
cache_node_type: 'cache.m3.medium', | ||
engine: 'redis', | ||
engine_version: '2.8.21', | ||
cache_cluster_status: 'available', | ||
num_cache_nodes: 1, | ||
preferred_availability_zone: 'ap-northeast-1b', | ||
cache_cluster_create_time: Time.new(2015, 1, 2, 10, 00, 00, '+00:00'), | ||
preferred_maintenance_window: 'wed:15:30-wed:16:30', | ||
pending_modified_values: | ||
{ | ||
num_cache_nodes: nil, | ||
cache_node_ids_to_remove: [], | ||
engine_version: nil | ||
}, | ||
notification_configuration: nil, | ||
cache_security_groups: [], | ||
cache_parameter_group: | ||
{ | ||
cache_parameter_group_name: 'my-cache-parameter-group', | ||
parameter_apply_status: 'in-sync', | ||
cache_node_ids_to_reboot: [] | ||
}, | ||
cache_subnet_group_name: 'my-cache-subnet-group', | ||
cache_nodes: [], | ||
auto_minor_version_upgrade: true, | ||
security_groups: [ | ||
{ | ||
security_group_id: 'sg-da1bc2ef', | ||
status: 'active' | ||
} | ||
], | ||
replication_group_id: 'my-rep-group', | ||
snapshot_retention_limit: 0, | ||
snapshot_window: '17:30-18:30' | ||
} | ||
] | ||
}, | ||
describe_cache_subnet_groups: { | ||
cache_subnet_groups: [ | ||
{ | ||
cache_subnet_group_name: 'my-cache-subnet-group', | ||
cache_subnet_group_description: 'stub', | ||
vpc_id: 'vpc-ab123cde', | ||
subnets: [] | ||
} | ||
] | ||
} | ||
} | ||
} | ||
|
||
Aws.config[:ec2] = { | ||
stub_responses: { | ||
describe_vpcs: { | ||
vpcs: [ | ||
{ | ||
vpc_id: 'vpc-ab123cde', | ||
tags: [ | ||
{ | ||
key: 'Name', | ||
value: 'my-vpc' | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module Awspec::Type | ||
class Elasticache < Base | ||
def initialize(id) | ||
super | ||
@resource = find_cache_cluster(id) | ||
@id = @resource[:cache_cluster_id] if @resource | ||
end | ||
|
||
states = %w( | ||
available creating deleted deleting | ||
incompatible-network modifying | ||
rebooting-cache-cluster-nodes restore-failed | ||
snapshotting | ||
) | ||
|
||
states.each do |state| | ||
define_method state.tr('-', '_') + '?' do | ||
@resource[:cache_cluster_status] == state | ||
end | ||
end | ||
|
||
def has_cache_parameter_group?(group_name) | ||
@resource[:cache_parameter_group][:cache_parameter_group_name] == group_name | ||
end | ||
|
||
def vpc_id | ||
cache_subnet_group = find_cache_subnet_group(@resource[:cache_subnet_group_name]) | ||
cache_subnet_group[:vpc_id] if cache_subnet_group | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require 'spec_helper' | ||
Awspec::Stub.load 'elasticache' | ||
|
||
describe elasticache('my-rep-group-001') do | ||
it { should exist } | ||
it { should be_available } | ||
it { should have_cache_parameter_group('my-cache-parameter-group') } | ||
it { should belong_to_replication_group('my-rep-group') } | ||
it { should belong_to_cache_subnet_group('my-cache-subnet-group') } | ||
it { should belong_to_vpc('my-vpc') } | ||
end |