Class: BuildCloud::ASGroup

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

Constant Summary collapse

@@objects =
[]

Instance Method Summary collapse

Methods included from Component

included

Constructor Details

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

Returns a new instance of ASGroup.



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

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

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

    @log.debug( options.inspect )

    required_options(:id, :launch_configuration_name, :min_size, :max_size,
                     :desired_capacity, :availability_zones, :health_check_grace_period)
    require_one_of(:vpc_zone_identifier, :subnet_names)

end

Instance Method Details

#createObject



21
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
48
49
50
51
52
53
54
# File 'lib/build-cloud/asgroup.rb', line 21

def create
    
    return if exists?

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

    options = @options.dup

    unless options[:vpc_zone_identifier]

        subnet_ids = []

        options[:subnet_names].each do |subnet|
            subnet_ids << BuildCloud::Subnet.get_id_by_name( subnet )
        end

        options.delete(:subnet_names)
        options[:vpc_zone_identifier] = subnet_ids.join(',')

    end

    @log.debug( options )

    asg = @as.groups.new( options )
    asg.save
    
    if options[:enabled_metrics]
       @log.debug( 'metrics enabled')
       asg.enable_metrics_collection('1Minute', options[:enable_metrics])
    end

    @log.debug( asg.inspect )

end

#deleteObject



62
63
64
65
66
67
68
69
70
# File 'lib/build-cloud/asgroup.rb', line 62

def delete

    return unless exists?

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

    fog_object.destroy( :force => true )

end

#readObject Also known as: fog_object



56
57
58
# File 'lib/build-cloud/asgroup.rb', line 56

def read
    @as.groups.select { |g| g.id == @options[:id] }.first
end