Class: BuildCloud::ASGroup
- Inherits:
-
Object
- Object
- BuildCloud::ASGroup
- Includes:
- Component
- Defined in:
- lib/build-cloud/asgroup.rb
Constant Summary collapse
- @@objects =
[]
Instance Method Summary collapse
- #create ⇒ Object
- #create_tags(tags) ⇒ Object
- #delete ⇒ Object
-
#initialize(fog_interfaces, log, options = {}) ⇒ ASGroup
constructor
A new instance of ASGroup.
- #read ⇒ Object (also: #fog_object)
Methods included from Component
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, = {} ) @as = fog_interfaces[:as] @log = log @options = @log.debug( .inspect ) (: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
#create ⇒ Object
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 55 56 57 58 59 60 |
# File 'lib/build-cloud/asgroup.rb', line 21 def create = @options.dup if exists? # If exists update tags if [:tags] ([:tags]) end return end @log.info( "Creating AS Group #{[:id]}" ) unless [:vpc_zone_identifier] subnet_ids = [] [:subnet_names].each do |subnet| subnet_ids << BuildCloud::Subnet.get_id_by_name( subnet ) end .delete(:subnet_names) [:vpc_zone_identifier] = subnet_ids.join(',') end @log.debug( ) asg = @as.groups.new( ) asg.save if [:enabled_metrics] @log.debug( 'metrics enabled') asg.enable_metrics_collection('1Minute', [:enable_metrics]) end @log.debug( asg.inspect ) end |
#create_tags(tags) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/build-cloud/asgroup.rb', line 78 def () @log.debug("Tags passed in: #{.inspect}") @log.debug("Current tags: #{fog_object..inspect}") tag_array = fog_object..dup .each do |k,v| if tag_array.find {|t| t['Key'] == k } unless tag_array.find {|t| t['Value'] == v } tag_array.find {|t| t['Value'] = v } end else tag_array << { "ResourceId" => fog_object.id, "PropagateAtLaunch" => true, "Key" => k, "Value" => v, "ResourceType" => "auto-scaling-group" } end end @log.debug("Tags to act on: #{tag_array.inspect}") if tag_array != fog_object. @log.info("Updating tags for ASG #{fog_object.id}") @as.( tag_array ) end end |
#delete ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/build-cloud/asgroup.rb', line 68 def delete return unless exists? @log.info( "Deleting ASG #{@options[:id]}" ) fog_object.destroy( :force => true ) end |
#read ⇒ Object Also known as: fog_object
62 63 64 |
# File 'lib/build-cloud/asgroup.rb', line 62 def read @as.groups.select { |g| g.id == @options[:id] }.first end |