kitchen-softlayer 0.0.7 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a682dc5e86608aba4f73514a566c33a5bf3facb3
4
- data.tar.gz: 97350b99e4b7ece3b87fc0b3a3f54c631d99706e
3
+ metadata.gz: 490411db2bd36714e967aabfbd5517b83e9f93e0
4
+ data.tar.gz: 43689042ddcf3bebcc6a6a84aa313f22119e61dd
5
5
  SHA512:
6
- metadata.gz: 89573962a152f004c8a476485017c9836d7504a2dfaf5d563efbf88e7c5ffccb661674677b9cd3a66e0b26062c6bf6ebac3411b5dd031133b2e79740eccf0d14
7
- data.tar.gz: a4dd15a31f74a36f05c692583a64fae72401d862efeb2b3ef2708abda5c4a80f305454fa45e1695a61152d7961b61daab4ad9d71080dbb51f3ba6caa5d8d2551
6
+ metadata.gz: 077925f2ca58b015d1097b7401b77ef6f8fa04aaa7aa7dc2e489f7079924b348e65071c8fc157b7d4721f426d863d17329010215ac3d3bd1fff7e9857c187761
7
+ data.tar.gz: 9df0820590baad9db937adcdff8957737f4d55ea0b02aab3d91205eb4b1b67b69d6cbb0626e7be0700e80449b5335a9e8304ea7a7b921af9c8591dbd8d23fcb4
data/README.md CHANGED
@@ -96,6 +96,7 @@ softlayer_api_key | ENV['softlayer_api_key']
96
96
  softlayer_default_datacenter | ENV['softlayer_default_datacenter']
97
97
  softlayer_default_domain | ENV['softlayer_default_domain']
98
98
  server_name | nil | Server Name
99
+ server_name_prefix | nil | If you want to have a static prefix for a random server name.
99
100
  key_name | nil | the label of the uploaded key
100
101
  ssh_key| nil | file location of private key
101
102
  disable_ssl_validation | false | ssl validation for fog softlayer api
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
17
17
  candidates += ['CHANGELOG.md', 'kitchen-softlayer.gemspec']
18
18
  spec.files = candidates.sort
19
19
  spec.require_paths = ['lib']
20
- spec.required_ruby_version = '>= 2.0.0'
20
+ spec.required_ruby_version = '>= 2.1.0'
21
21
  spec.add_dependency 'test-kitchen', '~> 1.4'
22
22
  spec.add_dependency 'fog', '~> 1.18'
23
23
  spec.add_dependency 'fog-softlayer', '~> 1'
@@ -23,6 +23,7 @@ module Kitchen
23
23
  # rubocop:disable Metrics/LineLength
24
24
  class Softlayer < Kitchen::Driver::SSHBase
25
25
  default_config :server_name, nil
26
+ default_config :server_name_prefix, nil
26
27
  default_config :key_name, nil
27
28
  required_config :key_name
28
29
  default_config :ssh_key do
@@ -76,7 +77,7 @@ module Kitchen
76
77
  default_config :alternate_ip, nil
77
78
 
78
79
  def create(state)
79
- config[:server_name] = default_name unless config[:server_name]
80
+ config_server_name
80
81
  config[:disable_ssl_validation] && disable_ssl_validation
81
82
  server = find_server(config[:hostname])
82
83
  server = create_server unless server
@@ -88,13 +89,13 @@ module Kitchen
88
89
  end
89
90
  info "\n(server ready)"
90
91
  tag_server(server)
91
- if config[:ssh_via_hostname]
92
- state[:hostname] = config[:hostname]
93
- elsif config[:alternate_ip]
94
- state[:hostname] = config[:alternate_ip]
95
- else
96
- state[:hostname] = get_ip(server)
97
- end
92
+ state[:hostname] = if config[:ssh_via_hostname]
93
+ config[:hostname]
94
+ elsif config[:alternate_ip]
95
+ config[:alternate_ip]
96
+ else
97
+ get_ip(server)
98
+ end
98
99
  setup_ssh(server, state)
99
100
  wait_for_ssh_key_access(state)
100
101
  rescue Fog::Errors::Error, Excon::Errors::Error => ex
@@ -115,6 +116,17 @@ module Kitchen
115
116
 
116
117
  private
117
118
 
119
+ # Set the proper server name in the config
120
+ def config_server_name
121
+ return if config[:server_name]
122
+
123
+ config[:server_name] = if config[:server_name_prefix]
124
+ server_name_prefix(config[:server_name_prefix])
125
+ else
126
+ default_name
127
+ end
128
+ end
129
+
118
130
  def wait_for_server_to_delete(state)
119
131
  ((config[:destroy_timeout].to_i / 15).floor).times do
120
132
  info 'Deleting server in softlayer'
@@ -122,7 +134,7 @@ module Kitchen
122
134
  server = compute.servers.get(state[:server_id])
123
135
  return if server.nil? || server.id.nil?
124
136
  end
125
- fail "#{config[:destroy_timeout]} seconds went by and server not deleted by softlayer"
137
+ raise "#{config[:destroy_timeout]} seconds went by and server not deleted by softlayer"
126
138
  end
127
139
 
128
140
  def wait_for_ssh_key_access(state)
@@ -142,7 +154,7 @@ module Kitchen
142
154
  return
143
155
  end
144
156
  end
145
- fail "#{config[:ssh_timeout]} seconds went by and we couldn't connect, somethings broken"
157
+ raise "#{config[:ssh_timeout]} seconds went by and we couldn't connect, somethings broken"
146
158
  end
147
159
 
148
160
  def compute
@@ -191,7 +203,7 @@ module Kitchen
191
203
  debug "Found private image #{id} for name #{image_name}"
192
204
  end
193
205
  end
194
- fail "No image found with name #{image_name}" if id.nil?
206
+ raise "No image found with name #{image_name}" if id.nil?
195
207
  id
196
208
  end
197
209
 
@@ -203,7 +215,7 @@ module Kitchen
203
215
  debug "Found network id #{r['id']} for vlan number #{r['vlanNumber']}"
204
216
  return r['id']
205
217
  end
206
- fail "No network found for vlan number #{r['vlanNumber']}"
218
+ raise "No network found for vlan number #{r['vlanNumber']}"
207
219
  end
208
220
 
209
221
  def create_server
@@ -288,6 +300,32 @@ module Kitchen
288
300
  ].join('-')
289
301
  end
290
302
 
303
+ def server_name_prefix(server_name_prefix)
304
+ # Generate what should be a unique server name with given prefix
305
+ # of up to 63 total chars
306
+ #
307
+ # Provided prefix: variable, max 54
308
+ # Separator: 1
309
+ # Random string: 8
310
+ # ===================
311
+ # Max: 63
312
+ #
313
+ if server_name_prefix.length > 54
314
+ warn 'Server name prefix too long, truncated to 54 characters'
315
+ server_name_prefix = server_name_prefix[0..53]
316
+ end
317
+
318
+ server_name_prefix.gsub!(/\W/, '')
319
+
320
+ if server_name_prefix.empty?
321
+ warn 'Server name prefix empty or invalid; using fully generated name'
322
+ default_name
323
+ else
324
+ random_suffix = ('a'..'z').to_a.sample(8).join
325
+ server_name_prefix + '-' + random_suffix
326
+ end
327
+ end
328
+
291
329
  # TODO: code has support for multiple ips but not used.
292
330
 
293
331
  def get_public_private_ips(server)
@@ -301,14 +339,10 @@ module Kitchen
301
339
  pub, priv = parse_ips(pub, priv)
302
340
  pub[config[:public_ip_order].to_i] ||
303
341
  priv[config[:private_ip_order].to_i] ||
304
- fail(ActionFailed, 'Could not find an IP')
305
- if config[:use_private_ip_with_public_network] && !config[:private_network_only]
306
- return priv[0]
307
- elsif config[:private_network_only]
308
- return priv[0]
309
- else
310
- return pub[0]
311
- end
342
+ raise(ActionFailed, 'Could not find an IP')
343
+ return priv[0] if config[:use_private_ip_with_public_network] && !config[:private_network_only]
344
+ return priv[0] if config[:private_network_only]
345
+ pub[0]
312
346
  end
313
347
 
314
348
  def parse_ips(pub, priv)
@@ -15,6 +15,6 @@
15
15
  module Kitchen
16
16
  # Version string for Softlayer Kitchen driver
17
17
  module Driver
18
- SOFTLAYER_VERSION = '0.0.7'
18
+ SOFTLAYER_VERSION = '0.1.0'.freeze
19
19
  end
20
20
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kitchen-softlayer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Neill Turner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-16 00:00:00.000000000 Z
11
+ date: 2017-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-kitchen
@@ -77,7 +77,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
77
77
  requirements:
78
78
  - - ">="
79
79
  - !ruby/object:Gem::Version
80
- version: 2.0.0
80
+ version: 2.1.0
81
81
  required_rubygems_version: !ruby/object:Gem::Requirement
82
82
  requirements:
83
83
  - - ">="
@@ -85,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
85
  version: '0'
86
86
  requirements: []
87
87
  rubyforge_project:
88
- rubygems_version: 2.2.2
88
+ rubygems_version: 2.4.5.1
89
89
  signing_key:
90
90
  specification_version: 4
91
91
  summary: Test Kitchen Softlayer driver