kitchen-cloudstack 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +4 -0
- data/lib/kitchen/driver/cloudstack.rb +52 -18
- data/lib/kitchen/driver/cloudstack_version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -21,6 +21,8 @@ Provide, at a minimum, the required driver options in your `.kitchen.yml` file:
|
|
21
21
|
cloudstack_secret_key: [YOUR CLOUDSTACK SECRET KEY]
|
22
22
|
cloudstack_api_url: [YOUR CLOUDSTACK API URL]
|
23
23
|
require_chef_omnibus: latest (if you'll be using Chef)
|
24
|
+
OPTIONAL
|
25
|
+
cloudstack_sync_time: [NUMBER OF SECONDS TO WAIT FOR CLOUD-SET-GUEST-PASSWORD/SSHKEY]
|
24
26
|
|
25
27
|
Then to specify different OS templates,
|
26
28
|
|
@@ -32,6 +34,8 @@ Then to specify different OS templates,
|
|
32
34
|
cloudstack_security_group_id: [SECURITY GROUP ID FOR SHARED NETWORKS]
|
33
35
|
OPTIONAL
|
34
36
|
cloudstack_ssh_keypair_name: [SSH KEY NAME]
|
37
|
+
To use the CloudStack public key provider, you need to have the .PEM file located in the same directory as
|
38
|
+
your .kitchen.yml file.
|
35
39
|
|
36
40
|
By default, a unique server name will be generated and the randomly generated password will be used, though that
|
37
41
|
behavior can be overridden with additional options (e.g., to specify a SSH private key):
|
@@ -89,7 +89,7 @@ module Kitchen
|
|
89
89
|
debug("Job ID #{jobid}")
|
90
90
|
server_start = compute.query_async_job_result('jobid'=>jobid)
|
91
91
|
while server_start['queryasyncjobresultresponse'].fetch('jobstatus') == 0
|
92
|
-
print "."
|
92
|
+
print ". "
|
93
93
|
sleep(10)
|
94
94
|
server_start = compute.query_async_job_result('jobid'=>jobid)
|
95
95
|
debug("Server_Start: #{server_start} \n")
|
@@ -102,31 +102,44 @@ module Kitchen
|
|
102
102
|
if server_start['queryasyncjobresultresponse'].fetch('jobstatus') == 1
|
103
103
|
server_info = server_start['queryasyncjobresultresponse']['jobresult']['virtualmachine']
|
104
104
|
debug(server_info)
|
105
|
-
|
106
|
-
|
105
|
+
print "(server ready)"
|
106
|
+
|
107
|
+
#Check first if the API response has a keypair. I should probably just make this check the config, but this
|
108
|
+
#should save against typos in the config file.
|
109
|
+
|
110
|
+
if (!server_info.fetch('keypair').nil?)
|
111
|
+
state[:hostname] = server_info.fetch('nic').first.fetch('ipaddress')
|
112
|
+
info("SSH for #{state[:hostname]} with SSH Key #{server_info.fetch('keypair')}.")
|
113
|
+
if File.exist?("./#{server_info.fetch('keypair')}.pem")
|
114
|
+
keypair = "./#{server_info.fetch('keypair')}.pem"
|
115
|
+
elsif File.exist?("~/#{server_info.fetch('keypair')}.pem")
|
116
|
+
keypair = "~/#{server_info.fetch('keypair')}.pem"
|
117
|
+
elsif File.exist?("~/.ssh/#{server_info.fetch('keypair')}.pem")
|
118
|
+
keypair = "~/.ssh/#{server_info.fetch('keypair')}.pem"
|
119
|
+
else
|
120
|
+
error("Cannot find PEM file specified.")
|
121
|
+
end
|
122
|
+
|
123
|
+
ssh = Fog::SSH.new(state[:hostname], config[:username], {:keys => keypair})
|
124
|
+
debug(state[:hostname])
|
125
|
+
debug(config[:username])
|
126
|
+
debug(keypair)
|
127
|
+
deploy_private_key(state[:hostname], ssh)
|
128
|
+
elsif (server_info.fetch('keypair').nil? && server_info.fetch('passwordenabled') == true)
|
107
129
|
password = server_info.fetch('password')
|
108
130
|
state[:hostname] = server_info.fetch('nic').first.fetch('ipaddress')
|
131
|
+
# Print out IP and password so you can record it if you want.
|
109
132
|
info("Password for #{config[:username]} at #{state[:hostname]} is #{password}")
|
110
133
|
ssh = Fog::SSH.new(state[:hostname], config[:username], {:password => password})
|
111
134
|
debug(state[:hostname])
|
112
135
|
debug(config[:username])
|
113
136
|
debug(password)
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
# Wait a few moments for the OS to run the cloud-setup-sshkey/password scripts
|
119
|
-
sleep(30)
|
120
|
-
ssh.run([
|
121
|
-
%{mkdir .ssh},
|
122
|
-
%{echo "#{pub_key}" >> ~/.ssh/authorized_keys}
|
123
|
-
])
|
124
|
-
end
|
125
|
-
info("(ssh ready)")
|
137
|
+
deploy_private_key(state[:hostname], ssh)
|
138
|
+
elsif (server_info.fetch('keypair').nil? && server_info.fetch('passwordenabled') == false)
|
139
|
+
state[:hostname] = server_info.fetch('nic').first.fetch('ipaddress')
|
140
|
+
info("No SSH key specified nor is this a password enabled template. You will have to manually copy your SSH public key to #{state[:hostname]} to use this Kitchen.")
|
126
141
|
end
|
127
|
-
|
128
142
|
end
|
129
|
-
|
130
143
|
end
|
131
144
|
|
132
145
|
def destroy(state)
|
@@ -140,7 +153,8 @@ module Kitchen
|
|
140
153
|
end
|
141
154
|
|
142
155
|
def tcp_test_ssh(hostname)
|
143
|
-
|
156
|
+
# Ripped unceremoniously from knife-cloudstack-fog as I was having issues with the wait_for_sshd() function.
|
157
|
+
print(". ")
|
144
158
|
tcp_socket = TCPSocket.new(hostname, 22)
|
145
159
|
readable = IO.select([tcp_socket], nil, nil, 5)
|
146
160
|
if readable
|
@@ -169,6 +183,26 @@ module Kitchen
|
|
169
183
|
tcp_socket && tcp_socket.close
|
170
184
|
end
|
171
185
|
|
186
|
+
def deploy_private_key(hostname, ssh)
|
187
|
+
debug("Deploying private key to #{hostname} using connection #{ssh}")
|
188
|
+
tcp_test_ssh(hostname)
|
189
|
+
sync_time = 45
|
190
|
+
if (config[:cloudstack_sync_time])
|
191
|
+
debug("Setting sync time to #{config[:cloudstack_sync_time]}")
|
192
|
+
sync_time = config[:cloudstack_sync_time]
|
193
|
+
end
|
194
|
+
if !(config[:public_key_path].nil?)
|
195
|
+
pub_key = open(config[:public_key_path]).read
|
196
|
+
# Wait a few moments for the OS to run the cloud-setup-password scripts
|
197
|
+
sleep(sync_time)
|
198
|
+
ssh.run([
|
199
|
+
%{mkdir .ssh},
|
200
|
+
%{echo "#{pub_key}" >> ~/.ssh/authorized_keys}
|
201
|
+
])
|
202
|
+
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
172
206
|
end
|
173
207
|
end
|
174
208
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kitchen-cloudstack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.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: 2013-04-
|
12
|
+
date: 2013-04-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: test-kitchen
|