vagrant-softlayer 0.3.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +16 -16
- data/CHANGELOG.md +61 -49
- data/QUICKSTART.md +380 -376
- data/README.md +258 -256
- data/contrib/vagrant-softlayer-boxes +418 -416
- data/contrib/vagrant-softlayer-vlans +339 -329
- data/lib/vagrant-softlayer/action/create_instance.rb +74 -74
- data/lib/vagrant-softlayer/action/setup_softlayer.rb +39 -39
- data/lib/vagrant-softlayer/action/update_dns.rb +94 -94
- data/lib/vagrant-softlayer/action/wait_for_provision.rb +40 -40
- data/lib/vagrant-softlayer/action/wait_for_rebuild.rb +38 -36
- data/lib/vagrant-softlayer/config.rb +282 -268
- data/lib/vagrant-softlayer/util/load_balancer.rb +96 -103
- data/lib/vagrant-softlayer/util/network.rb +75 -75
- data/lib/vagrant-softlayer/util/warden.rb +38 -38
- data/lib/vagrant-softlayer/version.rb +5 -5
- data/spec/vagrant-softlayer/config_spec.rb +271 -267
- data/vagrant-softlayer.gemspec +55 -55
- metadata +4 -4
@@ -1,329 +1,339 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'csv'
|
4
|
-
require 'getoptlong'
|
5
|
-
require 'json'
|
6
|
-
require 'pp'
|
7
|
-
|
8
|
-
require 'rubygems'
|
9
|
-
require 'softlayer_api'
|
10
|
-
|
11
|
-
class SoftLayerVlans
|
12
|
-
def initialize(sl_api_key, sl_username, sl_endpoint_url = SoftLayer::API_PUBLIC_ENDPOINT)
|
13
|
-
if ! [ SoftLayer::API_PUBLIC_ENDPOINT, SoftLayer::API_PRIVATE_ENDPOINT ].include?(sl_endpoint_url)
|
14
|
-
raise ArgumentError, "Invalid SoftLayer Endpoint URL provided, expected one of #{ [ SoftLayer::API_PUBLIC_ENDPOINT, SoftLayer::API_PRIVATE_ENDPOINT ].inspect }: #{ sl_endpoint_url.inspect }"
|
15
|
-
end
|
16
|
-
|
17
|
-
@sl_credentials = {
|
18
|
-
:api_key => sl_api_key,
|
19
|
-
:endpoint_url => sl_endpoint_url,
|
20
|
-
:
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
routers
|
72
|
-
|
73
|
-
|
74
|
-
router["networkVlans"].
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
:
|
79
|
-
:
|
80
|
-
:
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
)
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
)
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
[ '--
|
111
|
-
[ '--
|
112
|
-
[ '--
|
113
|
-
[ '--
|
114
|
-
[ '--
|
115
|
-
[ '--
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
:
|
124
|
-
:
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
:
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
--
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
begin
|
180
|
-
|
181
|
-
rescue Exception => e
|
182
|
-
$stderr.puts "ERROR: Failed to
|
183
|
-
exit 1
|
184
|
-
end
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
@config[:
|
215
|
-
|
216
|
-
when '--
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
end
|
266
|
-
|
267
|
-
if @config[:sl_credentials][:
|
268
|
-
$stderr.puts "ERROR: No SoftLayer
|
269
|
-
exit 2
|
270
|
-
end
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
table[
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'csv'
|
4
|
+
require 'getoptlong'
|
5
|
+
require 'json'
|
6
|
+
require 'pp'
|
7
|
+
|
8
|
+
require 'rubygems'
|
9
|
+
require 'softlayer_api'
|
10
|
+
|
11
|
+
class SoftLayerVlans
|
12
|
+
def initialize(sl_api_key, sl_username, sl_endpoint_url = SoftLayer::API_PUBLIC_ENDPOINT, sl_timeout = 60)
|
13
|
+
if ! [ SoftLayer::API_PUBLIC_ENDPOINT, SoftLayer::API_PRIVATE_ENDPOINT ].include?(sl_endpoint_url)
|
14
|
+
raise ArgumentError, "Invalid SoftLayer Endpoint URL provided, expected one of #{ [ SoftLayer::API_PUBLIC_ENDPOINT, SoftLayer::API_PRIVATE_ENDPOINT ].inspect }: #{ sl_endpoint_url.inspect }"
|
15
|
+
end
|
16
|
+
|
17
|
+
@sl_credentials = {
|
18
|
+
:api_key => sl_api_key,
|
19
|
+
:endpoint_url => sl_endpoint_url,
|
20
|
+
:timeout => sl_timeout,
|
21
|
+
:user_agent => "vagrant-softlayer",
|
22
|
+
:username => sl_username
|
23
|
+
}
|
24
|
+
|
25
|
+
begin
|
26
|
+
@sl_services = {
|
27
|
+
:account => SoftLayer::Client.new(@sl_credentials)["SoftLayer_Account"]
|
28
|
+
}
|
29
|
+
rescue Exception => e
|
30
|
+
raise Exception, "Failed to initialize SoftLayer Account service for retrieving network vlan details: #{ e.message }"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def [](vlan_name)
|
35
|
+
vlan_details = vlans(:vlan_name => vlan_name)
|
36
|
+
|
37
|
+
raise KeyError, "Invalid vlan name provided as a SoftLayerVlans key: #{ vlan_name.inspect }" if vlan_details.empty?
|
38
|
+
|
39
|
+
return vlan_details[0]
|
40
|
+
end
|
41
|
+
|
42
|
+
def has_vlan?(vlan_name)
|
43
|
+
vlan_details = vlans(:vlan_name => vlan_name)
|
44
|
+
|
45
|
+
return ! vlan_details.empty?
|
46
|
+
end
|
47
|
+
|
48
|
+
def vlans(filter = { :datacenter_name => nil, :vlan_name => nil, :vlan_space => nil })
|
49
|
+
vlan_details = []
|
50
|
+
|
51
|
+
if filter.class != Hash
|
52
|
+
raise TypeError, "Invalid value specified for filter, expected hash of filter values #{ { :datacenter_name => nil, :vlan_name => nil, :vlan_space => nil }.inspect }: #{ filter.inspect }"
|
53
|
+
end
|
54
|
+
|
55
|
+
if ! filter.keys.select{|vlan_property| ! [ :datacenter_name, :vlan_name, :vlan_space ].include?(vlan_property)}.empty?
|
56
|
+
raise KeyError, "Invalid vlan property used as filter key, expected one of #{ [ :datacenter_name, :vlan_name, :vlan_space ].inspect }: #{ filter.keys.inspect }"
|
57
|
+
end
|
58
|
+
|
59
|
+
if filter.has_key?(:datacenter_name) && ! filter[:datacenter_name].nil? && ! [Array, String].include?(filter[:datacenter_name].class)
|
60
|
+
raise TypeError, "Invalid type for filter key :datacenter_name, must be a Array or String of datacenter name(s): #{ filter[:datacenter_name].class }"
|
61
|
+
end
|
62
|
+
|
63
|
+
if filter.has_key?(:vlan_name) && ! filter[:vlan_name].nil? && ! [ Array, String ].include?(filter[:vlan_name].class)
|
64
|
+
raise TypeError, "Invalid type for filter key :vlan_name, must be a Array or String of vlan name(s): #{ filter[:vlan_name].class }"
|
65
|
+
end
|
66
|
+
|
67
|
+
if filter.has_key?(:vlan_space) && ! filter[:vlan_space].nil? && ! [ nil, :public, :private ].include?(filter[:vlan_space])
|
68
|
+
raise ArgumentError, "Invalid value for filter key :vlan_space, expected one of #{ [ nil, :public, :private ].inspect }: #{ filter[:vlan_space].inspect }"
|
69
|
+
end
|
70
|
+
|
71
|
+
routers = @sl_services[:account].object_mask("mask[routers,routers.datacenter,routers.networkVlans,routers.networkVlans.networkSpace,routers.networkVlans.type]").getObject["routers"]
|
72
|
+
|
73
|
+
routers.each do |router|
|
74
|
+
router["networkVlans"].delete_if {|vlan| ! vlan.has_key?("name") || vlan["type"]["keyName"] != "STANDARD"}
|
75
|
+
|
76
|
+
router["networkVlans"].each do |vlan|
|
77
|
+
vlan_details.push({
|
78
|
+
:datacenter => router["datacenter"]["name"],
|
79
|
+
:id => vlan["id"],
|
80
|
+
:name => vlan["name"],
|
81
|
+
:qualified_name => [ router["hostname"].split('.').reverse.join('.'), vlan["vlanNumber"] ].join('.'),
|
82
|
+
:space => vlan["networkSpace"].to_s.downcase
|
83
|
+
})
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
if filter.has_key?(:datacenter_name) && ! filter[:datacenter_name].nil?
|
88
|
+
vlan_details.delete_if {|vlan| (filter[:datacenter_name].class == Array ?
|
89
|
+
(! filter[:datacenter_name].include?(vlan[:datacenter])) :
|
90
|
+
(filter[:datacenter_name] != vlan[:datacenter])
|
91
|
+
)}
|
92
|
+
end
|
93
|
+
|
94
|
+
if filter.has_key?(:vlan_name) && ! filter[:vlan_name].nil?
|
95
|
+
vlan_details.delete_if {|vlan| (filter[:vlan_name].class == Array ?
|
96
|
+
(! (filter[:vlan_name].include?(vlan[:name]) || filter[:vlan_name].include?(vlan[:qualified_name]))) :
|
97
|
+
(filter[:vlan_name] != vlan[:name] && filter[:vlan_name] != vlan[:qualified_name])
|
98
|
+
)}
|
99
|
+
end
|
100
|
+
|
101
|
+
vlan_details.delete_if {|vlan| filter[:vlan_space].to_s != vlan[:space]} if filter.has_key?(:vlan_space) && ! filter[:vlan_space].nil?
|
102
|
+
|
103
|
+
return vlan_details
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
class VagrantSoftLayerVlans
|
108
|
+
def initialize()
|
109
|
+
@cli_opts = [
|
110
|
+
[ '--datacenter_name', '-d', GetoptLong::REQUIRED_ARGUMENT ],
|
111
|
+
[ '--format', '-f', GetoptLong::REQUIRED_ARGUMENT ],
|
112
|
+
[ '--help', '-h', GetoptLong::NO_ARGUMENT ],
|
113
|
+
[ '--sl_api_key', '-k', GetoptLong::REQUIRED_ARGUMENT ],
|
114
|
+
[ '--sl_endpoint_url', '-e', GetoptLong::REQUIRED_ARGUMENT ],
|
115
|
+
[ '--sl_timeout', '-t', GetoptLong::REQUIRED_ARGUMENT ],
|
116
|
+
[ '--sl_username', '-u', GetoptLong::REQUIRED_ARGUMENT ],
|
117
|
+
[ '--vlan_name', '-v', GetoptLong::REQUIRED_ARGUMENT ],
|
118
|
+
[ '--vlan_space', '-s', GetoptLong::REQUIRED_ARGUMENT ]
|
119
|
+
]
|
120
|
+
@config = {
|
121
|
+
:columns => [ :id, :name, :qualified_name, :space, :datacenter ],
|
122
|
+
:column_labels => {
|
123
|
+
:datacenter => 'datacenter',
|
124
|
+
:id => 'id',
|
125
|
+
:name => 'name',
|
126
|
+
:qualified_name => 'qualified name',
|
127
|
+
:space => 'space'
|
128
|
+
},
|
129
|
+
:datacenter_name => nil,
|
130
|
+
:format => :pretty,
|
131
|
+
:formats => [ :csv, :json, :perty, :pretty, :raw ],
|
132
|
+
:sl_credentials => {
|
133
|
+
:api_key => nil,
|
134
|
+
:endpoint_url => SoftLayer::API_PUBLIC_ENDPOINT,
|
135
|
+
:timeout => 60,
|
136
|
+
:username => nil
|
137
|
+
},
|
138
|
+
:vlan_name => nil,
|
139
|
+
:vlan_space => nil
|
140
|
+
}
|
141
|
+
@help = <<-EOF
|
142
|
+
vagrant-softlayer-vlans [OPTION]
|
143
|
+
|
144
|
+
--datacenter_name|-d DCNAME,...:
|
145
|
+
Comma separated list of datacenter names to filter vlan results on.
|
146
|
+
|
147
|
+
--format|-f FORMAT:
|
148
|
+
Sets the output format of the vlan results. Acceptable values are 'csv', 'json', 'perty', 'pretty', or 'raw'.
|
149
|
+
Defaults to 'pretty'.
|
150
|
+
|
151
|
+
--help|-h:
|
152
|
+
Print this help.
|
153
|
+
|
154
|
+
--sl_api_key|-k SL_API_KEY
|
155
|
+
Sets the SoftLayer API key. If not specified, it is assumed SL_API_KEY environment variable is set.
|
156
|
+
|
157
|
+
--sl_endpoint_url|-e SL_API_BASE_URL
|
158
|
+
Sets the SoftLayer endpoint URL. If not specified, it assumed SL_API_BASE_URL environment variable is set to API_PUBLIC_ENDPOINT or API_PRIVATE_ENDPOINT.
|
159
|
+
Defaults to API_PUBLIC_ENDPOINT.
|
160
|
+
|
161
|
+
--sl_timeout|-t SL_TIMEOUT
|
162
|
+
Sets the SoftLayer API call timeout value in seconds.
|
163
|
+
|
164
|
+
--sl_username|-u USERNAME
|
165
|
+
Sets the SoftLayer account user name. If not specified, it is assumed SL_API_USERNAME environment variable is set.
|
166
|
+
|
167
|
+
--vlan_name|-v VLAN_NAME,...
|
168
|
+
Comma separated list of vlan names to filter vlan results on. A vlan name can be the vlan name or qualified name.
|
169
|
+
|
170
|
+
--vlan_space|-s VLAN_SPACE
|
171
|
+
Sets the vlan space to filter vlan results on. Acceptable spaces are 'public' or 'private'.
|
172
|
+
|
173
|
+
EOF
|
174
|
+
end
|
175
|
+
|
176
|
+
def run()
|
177
|
+
proc_cli_options
|
178
|
+
|
179
|
+
begin
|
180
|
+
sl_vlans = SoftLayerVlans.new(@config[:sl_credentials][:api_key], @config[:sl_credentials][:username], @config[:sl_credentials][:endpoint_url], @config[:sl_credentials][:timeout])
|
181
|
+
rescue Exception => e
|
182
|
+
$stderr.puts "ERROR: Failed to instantiate SoftLayerVlans instance: #{ e.message }"
|
183
|
+
exit 1
|
184
|
+
end
|
185
|
+
|
186
|
+
begin
|
187
|
+
vlan_details = sl_vlans.vlans(:datacenter_name => @config[:datacenter_name], :vlan_name => @config[:vlan_name], :vlan_space => @config[:vlan_space])
|
188
|
+
rescue Exception => e
|
189
|
+
$stderr.puts "ERROR: Failed to retrieve SoftLayer account vlans: #{ e.message }"
|
190
|
+
exit 1
|
191
|
+
end
|
192
|
+
|
193
|
+
print_vlans(vlan_details) if ! vlan_details.empty?
|
194
|
+
end
|
195
|
+
|
196
|
+
private
|
197
|
+
|
198
|
+
def proc_cli_options()
|
199
|
+
begin
|
200
|
+
opts = GetoptLong.new(*@cli_opts)
|
201
|
+
opts.quiet = true
|
202
|
+
|
203
|
+
opts.each do |opt, optval|
|
204
|
+
case opt
|
205
|
+
when '--datacenter_name'
|
206
|
+
@config[:datacenter_name] = optval.to_s.split(',')
|
207
|
+
|
208
|
+
when '--format'
|
209
|
+
if ! @config[:formats].include?(optval.to_s.downcase.to_sym)
|
210
|
+
$stderr.puts "ERROR: Invalid format value, expected one of #{ @config[:formats].map{|format| format.to_s}.inspect }: #{ optval.inspect }"
|
211
|
+
exit 2
|
212
|
+
end
|
213
|
+
|
214
|
+
@config[:format] = optval.to_s.downcase.to_sym
|
215
|
+
|
216
|
+
when '--help'
|
217
|
+
puts @help
|
218
|
+
exit 0
|
219
|
+
|
220
|
+
when '--sl_api_key'
|
221
|
+
@config[:sl_credentials][:api_key] = optval.to_s
|
222
|
+
|
223
|
+
when '--sl_endpoint_url'
|
224
|
+
if ! [ "API_PUBLIC_ENDPOINT", "API_PRIVATE_ENDPOINT" ].include?(optval.to_s.upcase)
|
225
|
+
$stderr.puts "ERROR: Invalid endpoint_url value: " + optval.to_s.upcase
|
226
|
+
exit 2
|
227
|
+
end
|
228
|
+
|
229
|
+
@config[:sl_credentials][:endpoint_url] = (optval.to_s.upcase == 'API_PUBLIC_ENDPOINT' ? SoftLayer::API_PUBLIC_ENDPOINT : SoftLayer::API_PRIVATE_ENDPOINT)
|
230
|
+
|
231
|
+
when '--sl_timeoout'
|
232
|
+
@config[:sl_credentials][:timeout] = optval.to_i
|
233
|
+
|
234
|
+
when '--sl_username'
|
235
|
+
@config[:sl_credentials][:username] = optval.to_s
|
236
|
+
|
237
|
+
when '--vlan_name'
|
238
|
+
@config[:vlan_name] = optval.to_s.split(',')
|
239
|
+
|
240
|
+
when '--vlan_space'
|
241
|
+
if ! [ :private, :public ].include?(optval.to_s.downcase.to_sym)
|
242
|
+
$stderr.puts "ERROR: Invalid vlan space value, expected one of #{ [ 'private', 'public' ].inspect }: #{ optval.inspect }"
|
243
|
+
exit 2
|
244
|
+
end
|
245
|
+
|
246
|
+
@config[:vlan_space] = optval.to_s.downcase.to_sym
|
247
|
+
|
248
|
+
end
|
249
|
+
end
|
250
|
+
rescue GetoptLong::Error => e
|
251
|
+
$stderr.puts "vagrant-softlayer-vlans failed to process cli options: #{ e.message }"
|
252
|
+
exit 1
|
253
|
+
end
|
254
|
+
|
255
|
+
@config[:sl_credentials][:username] = ENV["SL_API_USERNAME"] if @config[:sl_credentials][:username].nil? && ENV.include?("SL_API_USERNAME")
|
256
|
+
@config[:sl_credentials][:api_key] = ENV["SL_API_KEY"] if @config[:sl_credentials][:api_key].nil? && ENV.include?("SL_API_KEY")
|
257
|
+
|
258
|
+
if @config[:sl_credentials][:endpoint_url].nil? && ENV.include?("SL_API_BASE_URL")
|
259
|
+
if ! [ 'API_PRIVATE_ENDPOINT', 'API_PUBLIC_ENDPOINT' ].include?(ENV["SL_API_BASE_URL"])
|
260
|
+
$stderr.puts "ERROR: Invalid SoftLayer endpoint URL specified in environment variable SL_API_BASE_URL, expected one of #{ [ 'API_PRIVATE_ENDPOINT', 'API_PUBLIC_ENDPOINT' ].inspect }: #{ ENV["SL_API_BASE_URL"].inspect }"
|
261
|
+
exit 2
|
262
|
+
end
|
263
|
+
|
264
|
+
@config[:sl_credentials][:endpoint_url] = (ENV["SL_API_BASE_URL"] == "API_PUBLIC_ENDPOINT" ? SoftLayer::API_PUBLIC_ENDPOINT : SoftLayer::API_PRIVATE_ENDPOINT)
|
265
|
+
end
|
266
|
+
|
267
|
+
if @config[:sl_credentials][:username].nil?
|
268
|
+
$stderr.puts "ERROR: No SoftLayer username specified"
|
269
|
+
exit 2
|
270
|
+
end
|
271
|
+
|
272
|
+
if @config[:sl_credentials][:username].nil?
|
273
|
+
$stderr.puts "ERROR: No SoftLayer user name specified"
|
274
|
+
exit 2
|
275
|
+
end
|
276
|
+
|
277
|
+
if @config[:sl_credentials][:api_key].nil?
|
278
|
+
$stderr.puts "ERROR: No SoftLayer API key specified"
|
279
|
+
exit 2
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
def print_vlans(vlan_details)
|
284
|
+
case @config[:format]
|
285
|
+
when :csv
|
286
|
+
puts @config[:columns].map{|col| @config[:column_labels][col]}.to_csv(:force_quotes => true)
|
287
|
+
|
288
|
+
vlan_details.each do |vlan|
|
289
|
+
csv_row = []
|
290
|
+
|
291
|
+
@config[:columns].each {|col| csv_row.push(vlan[col])}
|
292
|
+
|
293
|
+
puts csv_row.to_csv(:force_quotes => true)
|
294
|
+
end
|
295
|
+
|
296
|
+
when :json
|
297
|
+
puts JSON.pretty_generate(vlan_details)
|
298
|
+
|
299
|
+
when :perty, :pretty
|
300
|
+
table = []
|
301
|
+
|
302
|
+
table.push(@config[:columns].map{|col| @config[:column_labels][col]})
|
303
|
+
|
304
|
+
vlan_details.each {|vlan| table.push(@config[:columns].map {|col| vlan[col].to_s})}
|
305
|
+
|
306
|
+
max_col_widths = table.transpose.map{|col| col.group_by(&:size).max.first + 2}
|
307
|
+
|
308
|
+
puts ':' + max_col_widths.map{|col_width| '.' * col_width}.join(':') + ':'
|
309
|
+
|
310
|
+
print ':'
|
311
|
+
|
312
|
+
table[0].each_index {|col| print table[0][col].center(max_col_widths[col]) + ':'}
|
313
|
+
|
314
|
+
puts
|
315
|
+
|
316
|
+
puts ':' + max_col_widths.map{|colWidth| '.' * colWidth}.join(':') + ':'
|
317
|
+
|
318
|
+
table.shift
|
319
|
+
|
320
|
+
table.each do |row|
|
321
|
+
print ':'
|
322
|
+
|
323
|
+
row.each_index {|col| print row[col].center(max_col_widths[col]) + ':'}
|
324
|
+
|
325
|
+
puts
|
326
|
+
end
|
327
|
+
|
328
|
+
puts ':' + max_col_widths.map{|col_width| '.' * col_width}.join(':') + ':'
|
329
|
+
|
330
|
+
when :raw
|
331
|
+
pp vlan_details
|
332
|
+
|
333
|
+
end
|
334
|
+
end
|
335
|
+
end
|
336
|
+
|
337
|
+
if __FILE__ == $0
|
338
|
+
VagrantSoftLayerVlans.new.run()
|
339
|
+
end
|