mappru 0.1.0 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4f5864c5b6cc52cc629a4ae35a83f18f399ef296
4
- data.tar.gz: 03d30ac958f959f74900786ac356cb2f1a3e97ab
3
+ metadata.gz: 91fb9f0fc2af0eb772f30a17cf48a9e369e0fbb9
4
+ data.tar.gz: 5c73c0ff7481a80f1306faaee92b1172da7e340a
5
5
  SHA512:
6
- metadata.gz: 5ded9bd4f3118d025cb55b9dadf41b92c7fb045ca9004ef454a39444333e6f429e2dadc97460fb5be898e544291aa87a2767c0e46386012f26734f65f4286682
7
- data.tar.gz: 38a59ce1b8050cfbeda278ce4092eaddefabb414fed9935a2a9cc04648947aecfdf7dad3ca462977a47a6c6e73ec7fce5304a58d5bed0248afd0cef99a0656f4
6
+ metadata.gz: a768ea8894402927fce8b21478ac9aad18b91da9a4477c3544204047e4e4b51a8571c12ddff7402e64bb42f363c3fe475d5fc92869271b6ba82ddc3258d15da7
7
+ data.tar.gz: 27749ece277cccf758eaec61efeab991527fc04f6bd9eb0a969ec8921c21dbc50e9b655119e743385ca36dd01aae4bbbe57aec25b0ab392c5e651ce673836b7f
data/.gitignore CHANGED
@@ -9,4 +9,4 @@
9
9
  /tmp/
10
10
  test.rb
11
11
  RouteTable
12
- *.table
12
+ *.rtbl
data/exe/mappru CHANGED
@@ -77,81 +77,91 @@ rescue => e
77
77
  exit 1
78
78
  end
79
79
 
80
- def main(argv)
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
- case options[:mode]
86
- when :export
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
- output = DEFAULT_FILENAME if output == '-'
94
- dir = File.dirname(output)
95
- FileUtils.mkdir_p(dir)
96
- requires = []
88
+ output = DEFAULT_FILENAME if output == '-'
89
+ dir = File.dirname(output)
90
+ FileUtils.mkdir_p(dir)
91
+ requires = []
97
92
 
98
- exported.each do |vpc_id, rts|
99
- vpc_dir = File.join(dir, vpc_id)
100
- FileUtils.mkdir_p(vpc_id)
93
+ exported.each do |vpc_id, rts|
94
+ vpc_dir = File.join(dir, vpc_id)
95
+ FileUtils.mkdir_p(vpc_id)
101
96
 
102
- rts.each do |rt_name, attrs|
103
- filename = "#{rt_name}.table"
104
- requires << File.join(vpc_id, filename)
105
- rt_file = File.join(vpc_dir, filename)
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
- logger.info(" write `#{rt_file}`")
102
+ logger.info(" write `#{rt_file}`")
108
103
 
109
- dsl = Mappru::DSL.convert({vpc_id => {rt_name => attrs}}, options)
104
+ dsl = Mappru::DSL.convert({vpc_id => {rt_name => attrs}}, options)
110
105
 
111
- open(rt_file, 'wb') do |f|
112
- f.puts MAGIC_COMMENT
113
- f.puts dsl
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
- logger.info(" write `#{output}`")
113
+ logger.info(" write `#{output}`")
119
114
 
120
- open(output, 'wb') do |f|
121
- f.puts MAGIC_COMMENT
115
+ open(output, 'wb') do |f|
116
+ f.puts MAGIC_COMMENT
122
117
 
123
- requires.each do |rt_file|
124
- f.puts "require '#{rt_file}'"
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
- dsl = Mappru::DSL.convert(exported, options)
129
-
130
- if output == '-'
131
- logger.info('# Export Route Table')
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
- when :apply
142
- file = options[:file]
135
+ end
136
+ end
143
137
 
144
- unless File.exist?(file)
145
- raise "No RouteTable found (looking for: #{file})"
146
- end
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
- message = "Apply `#{file}` to Route Table"
149
- message << ' (dry-run)' if options[:dry_run]
150
- logger.info(message)
150
+ updated = client.apply(file)
151
151
 
152
- updated = client.apply(file)
152
+ logger.info('No change'.intense_blue) unless updated
153
+ end
153
154
 
154
- logger.info('No change'.intense_blue) unless updated
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
@@ -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, "No name Route Table can not manage: #{vpc_id}", color: :yellow)
29
+ log(:warn, "Cannot manage the nameless Route Table: #{vpc_id}", color: :yellow)
30
30
  next
31
31
  end
32
32
 
@@ -1,3 +1,3 @@
1
1
  module Mappru
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mappru
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - winebarrel