vagrant-softlayer 0.3.1 → 0.3.2

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