Class: Fog::AWS::Elasticache::Real

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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/fog/aws/elasticache.rb', line 51

def initialize(options={})
  @aws_access_key_id      = options[:aws_access_key_id]
  @aws_secret_access_key  = options[:aws_secret_access_key]
  @hmac = Fog::HMAC.new('sha256', @aws_secret_access_key)

  options[:region] ||= 'us-east-1'
  @host = options[:host] || case options[:region]
  when 'us-east-1'
    'elasticache.us-east-1.amazonaws.com'
    #TODO: Support other regions
  else
    raise ArgumentError, "Unknown region: #{options[:region].inspect}"
  end
  @path       = options[:path]      || '/'
  @port       = options[:port]      || 443
  @scheme     = options[:scheme]    || 'https'
  @connection = Fog::Connection.new(
    "#{@scheme}://#{@host}:#{@port}#{@path}", options[:persistent]
  )
end

Instance Method Details

#authorize_cache_security_group_ingress(name, ec2_name, ec2_owner_id) ⇒ Object

Authorize ingress to a CacheSecurityGroup using EC2 Security Groups

Parameters

  • name <~String> - The name of the cache security group

  • ec2_name <~String> - The name of the EC2 security group to authorize

  • ec2_owner_id <~String> - The AWS Account Number of the EC2 security group

Returns

  • response <~Excon::Response>:

    • body <~Hash>



17
18
19
20
21
22
23
24
25
# File 'lib/fog/aws/requests/elasticache/authorize_cache_security_group_ingress.rb', line 17

def authorize_cache_security_group_ingress(name, ec2_name, ec2_owner_id)
  request({
    'Action' => 'AuthorizeCacheSecurityGroupIngress',
    'CacheSecurityGroupName' => name,
    'EC2SecurityGroupName' => ec2_name,
    'EC2SecurityGroupOwnerId' => ec2_owner_id,
    :parser => Fog::Parsers::AWS::Elasticache::SingleSecurityGroup.new
  })
end

#create_cache_cluster(id, options = {}) ⇒ Object

creates a cache cluster

Required Parameters

  • id <~String> - A unique cluster ID - 20 characters max.

Optional Parameters

  • options <~Hash> - All optional parameters should be set in this Hash:

    • :node_type <~String> - The size (flavor) of the cache Nodes

    • :security_group_names <~Array> - Array of Elasticache::SecurityGroup names

    • :num_nodes <~Integer> - The number of nodes in the Cluster

    • :auto_minor_version_upgrade <~TrueFalseClass>

    • :parameter_group_name <~String> - Name of the Cluster’s ParameterGroup

    • :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

    • :port <~Integer> - The memcached port number

    • :preferred_availablility_zone <~String>

    • :preferred_maintenance_window <~String>

Returns

  • response <~Excon::Response>:

    • body <~Hash>



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/fog/aws/requests/elasticache/create_cache_cluster.rb', line 27

def create_cache_cluster(id, options = {})
  # Construct Cache Security Group parameters in the format:
  #   CacheSecurityGroupNames.member.N => "security_group_name"
  group_names = options[:security_group_names] || ['default']
  sec_group_params = group_names.inject({}) do |group_hash, name|
    index = group_names.index(name) + 1
    group_hash["CacheSecurityGroupNames.member.#{index}"] = name
    group_hash
  end
  # Merge the Cache Security Group parameters with the normal options
  request(sec_group_params.merge(
    'Action'          => 'CreateCacheCluster',
    'CacheClusterId'  => id,
    'CacheNodeType'   => options[:node_type]  || 'cache.m1.large',
    'Engine'          => options[:engine]     || 'memcached',
    'NumCacheNodes'   => options[:num_nodes]  || 1,
    'AutoMinorVersionUpgrade'     => options[:auto_minor_version_upgrade],
    'CacheParameterGroupName'     => options[:parameter_group_name],
    'EngineVersion'               => options[:engine_version],
    'NotificationTopicArn'        => options[:notification_topic_arn],
    'Port'                        => options[:port],
    'PreferredAvailabilityZone'   => options[:preferred_availablility_zone],
    'PreferredMaintenanceWindow'  => options[:preferred_maintenance_window],
    :parser => Fog::Parsers::AWS::Elasticache::SingleCacheCluster.new
  ))
end

#create_cache_parameter_group(name, description = name, family = 'memcached1.4') ⇒ Object

creates a cache parameter group

Parameters

  • name <~String> - The name for the Cache Parameter Group

Optional Parameters

  • description <~String> - The description for the Cache Parameter Group

  • family <~String> - The description for the Cache Parameter Group

Returns

  • response <~Excon::Response>:

    • body <~Hash>



18
19
20
21
22
23
24
25
26
# File 'lib/fog/aws/requests/elasticache/create_cache_parameter_group.rb', line 18

def create_cache_parameter_group(name, description = name, family = 'memcached1.4')
  request({
    'Action' => 'CreateCacheParameterGroup',
    'CacheParameterGroupName' => name,
    'Description' => description,
    'CacheParameterGroupFamily' => family,
    :parser => Fog::Parsers::AWS::Elasticache::SingleParameterGroup.new
  })
end

#create_cache_security_group(name, description = name) ⇒ Object

creates a cache security group

Parameters

  • name <~String> - The name for the Cache Security Group

  • description <~String> - The description for the Cache Security Group

Returns

  • response <~Excon::Response>:

    • body <~Hash>



16
17
18
19
20
21
22
23
# File 'lib/fog/aws/requests/elasticache/create_cache_security_group.rb', line 16

def create_cache_security_group(name, description = name)
  request({
    'Action' => 'CreateCacheSecurityGroup',
    'CacheSecurityGroupName' => name,
    'Description' => description,
    :parser => Fog::Parsers::AWS::Elasticache::SingleSecurityGroup.new
  })
end

#delete_cache_cluster(cluster_id) ⇒ Object

Deletes a Cache Cluster

Parameter (required):

  • id <~String> - The ID of the cache cluster to delete

Returns

  • response <~Excon::Response>:

    • body <~Hash>



15
16
17
18
19
20
21
# File 'lib/fog/aws/requests/elasticache/delete_cache_cluster.rb', line 15

def delete_cache_cluster(cluster_id)
  request(
    'Action'          => 'DeleteCacheCluster',
    'CacheClusterId'  => cluster_id,
    :parser => Fog::Parsers::AWS::Elasticache::DescribeCacheClusters.new
  )
end

#delete_cache_parameter_group(name) ⇒ Object

deletes a cache parameter group

Parameters

  • name <~String> - The name for the Cache Parameter Group

Returns

  • response <~Excon::Response>:

    • body <~Hash>



15
16
17
18
19
20
21
# File 'lib/fog/aws/requests/elasticache/delete_cache_parameter_group.rb', line 15

def delete_cache_parameter_group(name)
  request({
    'Action' => 'DeleteCacheParameterGroup',
    'CacheParameterGroupName' => name,
    :parser => Fog::Parsers::AWS::Elasticache::Base.new
  })
end

#delete_cache_security_group(name) ⇒ Object

deletes a cache security group

Parameters

  • name <~String> - The name for the Cache Security Group

Returns

  • response <~Excon::Response>:

    • body <~Hash>



15
16
17
18
19
20
21
# File 'lib/fog/aws/requests/elasticache/delete_cache_security_group.rb', line 15

def delete_cache_security_group(name)
  request({
    'Action' => 'DeleteCacheSecurityGroup',
    'CacheSecurityGroupName' => name,
    :parser => Fog::Parsers::AWS::Elasticache::Base.new
  })
end

#describe_cache_clusters(id = nil, options = {}) ⇒ Object

Returns a list of Cache Cluster descriptions

Parameters (optional)

  • id - The ID of an existing cache cluster

  • options <~Hash> (optional):

  • :marker <~String> - marker provided in the previous request

  • :max_records <~Integer> - the maximum number of records to include

  • :show_node_info <~Boolean> - whether to show node info

Returns

  • response <~Excon::Response>:

    • body <~Hash>



19
20
21
22
23
24
25
26
27
28
# File 'lib/fog/aws/requests/elasticache/describe_cache_clusters.rb', line 19

def describe_cache_clusters(id = nil, options = {})
  request({
    'Action'            => 'DescribeCacheClusters',
    'CacheClusterId'    => id,
    'Marker'            => options[:marker],
    'MaxRecords'        => options[:max_records],
    'ShowCacheNodeInfo' => options[:show_node_info],
    :parser => Fog::Parsers::AWS::Elasticache::DescribeCacheClusters.new
  })
end

#describe_cache_parameter_groups(name = nil, options = {}) ⇒ Object

Returns a list of CacheParameterGroup descriptions

Parameters (optional)

  • name <~String> - The name of an existing cache parameter group

  • options <~Hash> (optional):

  • :marker <~String> - marker provided in the previous request

  • :max_records <~Integer> - the maximum number of records to include



15
16
17
18
19
20
21
22
23
# File 'lib/fog/aws/requests/elasticache/describe_cache_parameter_groups.rb', line 15

def describe_cache_parameter_groups(name = nil, options = {})
  request({
    'Action'                  => 'DescribeCacheParameterGroups',
    'CacheParameterGroupName' => name,
    'Marker'                  => options[:marker],
    'MaxRecords'              => options[:max_records],
    :parser => Fog::Parsers::AWS::Elasticache::DescribeParameterGroups.new
  }.merge(options))
end

#describe_cache_parameters(name = nil, options = {}) ⇒ Object

Returns a list of CacheParameterGroup descriptions

Parameters (optional)

  • name <~String> - The name of an existing cache parameter group

  • options <~Hash> (optional):

  • :marker <~String> - marker provided in the previous request

  • :max_records <~Integer> - the maximum number of records to include

  • :source <~String> - the parameter types to return.



16
17
18
19
20
21
22
23
24
25
# File 'lib/fog/aws/requests/elasticache/describe_cache_parameters.rb', line 16

def describe_cache_parameters(name = nil, options = {})
  request({
    'Action'                  => 'DescribeCacheParameters',
    'CacheParameterGroupName' => name,
    'Marker'                  => options[:marker],
    'MaxRecords'              => options[:max_records],
    'Source'                  => options[:source],
    :parser => Fog::Parsers::AWS::Elasticache::DescribeCacheParameters.new
  })
end

#describe_cache_security_groups(name = nil, options = {}) ⇒ Object

Returns a list of CacheSecurityGroup descriptions

Parameters (optional)

  • name <~String> - The name of an existing cache security group

  • options <~Hash> (optional):

  • :marker <~String> - marker provided in the previous request

  • :max_records <~Integer> - the maximum number of records to include



15
16
17
18
19
20
21
22
23
# File 'lib/fog/aws/requests/elasticache/describe_cache_security_groups.rb', line 15

def describe_cache_security_groups(name = nil, options = {})
  request({
    'Action'                  => 'DescribeCacheSecurityGroups',
    'CacheSecurityGroupName'  => name,
    'Marker'                  => options[:marker],
    'MaxRecords'              => options[:max_records],
    :parser => Fog::Parsers::AWS::Elasticache::DescribeSecurityGroups.new
  }.merge(options))
end

#describe_engine_default_parameters(options = {}) ⇒ Object

Returns the default engine and system parameter information for the specified cache engine.

Parameters (optional)

  • options <~Hash>:

  • :engine <~String> - the engine whose parameters are requested

  • :marker <~String> - marker provided in the previous request

  • :max_records <~Integer> - the maximum number of records to include



16
17
18
19
20
21
22
23
24
# File 'lib/fog/aws/requests/elasticache/describe_engine_default_parameters.rb', line 16

def describe_engine_default_parameters(options = {})
  request({
    'Action'                    => 'DescribeEngineDefaultParameters',
    'CacheParameterGroupFamily' => options[:engine] || 'memcached1.4',
    'Marker'                    => options[:marker],
    'MaxRecords'                => options[:max_records],
    :parser => Fog::Parsers::AWS::Elasticache::DescribeEngineDefaultParameters.new
  })
end

#describe_events(options = {}) ⇒ Object

Returns a list of service events

Parameters (optional)

  • options <~Hash> (optional):

  • :start_time <~DateTime> - starting time for event records

  • :end_time <~DateTime> - ending time for event records

  • :duration <~DateTime> - time span for event records

  • :marker <~String> - marker provided in the previous request

  • :max_records <~Integer> - the maximum number of records to include

  • :source_identifier <~DateTime> - identifier of the event source

  • :source_type <~DateTime> - event type, one of:

    (cache-cluster | cache-parameter-group | cache-security-group)
    

Returns

  • response <~Excon::Response>:

    • body <~Hash>



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/fog/aws/requests/elasticache/describe_events.rb', line 23

def describe_events(options = {})
  request(
    'Action'            => 'DescribeEvents',
    'StartTime'         => options[:sart_time],
    'EndTime'           => options[:end_time],
    'Duration'          => options[:duration],
    'Marker'            => options[:marker],
    'MaxRecords'        => options[:max_records],
    'SourceIdentifier'  => options[:source_identifier],
    'SourceType'        => options[:source_type],
    :parser => Fog::Parsers::AWS::Elasticache::EventListParser.new
  )
end

#modify_cache_cluster(id, options = {}) ⇒ Object

Modifies an existing cache cluster Returns a cache cluster description

Required Parameters

  • id <~String> - The ID of the existing cluster to be modified

Optional Parameters

  • options <~Hash> - All optional parameters should be set in this Hash:

    • :apply_immediately <~TrueFalseClass> - whether to apply changes now

    • :auto_minor_version_upgrade <~TrueFalseClass>

    • :num_nodes <~Integer> - The number of nodes in the Cluster

    • :nodes_to_remove <~Array> - Array of node IDs to delete

    • :security_group_names <~Array> - Array of Elasticache::SecurityGroup names

    • :parameter_group_name <~String> - Name of the Cluster’s ParameterGroup

    • :engine_version <~String> - The Cluster’s caching software version

    • :notification_topic_arn <~String> - Amazon SNS Resource Name

    • :notification_topic_status <~String> - Amazon SNS Topic status

    • :preferred_maintenance_window <~String>

Returns

  • response <~Excon::Response>:

    • body <~Hash>



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/fog/aws/requests/elasticache/modify_cache_cluster.rb', line 28

def modify_cache_cluster(id, options = {})
  # Construct Cache Security Group parameters in the format:
  #   CacheSecurityGroupNames.member.N => "security_group_name"
  group_names = options[:security_group_names] || []
  sec_group_params = group_names.inject({}) do |group_hash, name|
    index = group_names.index(name) + 1
    group_hash["CacheSecurityGroupNames.member.#{index}"] = name
    group_hash
  end
  # Construct CacheNodeIdsToRemove parameters in the format:
  #   CacheNodeIdsToRemove.member.N => "node_id"
  node_ids = options[:nodes_to_remove] || []
  node_id_params = node_ids.inject({}) do |node_hash, node_id|
    index = node_ids.index(node_id) + 1
    node_hash["CacheNodeIdsToRemove.member.#{index}"] = node_id
    node_hash
  end
  # Merge the Cache Security Group parameters with the normal options
  request(node_id_params.merge(sec_group_params.merge(
    'Action'                      => 'ModifyCacheCluster',
    'CacheClusterId'              => id,
    'ApplyImmediately'            => options[:apply_immediately],
    'NumCacheNodes'               => options[:num_nodes],
    'AutoMinorVersionUpgrade'     => options[:auto_minor_version_upgrade],
    'CacheParameterGroupName'     => options[:parameter_group_name],
    'EngineVersion'               => options[:engine_version],
    'NotificationTopicArn'        => options[:notification_topic_arn],
    'NotificationTopicStatus'     => options[:notification_topic_status],
    'PreferredMaintenanceWindow'  => options[:preferred_maintenance_window],
    :parser => Fog::Parsers::AWS::Elasticache::SingleCacheCluster.new
  )))
end

#modify_cache_parameter_group(id, new_parameters) ⇒ Object

Modifies an existing cache parameter group Returns a the name of the modified parameter group

Required Parameters

  • id <~String> - The ID of the parameter group to be modified

  • new_parameters <~Hash> - The parameters to modify, and their values

Returns

  • response <~Excon::Response>:

    • body <~Hash>



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/fog/aws/requests/elasticache/modify_cache_parameter_group.rb', line 17

def modify_cache_parameter_group(id, new_parameters)
  # Construct Parameter Modifications in the format:
  #   ParameterNameValues.member.N.ParameterName => "param_name"
  #   ParameterNameValues.member.N.ParameterValue => "param_value"
  n = 0   # n is the parameter index
  parameter_changes = new_parameters.inject({}) do |new_args,pair|
    n += 1
    new_args["ParameterNameValues.member.#{n}.ParameterName"] = pair[0]
    new_args["ParameterNameValues.member.#{n}.ParameterValue"] = pair[1]
    new_args
  end
  # Merge the Cache Security Group parameters with the normal options
  request(parameter_changes.merge(
    'Action'                      => 'ModifyCacheParameterGroup',
    'CacheParameterGroupName'     => id,
    :parser => Fog::Parsers::AWS::Elasticache::ModifyParameterGroup.new
  ))
end

#reboot_cache_cluster(id, nodes_to_reboot) ⇒ Object

Reboots some or all of an existing cache cluster’s nodes Returns a cache cluster description

Required Parameters

  • id <~String> - The ID of the existing cluster to be rebooted

Optional Parameters

  • nodes_to_reboot <~Array> - Array of node IDs to reboot

Returns

  • response <~Excon::Response>:

    • body <~Hash>



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/fog/aws/requests/elasticache/reboot_cache_cluster.rb', line 18

def reboot_cache_cluster(id, nodes_to_reboot)
  # Construct CacheNodeIdsToReboot parameters in the format:
  #   CacheNodeIdsToReboot.member.N => "node_id"
  node_ids = nodes_to_reboot || []
  node_id_params = node_ids.inject({}) do |node_hash, node_id|
    index = node_ids.index(node_id) + 1
    node_hash["CacheNodeIdsToReboot.member.#{index}"] = node_id
    node_hash
  end
  # Merge the CacheNodeIdsToReboot parameters with the normal options
  request(node_id_params.merge(
    'Action'          => 'RebootCacheCluster',
    'CacheClusterId'  => id,
    :parser => Fog::Parsers::AWS::Elasticache::SingleCacheCluster.new
  ))
end

#reloadObject



72
73
74
# File 'lib/fog/aws/elasticache.rb', line 72

def reload
  @connection.reset
end

#reset_cache_parameter_group(id, parameter_names = []) ⇒ Object

Resets an existing cache parameter group Returns a the name of the modified parameter group

Required Parameters

  • id <~String> - The ID of the parameter group to be modified

Optional Parameters

  • parameter_names <~Array> - The parameters to reset

Returns

  • response <~Excon::Response>:

    • body <~Hash>



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/fog/aws/requests/elasticache/reset_cache_parameter_group.rb', line 18

def reset_cache_parameter_group(id, parameter_names = [])
  # Construct Parameter resets in the format:
  #   ParameterNameValues.member.N => "param_name"
  parameter_changes = parameter_names.inject({}) do |new_args, param|
    index = parameter_names.index(param) + 1
    new_args["ParameterNameValues.member.#{index}"] = param
    new_args
  end
  if parameter_changes.empty?
    parameter_changes = {'ResetAllParameters' => 'true'}
  end
  # Merge the Cache Security Group parameters with the normal options
  request(parameter_changes.merge(
    'Action'                      => 'ResetCacheParameterGroup',
    'CacheParameterGroupName'     => id,
    :parser => Fog::Parsers::AWS::Elasticache::ResetParameterGroup.new
  ))
end

#revoke_cache_security_group_ingress(name, ec2_name, ec2_owner_id) ⇒ Object

Revoke ingress to a CacheSecurityGroup using EC2 Security Groups

Parameters

  • name <~String> - The name of the cache security group

  • ec2_name <~String> - The name of the EC2 security group to revoke

  • ec2_owner_id <~String> - The AWS Account Number of the EC2 security group

Returns

  • response <~Excon::Response>:

    • body <~Hash>



18
19
20
21
22
23
24
25
26
# File 'lib/fog/aws/requests/elasticache/revoke_cache_security_group_ingress.rb', line 18

def revoke_cache_security_group_ingress(name, ec2_name, ec2_owner_id)
  request({
    'Action' => 'RevokeCacheSecurityGroupIngress',
    'CacheSecurityGroupName' => name,
    'EC2SecurityGroupName' => ec2_name,
    'EC2SecurityGroupOwnerId' => ec2_owner_id,
    :parser => Fog::Parsers::AWS::Elasticache::SingleSecurityGroup.new
  })
end