kitchen-rax 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/kitchen/driver/helper.rb +16 -0
- data/lib/kitchen/driver/rax.rb +91 -29
- data/lib/kitchen/driver/rax_version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0109d9348db441b6600d8035ec7f33d5adc7f49
|
4
|
+
data.tar.gz: 9356b8368eefdb41221eda9bd2a88fef91640c01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1c1984bd5fde64482a9e71ed0aaf699cafb333f3ffaf3578235167192a5244e67cce58bf3fbf283b8953d75835c4bbaef2620d3b58cc518d849457ba1264a48
|
7
|
+
data.tar.gz: 2e8003ff10c41fcf84df49249d1256e9cbc641ce396b8d3c3a0e5732625ea8fa7738a53d870fd0350b2d2c6de78e909b9abedf438ae0ddc0b6fbfd63e6f5d292
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Kitchen
|
2
|
+
|
3
|
+
module Driver
|
4
|
+
|
5
|
+
def self.default_name
|
6
|
+
[
|
7
|
+
instance.name.gsub(/\W/, '')[0..14],
|
8
|
+
(Etc.getlogin || 'nologin').gsub(/\W/, '')[0..14],
|
9
|
+
Socket.gethostname.gsub(/\W/, '')[0..22],
|
10
|
+
Array.new(7) { rand(36).to_s(36) }.join
|
11
|
+
].join('-')
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
data/lib/kitchen/driver/rax.rb
CHANGED
@@ -1,37 +1,99 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
#
|
3
|
-
# Author:: Olivier Kouame (<olivier.kouame@salesforce.com>)
|
4
|
-
#
|
5
|
-
# Copyright (C) 2017, Olivier Kouame
|
6
|
-
#
|
7
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
-
# you may not use this file except in compliance with the License.
|
9
|
-
# You may obtain a copy of the License at
|
10
|
-
#
|
11
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
-
#
|
13
|
-
# Unless required by applicable law or agreed to in writing, software
|
14
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
-
# See the License for the specific language governing permissions and
|
17
|
-
# limitations under the License.
|
18
|
-
|
19
1
|
require 'kitchen'
|
20
2
|
|
21
3
|
module Kitchen
|
22
4
|
|
23
|
-
|
5
|
+
module Driver
|
6
|
+
|
7
|
+
class Rax < Kitchen::Driver::Base
|
8
|
+
|
9
|
+
default_config :version, 'v2'
|
10
|
+
default_config :flavor_id, 'performance1-1'
|
11
|
+
default_config :port, '22'
|
12
|
+
default_config :rackspace_region, 'lon'
|
13
|
+
default_config :wait_for, 600
|
14
|
+
default_config(:image_id, &:default_image)
|
15
|
+
default_config(:server_name, &:default_name)
|
16
|
+
default_config :networks, nil
|
17
|
+
|
18
|
+
default_config :rackspace_username do
|
19
|
+
ENV['RACKSPACE_USERNAME']
|
20
|
+
end
|
21
|
+
|
22
|
+
default_config :rackspace_api_key do
|
23
|
+
ENV['RACKSPACE_API_KEY']
|
24
|
+
end
|
25
|
+
|
26
|
+
required_config :rackspace_username
|
27
|
+
required_config :rackspace_api_key
|
28
|
+
required_config :image_id
|
29
|
+
|
30
|
+
def initialize(config)
|
31
|
+
super
|
32
|
+
Fog.timeout = config[:wait_for].to_i
|
33
|
+
end
|
34
|
+
|
35
|
+
def create(state)
|
36
|
+
server = create_server
|
37
|
+
state[:server_id] = server.id
|
38
|
+
info("Rackspace instance <#{state[:server_id]}> created.")
|
39
|
+
server.wait_for { ready? }
|
40
|
+
puts '(server ready)'
|
41
|
+
rackconnect_check(server)
|
42
|
+
state[:hostname] = hostname(server)
|
43
|
+
tcp_check(state)
|
44
|
+
rescue Fog::Errors::Error, Excon::Errors::Error => ex
|
45
|
+
raise ActionFailed, ex.message
|
46
|
+
end
|
47
|
+
|
48
|
+
def destroy(state)
|
49
|
+
return if state[:server_id].nil?
|
50
|
+
server = compute.servers.get(state[:server_id])
|
51
|
+
server.destroy unless server.nil?
|
52
|
+
info("Rackspace instance <#{state[:server_id]}> destroyed.")
|
53
|
+
state.delete(:server_id)
|
54
|
+
state.delete(:hostname)
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def compute
|
60
|
+
server_def = { provider: 'Rackspace' }
|
61
|
+
opts = [:version, :rackspace_username, :rackspace_api_key, :rackspace_region]
|
62
|
+
opts.each do |opt|
|
63
|
+
server_def[opt] = config[opt]
|
64
|
+
end
|
65
|
+
Fog::Compute.new(server_def)
|
66
|
+
end
|
67
|
+
|
68
|
+
def create_server
|
69
|
+
server_def = { name: config[:server_name], networks: networks }
|
70
|
+
[:image_id, :flavor_id].each do |opt|
|
71
|
+
server_def[opt] = config[opt]
|
72
|
+
end
|
73
|
+
server_def[:no_passwd_lock] = true
|
74
|
+
server = compute.servers.new(server_def).save
|
75
|
+
username = instance.transport[:username]
|
76
|
+
state[:password] = server.password
|
77
|
+
end
|
78
|
+
|
79
|
+
def rackconnect_check(server)
|
80
|
+
server.wait_for { metadata.all['rackconnect_automation_status'] == 'DEPLOYED' }
|
81
|
+
puts '(rackconnect automation complete)'
|
82
|
+
server.update
|
83
|
+
end
|
84
|
+
|
85
|
+
def winrm_transport?
|
86
|
+
instance.transport.name.casecmp("winrm") == 0
|
87
|
+
end
|
24
88
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
class Rax < Kitchen::Driver::SSHBase
|
89
|
+
def hostname(server)
|
90
|
+
server.public_ip_address
|
91
|
+
end
|
29
92
|
|
30
|
-
|
31
|
-
|
93
|
+
def networks
|
94
|
+
nil
|
95
|
+
end
|
32
96
|
|
33
|
-
|
34
|
-
|
35
|
-
end
|
36
|
-
end
|
97
|
+
end
|
98
|
+
end
|
37
99
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kitchen-rax
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Olivier Kouame
|
@@ -113,6 +113,7 @@ files:
|
|
113
113
|
- bin/console
|
114
114
|
- bin/setup
|
115
115
|
- kitchen-rax.gemspec
|
116
|
+
- lib/kitchen/driver/helper.rb
|
116
117
|
- lib/kitchen/driver/rax.rb
|
117
118
|
- lib/kitchen/driver/rax_version.rb
|
118
119
|
- spec/kitchen/rax_spec.rb
|