Class: Fog::AWS::Elasticache::Mock
- Inherits:
-
Object
- Object
- Fog::AWS::Elasticache::Mock
- Includes:
- CredentialFetcher::ConnectionMethods
- Defined in:
- lib/fog/aws/elasticache.rb,
lib/fog/aws/requests/elasticache/describe_events.rb,
lib/fog/aws/requests/elasticache/create_cache_cluster.rb,
lib/fog/aws/requests/elasticache/delete_cache_cluster.rb,
lib/fog/aws/requests/elasticache/modify_cache_cluster.rb,
lib/fog/aws/requests/elasticache/reboot_cache_cluster.rb,
lib/fog/aws/requests/elasticache/describe_cache_clusters.rb,
lib/fog/aws/requests/elasticache/describe_cache_parameters.rb,
lib/fog/aws/requests/elasticache/create_cache_security_group.rb,
lib/fog/aws/requests/elasticache/delete_cache_security_group.rb,
lib/fog/aws/requests/elasticache/reset_cache_parameter_group.rb,
lib/fog/aws/requests/elasticache/create_cache_parameter_group.rb,
lib/fog/aws/requests/elasticache/delete_cache_parameter_group.rb,
lib/fog/aws/requests/elasticache/modify_cache_parameter_group.rb,
lib/fog/aws/requests/elasticache/describe_cache_security_groups.rb,
lib/fog/aws/requests/elasticache/describe_cache_parameter_groups.rb,
lib/fog/aws/requests/elasticache/describe_engine_default_parameters.rb,
lib/fog/aws/requests/elasticache/revoke_cache_security_group_ingress.rb,
lib/fog/aws/requests/elasticache/authorize_cache_security_group_ingress.rb
Class Method Summary collapse
Instance Method Summary collapse
- #authorize_cache_security_group_ingress ⇒ Object
- #create_cache_cluster(id, options = {}) ⇒ Object
-
#create_cache_nodes(cluster_id, num_nodes = 1, port = '11211') ⇒ Object
returns an Array of (Mock) elasticache nodes, representated as Hashes.
- #create_cache_parameter_group(name, description = name, family = 'memcached1.4') ⇒ Object
- #create_cache_security_group(name, desciption = name) ⇒ Object
- #data ⇒ Object
- #delete_cache_cluster(cluster_id) ⇒ Object
- #delete_cache_parameter_group(name) ⇒ Object
- #delete_cache_security_group(name) ⇒ Object
- #describe_cache_clusters(id = nil, options = {}) ⇒ Object
- #describe_cache_parameter_groups(name = nil, options = {}) ⇒ Object
- #describe_cache_parameters(name = nil, options = {}) ⇒ Object
- #describe_cache_security_groups(name = nil, options = {}) ⇒ Object
- #describe_engine_defalut_parameters(options = {}) ⇒ Object
- #describe_events ⇒ Object
-
#initialize(options = {}) ⇒ Mock
constructor
A new instance of Mock.
- #modify_cache_cluster(id, options = {}) ⇒ Object
- #modify_cache_parameter_group(id, new_parameters) ⇒ Object
- #reboot_cache_cluster(id, nodes_to_reboot) ⇒ Object
- #region_data ⇒ Object
- #reset_cache_parameter_group(id, parameter_names) ⇒ Object
- #reset_data ⇒ Object
- #revoke_cache_security_group_ingress ⇒ Object
- #setup_credentials(options) ⇒ Object
Methods included from CredentialFetcher::ConnectionMethods
#refresh_credentials_if_expired
Constructor Details
#initialize(options = {}) ⇒ Mock
Returns a new instance of Mock.
146 147 148 149 150 151 152 153 154 |
# File 'lib/fog/aws/elasticache.rb', line 146 def initialize(={}) @aws_credentials_expire_at = Time::now + 20 setup_credentials() @region = [:region] || 'us-east-1' unless ['ap-northeast-1', 'ap-southeast-1', 'eu-west-1', 'us-east-1', 'us-west-1', 'us-west-2', 'sa-east-1'].include?(@region) raise ArgumentError, "Unknown region: #{@region.inspect}" end end |
Class Method Details
.data ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/fog/aws/elasticache.rb', line 130 def self.data @data ||= Hash.new do |hash, region| hash[region] = Hash.new do |region_hash, key| owner_id = Fog::AWS::Mock.owner_id security_group_id = Fog::AWS::Mock.security_group_id region_hash[key] = { :clusters => {}, # cache cluster data, indexed by cluster ID } end end end |
.reset ⇒ Object
142 143 144 |
# File 'lib/fog/aws/elasticache.rb', line 142 def self.reset @data = nil end |
Instance Method Details
#authorize_cache_security_group_ingress ⇒ Object
30 31 32 |
# File 'lib/fog/aws/requests/elasticache/authorize_cache_security_group_ingress.rb', line 30 def Fog::Mock.not_implemented end |
#create_cache_cluster(id, options = {}) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/fog/aws/requests/elasticache/create_cache_cluster.rb', line 56 def create_cache_cluster(id, = {}) response = Excon::Response.new cluster = { # create an in-memory representation of this cluster 'CacheClusterId' => id.strip, 'NumCacheNodes' => [:num_nodes] || 1, 'CacheNodeType' => [:node_type] || 'cache.m1.large', 'Engine' => [:engine] || 'memcached', 'EngineVersion' => [:engine_version] || '1.4.5', 'CacheClusterStatus' => 'available', 'CacheNodes' => create_cache_nodes(id.strip, [:num_nodes]), 'CacheSecurityGroups' => [], 'CacheParameterGroup' => { 'CacheParameterGroupName' => [:parameter_group_name] || 'default.memcached1.4' }, 'PendingModifiedValues' => {}, 'AutoMinorVersionUpgrade' => [:auto_minor_version_upgrade] || 'true', 'PreferredMaintenanceWindow' => [:preferred_maintenance_window] || 'sun:05:00-sun:09:00', } self.data[:clusters][id] = cluster # store the in-memory cluster response.body = { 'CacheCluster' => cluster.merge({'CacheClusterStatus' => 'creating'}), 'ResponseMetadata' => { 'RequestId' => Fog::AWS::Mock.request_id } } response end |
#create_cache_nodes(cluster_id, num_nodes = 1, port = '11211') ⇒ Object
returns an Array of (Mock) elasticache nodes, representated as Hashes
173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/fog/aws/elasticache.rb', line 173 def create_cache_nodes(cluster_id, num_nodes = 1, port = '11211') (1..num_nodes).map do |node_number| node_id = "%04d" % node_number { # each hash represents a cache cluster node "CacheNodeId" => node_id, "Port" => port, "ParameterGroupStatus" => "in-sync", "CacheNodeStatus" => "available", "CacheNodeCreateTime" => Time.now.utc.to_s, "Address" => "#{cluster_id}.#{node_id}.use1.cache.amazonaws.com" } end end |
#create_cache_parameter_group(name, description = name, family = 'memcached1.4') ⇒ Object
30 31 32 33 |
# File 'lib/fog/aws/requests/elasticache/create_cache_parameter_group.rb', line 30 def create_cache_parameter_group(name, description = name, family = 'memcached1.4') Fog::Mock.not_implemented end |
#create_cache_security_group(name, desciption = name) ⇒ Object
27 28 29 |
# File 'lib/fog/aws/requests/elasticache/create_cache_security_group.rb', line 27 def create_cache_security_group(name, desciption=name) Fog::Mock.not_implemented end |
#data ⇒ Object
160 161 162 |
# File 'lib/fog/aws/elasticache.rb', line 160 def data self.region_data[@aws_access_key_id] end |
#delete_cache_cluster(cluster_id) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/fog/aws/requests/elasticache/delete_cache_cluster.rb', line 26 def delete_cache_cluster(cluster_id) response = Excon::Response.new cluster = self.data[:clusters][cluster_id] cluster['CacheClusterStatus'] = 'deleting' response.body = { 'CacheClusters' => self.data[:clusters].values, 'ResponseMetadata' => { 'RequestId' => Fog::AWS::Mock.request_id } } self.data[:clusters].delete(cluster_id) response end |
#delete_cache_parameter_group(name) ⇒ Object
25 26 27 |
# File 'lib/fog/aws/requests/elasticache/delete_cache_parameter_group.rb', line 25 def delete_cache_parameter_group(name) Fog::Mock.not_implemented end |
#delete_cache_security_group(name) ⇒ Object
25 26 27 |
# File 'lib/fog/aws/requests/elasticache/delete_cache_security_group.rb', line 25 def delete_cache_security_group(name) Fog::Mock.not_implemented end |
#describe_cache_clusters(id = nil, options = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/fog/aws/requests/elasticache/describe_cache_clusters.rb', line 33 def describe_cache_clusters(id = nil, = {}) response = Excon::Response.new all_clusters = self.data[:clusters].values.map do |cluster| cluster.merge!([:show_node_info] ? { 'CacheClusterCreateTime' => DateTime.now - 60, 'PreferredAvailabilityZone' => 'us-east-1a' } : {}) end if (id != nil) && (all_clusters.empty?) raise Fog::AWS::Elasticache::NotFound end response.body = { 'CacheClusters' => all_clusters, 'ResponseMetadata' => { 'RequestId' => Fog::AWS::Mock.request_id } } response end |
#describe_cache_parameter_groups(name = nil, options = {}) ⇒ Object
28 29 30 |
# File 'lib/fog/aws/requests/elasticache/describe_cache_parameter_groups.rb', line 28 def describe_cache_parameter_groups(name = nil, = {}) Fog::Mock.not_implemented end |
#describe_cache_parameters(name = nil, options = {}) ⇒ Object
30 31 32 |
# File 'lib/fog/aws/requests/elasticache/describe_cache_parameters.rb', line 30 def describe_cache_parameters(name = nil, = {}) Fog::Mock.not_implemented end |
#describe_cache_security_groups(name = nil, options = {}) ⇒ Object
28 29 30 |
# File 'lib/fog/aws/requests/elasticache/describe_cache_security_groups.rb', line 28 def describe_cache_security_groups(name = nil, = {}) Fog::Mock.not_implemented end |
#describe_engine_defalut_parameters(options = {}) ⇒ Object
29 30 31 |
# File 'lib/fog/aws/requests/elasticache/describe_engine_default_parameters.rb', line 29 def describe_engine_defalut_parameters( = {}) Fog::Mock.not_implemented end |
#describe_events ⇒ Object
40 41 42 |
# File 'lib/fog/aws/requests/elasticache/describe_events.rb', line 40 def describe_events Fog::Mock.not_implemented end |
#modify_cache_cluster(id, options = {}) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/fog/aws/requests/elasticache/modify_cache_cluster.rb', line 64 def modify_cache_cluster(id, = {}) response = Excon::Response.new cluster = self.data[:clusters][id] pending_values = Hash.new # For any given option, update the cluster's corresponding value { :auto_minor_version_upgrade => 'AutoMinorVersionUpgrade', :preferred_maintenance_window => 'PreferredMaintenanceWindow', :engine_version => 'EngineVersion', :num_nodes => 'NumCacheNodes', }.each do |option, cluster_key| if [option] != nil cluster[cluster_key] = [option].to_s pending_values[cluster_key] = [option] end end cache['CacheParameterGroup'] = { 'CacheParameterGroupName' => [:parameter_group_name] } if [:parameter_group_name] if [:num_nodes] || [:engine_version] cluster['CacheNodes'] = create_cache_nodes(cluster['CacheClusterId'], [:num_nodes]) cluster['NumCacheNodes'] = cluster['CacheNodes'].size end if [:nodes_to_remove] pending_values['CacheNodeId'] = [:nodes_to_remove].join(',') end response.body = { 'CacheCluster' => cluster.merge({ 'PendingModifiedValues' => pending_values }), 'ResponseMetadata' => { 'RequestId' => Fog::AWS::Mock.request_id } } response end |
#modify_cache_parameter_group(id, new_parameters) ⇒ Object
39 40 41 |
# File 'lib/fog/aws/requests/elasticache/modify_cache_parameter_group.rb', line 39 def modify_cache_parameter_group(id, new_parameters) Fog::Mock.not_implemented end |
#reboot_cache_cluster(id, nodes_to_reboot) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/fog/aws/requests/elasticache/reboot_cache_cluster.rb', line 38 def reboot_cache_cluster(id, nodes_to_reboot) response = Excon::Response.new response.body = { 'CacheCluster' => self.data[:clusters][id].merge({ 'CacheClusterStatus' => 'rebooting cache cluster nodes' }), 'ResponseMetadata' => { 'RequestId' => Fog::AWS::Mock.request_id } } response end |
#region_data ⇒ Object
156 157 158 |
# File 'lib/fog/aws/elasticache.rb', line 156 def region_data self.class.data[@region] end |
#reset_cache_parameter_group(id, parameter_names) ⇒ Object
40 41 42 |
# File 'lib/fog/aws/requests/elasticache/reset_cache_parameter_group.rb', line 40 def reset_cache_parameter_group(id, parameter_names) Fog::Mock.not_implemented end |
#reset_data ⇒ Object
164 165 166 |
# File 'lib/fog/aws/elasticache.rb', line 164 def reset_data self.region_data.delete(@aws_access_key_id) end |
#revoke_cache_security_group_ingress ⇒ Object
31 32 33 |
# File 'lib/fog/aws/requests/elasticache/revoke_cache_security_group_ingress.rb', line 31 def revoke_cache_security_group_ingress Fog::Mock.not_implemented end |
#setup_credentials(options) ⇒ Object
168 169 170 |
# File 'lib/fog/aws/elasticache.rb', line 168 def setup_credentials() @aws_access_key_id = [:aws_access_key_id] end |