vzcdn 0.1.4 → 0.1.5

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.
data/lib/config_reader.rb CHANGED
@@ -8,14 +8,25 @@ module ConfigReader
8
8
  ConfigHandler::CONFIG_DIRECTORY
9
9
  end
10
10
 
11
- def mkdir(*dirs)
12
- path = config_file(*dirs)
11
+ def imkdir(path)
13
12
  if ! Dir.exists?(path)
14
13
  Dir.mkdir path
15
14
  end
16
15
  path
17
16
  end
18
17
 
18
+ def mk_user_dir(*dirs)
19
+ imkdir user_file(*dirs)
20
+ end
21
+
22
+ def mk_config_dir(*dirs)
23
+ imkdir config_file(*dirs)
24
+ end
25
+
26
+ def user_file(*dirs_file)
27
+ File.join(*dirs_file)
28
+ end
29
+
19
30
  def config_file(*dirs_file)
20
31
  File.join(config_dir, *dirs_file)
21
32
  end
data/lib/makeBind.sh ADDED
@@ -0,0 +1,90 @@
1
+ #!/bin/bash
2
+ usage(){
3
+ echo "requires 2 arguments"
4
+ echo "Usage: $0 Input_filename[as argument] Output_Filename[as argument]"
5
+ exit 1
6
+ }
7
+
8
+
9
+ osarch(){
10
+ case $(uname -m) in
11
+ x86_64) echo 64bit;;
12
+ *) echo 32bit;;
13
+ esac
14
+ }
15
+
16
+ ostype(){
17
+ case $(uname -s) in
18
+ Linux)
19
+ if [[ "$(osarch)" == 64bit ]]; then
20
+ `curl -O --silent http://stedolan.github.io/jq/download/linux64/jq`
21
+ else
22
+ `curl -O --silent http://stedolan.github.io/jq/download/linux32/jq`
23
+ fi
24
+ `chmod +x jq`
25
+ ;;
26
+ Darwin)
27
+ if [[ "$(osarch)" == 64bit ]]; then
28
+ `curl -O --silent http://stedolan.github.io/jq/download/osx64/jq`
29
+ else
30
+ `curl -O --silent http://stedolan.github.io/jq/download/osx32/jq`
31
+ fi
32
+ `chmod +x jq`
33
+ ;;
34
+ *) echo not supported;;
35
+ esac
36
+ }
37
+
38
+
39
+ overwrite_yes_or_no(){
40
+ read -p "$1 ([y]es or [N]o): "
41
+ case $(echo $REPLY | tr '[A-Z]' '[a-z]') in
42
+ y|yes) echo "yes";;
43
+ *) echo "no";;
44
+ esac
45
+ }
46
+
47
+ if [ -f $2 ]; then
48
+ if [[ "yes" == $(overwrite_yes_or_no "$2 exists. Do you want to overwrite?") ]]; then
49
+ `cat /dev/null > $2`
50
+ else
51
+ echo "exiting out"
52
+ exit 1
53
+ fi
54
+ fi
55
+
56
+ if [ ! -f jq ]; then
57
+ ostype
58
+ fi
59
+
60
+ if [ "$#" -ne "2" ]
61
+ then
62
+ usage
63
+ fi
64
+ RECORDS=`cat $1 |./jq '.Records'`
65
+ printf "%s\t%s\t%s\n" "\$TTL" "86400" "; 24 hours could have been written as 24h or 1d" >> $2
66
+ printf "%s\t%s\n" "\$ORIGIN" `cat $1 |./jq '.DomainName'|tr -d '"'` >> $2
67
+ printf "%s\t%s\t%s\t%s\t%s\t%s\n" "@" "IN" "SOA" "ns1.`cat $1 |./jq '.DomainName'|tr -d '"'`" "ns2.`cat $1 |./jq '.DomainName'|tr -d '"'`(" >> $2
68
+ printf "%s\t%s\t%s\t%s\t%s\t%s\n" "" "" "" "2014041501" "; Serial yyyymmddnn" >> $2
69
+ printf "%s\t%s\t%s\t%s\t%s\t%s\n" "" "" "" "3600" "; Refresh after 3 hours" >> $2
70
+ printf "%s\t%s\t%s\t%s\t%s\t%s\n" "" "" "" "600" "; Retry after 1 hour" >> $2
71
+ printf "%s\t%s\t%s\t%s\t%s\t%s\n" "" "" "" "604800" "; Expire after 1 week" >> $2
72
+ printf "%s\t%s\t%s\t%s\t%s\t%s\n" "" "" "" "600)" "; Minimum negative caching of 1 hour" >> $2
73
+
74
+ if [ `echo $RECORDS|./jq 'length'` -ne "0" ]
75
+ then
76
+ for record in A AAAA CNAME MX NS SPF SRV TXT
77
+ do
78
+ # echo `cat $1 |./jq '.Records.'$record''`
79
+ if [ `echo $RECORDS |./jq '.'$record'|length'` -ne "0" ]
80
+ then
81
+ printf "\n" >> $2
82
+ printf "; $record Records\n" >> $2
83
+ for(( i=0; i <= `echo $RECORDS |./jq '.'$record'|length'` -1; i++ ))
84
+ do
85
+ printf "%s\t%s\t%s\t%s\t%s\n" `echo $RECORDS |./jq '.'$record'['$i'].Name'|tr -d '"'` `echo $RECORDS |./jq '.'$record'['$i'].TTL'|tr -d '"'` "IN" $record `echo $RECORDS |./jq '.'$record'['$i'].Rdata'|tr -d '"'` >> $2
86
+ done
87
+ fi
88
+ done
89
+ fi
90
+
data/lib/method.rb ADDED
@@ -0,0 +1,5 @@
1
+ class Method
2
+ def initialize(args)
3
+
4
+ end
5
+ end
data/lib/print.rb ADDED
@@ -0,0 +1,270 @@
1
+ require_relative 'util'
2
+ require_relative 'config_reader'
3
+
4
+ class TablePrint
5
+ DELIM = '|'
6
+
7
+ def char_repeat(n, char)
8
+ result = ""
9
+ (1..n).each { |i|
10
+ result = result + char
11
+ }
12
+ result
13
+ end
14
+
15
+ def spaces(n)
16
+ char_repeat(n, ' ')
17
+ end
18
+
19
+ def initialize(sep_char, *titles)
20
+ @ncols = titles.length
21
+ @lines = [ ]
22
+ @width = nil
23
+ @sep_char = sep_char
24
+ @lines << titles
25
+ separator = [ ]
26
+ titles.each { |title|
27
+ separator << char_repeat(title.length, @sep_char)
28
+ }
29
+ @lines << separator
30
+ end
31
+
32
+ def append(*columns)
33
+ @lines << columns
34
+ end
35
+
36
+ def indent(column)
37
+ if column == 0
38
+ ""
39
+ else
40
+ segment = spaces(@width-1) + DELIM
41
+ segment * column
42
+ end
43
+ end
44
+
45
+ def strip(line)
46
+ regexp = Regexp.new(' *' + Regexp.escape(DELIM) + '*\Z')
47
+ line.sub(regexp, "")
48
+ end
49
+
50
+ def calc_column(line)
51
+ line.length / @width
52
+ end
53
+
54
+ def fill_to_next_column(line)
55
+ tab = @width - (line.length % @width)
56
+ line = line + spaces(tab-1) + DELIM
57
+ end
58
+
59
+ # prints a line with DELIMs following in proper columns
60
+ def println(line)
61
+ column = calc_column(line)
62
+ if (column < @ncols)
63
+ line = fill_to_next_column(line)
64
+ column = calc_column(line)
65
+ end
66
+ if (column < @ncols)
67
+ segment = spaces(@width-1) + DELIM
68
+ line = line + segment * (@ncols - column)
69
+ end
70
+ puts strip(line)
71
+ end
72
+
73
+ def next_unprinted_column(col_array, start=0)
74
+ for i in (start...col_array.length)
75
+ return i if col_array[i]
76
+ end
77
+ nil
78
+ end
79
+
80
+ def calc_max_widths
81
+ maxwidth = Array.new(@ncols, 0)
82
+ @lines.each { |line|
83
+ line.each_with_index { |value, index|
84
+ maxwidth[index] = [value.to_s.length, maxwidth[index]].max
85
+ }
86
+ }
87
+ maxwidth
88
+ end
89
+
90
+ def print_table_normally(maxwidth, header)
91
+ @lines.each_with_index { |line, lineno|
92
+ if lineno < 2 && ! header
93
+ next
94
+ end
95
+ output = ""
96
+ line.each_with_index { |value, index|
97
+ output = output + value.to_s + spaces(maxwidth[index] - value.to_s.length + 2)
98
+ }
99
+ puts output[0...-2]
100
+ }
101
+ end
102
+
103
+ def separator(width)
104
+ char_repeat(width, @sep_char)
105
+ end
106
+
107
+ def print_staggered(maxwidth, term_width, header)
108
+ minw = term_width
109
+ maxwidth.each_with_index { |w, index|
110
+ next if index == 0
111
+ width = (term_width - w) / index
112
+ minw = [width, minw].min
113
+ }
114
+ @width = minw
115
+ puts separator(term_width)
116
+ @lines.each_with_index { |line, lineno|
117
+ next if lineno == 1 # skip line of separators
118
+ if lineno == 0 && ! header
119
+ next
120
+ end
121
+ output = ""
122
+ cols_left = Array.new(@ncols, true)
123
+ while column = next_unprinted_column(cols_left)
124
+ output = indent(column) if output.length == 0
125
+ while column
126
+ value = line[column].to_s
127
+ cols_left[column] = false # indicate this column has been printed
128
+ output = output + value
129
+ output = fill_to_next_column(output)
130
+ next_column = calc_column(output)
131
+ column = next_unprinted_column(cols_left, next_column)
132
+ if column && (column > next_column)
133
+ output = output + (spaces(@width-1) + DELIM) * (column - next_column)
134
+ end
135
+ end
136
+ println(output)
137
+ output = ""
138
+ end
139
+ puts separator(term_width)
140
+ }
141
+ end
142
+
143
+ def print_old_staggered(maxwidth, term_width)
144
+ puts separator(term_width)
145
+ @lines.each_with_index { |line, index|
146
+ next if index == 1
147
+ output = ""
148
+ column = 0
149
+ line.each_with_index { |value, column|
150
+ value = value.to_s
151
+ output = indent(column) if output.length == 0
152
+ if value.length > (@width - 1)
153
+ output = output + value
154
+ println(output)
155
+ output = ""
156
+ else
157
+ output = output + value + spaces(@width - value.length - 1) + DELIM
158
+ end
159
+ column += 1
160
+ }
161
+ println(output) if output.length > 0
162
+ puts separator(term_width)
163
+ }
164
+ end
165
+
166
+ # TODO: suppress headers
167
+ def print_table(header = true)
168
+ return if @lines.nil?
169
+ return if @ncols == 0
170
+ if @ncols == 1
171
+ @lines.each { |line| puts line }
172
+ return
173
+ end
174
+
175
+ maxwidth = calc_max_widths
176
+ # will lines fit in terminal
177
+ width_needed = maxwidth.reduce(:+) + (@ncols-1) * 2
178
+ term_width, h = Util.detect_terminal_size
179
+ if width_needed <= term_width
180
+ print_table_normally(maxwidth, header)
181
+ else
182
+ print_staggered(maxwidth, term_width, header)
183
+ end
184
+ end
185
+
186
+ end
187
+
188
+ class StructurePrint
189
+ include ConfigReader
190
+
191
+ def initialize(sep_char)
192
+ @sep_char = sep_char
193
+ end
194
+
195
+ def get_indexes(level, key_array)
196
+ print_config_file = config_file("print.cfg")
197
+ if File.exists? print_config_file
198
+ level.gsub!(/\[\d*\]/, '')
199
+ level_map = JSON.parse(File.open(print_config_file).read)
200
+ if level_map.has_key? level
201
+ column_names = level_map[level]
202
+ result = []
203
+ column_names.each { |name|
204
+ index = key_array.index name
205
+ result << index
206
+ }
207
+ return result
208
+ end
209
+ end
210
+ (0...key_array.length).to_a
211
+ end
212
+
213
+ def extract_printed_columns(indexes, values, index_value, add_index = false)
214
+ print_values = []
215
+ print_values << index_value.to_s if add_index
216
+ indexes.each { |index|
217
+ print_values << values[index]
218
+ }
219
+ print_values
220
+ end
221
+
222
+ def structure_print(struct, level, header = true)
223
+ istructure_print(struct, level, header)
224
+ if $debug
225
+ puts "level = #{level}"
226
+ end
227
+ @table.print_table(header) if @table
228
+ end
229
+
230
+ def istructure_print(struct, level, header, add_index = false)
231
+ if (struct.class == Array)
232
+ struct.each_with_index { |elt, index|
233
+ istructure_print(elt, level, header, struct.length > 1)
234
+ header = false
235
+ }
236
+ elsif (struct.class == Hash)
237
+ # print top level elements of hash
238
+ indexes = get_indexes(level, struct.keys)
239
+ if @table.nil?
240
+ @table = TablePrint.new(@sep_char, *extract_printed_columns(indexes, struct.keys, "item", add_index))
241
+ @rownum = 0
242
+ end
243
+ values = []
244
+ struct.keys.each { |key|
245
+ value = struct[key]
246
+ if (value.nil?)
247
+ value = "null"
248
+ elsif (value.class == Array)
249
+ value = "[" + value.length.to_s + "]"
250
+ elsif (value.class == String)
251
+ elsif (value.class == Fixnum)
252
+ value = value.to_s
253
+ elsif (value.class == Hash)
254
+ value = "..."
255
+ elsif value.class == TrueClass
256
+ value = "true"
257
+ elsif value.class == FalseClass
258
+ value = "false"
259
+ else
260
+ value = "<" + value.class.to_s + ">"
261
+ end
262
+ values << value
263
+ }
264
+ @rownum += 1
265
+ @table.append(*extract_printed_columns(indexes, values, @rownum, add_index))
266
+ else
267
+ puts struct.to_s
268
+ end
269
+ end
270
+ end
data/lib/route.rb CHANGED
@@ -69,6 +69,7 @@ class Route
69
69
  def translate_hc(rec_array)
70
70
  rec_array.each { |rec|
71
71
  hc = rec["HealthCheck"]
72
+ return nil unless hc
72
73
  translate_value(:hc_type, hc, "CheckTypeId")
73
74
  translate_value(:http_method, hc, "HTTPMethodId")
74
75
  translate_value(:ip_version, hc, "IPVersion")
@@ -79,6 +80,7 @@ class Route
79
80
  def untranslate_hc(rec_array)
80
81
  rec_array.each { |rec|
81
82
  hc = rec["HealthCheck"]
83
+ return nil unless hc
82
84
  untranslate_value(:hc_type, hc, "CheckTypeId")
83
85
  untranslate_value(:http_method, hc, "HTTPMethodId")
84
86
  untranslate_value(:ip_version, hc, "IPVersion")
@@ -153,6 +155,7 @@ class Route
153
155
  return hash["Name"]
154
156
  end
155
157
  }
158
+ return nil
156
159
  end
157
160
 
158
161
  def cache_filename(data)
@@ -195,30 +198,30 @@ class Route
195
198
  end
196
199
 
197
200
  def get_available_record_types()
198
- get_available(:record_type, "routezonerecordtypes")
201
+ get_available(:record_type)
199
202
  end
200
203
 
201
204
  def get_available_zone_statuses()
202
- get_available(:zone_status, "routezonestatus")
205
+ get_available(:zone_status)
203
206
  end
204
207
 
205
208
  def get_available_route_groups()
206
- get_available(:route_group, "routegrouptypes")
209
+ get_available(:route_group)
207
210
  end
208
211
 
209
212
  def get_available_http_methods()
210
- get_available(:http_method, "routehttpmethodtypes")
213
+ get_available(:http_method)
211
214
  end
212
215
 
213
216
  def get_available_ip_versions()
214
- get_available(:ip_version, "routehealthcheckipversion")
217
+ get_available(:ip_version)
215
218
  end
216
219
 
217
220
  def get_available_hc_types()
218
- get_available(:hc_type, "routehealthchecktypes")
221
+ get_available(:hc_type)
219
222
  end
220
223
 
221
224
  def get_available_hc_rm()
222
- get_available(:hc_rm, "routereintegrationmethodtypes")
225
+ get_available(:hc_rm)
223
226
  end
224
227
  end