cumulus-aws 0.11.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (173) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +3 -0
  3. data/.travis.yml +12 -0
  4. data/Gemfile +4 -0
  5. data/Gemfile.lock +29 -0
  6. data/LICENSE +202 -0
  7. data/README.md +41 -0
  8. data/autocomplete +137 -0
  9. data/bin/cumulus +658 -0
  10. data/cumulus +2 -0
  11. data/cumulus-aws.gemspec +20 -0
  12. data/lib/autoscaling/AutoScaling.rb +40 -0
  13. data/lib/autoscaling/loader/Loader.rb +56 -0
  14. data/lib/autoscaling/manager/Manager.rb +360 -0
  15. data/lib/autoscaling/models/AlarmConfig.rb +165 -0
  16. data/lib/autoscaling/models/AlarmDiff.rb +172 -0
  17. data/lib/autoscaling/models/AutoScalingDiff.rb +178 -0
  18. data/lib/autoscaling/models/GroupConfig.rb +330 -0
  19. data/lib/autoscaling/models/PolicyConfig.rb +135 -0
  20. data/lib/autoscaling/models/PolicyDiff.rb +73 -0
  21. data/lib/autoscaling/models/ScheduledActionDiff.rb +53 -0
  22. data/lib/autoscaling/models/ScheduledConfig.rb +96 -0
  23. data/lib/aws_extensions/ec2/DhcpOptions.rb +41 -0
  24. data/lib/aws_extensions/ec2/Instance.rb +29 -0
  25. data/lib/aws_extensions/ec2/NetworkAcl.rb +25 -0
  26. data/lib/aws_extensions/ec2/NetworkInterface.rb +14 -0
  27. data/lib/aws_extensions/ec2/RouteTable.rb +26 -0
  28. data/lib/aws_extensions/ec2/SecurityGroup.rb +16 -0
  29. data/lib/aws_extensions/ec2/Subnet.rb +28 -0
  30. data/lib/aws_extensions/ec2/Volume.rb +24 -0
  31. data/lib/aws_extensions/ec2/Vpc.rb +14 -0
  32. data/lib/aws_extensions/ec2/VpcEndpoint.rb +11 -0
  33. data/lib/aws_extensions/elb/BackendServerDescription.rb +12 -0
  34. data/lib/aws_extensions/elb/PolicyDescription.rb +14 -0
  35. data/lib/aws_extensions/kinesis/StreamDescription.rb +12 -0
  36. data/lib/aws_extensions/route53/AliasTarget.rb +21 -0
  37. data/lib/aws_extensions/s3/Bucket.rb +33 -0
  38. data/lib/aws_extensions/s3/BucketAcl.rb +28 -0
  39. data/lib/aws_extensions/s3/BucketCors.rb +17 -0
  40. data/lib/aws_extensions/s3/BucketLifecycle.rb +21 -0
  41. data/lib/aws_extensions/s3/BucketLogging.rb +18 -0
  42. data/lib/aws_extensions/s3/BucketNotification.rb +23 -0
  43. data/lib/aws_extensions/s3/BucketPolicy.rb +18 -0
  44. data/lib/aws_extensions/s3/BucketTagging.rb +15 -0
  45. data/lib/aws_extensions/s3/BucketVersioning.rb +14 -0
  46. data/lib/aws_extensions/s3/BucketWebsite.rb +49 -0
  47. data/lib/aws_extensions/s3/CORSRule.rb +27 -0
  48. data/lib/aws_extensions/s3/ReplicationConfiguration.rb +22 -0
  49. data/lib/cloudfront/CloudFront.rb +83 -0
  50. data/lib/cloudfront/loader/Loader.rb +31 -0
  51. data/lib/cloudfront/manager/Manager.rb +183 -0
  52. data/lib/cloudfront/models/CacheBehaviorConfig.rb +237 -0
  53. data/lib/cloudfront/models/CacheBehaviorDiff.rb +211 -0
  54. data/lib/cloudfront/models/CustomOriginConfig.rb +51 -0
  55. data/lib/cloudfront/models/CustomOriginDiff.rb +74 -0
  56. data/lib/cloudfront/models/DistributionConfig.rb +183 -0
  57. data/lib/cloudfront/models/DistributionDiff.rb +131 -0
  58. data/lib/cloudfront/models/InvalidationConfig.rb +37 -0
  59. data/lib/cloudfront/models/OriginConfig.rb +144 -0
  60. data/lib/cloudfront/models/OriginDiff.rb +86 -0
  61. data/lib/cloudfront/models/OriginSslProtocols.rb +28 -0
  62. data/lib/cloudfront/models/OriginSslProtocolsDiff.rb +39 -0
  63. data/lib/common/BaseLoader.rb +80 -0
  64. data/lib/common/manager/Manager.rb +148 -0
  65. data/lib/common/models/Diff.rb +114 -0
  66. data/lib/common/models/ListChange.rb +21 -0
  67. data/lib/common/models/TagsDiff.rb +55 -0
  68. data/lib/common/models/UTCTimeSource.rb +17 -0
  69. data/lib/conf/Configuration.rb +365 -0
  70. data/lib/ec2/EC2.rb +503 -0
  71. data/lib/ec2/IPProtocolMapping.rb +165 -0
  72. data/lib/ec2/loaders/EbsLoader.rb +19 -0
  73. data/lib/ec2/loaders/InstanceLoader.rb +32 -0
  74. data/lib/ec2/managers/EbsManager.rb +176 -0
  75. data/lib/ec2/managers/InstanceManager.rb +509 -0
  76. data/lib/ec2/models/EbsGroupConfig.rb +133 -0
  77. data/lib/ec2/models/EbsGroupDiff.rb +48 -0
  78. data/lib/ec2/models/InstanceConfig.rb +202 -0
  79. data/lib/ec2/models/InstanceDiff.rb +95 -0
  80. data/lib/elb/ELB.rb +148 -0
  81. data/lib/elb/loader/Loader.rb +65 -0
  82. data/lib/elb/manager/Manager.rb +581 -0
  83. data/lib/elb/models/AccessLogConfig.rb +82 -0
  84. data/lib/elb/models/AccessLogDiff.rb +47 -0
  85. data/lib/elb/models/HealthCheckConfig.rb +91 -0
  86. data/lib/elb/models/HealthCheckDiff.rb +50 -0
  87. data/lib/elb/models/ListenerConfig.rb +99 -0
  88. data/lib/elb/models/ListenerDiff.rb +91 -0
  89. data/lib/elb/models/LoadBalancerConfig.rb +239 -0
  90. data/lib/elb/models/LoadBalancerDiff.rb +265 -0
  91. data/lib/iam/IAM.rb +36 -0
  92. data/lib/iam/loader/Loader.rb +117 -0
  93. data/lib/iam/manager/IamGroups.rb +98 -0
  94. data/lib/iam/manager/IamResource.rb +288 -0
  95. data/lib/iam/manager/IamRoles.rb +112 -0
  96. data/lib/iam/manager/IamUsers.rb +54 -0
  97. data/lib/iam/manager/Manager.rb +29 -0
  98. data/lib/iam/migration/AssumeRoleUnifier.rb +34 -0
  99. data/lib/iam/migration/PolicyUnifier.rb +90 -0
  100. data/lib/iam/models/GroupConfig.rb +40 -0
  101. data/lib/iam/models/IamDiff.rb +132 -0
  102. data/lib/iam/models/PolicyConfig.rb +67 -0
  103. data/lib/iam/models/ResourceWithPolicy.rb +208 -0
  104. data/lib/iam/models/RoleConfig.rb +53 -0
  105. data/lib/iam/models/StatementConfig.rb +35 -0
  106. data/lib/iam/models/UserConfig.rb +21 -0
  107. data/lib/kinesis/Kinesis.rb +94 -0
  108. data/lib/kinesis/loader/Loader.rb +19 -0
  109. data/lib/kinesis/manager/Manager.rb +206 -0
  110. data/lib/kinesis/models/StreamConfig.rb +75 -0
  111. data/lib/kinesis/models/StreamDiff.rb +58 -0
  112. data/lib/lambda/Lambda.rb +41 -0
  113. data/lib/route53/loader/Loader.rb +32 -0
  114. data/lib/route53/manager/Manager.rb +241 -0
  115. data/lib/route53/models/AliasTarget.rb +86 -0
  116. data/lib/route53/models/RecordConfig.rb +178 -0
  117. data/lib/route53/models/RecordDiff.rb +140 -0
  118. data/lib/route53/models/Vpc.rb +24 -0
  119. data/lib/route53/models/ZoneConfig.rb +156 -0
  120. data/lib/route53/models/ZoneDiff.rb +118 -0
  121. data/lib/s3/S3.rb +89 -0
  122. data/lib/s3/loader/Loader.rb +66 -0
  123. data/lib/s3/manager/Manager.rb +296 -0
  124. data/lib/s3/models/BucketConfig.rb +321 -0
  125. data/lib/s3/models/BucketDiff.rb +167 -0
  126. data/lib/s3/models/GrantConfig.rb +189 -0
  127. data/lib/s3/models/GrantDiff.rb +50 -0
  128. data/lib/s3/models/LifecycleConfig.rb +142 -0
  129. data/lib/s3/models/LifecycleDiff.rb +46 -0
  130. data/lib/s3/models/LoggingConfig.rb +81 -0
  131. data/lib/s3/models/NotificationConfig.rb +157 -0
  132. data/lib/s3/models/NotificationDiff.rb +62 -0
  133. data/lib/s3/models/ReplicationConfig.rb +133 -0
  134. data/lib/s3/models/ReplicationDiff.rb +60 -0
  135. data/lib/s3/models/WebsiteConfig.rb +107 -0
  136. data/lib/security/SecurityGroups.rb +39 -0
  137. data/lib/security/loader/Loader.rb +94 -0
  138. data/lib/security/manager/Manager.rb +246 -0
  139. data/lib/security/models/RuleConfig.rb +161 -0
  140. data/lib/security/models/RuleDiff.rb +72 -0
  141. data/lib/security/models/RuleMigration.rb +127 -0
  142. data/lib/security/models/SecurityGroupConfig.rb +172 -0
  143. data/lib/security/models/SecurityGroupDiff.rb +112 -0
  144. data/lib/sns/SNS.rb +40 -0
  145. data/lib/sqs/SQS.rb +62 -0
  146. data/lib/sqs/loader/Loader.rb +34 -0
  147. data/lib/sqs/manager/Manager.rb +128 -0
  148. data/lib/sqs/models/DeadLetterConfig.rb +70 -0
  149. data/lib/sqs/models/DeadLetterDiff.rb +35 -0
  150. data/lib/sqs/models/QueueConfig.rb +115 -0
  151. data/lib/sqs/models/QueueDiff.rb +89 -0
  152. data/lib/util/Colors.rb +111 -0
  153. data/lib/util/StatusCodes.rb +51 -0
  154. data/lib/vpc/loader/Loader.rb +73 -0
  155. data/lib/vpc/manager/Manager.rb +954 -0
  156. data/lib/vpc/models/AclEntryConfig.rb +150 -0
  157. data/lib/vpc/models/AclEntryDiff.rb +54 -0
  158. data/lib/vpc/models/DhcpConfig.rb +100 -0
  159. data/lib/vpc/models/DhcpDiff.rb +90 -0
  160. data/lib/vpc/models/EndpointConfig.rb +76 -0
  161. data/lib/vpc/models/EndpointDiff.rb +69 -0
  162. data/lib/vpc/models/NetworkAclConfig.rb +87 -0
  163. data/lib/vpc/models/NetworkAclDiff.rb +116 -0
  164. data/lib/vpc/models/RouteConfig.rb +82 -0
  165. data/lib/vpc/models/RouteDiff.rb +50 -0
  166. data/lib/vpc/models/RouteTableConfig.rb +92 -0
  167. data/lib/vpc/models/RouteTableDiff.rb +101 -0
  168. data/lib/vpc/models/SubnetConfig.rb +113 -0
  169. data/lib/vpc/models/SubnetDiff.rb +78 -0
  170. data/lib/vpc/models/VpcConfig.rb +173 -0
  171. data/lib/vpc/models/VpcDiff.rb +315 -0
  172. data/rakefile.rb +8 -0
  173. metadata +245 -0
@@ -0,0 +1,73 @@
1
+ require "common/models/Diff"
2
+ require "util/Colors"
3
+
4
+ module Cumulus
5
+ module AutoScaling
6
+ # Public: The types of changes that can be made to scaling policies
7
+ module PolicyChange
8
+ include Common::DiffChange
9
+
10
+ ADJUSTMENT = Common::DiffChange::next_change_id
11
+ ADJUSTMENT_TYPE = Common::DiffChange::next_change_id
12
+ ALARM = Common::DiffChange::next_change_id
13
+ COOLDOWN = Common::DiffChange::next_change_id
14
+ MIN_ADJUSTMENT = Common::DiffChange::next_change_id
15
+ end
16
+
17
+ # Public: Represents a single difference between local configuration and AWS
18
+ # configuration of scaling policies
19
+ class PolicyDiff < Common::Diff
20
+ include PolicyChange
21
+
22
+ attr_accessor :alarm_diffs
23
+ attr_accessor :policy_arn
24
+
25
+ # Public: Static method that will produce a diff that contains changes in
26
+ # cloudwatch alarms
27
+ #
28
+ # alarm_diffs - the differences in alarms
29
+ # local - the local configuration for the change
30
+ # policy_arn - the arn of the policy the alarms should be associated with
31
+ #
32
+ # Returns the diff
33
+ def self.alarms(alarm_diffs, local, policy_arn)
34
+ diff = PolicyDiff.new(ALARM, nil, local)
35
+ diff.alarm_diffs = alarm_diffs
36
+ diff.policy_arn = policy_arn
37
+ diff
38
+ end
39
+
40
+ def diff_string
41
+ diff_lines = [@local.name]
42
+
43
+ case @type
44
+ when ADJUSTMENT_TYPE
45
+ diff_lines << "\tAdjustment type: AWS - #{Colors.aws_changes(@aws.adjustment_type)}, Local - #{Colors.local_changes(@local.adjustment_type)}"
46
+ when ADJUSTMENT
47
+ diff_lines << "\tScaling adjustment: AWS - #{Colors.aws_changes(@aws.scaling_adjustment)}, Local - #{Colors.local_changes(@local.adjustment)}"
48
+ when ALARM
49
+ lines = ["\t\tCloudwatch alarms:"]
50
+ lines << alarm_diffs.map do |diff|
51
+ diff.to_s.lines.map {|s| "\t\t\t#{s}" }.join
52
+ end
53
+ diff_lines << lines.flatten.join("\n")
54
+ when COOLDOWN
55
+ diff_lines << "\tCooldown: AWS - #{Colors.aws_changes(@aws.cooldown)}, Local - #{Colors.local_changes(@local.cooldown)}"
56
+ when MIN_ADJUSTMENT
57
+ diff_lines << "\tMin adjustment step: AWS - #{Colors.aws_changes(@aws.min_adjustment_step)}, Local - #{Colors.local_changes(@local.min_adjustment)}"
58
+ end
59
+
60
+ diff_lines.flatten.join("\n")
61
+ end
62
+
63
+ def asset_type
64
+ "Scaling policy"
65
+ end
66
+
67
+ def aws_name
68
+ @aws.policy_name
69
+ end
70
+
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,53 @@
1
+ require "common/models/Diff"
2
+ require "util/Colors"
3
+
4
+ module Cumulus
5
+ module AutoScaling
6
+ # Public: The types of changes that can be made to Scheduled Actions
7
+ module ScheduledActionChange
8
+ include Common::DiffChange
9
+
10
+ START = Common::DiffChange::next_change_id
11
+ ENDTIME = Common::DiffChange::next_change_id
12
+ RECURRENCE = Common::DiffChange::next_change_id
13
+ MIN = Common::DiffChange::next_change_id
14
+ MAX = Common::DiffChange::next_change_id
15
+ DESIRED = Common::DiffChange::next_change_id
16
+ end
17
+
18
+ # Public: Represents a single difference between local configuration and AWS
19
+ # configuration of Scheduled Actions
20
+ class ScheduledActionDiff < Common::Diff
21
+ include ScheduledActionChange
22
+
23
+ def diff_string
24
+ diff_lines = []
25
+
26
+ case @type
27
+ when START
28
+ diff_lines << "Start: AWS - #{Colors.aws_changes(@aws.start_time)}, Local - #{Colors.local_changes(@local.start)}"
29
+ when ENDTIME
30
+ diff_lines << "End: AWS - #{Colors.aws_changes(@aws.end_time)}, Local - #{Colors.local_changes(@local.end)}"
31
+ when RECURRENCE
32
+ diff_lines << "Recurrence: AWS - #{Colors.aws_changes(@aws.recurrence)}, Local - #{Colors.local_changes(@local.recurrence)}"
33
+ when MIN
34
+ diff_lines << "Min size: AWS - #{Colors.aws_changes(@aws.min_size)}, Local - #{Colors.local_changes(@local.min)}"
35
+ when MAX
36
+ diff_lines << "Max size: AWS - #{Colors.aws_changes(@aws.max_size)}, Local - #{Colors.local_changes(@local.max)}"
37
+ when DESIRED
38
+ diff_lines << "Desired capacity: AWS - #{Colors.aws_changes(@aws.desired_capacity)}, Local - #{Colors.local_changes(@local.desired)}"
39
+ end
40
+
41
+ diff_lines.flatten.join("\n")
42
+ end
43
+
44
+ def asset_type
45
+ "Scheduled action"
46
+ end
47
+
48
+ def aws_name
49
+ @aws.scheduled_action_name
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,96 @@
1
+ require "autoscaling/models/ScheduledActionDiff"
2
+
3
+ module Cumulus
4
+ module AutoScaling
5
+ # Public: A class representing the configuration for a scheduled scaling action
6
+ class ScheduledConfig
7
+ attr_accessor :desired
8
+ attr_accessor :end
9
+ attr_accessor :max
10
+ attr_accessor :min
11
+ attr_accessor :name
12
+ attr_accessor :recurrence
13
+ attr_accessor :start
14
+
15
+ # Public: Constructor
16
+ #
17
+ # json - a hash representing the JSON configuration for this action
18
+ def initialize(json = nil)
19
+ if !json.nil?
20
+ @name = json["name"]
21
+ if !json["start"].nil? and json["start"] != ""
22
+ @start = Time.parse(json["start"])
23
+ end
24
+ if !json["end"].nil? and json["end"] != ""
25
+ @end = Time.parse(json["end"])
26
+ end
27
+ @recurrence = json["recurrence"]
28
+ @min = json["min"]
29
+ @max = json["max"]
30
+ @desired = json["desired"]
31
+ end
32
+ end
33
+
34
+ # Public: Get the configuration as a hash
35
+ #
36
+ # Returns the hash
37
+ def hash
38
+ {
39
+ "desired" => @desired,
40
+ "end" => @end,
41
+ "max" => @max,
42
+ "min" => @min,
43
+ "name" => @name,
44
+ "recurrence" => @recurrence,
45
+ "start" => @start
46
+ }.reject { |k, v| v.nil? }
47
+ end
48
+
49
+ # Public: Produce the differences between this local configuration and the
50
+ # configuration in AWS
51
+ #
52
+ # aws - the scheduled action in AWS
53
+ def diff(aws)
54
+ diffs = []
55
+
56
+ # we check if start is nil, cause even in the case that it is nil, aws
57
+ # will still give the scheduled action a start time on creation. This is
58
+ # annoying, because it will make it seem as if start time is always changed.
59
+ if @start != aws.start_time and !@start.nil?
60
+ diffs << ScheduledActionDiff.new(ScheduledActionChange::START, aws, self)
61
+ end
62
+ if @end != aws.end_time
63
+ diffs << ScheduledActionDiff.new(ScheduledActionChange::ENDTIME, aws, self)
64
+ end
65
+ if @recurrence != aws.recurrence
66
+ diffs << ScheduledActionDiff.new(ScheduledActionChange::RECURRENCE, aws, self)
67
+ end
68
+ if @min != aws.min_size
69
+ diffs << ScheduledActionDiff.new(ScheduledActionChange::MIN, aws, self)
70
+ end
71
+ if @max != aws.max_size
72
+ diffs << ScheduledActionDiff.new(ScheduledActionChange::MAX, aws, self)
73
+ end
74
+ if @desired != aws.desired_capacity
75
+ diffs << ScheduledActionDiff.new(ScheduledActionChange::DESIRED, aws, self)
76
+ end
77
+
78
+ diffs
79
+ end
80
+
81
+ # Public: Populate the ScheduledConfig from an existing AWS resource
82
+ #
83
+ # resource - the aws resource to populate from
84
+ def populate(resource)
85
+ @desired = resource.desired_capacity
86
+ @end = resource.end_time
87
+ @max = resource.max_size
88
+ @min = resource.min_size
89
+ @name = resource.scheduled_action_name
90
+ @recurrence = resource.recurrence
91
+ @start = resource.start_time
92
+ end
93
+
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,41 @@
1
+ module AwsExtensions
2
+ module EC2
3
+ module DhcpOptions
4
+
5
+ # Public: Returns the value of the domain-name-servers
6
+ def domain_name_servers
7
+ get_attribute_values("domain-name-servers")
8
+ end
9
+
10
+ # Public: Returns the value of domain-name
11
+ def domain_name
12
+ get_attribute_values("domain-name").first
13
+ end
14
+
15
+ # Public: Returns the value of ntp-servers if set
16
+ def ntp_servers
17
+ get_attribute_values("ntp-servers")
18
+ end
19
+
20
+ # Public: Returns the value of netbios-name-servers
21
+ def netbios_name_servers
22
+ get_attribute_values("netbios-name-servers")
23
+ end
24
+
25
+ # Public: Returns the value of netbios-node-type
26
+ def netbios_node_type
27
+ get_attribute_values("netbios-node-type").first
28
+ end
29
+
30
+ private
31
+
32
+ # Internal: Gets an named attribute from the dhcp_configuration
33
+ def get_attribute_values(attr_name)
34
+ self.dhcp_configurations.select { |conf| conf.key == attr_name }.first.values.map(&:value)
35
+ rescue
36
+ []
37
+ end
38
+
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,29 @@
1
+ module AwsExtensions
2
+ module EC2
3
+ module Instance
4
+
5
+ # Public: Returns the value of the "Name" tag for the Instance
6
+ def name
7
+ self.tags.select { |tag| tag.key == "Name" }.first.value
8
+ rescue
9
+ nil
10
+ end
11
+
12
+ # Public: Returns an array of the block device mappings that are not for the root device
13
+ def nonroot_devices
14
+ self.block_device_mappings.reject { |m| m.device_name == self.root_device_name }
15
+ end
16
+
17
+ # Public: Returns true if the instance is stopped
18
+ def stopped?
19
+ self.state.name == "stopped"
20
+ end
21
+
22
+ # Public: Returns true if the instance is terminated
23
+ def terminated?
24
+ self.state.name == "terminated"
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,25 @@
1
+ module AwsExtensions
2
+ module EC2
3
+ module NetworkAcl
4
+
5
+ # Public: Returns the value of the "Name" tag for the ACL
6
+ def name
7
+ self.tags.select { |tag| tag.key == "Name" }.first.value
8
+ rescue
9
+ nil
10
+ end
11
+
12
+ # Public: Returns the subnet ids associated with an ACL
13
+ def subnet_ids
14
+ self.associations.map { |assoc| assoc.subnet_id }
15
+ end
16
+
17
+ # Public: Returns the enteries that are diffable by leaving out
18
+ # the last rule that denies all
19
+ def diffable_entries
20
+ self.entries.select { |entry| entry.rule_number < 32767 }
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,14 @@
1
+ module AwsExtensions
2
+ module EC2
3
+ module NetworkInterface
4
+
5
+ # Public: Returns the value of the "Name" tag for the route table
6
+ def name
7
+ self.tag_set.select { |tag| tag.key == "Name" }.first.value
8
+ rescue
9
+ nil
10
+ end
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,26 @@
1
+ module AwsExtensions
2
+ module EC2
3
+ module RouteTable
4
+
5
+ # Public: Returns the value of the "Name" tag for the route table
6
+ def name
7
+ self.tags.select { |tag| tag.key == "Name" }.first.value
8
+ rescue
9
+ nil
10
+ end
11
+
12
+ # Public: Returns an array of subnet ids associated with the route table
13
+ def subnet_ids
14
+ self.associations.map { |assoc| assoc.subnet_id }
15
+ end
16
+
17
+ # Public: Selects the routes in the route table that we care about by filtering out
18
+ # the default route with the local gateway and any routes that are for s3 service endpoints
19
+ # (ones that have a destination_prefix_list_id)
20
+ def diffable_routes
21
+ self.routes.select { |route| route.gateway_id != "local" and route.origin != "CreateRouteTable" and !route.destination_prefix_list_id }
22
+ end
23
+
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,16 @@
1
+ require "ec2/EC2"
2
+
3
+ module AwsExtensions
4
+ module EC2
5
+ module SecurityGroup
6
+
7
+ # Public: Returns the name of the security group prefixed by the vpc name or id
8
+ def vpc_group_name
9
+ vpc = Cumulus::EC2::id_vpcs[self.vpc_id]
10
+ vpc_name = if vpc then "#{vpc.name}/" else "" end
11
+ "#{vpc_name}#{self.group_name}"
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,28 @@
1
+ require "ec2/EC2"
2
+
3
+ module AwsExtensions
4
+ module EC2
5
+ module Subnet
6
+
7
+ # Public: Returns the value of the "Name" tag for the subnet or nil if there is not one
8
+ def name
9
+ self.tags.select { |tag| tag.key == "Name" }.first.value
10
+ rescue
11
+ nil
12
+ end
13
+
14
+ # Public: Returns the name of the security group prefixed by the vpc name or id
15
+ def vpc_subnet_name
16
+ vpc = Cumulus::EC2::id_vpcs[self.vpc_id]
17
+ vpc_name = vpc.name || vpc.vpd_id
18
+ "#{vpc_name}/#{self.name}"
19
+ end
20
+
21
+ # Implement comparison by using subnet id
22
+ def <=>(other)
23
+ self.subnet_id <=> other.subnet_id
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,24 @@
1
+ module AwsExtensions
2
+ module EC2
3
+ module Volume
4
+
5
+ # Public: Returns the value of the "Group" tag for the Volume
6
+ def group
7
+ self.tags.select { |tag| tag.key == "Group" }.first.value
8
+ rescue
9
+ nil
10
+ end
11
+
12
+ # Public: Returns true if the volume is attached or attaching to anything
13
+ def attached?
14
+ self.attachments.map(&:state).any? { |state| state == "attached" || state == "attaching" }
15
+ end
16
+
17
+ # Public: Returns true if the volume is not attached or attaching to anything
18
+ def detached?
19
+ !self.attached?
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,14 @@
1
+ module AwsExtensions
2
+ module EC2
3
+ module Vpc
4
+
5
+ # Public: Returns the value of the "Name" tag for the VPC
6
+ def name
7
+ self.tags.select { |tag| tag.key == "Name" }.first.value
8
+ rescue
9
+ nil
10
+ end
11
+
12
+ end
13
+ end
14
+ end