Class: Fog::AWS::Elasticache::Mock

Inherits:
Object
  • Object
show all
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

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(options={})
  @aws_credentials_expire_at = Time::now + 20
  setup_credentials(options)
  @region = options[: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

.dataObject



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

.resetObject



142
143
144
# File 'lib/fog/aws/elasticache.rb', line 142

def self.reset
  @data = nil
end

Instance Method Details

#authorize_cache_security_group_ingressObject



30
31
32
# File 'lib/fog/aws/requests/elasticache/authorize_cache_security_group_ingress.rb', line 30

def authorize_cache_security_group_ingress
  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, options = {})
  response        = Excon::Response.new
  cluster         = { # create an in-memory representation of this cluster
    'CacheClusterId'  => id.strip,
    'NumCacheNodes'   => options[:num_nodes]      || 1,
    'CacheNodeType'   => options[:node_type]      || 'cache.m1.large',
    'Engine'          => options[:engine]         || 'memcached',
    'EngineVersion'   => options[:engine_version] || '1.4.5',
    'CacheClusterStatus'  => 'available',
    'CacheNodes'          => create_cache_nodes(id.strip, options[:num_nodes]),
    'CacheSecurityGroups' => [],
    'CacheParameterGroup' => { 'CacheParameterGroupName' =>
        options[:parameter_group_name] || 'default.memcached1.4' },
    'PendingModifiedValues'       => {},
    'AutoMinorVersionUpgrade'     =>
      options[:auto_minor_version_upgrade]    || 'true',
    'PreferredMaintenanceWindow'  =>
      options[: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

#dataObject



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, options = {})
  response        = Excon::Response.new
  all_clusters    = self.data[:clusters].values.map do |cluster|
    cluster.merge!(options[: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, options = {})
  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, options = {})
  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, options = {})
  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(options = {})
  Fog::Mock.not_implemented
end

#describe_eventsObject



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, options = {})
  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 options[option] != nil
      cluster[cluster_key] = options[option].to_s
      pending_values[cluster_key] = options[option]
    end
  end
  cache['CacheParameterGroup'] = {
    'CacheParameterGroupName' => options[:parameter_group_name]
  } if options[:parameter_group_name]
  if options[:num_nodes] || options[:engine_version]
    cluster['CacheNodes'] =
      create_cache_nodes(cluster['CacheClusterId'], options[:num_nodes])
    cluster['NumCacheNodes'] = cluster['CacheNodes'].size
  end
  if options[:nodes_to_remove]
    pending_values['CacheNodeId'] = options[: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_dataObject



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_dataObject



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_ingressObject



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(options)
  @aws_access_key_id = options[:aws_access_key_id]
end