Class: DrawCloud::ASGroup

Inherits:
Base
  • Object
show all
Defined in:
lib/draw_cloud/as_group.rb

Constant Summary collapse

NOTIFY_EC2_INSTANCE_LAUNCH =
"autoscaling:EC2_INSTANCE_LAUNCH"
NOTIFY_EC2_INSTANCE_LAUNCH_ERROR =
"autoscaling:EC2_INSTANCE_LAUNCH_ERROR"
NOTIFY_EC2_INSTANCE_TERMINATE =
"autoscaling:EC2_INSTANCE_TERMINATE"
NOTIFY_EC2_INSTANCE_TERMINATE_ERROR =
"autoscaling:EC2_INSTANCE_TERMINATE_ERROR"
NOTIFY_EC2_TEST_NOTIFICATION =
"autoscaling:TEST_NOTIFICATION"
ALL_NOTIFICATIONS =
[ NOTIFY_EC2_INSTANCE_LAUNCH,
NOTIFY_EC2_INSTANCE_LAUNCH_ERROR,
NOTIFY_EC2_INSTANCE_TERMINATE,
NOTIFY_EC2_INSTANCE_TERMINATE_ERROR,
NOTIFY_EC2_TEST_NOTIFICATION ]
ALL_ERRORS =
[ NOTIFY_EC2_INSTANCE_LAUNCH_ERROR,
NOTIFY_EC2_INSTANCE_TERMINATE_ERROR ]
ALL_ACTIVITY =
[ NOTIFY_EC2_INSTANCE_LAUNCH,
NOTIFY_EC2_INSTANCE_LAUNCH_ERROR,
NOTIFY_EC2_INSTANCE_TERMINATE,
NOTIFY_EC2_INSTANCE_TERMINATE_ERROR ]

Instance Attribute Summary collapse

Attributes inherited from Base

#as_groups, #as_launch_configurations, #deletion_policy, #depends_on, #ec2_instances, #elastic_ips, #gateways, #iam_access_keys, #iam_policies, #iam_users, #mappings, #metadata, #network_acls, #network_interfaces, #outputs, #parameters, #parent, #rdses, #resources, #route_tables, #security_groups, #sns_topics, #vpcs, #wait_handles

Instance Method Summary collapse

Methods inherited from Base

#[], #accessor, #add_standard_properties, #create_as_group, #create_as_launch_configuration, #create_ec2_instance, #create_ec2_instance_template, #create_elastic_ip, #create_iam_access_key, #create_iam_policy, #create_iam_user, #create_mapping, #create_network_acl, #create_network_interface, #create_output, #create_parameter, #create_rds, #create_route_table, #create_security_group, #create_service, #create_sns_topic, #create_subnet, #create_vpc, #create_wait_handle, #ref

Methods included from Locations

#arn_s3

Methods included from Utilities

#desplice, #fnbase64, #fngetatt, #fnjoin, #hash_to_tag_array, #region, #resource_style, #splice, #stack_name

Constructor Details

#initialize(name, options = {}, &block) ⇒ ASGroup

Returns a new instance of ASGroup.



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/draw_cloud/as_group.rb', line 41

def initialize(name, options={}, &block)
  @name = name
  @availability_zones = options.fetch(:availability_zones, [])
  @cooldown = options.fetch(:cooldown, nil)
  @launch_configuration_name = options.fetch(:launch_configuration_name, nil)
  @max_size = options.fetch(:max_size, nil)
  @min_size = options.fetch(:min_size, nil)
  @notification_configuration = options.fetch(:notification_configuration, nil)
  @desired_capacity = options.fetch(:desired_capacity, nil)
  @tags = options.fetch(:tags, [])
  @vpc_zone_identifier = options.fetch(:vpc_zone_identifier, nil)
  super(options, &block)
end

Instance Attribute Details

#availability_zonesObject

Returns the value of attribute availability_zones.



37
38
39
# File 'lib/draw_cloud/as_group.rb', line 37

def availability_zones
  @availability_zones
end

#cooldownObject

Returns the value of attribute cooldown.



37
38
39
# File 'lib/draw_cloud/as_group.rb', line 37

def cooldown
  @cooldown
end

#desired_capacityObject

Returns the value of attribute desired_capacity.



37
38
39
# File 'lib/draw_cloud/as_group.rb', line 37

def desired_capacity
  @desired_capacity
end

#launch_configuration_nameObject Also known as: launch_configuration

Returns the value of attribute launch_configuration_name.



37
38
39
# File 'lib/draw_cloud/as_group.rb', line 37

def launch_configuration_name
  @launch_configuration_name
end

#max_sizeObject

Returns the value of attribute max_size.



37
38
39
# File 'lib/draw_cloud/as_group.rb', line 37

def max_size
  @max_size
end

#min_sizeObject

Returns the value of attribute min_size.



37
38
39
# File 'lib/draw_cloud/as_group.rb', line 37

def min_size
  @min_size
end

#nameObject

Returns the value of attribute name.



37
38
39
# File 'lib/draw_cloud/as_group.rb', line 37

def name
  @name
end

#notification_configurationObject

Returns the value of attribute notification_configuration.



37
38
39
# File 'lib/draw_cloud/as_group.rb', line 37

def notification_configuration
  @notification_configuration
end

#tagsObject

Returns the value of attribute tags.



37
38
39
# File 'lib/draw_cloud/as_group.rb', line 37

def tags
  @tags
end

#vpc_zone_identifierObject Also known as: subnets

Returns the value of attribute vpc_zone_identifier.



37
38
39
# File 'lib/draw_cloud/as_group.rb', line 37

def vpc_zone_identifier
  @vpc_zone_identifier
end

Instance Method Details

#as_groupObject



55
56
57
# File 'lib/draw_cloud/as_group.rb', line 55

def as_group
  self
end

#load_into_config(config) ⇒ Object



71
72
73
74
# File 'lib/draw_cloud/as_group.rb', line 71

def load_into_config(config)
  config.cf_add_resource resource_name, self
  super(config)
end

#notify(topic_arn, notification_types) ⇒ Object



59
60
61
# File 'lib/draw_cloud/as_group.rb', line 59

def notify(topic_arn, notification_types)
  self.notification_configuration = {:arn => topic_arn, :types => notification_types}
end

#resource_nameObject



76
77
78
# File 'lib/draw_cloud/as_group.rb', line 76

def resource_name
  resource_style(name) + "AS"
end

#to_hObject



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/draw_cloud/as_group.rb', line 80

def to_h
  h = {
    "Type" => "AWS::AutoScaling::AutoScalingGroup",
    "Properties" => {
      "AvailabilityZones" => availability_zones.collect {|g| DrawCloud.ref(g) },
      "LaunchConfigurationName" => DrawCloud.ref(launch_configuration_name),
      "MaxSize" => max_size,
      "MinSize" => min_size,
      "Tags" => [], # FIXME
    }
  }
  p = h["Properties"]
  p["AvailabilityZones"] = DrawCloud.ref(availability_zones) if cooldown
  p["Cooldown"] = DrawCloud.ref(cooldown) if cooldown
  p["DesiredCapacity"] = DrawCloud.ref(desired_capacity) if desired_capacity
  p["VPCZoneIdentifier"] = vpc_zone_identifier.collect {|z| DrawCloud.ref(z) }
  p["NotificationConfiguration"] = {
    "TopicARN" => DrawCloud.ref(self.notification_configuration[:arn]),
    "NotificationTypes" => self.notification_configuration[:types],
  } if self.notification_configuration

  add_standard_properties(h)
end