Class: BuildCloud::CacheCluster

Inherits:
Object
  • Object
show all
Includes:
Component
Defined in:
lib/build-cloud/cachecluster.rb

Constant Summary collapse

@@objects =
[]

Instance Method Summary collapse

Methods included from Component

included

Constructor Details

#initialize(fog_interfaces, log, options = {}) ⇒ CacheCluster

Returns a new instance of CacheCluster.



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/build-cloud/cachecluster.rb', line 8

def initialize ( fog_interfaces, log, options = {} )

    @elasticache = fog_interfaces[:elasticache]
    @log         = log
    @options     = options

    @log.debug( options.inspect )

    required_options(:id, :node_type, :num_nodes, :auto_minor_version_upgrade, 
        :engine, :cache_subnet_group_name)
    require_one_of(:vpc_security_groups, :vpc_security_group_names)

end

Instance Method Details

#createObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/build-cloud/cachecluster.rb', line 22

def create

    return if exists?

    @log.info( "Creating Elasticache Cluster #{@options[:id]}" )

    options = @options.dup

    unless options[:vpc_security_groups]

        options[:vpc_security_groups] = []

        options[:vpc_security_group_names].each do |sg|
            options[:vpc_security_groups] << BuildCloud::SecurityGroup. get_id_by_name( sg )
        end

        options.delete(:vpc_security_group_names)

    end

    cluster = @elasticache.clusters.new( options )
    cluster.save

    @log.debug( cluster.inspect )

end

#deleteObject



55
56
57
58
59
60
61
62
63
# File 'lib/build-cloud/cachecluster.rb', line 55

def delete

    return unless exists?

    @log.info( "Deleting Elasticache cluster #{@options[:id]}" )

    fog_object.destroy

end

#readObject Also known as: fog_object



49
50
51
# File 'lib/build-cloud/cachecluster.rb', line 49

def read
    @elasticache.clusters.select { |c| c.id == @options[:id] }.first
end