bosh_cli 0.19 → 0.19.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/cli/commands/biff.rb +73 -12
- data/lib/cli/commands/stemcell.rb +6 -3
- data/lib/cli/runner.rb +1 -0
- data/lib/cli/version.rb +1 -1
- data/spec/unit/biff_spec.rb +23 -1
- metadata +4 -4
data/lib/cli/commands/biff.rb
CHANGED
@@ -37,7 +37,8 @@ module Bosh::Cli::Command
|
|
37
37
|
"Would you like the new version copied to '%s'? [yn]"
|
38
38
|
|
39
39
|
# Accessor for testing purposes.
|
40
|
-
attr_accessor :ip_helper
|
40
|
+
attr_accessor :ip_helper
|
41
|
+
attr_accessor :template_output
|
41
42
|
|
42
43
|
# Deletes the temporary files that were used.
|
43
44
|
def delete_temp_diff_files
|
@@ -208,12 +209,26 @@ module Bosh::Cli::Command
|
|
208
209
|
# from.
|
209
210
|
# @return [String] The network/mask.
|
210
211
|
def get_network_and_mask(netw_name)
|
211
|
-
netw_cidr =
|
212
|
+
netw_cidr = get_helper(netw_name)
|
212
213
|
"#{netw_cidr.network}#{netw_cidr.netmask}"
|
213
214
|
end
|
214
215
|
|
216
|
+
# Helper function for getting the first and last number from a range, but
|
217
|
+
# also taking into account negative ranges and the network size.
|
218
|
+
# @param [Range] range The range.
|
219
|
+
# @param [String] netw_name The cidr network object.
|
220
|
+
# @return [Array] The first and last number.
|
221
|
+
def get_first_last_from_range(range, netw_cidr)
|
222
|
+
first = (range.first >= 0) ? range.first :
|
223
|
+
netw_cidr.size + range.first
|
224
|
+
last = (range.last >= 0) ? range.last :
|
225
|
+
netw_cidr.size + range.last
|
226
|
+
return [first, last]
|
227
|
+
end
|
228
|
+
|
215
229
|
# Used by the template to specify IPs for jobs. It uses the CIDR tool to get
|
216
|
-
# them.
|
230
|
+
# them. Netw_name can include .range or .static, such as default.static to
|
231
|
+
# choose what range the IPs are based on.
|
217
232
|
# @param [Integer] ip_num The nth IP number to get.
|
218
233
|
# @param [String] netw_name The name of the network to get the IP from.
|
219
234
|
# @return [String] An IP in the network.
|
@@ -227,14 +242,58 @@ module Bosh::Cli::Command
|
|
227
242
|
# @param [String] netw_name The name of the network to get the IPs from.
|
228
243
|
# @return [String] An IP return in the network.
|
229
244
|
def ip_range(range, netw_name)
|
230
|
-
netw_cidr =
|
231
|
-
first = (range
|
232
|
-
|
233
|
-
|
234
|
-
|
245
|
+
netw_cidr = get_helper(netw_name)
|
246
|
+
first, last = get_first_last_from_range(range, netw_cidr)
|
247
|
+
unless netw_cidr[first] and netw_cidr[last]
|
248
|
+
raise "Ip range '#{range}' not in #{netw_name}."
|
249
|
+
end
|
250
|
+
first == last ? "#{netw_cidr[first].ip}" :
|
251
|
+
"#{netw_cidr[first].ip} - #{netw_cidr[last].ip}"
|
252
|
+
end
|
253
|
+
|
254
|
+
# Returns the array of IPs for a network name.
|
255
|
+
# @param [String] netw_name The name of the network, such as default.static.
|
256
|
+
# @return [Array|CIDR] An array or CIDR object that behaves like an array.
|
257
|
+
def get_helper(netw_name)
|
258
|
+
netw_name, type = netw_name.split(".")
|
259
|
+
type ||= "range"
|
260
|
+
@ip_helper[netw_name][type]
|
261
|
+
end
|
262
|
+
|
263
|
+
# Gets the range section out of the user's deployment config and creates a
|
264
|
+
# CIDR object. This is used for calculating IPs in the .erb template that
|
265
|
+
# uses the ip and ip_range methods.
|
266
|
+
# @param [Array] subnets The subnets in a network configuration.
|
267
|
+
# @return [CIDR] A CIDR object.
|
268
|
+
def get_range(subnets)
|
269
|
+
NetAddr::CIDR.create(subnets.first["range"])
|
270
|
+
end
|
235
271
|
|
236
|
-
|
237
|
-
|
272
|
+
# Gets the static ranges out of the user's deployment config and creates an
|
273
|
+
# array of CIDR objects. This is used for calculating IPs in the .erb
|
274
|
+
# template that uses the ip and ip_range methods.
|
275
|
+
# @param [Array] subnets The subnets in a network configuration.
|
276
|
+
# @return [Array] An array of CIDR objects.
|
277
|
+
def get_static_ranges(subnets)
|
278
|
+
static_ranges = subnets.first["static"]
|
279
|
+
if !static_ranges || static_ranges.empty?
|
280
|
+
return nil
|
281
|
+
end
|
282
|
+
static_ips = []
|
283
|
+
static_ranges.each do |static_range|
|
284
|
+
range_split = static_range.split("-")
|
285
|
+
if range_split.size == 1
|
286
|
+
static_ips.push(range_split[0])
|
287
|
+
next
|
288
|
+
end
|
289
|
+
|
290
|
+
start_range = NetAddr::CIDR.create(range_split[0].strip)
|
291
|
+
end_range = NetAddr::CIDR.create(range_split[1].strip)
|
292
|
+
(start_range..end_range).each do |ip_entry|
|
293
|
+
static_ips.push(ip_entry)
|
294
|
+
end
|
295
|
+
end
|
296
|
+
static_ips
|
238
297
|
end
|
239
298
|
|
240
299
|
# Creates the helper hash. Keys are the network name, values are the CIDR
|
@@ -249,7 +308,9 @@ module Bosh::Cli::Command
|
|
249
308
|
netw_arr.each do |netw|
|
250
309
|
subnets = netw["subnets"]
|
251
310
|
check_valid_network_config(netw, subnets)
|
252
|
-
helper[netw["name"]] =
|
311
|
+
helper[netw["name"]] = {}
|
312
|
+
helper[netw["name"]]["range"] = get_range(subnets)
|
313
|
+
helper[netw["name"]]["static"] = get_static_ranges(subnets)
|
253
314
|
end
|
254
315
|
helper
|
255
316
|
end
|
@@ -282,7 +343,7 @@ module Bosh::Cli::Command
|
|
282
343
|
copy_to_file = @diff_works ? @deployment_file : @deployment_file + ".new"
|
283
344
|
agree_text = @diff_works ?
|
284
345
|
KEEP_NEW_VERSION_TEXT : (DIFF_FAILED_KEEP_NEW_TEXT % copy_to_file)
|
285
|
-
if agree(agree_text)
|
346
|
+
if non_interactive? or agree(agree_text)
|
286
347
|
say("New version copied to '#{copy_to_file}'")
|
287
348
|
FileUtils.cp(@temp_file_path_2, copy_to_file)
|
288
349
|
end
|
@@ -110,18 +110,21 @@ module Bosh::Cli::Command
|
|
110
110
|
end
|
111
111
|
|
112
112
|
# Prints out the publicly available stemcells.
|
113
|
-
def list_public
|
113
|
+
def list_public(*args)
|
114
|
+
full = args.include?("--full")
|
114
115
|
yaml = get_public_stemcell_list
|
115
116
|
stemcells_table = table do |t|
|
116
117
|
t.headings = "Name", "Url"
|
117
118
|
yaml.keys.sort.each do |key|
|
118
119
|
if key != PUBLIC_STEMCELL_INDEX
|
119
|
-
|
120
|
+
url = full ? yaml[key]["url"] : "#{yaml[key]["url"][0..49]}..."
|
121
|
+
t << [key, url]
|
120
122
|
end
|
121
123
|
end
|
122
124
|
end
|
123
125
|
puts(stemcells_table)
|
124
|
-
puts("To download use 'bosh download public stemcell <stemcell_name>'."
|
126
|
+
puts("To download use 'bosh download public stemcell <stemcell_name>'." +
|
127
|
+
"For full url use --full.")
|
125
128
|
end
|
126
129
|
|
127
130
|
# Downloads one of the publicly available stemcells.
|
data/lib/cli/runner.rb
CHANGED
data/lib/cli/version.rb
CHANGED
data/spec/unit/biff_spec.rb
CHANGED
@@ -122,7 +122,7 @@ describe Bosh::Cli::Command::Biff do
|
|
122
122
|
|
123
123
|
it "allows ip_range to take negative ranges" do
|
124
124
|
@biff.ip_helper = {
|
125
|
-
"default" => NetAddr::CIDR.create("192.168.1.0/22")
|
125
|
+
"default" => { "range" => NetAddr::CIDR.create("192.168.1.0/22") }
|
126
126
|
}
|
127
127
|
@biff.ip_range(-11..-2, "default").should == "192.168.3.245 - 192.168.3.254"
|
128
128
|
end
|
@@ -137,4 +137,26 @@ describe Bosh::Cli::Command::Biff do
|
|
137
137
|
@biff.delete_all_except(obj, "b").should == [ {"name" => "b"} ]
|
138
138
|
end
|
139
139
|
|
140
|
+
it "gets a range from a static ip list correctly" do
|
141
|
+
@biff.ip_helper = {
|
142
|
+
"default" => {
|
143
|
+
"static" => [
|
144
|
+
NetAddr::CIDR.create("192.168.1.1"),
|
145
|
+
NetAddr::CIDR.create("192.168.1.2"),
|
146
|
+
NetAddr::CIDR.create("192.168.1.3") ]
|
147
|
+
}}
|
148
|
+
@biff.ip_range((1..2), "default.static").should ==
|
149
|
+
"192.168.1.2 - 192.168.1.3"
|
150
|
+
end
|
151
|
+
|
152
|
+
it "gets an IP from a static ip list correctly" do
|
153
|
+
@biff.ip_helper = {
|
154
|
+
"default" => {
|
155
|
+
"static" => [
|
156
|
+
NetAddr::CIDR.create("192.168.1.1"),
|
157
|
+
NetAddr::CIDR.create("192.168.1.2"),
|
158
|
+
NetAddr::CIDR.create("192.168.1.3") ]
|
159
|
+
}}
|
160
|
+
@biff.ip(0, "default.static").should == "192.168.1.1"
|
161
|
+
end
|
140
162
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bosh_cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.19.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-06-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json_pure
|
@@ -317,7 +317,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
317
317
|
version: '0'
|
318
318
|
segments:
|
319
319
|
- 0
|
320
|
-
hash: -
|
320
|
+
hash: -854955838650099269
|
321
321
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
322
322
|
none: false
|
323
323
|
requirements:
|
@@ -326,7 +326,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
326
326
|
version: '0'
|
327
327
|
segments:
|
328
328
|
- 0
|
329
|
-
hash: -
|
329
|
+
hash: -854955838650099269
|
330
330
|
requirements: []
|
331
331
|
rubyforge_project:
|
332
332
|
rubygems_version: 1.8.23
|