cumulus-aws 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/.gitignore +3 -0
- data/.travis.yml +12 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +29 -0
- data/LICENSE +202 -0
- data/README.md +41 -0
- data/autocomplete +137 -0
- data/bin/cumulus +658 -0
- data/cumulus +2 -0
- data/cumulus-aws.gemspec +20 -0
- data/lib/autoscaling/AutoScaling.rb +40 -0
- data/lib/autoscaling/loader/Loader.rb +56 -0
- data/lib/autoscaling/manager/Manager.rb +360 -0
- data/lib/autoscaling/models/AlarmConfig.rb +165 -0
- data/lib/autoscaling/models/AlarmDiff.rb +172 -0
- data/lib/autoscaling/models/AutoScalingDiff.rb +178 -0
- data/lib/autoscaling/models/GroupConfig.rb +330 -0
- data/lib/autoscaling/models/PolicyConfig.rb +135 -0
- data/lib/autoscaling/models/PolicyDiff.rb +73 -0
- data/lib/autoscaling/models/ScheduledActionDiff.rb +53 -0
- data/lib/autoscaling/models/ScheduledConfig.rb +96 -0
- data/lib/aws_extensions/ec2/DhcpOptions.rb +41 -0
- data/lib/aws_extensions/ec2/Instance.rb +29 -0
- data/lib/aws_extensions/ec2/NetworkAcl.rb +25 -0
- data/lib/aws_extensions/ec2/NetworkInterface.rb +14 -0
- data/lib/aws_extensions/ec2/RouteTable.rb +26 -0
- data/lib/aws_extensions/ec2/SecurityGroup.rb +16 -0
- data/lib/aws_extensions/ec2/Subnet.rb +28 -0
- data/lib/aws_extensions/ec2/Volume.rb +24 -0
- data/lib/aws_extensions/ec2/Vpc.rb +14 -0
- data/lib/aws_extensions/ec2/VpcEndpoint.rb +11 -0
- data/lib/aws_extensions/elb/BackendServerDescription.rb +12 -0
- data/lib/aws_extensions/elb/PolicyDescription.rb +14 -0
- data/lib/aws_extensions/kinesis/StreamDescription.rb +12 -0
- data/lib/aws_extensions/route53/AliasTarget.rb +21 -0
- data/lib/aws_extensions/s3/Bucket.rb +33 -0
- data/lib/aws_extensions/s3/BucketAcl.rb +28 -0
- data/lib/aws_extensions/s3/BucketCors.rb +17 -0
- data/lib/aws_extensions/s3/BucketLifecycle.rb +21 -0
- data/lib/aws_extensions/s3/BucketLogging.rb +18 -0
- data/lib/aws_extensions/s3/BucketNotification.rb +23 -0
- data/lib/aws_extensions/s3/BucketPolicy.rb +18 -0
- data/lib/aws_extensions/s3/BucketTagging.rb +15 -0
- data/lib/aws_extensions/s3/BucketVersioning.rb +14 -0
- data/lib/aws_extensions/s3/BucketWebsite.rb +49 -0
- data/lib/aws_extensions/s3/CORSRule.rb +27 -0
- data/lib/aws_extensions/s3/ReplicationConfiguration.rb +22 -0
- data/lib/cloudfront/CloudFront.rb +83 -0
- data/lib/cloudfront/loader/Loader.rb +31 -0
- data/lib/cloudfront/manager/Manager.rb +183 -0
- data/lib/cloudfront/models/CacheBehaviorConfig.rb +237 -0
- data/lib/cloudfront/models/CacheBehaviorDiff.rb +211 -0
- data/lib/cloudfront/models/CustomOriginConfig.rb +51 -0
- data/lib/cloudfront/models/CustomOriginDiff.rb +74 -0
- data/lib/cloudfront/models/DistributionConfig.rb +183 -0
- data/lib/cloudfront/models/DistributionDiff.rb +131 -0
- data/lib/cloudfront/models/InvalidationConfig.rb +37 -0
- data/lib/cloudfront/models/OriginConfig.rb +144 -0
- data/lib/cloudfront/models/OriginDiff.rb +86 -0
- data/lib/cloudfront/models/OriginSslProtocols.rb +28 -0
- data/lib/cloudfront/models/OriginSslProtocolsDiff.rb +39 -0
- data/lib/common/BaseLoader.rb +80 -0
- data/lib/common/manager/Manager.rb +148 -0
- data/lib/common/models/Diff.rb +114 -0
- data/lib/common/models/ListChange.rb +21 -0
- data/lib/common/models/TagsDiff.rb +55 -0
- data/lib/common/models/UTCTimeSource.rb +17 -0
- data/lib/conf/Configuration.rb +365 -0
- data/lib/ec2/EC2.rb +503 -0
- data/lib/ec2/IPProtocolMapping.rb +165 -0
- data/lib/ec2/loaders/EbsLoader.rb +19 -0
- data/lib/ec2/loaders/InstanceLoader.rb +32 -0
- data/lib/ec2/managers/EbsManager.rb +176 -0
- data/lib/ec2/managers/InstanceManager.rb +509 -0
- data/lib/ec2/models/EbsGroupConfig.rb +133 -0
- data/lib/ec2/models/EbsGroupDiff.rb +48 -0
- data/lib/ec2/models/InstanceConfig.rb +202 -0
- data/lib/ec2/models/InstanceDiff.rb +95 -0
- data/lib/elb/ELB.rb +148 -0
- data/lib/elb/loader/Loader.rb +65 -0
- data/lib/elb/manager/Manager.rb +581 -0
- data/lib/elb/models/AccessLogConfig.rb +82 -0
- data/lib/elb/models/AccessLogDiff.rb +47 -0
- data/lib/elb/models/HealthCheckConfig.rb +91 -0
- data/lib/elb/models/HealthCheckDiff.rb +50 -0
- data/lib/elb/models/ListenerConfig.rb +99 -0
- data/lib/elb/models/ListenerDiff.rb +91 -0
- data/lib/elb/models/LoadBalancerConfig.rb +239 -0
- data/lib/elb/models/LoadBalancerDiff.rb +265 -0
- data/lib/iam/IAM.rb +36 -0
- data/lib/iam/loader/Loader.rb +117 -0
- data/lib/iam/manager/IamGroups.rb +98 -0
- data/lib/iam/manager/IamResource.rb +288 -0
- data/lib/iam/manager/IamRoles.rb +112 -0
- data/lib/iam/manager/IamUsers.rb +54 -0
- data/lib/iam/manager/Manager.rb +29 -0
- data/lib/iam/migration/AssumeRoleUnifier.rb +34 -0
- data/lib/iam/migration/PolicyUnifier.rb +90 -0
- data/lib/iam/models/GroupConfig.rb +40 -0
- data/lib/iam/models/IamDiff.rb +132 -0
- data/lib/iam/models/PolicyConfig.rb +67 -0
- data/lib/iam/models/ResourceWithPolicy.rb +208 -0
- data/lib/iam/models/RoleConfig.rb +53 -0
- data/lib/iam/models/StatementConfig.rb +35 -0
- data/lib/iam/models/UserConfig.rb +21 -0
- data/lib/kinesis/Kinesis.rb +94 -0
- data/lib/kinesis/loader/Loader.rb +19 -0
- data/lib/kinesis/manager/Manager.rb +206 -0
- data/lib/kinesis/models/StreamConfig.rb +75 -0
- data/lib/kinesis/models/StreamDiff.rb +58 -0
- data/lib/lambda/Lambda.rb +41 -0
- data/lib/route53/loader/Loader.rb +32 -0
- data/lib/route53/manager/Manager.rb +241 -0
- data/lib/route53/models/AliasTarget.rb +86 -0
- data/lib/route53/models/RecordConfig.rb +178 -0
- data/lib/route53/models/RecordDiff.rb +140 -0
- data/lib/route53/models/Vpc.rb +24 -0
- data/lib/route53/models/ZoneConfig.rb +156 -0
- data/lib/route53/models/ZoneDiff.rb +118 -0
- data/lib/s3/S3.rb +89 -0
- data/lib/s3/loader/Loader.rb +66 -0
- data/lib/s3/manager/Manager.rb +296 -0
- data/lib/s3/models/BucketConfig.rb +321 -0
- data/lib/s3/models/BucketDiff.rb +167 -0
- data/lib/s3/models/GrantConfig.rb +189 -0
- data/lib/s3/models/GrantDiff.rb +50 -0
- data/lib/s3/models/LifecycleConfig.rb +142 -0
- data/lib/s3/models/LifecycleDiff.rb +46 -0
- data/lib/s3/models/LoggingConfig.rb +81 -0
- data/lib/s3/models/NotificationConfig.rb +157 -0
- data/lib/s3/models/NotificationDiff.rb +62 -0
- data/lib/s3/models/ReplicationConfig.rb +133 -0
- data/lib/s3/models/ReplicationDiff.rb +60 -0
- data/lib/s3/models/WebsiteConfig.rb +107 -0
- data/lib/security/SecurityGroups.rb +39 -0
- data/lib/security/loader/Loader.rb +94 -0
- data/lib/security/manager/Manager.rb +246 -0
- data/lib/security/models/RuleConfig.rb +161 -0
- data/lib/security/models/RuleDiff.rb +72 -0
- data/lib/security/models/RuleMigration.rb +127 -0
- data/lib/security/models/SecurityGroupConfig.rb +172 -0
- data/lib/security/models/SecurityGroupDiff.rb +112 -0
- data/lib/sns/SNS.rb +40 -0
- data/lib/sqs/SQS.rb +62 -0
- data/lib/sqs/loader/Loader.rb +34 -0
- data/lib/sqs/manager/Manager.rb +128 -0
- data/lib/sqs/models/DeadLetterConfig.rb +70 -0
- data/lib/sqs/models/DeadLetterDiff.rb +35 -0
- data/lib/sqs/models/QueueConfig.rb +115 -0
- data/lib/sqs/models/QueueDiff.rb +89 -0
- data/lib/util/Colors.rb +111 -0
- data/lib/util/StatusCodes.rb +51 -0
- data/lib/vpc/loader/Loader.rb +73 -0
- data/lib/vpc/manager/Manager.rb +954 -0
- data/lib/vpc/models/AclEntryConfig.rb +150 -0
- data/lib/vpc/models/AclEntryDiff.rb +54 -0
- data/lib/vpc/models/DhcpConfig.rb +100 -0
- data/lib/vpc/models/DhcpDiff.rb +90 -0
- data/lib/vpc/models/EndpointConfig.rb +76 -0
- data/lib/vpc/models/EndpointDiff.rb +69 -0
- data/lib/vpc/models/NetworkAclConfig.rb +87 -0
- data/lib/vpc/models/NetworkAclDiff.rb +116 -0
- data/lib/vpc/models/RouteConfig.rb +82 -0
- data/lib/vpc/models/RouteDiff.rb +50 -0
- data/lib/vpc/models/RouteTableConfig.rb +92 -0
- data/lib/vpc/models/RouteTableDiff.rb +101 -0
- data/lib/vpc/models/SubnetConfig.rb +113 -0
- data/lib/vpc/models/SubnetDiff.rb +78 -0
- data/lib/vpc/models/VpcConfig.rb +173 -0
- data/lib/vpc/models/VpcDiff.rb +315 -0
- data/rakefile.rb +8 -0
- metadata +245 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
require "conf/Configuration"
|
|
2
|
+
require "vpc/models/AclEntryDiff"
|
|
3
|
+
require "ec2/IPProtocolMapping"
|
|
4
|
+
|
|
5
|
+
module Cumulus
|
|
6
|
+
module VPC
|
|
7
|
+
|
|
8
|
+
# Public: An object representing configuration for a VPC Network ACL Entry
|
|
9
|
+
class AclEntryConfig
|
|
10
|
+
attr_reader :rule
|
|
11
|
+
attr_reader :protocol
|
|
12
|
+
attr_reader :action
|
|
13
|
+
attr_reader :cidr_block
|
|
14
|
+
attr_reader :ports
|
|
15
|
+
attr_reader :icmp_type
|
|
16
|
+
attr_reader :icmp_code
|
|
17
|
+
|
|
18
|
+
# Public: Constructor
|
|
19
|
+
#
|
|
20
|
+
# json - a hash containing the JSON configuration for the entry
|
|
21
|
+
def initialize(json = nil)
|
|
22
|
+
if !json.nil?
|
|
23
|
+
@rule = json["rule"]
|
|
24
|
+
@protocol = json["protocol"]
|
|
25
|
+
@action = json["action"]
|
|
26
|
+
@cidr_block = json["cidr-block"]
|
|
27
|
+
@ports = json["ports"]
|
|
28
|
+
@icmp_type = json["icmp-type"]
|
|
29
|
+
@icmp_code = json["icmp-code"]
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def to_hash
|
|
34
|
+
{
|
|
35
|
+
"rule" => @rule,
|
|
36
|
+
"protocol" => @protocol,
|
|
37
|
+
"action" => @action,
|
|
38
|
+
"cidr-block" => @cidr_block,
|
|
39
|
+
"ports" => @ports,
|
|
40
|
+
"icmp-type" => @icmp_type,
|
|
41
|
+
"icmp-code" => @icmp_code,
|
|
42
|
+
}.reject { |k, v| v.nil? }
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def populate!(aws)
|
|
46
|
+
@rule = aws.rule_number
|
|
47
|
+
@protocol = EC2::IPProtocolMapping.keyword(aws.protocol)
|
|
48
|
+
@action = aws.rule_action
|
|
49
|
+
@cidr_block = aws.cidr_block
|
|
50
|
+
|
|
51
|
+
aws_from_port = aws.port_range.from if aws.port_range
|
|
52
|
+
aws_to_port = aws.port_range.to if aws.port_range
|
|
53
|
+
|
|
54
|
+
if aws_from_port
|
|
55
|
+
if aws_from_port == aws_to_port
|
|
56
|
+
@ports = aws_from_port.to_i
|
|
57
|
+
else
|
|
58
|
+
@ports = "#{aws_from_port}-#{aws_to_port}"
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
aws_icmp_type = aws.icmp_type_code.type if aws.icmp_type_code
|
|
63
|
+
if aws_icmp_type
|
|
64
|
+
@icmp_type = aws_icmp_type
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
aws_icmp_code = aws.icmp_type_code.code if aws.icmp_type_code
|
|
68
|
+
if aws_icmp_code
|
|
69
|
+
@icmp_code = aws_icmp_code
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
self
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# Public: expands the ports string into a from and to port
|
|
76
|
+
#
|
|
77
|
+
# Returns the from port and to port as Integer
|
|
78
|
+
def expand_ports
|
|
79
|
+
# Get the local port values as integers
|
|
80
|
+
local_from_port = nil
|
|
81
|
+
local_to_port = nil
|
|
82
|
+
|
|
83
|
+
if @ports.is_a? String
|
|
84
|
+
parts = @ports.split("-").map(&:strip)
|
|
85
|
+
local_from_port = parts[0].to_i
|
|
86
|
+
local_to_port = parts[1].to_i
|
|
87
|
+
elsif @ports.is_a? Integer
|
|
88
|
+
local_from_port = port
|
|
89
|
+
local_to_port = port
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
return local_from_port, local_to_port
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# Public: creates a string representation of the entry
|
|
96
|
+
# for printing in the console. Not in JSON format
|
|
97
|
+
def pretty_string
|
|
98
|
+
[
|
|
99
|
+
"Rule:\t\t#{rule}",
|
|
100
|
+
"Protocol:\t#{protocol}",
|
|
101
|
+
"Action:\t\t#{action}",
|
|
102
|
+
"CIDR Block:\t#{cidr_block}",
|
|
103
|
+
if ports then "Ports:\t\t#{ports}" end,
|
|
104
|
+
if icmp_type then "ICMP Type:\t#{icmp_type}" end,
|
|
105
|
+
if icmp_code then "ICMP Code:\t#{icmp_code}" end,
|
|
106
|
+
].reject(&:nil?).join("\n")
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# Public: Produce an array of differences between this local configuration and the
|
|
110
|
+
# configuration in AWS
|
|
111
|
+
#
|
|
112
|
+
# aws - the AWS resource populated in an AclEntryConfig
|
|
113
|
+
#
|
|
114
|
+
# Returns an array of the AclEntryDiffs that were found
|
|
115
|
+
def diff(aws)
|
|
116
|
+
diffs = []
|
|
117
|
+
|
|
118
|
+
if @protocol.downcase != aws.protocol.downcase
|
|
119
|
+
diffs << AclEntryDiff.new(AclEntryChange::PROTOCOL, aws.protocol, @protocol)
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
if @action != aws.action
|
|
123
|
+
diffs << AclEntryDiff.new(AclEntryChange::ACTION, aws.action, @action)
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
if @cidr_block != aws.cidr_block
|
|
127
|
+
diffs << AclEntryDiff.new(AclEntryChange::CIDR, aws.cidr_block, @cidr_block)
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
local_from_port, local_to_port = expand_ports
|
|
131
|
+
aws_from_port, aws_to_port = aws.expand_ports
|
|
132
|
+
|
|
133
|
+
if local_from_port != aws_from_port or local_to_port != aws_to_port
|
|
134
|
+
diffs << AclEntryDiff.new(AclEntryChange::PORTS, aws.ports, @ports)
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
if @icmp_type != aws.icmp_type
|
|
138
|
+
diffs << AclEntryDiff.new(AclEntryChange::ICMP_TYPE, aws.icmp_type, @icmp_type)
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
if @icmp_code != aws.icmp_code
|
|
142
|
+
diffs << AclEntryDiff.new(AclEntryChange::ICMP_CODE, aws.icmp_code, @icmp_code)
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
diffs
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
require "common/models/Diff"
|
|
2
|
+
require "util/Colors"
|
|
3
|
+
|
|
4
|
+
module Cumulus
|
|
5
|
+
module VPC
|
|
6
|
+
# Public: The types of changes that can be made to an acl entry
|
|
7
|
+
module AclEntryChange
|
|
8
|
+
include Common::DiffChange
|
|
9
|
+
|
|
10
|
+
PROTOCOL = Common::DiffChange.next_change_id
|
|
11
|
+
ACTION = Common::DiffChange.next_change_id
|
|
12
|
+
CIDR = Common::DiffChange.next_change_id
|
|
13
|
+
PORTS = Common::DiffChange.next_change_id
|
|
14
|
+
ICMP_TYPE = Common::DiffChange.next_change_id
|
|
15
|
+
ICMP_CODE = Common::DiffChange.next_change_id
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Public: Represents a single difference between local configuration and AWS configuration
|
|
19
|
+
class AclEntryDiff < Common::Diff
|
|
20
|
+
include AclEntryChange
|
|
21
|
+
|
|
22
|
+
def asset_type
|
|
23
|
+
"Network Acl Entry"
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def aws_name
|
|
27
|
+
@aws.rule_number
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def diff_string
|
|
31
|
+
resource = case @type
|
|
32
|
+
when PROTOCOL
|
|
33
|
+
"Protocol"
|
|
34
|
+
when ACTION
|
|
35
|
+
"Action"
|
|
36
|
+
when CIDR
|
|
37
|
+
"CIDR Block"
|
|
38
|
+
when PORTS
|
|
39
|
+
"Ports"
|
|
40
|
+
when ICMP_TYPE
|
|
41
|
+
"ICMP Type"
|
|
42
|
+
when ICMP_CODE
|
|
43
|
+
"ICMP Code"
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
[
|
|
47
|
+
"#{resource}:",
|
|
48
|
+
Colors.aws_changes("\tAWS - #{aws}"),
|
|
49
|
+
Colors.local_changes("\tLocal - #{local}"),
|
|
50
|
+
].join("\n")
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
require "conf/Configuration"
|
|
2
|
+
require "vpc/models/DhcpDiff"
|
|
3
|
+
|
|
4
|
+
require "json"
|
|
5
|
+
|
|
6
|
+
module Cumulus
|
|
7
|
+
module VPC
|
|
8
|
+
|
|
9
|
+
# Public: An object representing configuration for a VPC's dhcp options
|
|
10
|
+
class DhcpConfig
|
|
11
|
+
attr_reader :domain_name_servers
|
|
12
|
+
attr_reader :domain_name
|
|
13
|
+
attr_reader :ntp_servers
|
|
14
|
+
attr_reader :netbios_name_servers
|
|
15
|
+
attr_reader :netbios_node_type
|
|
16
|
+
|
|
17
|
+
require "aws_extensions/ec2/DhcpOptions"
|
|
18
|
+
Aws::EC2::Types::DhcpOptions.send(:include, AwsExtensions::EC2::DhcpOptions)
|
|
19
|
+
|
|
20
|
+
# Public: Constructor
|
|
21
|
+
#
|
|
22
|
+
# json - a hash containing the JSON configuration for the dhcp options
|
|
23
|
+
def initialize(json = nil)
|
|
24
|
+
if !json.nil?
|
|
25
|
+
@domain_name_servers = json["domain-name-servers"] || []
|
|
26
|
+
@domain_name = json["domain-name"]
|
|
27
|
+
@ntp_servers = json["ntp-servers"] || []
|
|
28
|
+
@netbios_name_servers = json["netbios-name-servers"] || []
|
|
29
|
+
@netbios_node_type = json["netbios-node-type"]
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def to_hash
|
|
34
|
+
{
|
|
35
|
+
"domain-name-servers" => @domain_name_servers.sort,
|
|
36
|
+
"domain-name" => @domain_name,
|
|
37
|
+
"ntp-servers" => @ntp_servers.sort,
|
|
38
|
+
"netbios-name-servers" => @netbios_name_servers.sort,
|
|
39
|
+
"netbios-node-type" => @netbios_node_type,
|
|
40
|
+
}.reject { |k, v| v.nil? or v.empty? }
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def to_aws
|
|
44
|
+
to_hash.map do |key, value|
|
|
45
|
+
{
|
|
46
|
+
key: key,
|
|
47
|
+
values: [value].flatten
|
|
48
|
+
}
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def populate!(aws)
|
|
53
|
+
@domain_name_servers = aws.domain_name_servers
|
|
54
|
+
@domain_name = aws.domain_name
|
|
55
|
+
@ntp_servers = aws.ntp_servers
|
|
56
|
+
@netbios_name_servers = aws.netbios_name_servers
|
|
57
|
+
@netbios_node_type = aws.netbios_node_type
|
|
58
|
+
|
|
59
|
+
self
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Public: Produce an array of differences between this local configuration and the
|
|
63
|
+
# configuration in AWS
|
|
64
|
+
#
|
|
65
|
+
# aws - the AWS resource
|
|
66
|
+
#
|
|
67
|
+
# Returns an array of the DhcpDiffs that were found
|
|
68
|
+
def diff(aws)
|
|
69
|
+
diffs = []
|
|
70
|
+
|
|
71
|
+
aws_domain_name_servers = (aws.domain_name_servers || []).sort
|
|
72
|
+
if @domain_name_servers.sort != aws_domain_name_servers
|
|
73
|
+
domain_servers_diff = DhcpDiff.domain_servers(aws_domain_name_servers, @domain_name_servers)
|
|
74
|
+
diffs << domain_servers_diff if domain_servers_diff
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
if @domain_name != aws.domain_name
|
|
78
|
+
diffs << DhcpDiff.new(DhcpChange::DOMAIN_NAME, aws.domain_name, @domain_name)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
if @ntp_servers.sort != aws.ntp_servers.sort
|
|
82
|
+
ntp_diff = DhcpDiff.ntp_servers(aws.ntp_servers, @ntp_servers)
|
|
83
|
+
diffs << ntp_diff if ntp_diff
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
if @netbios_name_servers.sort != aws.netbios_name_servers.sort
|
|
87
|
+
netbios_diff = DhcpDiff.netbios_servers(aws.netbios_name_servers, @netbios_name_servers)
|
|
88
|
+
diffs << netbios_diff if netbios_diff
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
if @netbios_node_type != aws.netbios_node_type
|
|
92
|
+
diffs << DhcpDiff.new(DhcpChange::NETBIOS_NODE, aws.netbios_node_type, @netbios_node_type)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
diffs
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
require "common/models/Diff"
|
|
2
|
+
require "common/models/ListChange"
|
|
3
|
+
require "util/Colors"
|
|
4
|
+
|
|
5
|
+
module Cumulus
|
|
6
|
+
module VPC
|
|
7
|
+
# Public: The types of changes that can be made to the dhcp configuration
|
|
8
|
+
module DhcpChange
|
|
9
|
+
include Common::DiffChange
|
|
10
|
+
|
|
11
|
+
DOMAIN_SERVERS = Common::DiffChange.next_change_id
|
|
12
|
+
DOMAIN_NAME = Common::DiffChange.next_change_id
|
|
13
|
+
NTP_SERVERS = Common::DiffChange.next_change_id
|
|
14
|
+
NETBIOS_SERVERS = Common::DiffChange.next_change_id
|
|
15
|
+
NETBIOS_NODE = Common::DiffChange.next_change_id
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Public: Represents a single difference between local configuration and
|
|
19
|
+
# an AWS Load Balancer.
|
|
20
|
+
class DhcpDiff < Common::Diff
|
|
21
|
+
include DhcpChange
|
|
22
|
+
|
|
23
|
+
def self.domain_servers(aws, local)
|
|
24
|
+
changes = Common::ListChange.simple_list_diff(aws, local)
|
|
25
|
+
if changes
|
|
26
|
+
diff = DhcpDiff.new(DOMAIN_SERVERS, aws, local)
|
|
27
|
+
diff.changes = changes
|
|
28
|
+
diff
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def self.ntp_servers(aws, local)
|
|
33
|
+
changes = Common::ListChange.simple_list_diff(aws, local)
|
|
34
|
+
if changes
|
|
35
|
+
diff = DhcpDiff.new(NTP_SERVERS, aws, local)
|
|
36
|
+
diff.changes = changes
|
|
37
|
+
diff
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def self.netbios_servers(aws, local)
|
|
42
|
+
changes = Common::ListChange.simple_list_diff(aws, local)
|
|
43
|
+
if changes
|
|
44
|
+
diff = DhcpDiff.new(NETBIOS_SERVERS, aws, local, servers_diff)
|
|
45
|
+
diff.changes = changes
|
|
46
|
+
diff
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def asset_type
|
|
51
|
+
"DHCP Options"
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def diff_string
|
|
55
|
+
case @type
|
|
56
|
+
when DOMAIN_SERVERS
|
|
57
|
+
[
|
|
58
|
+
"Domain Name Servers:",
|
|
59
|
+
@changes.removed.map { |d| Colors.unmanaged("\t#{d}") },
|
|
60
|
+
@changes.added.map { |d| Colors.added("\t#{d}") },
|
|
61
|
+
].flatten.join("\n")
|
|
62
|
+
when DOMAIN_NAME
|
|
63
|
+
[
|
|
64
|
+
"Domain Name:",
|
|
65
|
+
Colors.aws_changes("\tAWS - #{aws}"),
|
|
66
|
+
Colors.local_changes("\tLocal - #{local}"),
|
|
67
|
+
].join("\n")
|
|
68
|
+
when NTP_SERVERS
|
|
69
|
+
[
|
|
70
|
+
"NTP Servers:",
|
|
71
|
+
@changes.removed.map { |n| Colors.unmanaged("\t#{n}") },
|
|
72
|
+
@changes.added.map { |n| Colors.added("\t#{n}") },
|
|
73
|
+
].flatten.join("\n")
|
|
74
|
+
when NETBIOS_SERVERS
|
|
75
|
+
[
|
|
76
|
+
"NETBIOS Name Servers:",
|
|
77
|
+
@changes.removed.map { |n| Colors.unmanaged("\t#{n}") },
|
|
78
|
+
@changes.added.map { |n| Colors.added("\t#{n}") },
|
|
79
|
+
].flatten.join("\n")
|
|
80
|
+
when NETBIOS_NODE
|
|
81
|
+
[
|
|
82
|
+
"NETBIOS Node Type:",
|
|
83
|
+
Colors.aws_changes("\tAWS - #{aws}"),
|
|
84
|
+
Colors.local_changes("\tLocal - #{local}"),
|
|
85
|
+
].join("\n")
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
require "conf/Configuration"
|
|
2
|
+
require "vpc/loader/Loader"
|
|
3
|
+
require "ec2/EC2"
|
|
4
|
+
|
|
5
|
+
require "json"
|
|
6
|
+
require "uri"
|
|
7
|
+
|
|
8
|
+
module Cumulus
|
|
9
|
+
module VPC
|
|
10
|
+
|
|
11
|
+
# Public: An object representing configuration for a VPC endpoint
|
|
12
|
+
class EndpointConfig
|
|
13
|
+
attr_reader :service_name
|
|
14
|
+
attr_accessor :policy
|
|
15
|
+
attr_reader :route_tables
|
|
16
|
+
|
|
17
|
+
# Public: Constructor
|
|
18
|
+
#
|
|
19
|
+
# json - a hash containing the JSON configuration for the endpoint
|
|
20
|
+
def initialize(json = nil)
|
|
21
|
+
if !json.nil?
|
|
22
|
+
@service_name = json["service-name"]
|
|
23
|
+
@policy = json["policy"]
|
|
24
|
+
@route_tables = json["route-tables"] || []
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def to_hash
|
|
29
|
+
{
|
|
30
|
+
"service-name" => @service_name,
|
|
31
|
+
"policy" => @policy,
|
|
32
|
+
"route-tables" => @route_tables.sort,
|
|
33
|
+
}.reject { |k, v| v.nil? }
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def populate!(aws, route_table_map)
|
|
37
|
+
@service_name = aws.service_name
|
|
38
|
+
@policy = aws.parsed_policy["Version"]
|
|
39
|
+
@route_tables = aws.route_table_ids.map { |rt_id| route_table_map[rt_id] || rt_id }
|
|
40
|
+
|
|
41
|
+
self
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Public: Produce an array of differences between this local configuration and the
|
|
45
|
+
# configuration in AWS
|
|
46
|
+
#
|
|
47
|
+
# aws - the AWS resource
|
|
48
|
+
#
|
|
49
|
+
# Returns an array of the EndpointDiffs that were found
|
|
50
|
+
def diff(aws)
|
|
51
|
+
diffs = []
|
|
52
|
+
|
|
53
|
+
# policy
|
|
54
|
+
aws_policy_statements = aws.parsed_policy["Statement"]
|
|
55
|
+
local_policy_statements = Loader.policy(@policy)["Statement"]
|
|
56
|
+
policy_diff = EndpointDiff.policy(aws_policy_statements, local_policy_statements)
|
|
57
|
+
|
|
58
|
+
if policy_diff
|
|
59
|
+
diffs << policy_diff
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# routes
|
|
63
|
+
aws_rts = aws.route_table_ids.map { |rt_id| EC2::id_route_tables[rt_id] }
|
|
64
|
+
aws_rt_names = aws_rts.map { |rt| rt.name || rt.route_table_id }
|
|
65
|
+
|
|
66
|
+
rt_diff = EndpointDiff.route_tables(aws_rt_names, @route_tables)
|
|
67
|
+
if rt_diff
|
|
68
|
+
diffs << rt_diff
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
diffs
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|