mappru 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/exe/mappru +64 -54
- data/lib/mappru/exporter.rb +1 -1
- data/lib/mappru/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 91fb9f0fc2af0eb772f30a17cf48a9e369e0fbb9
|
4
|
+
data.tar.gz: 5c73c0ff7481a80f1306faaee92b1172da7e340a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a768ea8894402927fce8b21478ac9aad18b91da9a4477c3544204047e4e4b51a8571c12ddff7402e64bb42f363c3fe475d5fc92869271b6ba82ddc3258d15da7
|
7
|
+
data.tar.gz: 27749ece277cccf758eaec61efeab991527fc04f6bd9eb0a969ec8921c21dbc50e9b655119e743385ca36dd01aae4bbbe57aec25b0ab392c5e651ce673836b7f
|
data/.gitignore
CHANGED
data/exe/mappru
CHANGED
@@ -77,81 +77,91 @@ rescue => e
|
|
77
77
|
exit 1
|
78
78
|
end
|
79
79
|
|
80
|
-
def
|
81
|
-
options = parse_options(argv)
|
82
|
-
client = Mappru::Client.new(options)
|
80
|
+
def run_export(client, options)
|
83
81
|
logger = Mappru::Logger.instance
|
82
|
+
exported = client.export
|
83
|
+
output = options[:output]
|
84
84
|
|
85
|
-
|
86
|
-
|
87
|
-
exported = client.export
|
88
|
-
output = options[:output]
|
89
|
-
|
90
|
-
if options[:split]
|
91
|
-
logger.info('Export Route Table')
|
85
|
+
if options[:split]
|
86
|
+
logger.info('Export Route Table')
|
92
87
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
88
|
+
output = DEFAULT_FILENAME if output == '-'
|
89
|
+
dir = File.dirname(output)
|
90
|
+
FileUtils.mkdir_p(dir)
|
91
|
+
requires = []
|
97
92
|
|
98
|
-
|
99
|
-
|
100
|
-
|
93
|
+
exported.each do |vpc_id, rts|
|
94
|
+
vpc_dir = File.join(dir, vpc_id)
|
95
|
+
FileUtils.mkdir_p(vpc_id)
|
101
96
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
97
|
+
rts.each do |rt_name, attrs|
|
98
|
+
filename = "#{rt_name}.rtbl"
|
99
|
+
requires << File.join(vpc_id, filename)
|
100
|
+
rt_file = File.join(vpc_dir, filename)
|
106
101
|
|
107
|
-
|
102
|
+
logger.info(" write `#{rt_file}`")
|
108
103
|
|
109
|
-
|
104
|
+
dsl = Mappru::DSL.convert({vpc_id => {rt_name => attrs}}, options)
|
110
105
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
end
|
106
|
+
open(rt_file, 'wb') do |f|
|
107
|
+
f.puts MAGIC_COMMENT
|
108
|
+
f.puts dsl
|
115
109
|
end
|
116
110
|
end
|
111
|
+
end
|
117
112
|
|
118
|
-
|
113
|
+
logger.info(" write `#{output}`")
|
119
114
|
|
120
|
-
|
121
|
-
|
115
|
+
open(output, 'wb') do |f|
|
116
|
+
f.puts MAGIC_COMMENT
|
122
117
|
|
123
|
-
|
124
|
-
|
125
|
-
end
|
118
|
+
requires.each do |rt_file|
|
119
|
+
f.puts "require '#{rt_file}'"
|
126
120
|
end
|
121
|
+
end
|
122
|
+
else
|
123
|
+
dsl = Mappru::DSL.convert(exported, options)
|
124
|
+
|
125
|
+
if output == '-'
|
126
|
+
logger.info('# Export Route Table')
|
127
|
+
puts dsl
|
127
128
|
else
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
puts dsl
|
133
|
-
else
|
134
|
-
logger.info("Export Route Table to `#{output}`")
|
135
|
-
open(output, 'wb') do |f|
|
136
|
-
f.puts MAGIC_COMMENT
|
137
|
-
f.puts dsl
|
138
|
-
end
|
129
|
+
logger.info("Export Route Table to `#{output}`")
|
130
|
+
open(output, 'wb') do |f|
|
131
|
+
f.puts MAGIC_COMMENT
|
132
|
+
f.puts dsl
|
139
133
|
end
|
140
134
|
end
|
141
|
-
|
142
|
-
|
135
|
+
end
|
136
|
+
end
|
143
137
|
|
144
|
-
|
145
|
-
|
146
|
-
|
138
|
+
def run_apply(client, options)
|
139
|
+
logger = Mappru::Logger.instance
|
140
|
+
file = options[:file]
|
141
|
+
|
142
|
+
unless File.exist?(file)
|
143
|
+
raise "No RouteTable found (looking for: #{file})"
|
144
|
+
end
|
145
|
+
|
146
|
+
message = "Apply `#{file}` to Route Table"
|
147
|
+
message << ' (dry-run)' if options[:dry_run]
|
148
|
+
logger.info(message)
|
147
149
|
|
148
|
-
|
149
|
-
message << ' (dry-run)' if options[:dry_run]
|
150
|
-
logger.info(message)
|
150
|
+
updated = client.apply(file)
|
151
151
|
|
152
|
-
|
152
|
+
logger.info('No change'.intense_blue) unless updated
|
153
|
+
end
|
153
154
|
|
154
|
-
|
155
|
+
def main(argv)
|
156
|
+
options = parse_options(argv)
|
157
|
+
client = Mappru::Client.new(options)
|
158
|
+
logger = Mappru::Logger.instance
|
159
|
+
|
160
|
+
case options[:mode]
|
161
|
+
when :export
|
162
|
+
run_export(client, options)
|
163
|
+
when :apply
|
164
|
+
run_apply(client, options)
|
155
165
|
else
|
156
166
|
raise "Unknown mode: #{options[:mode]}"
|
157
167
|
end
|
data/lib/mappru/exporter.rb
CHANGED
@@ -26,7 +26,7 @@ class Mappru::Exporter
|
|
26
26
|
next unless matched?(vpc_id, @options[:vpc_id])
|
27
27
|
|
28
28
|
unless name
|
29
|
-
log(:warn, "
|
29
|
+
log(:warn, "Cannot manage the nameless Route Table: #{vpc_id}", color: :yellow)
|
30
30
|
next
|
31
31
|
end
|
32
32
|
|
data/lib/mappru/version.rb
CHANGED