chef-vpc-toolkit 2.1.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/test/util_test.rb CHANGED
@@ -10,6 +10,13 @@ class UtilTest < Test::Unit::TestCase
10
10
 
11
11
  end
12
12
 
13
+ def test_load_public_key
14
+
15
+ key=Util.load_public_key
16
+ assert_not_nil key
17
+
18
+ end
19
+
13
20
  end
14
21
 
15
22
  end
@@ -6,6 +6,8 @@ module ChefVPCToolkit
6
6
 
7
7
  class VpnNetworkManagerTest < Test::Unit::TestCase
8
8
 
9
+ include ChefVPCToolkit::CloudServersVPC
10
+
9
11
  def setup
10
12
  tmpdir=TmpDir.new_tmp_dir
11
13
  File.open(File.join(tmpdir, "gconftool-2"), 'w') do |f|
@@ -16,14 +18,14 @@ class VpnNetworkManagerTest < Test::Unit::TestCase
16
18
  end
17
19
 
18
20
  def teardown
19
- group_hash=CloudServersVPC.server_group_hash(SERVER_GROUP_XML)
20
- VpnNetworkManager.delete_certs(group_hash['id'])
21
+ group=ServerGroup.from_xml(SERVER_GROUP_XML)
22
+ VpnNetworkManager.delete_certs(group.id)
21
23
  end
22
24
 
23
25
  def test_configure_gconf
24
- group_hash=CloudServersVPC.server_group_hash(SERVER_GROUP_XML)
25
- client_hash=CloudServersVPC.client_hash(CLIENT_XML)
26
- assert VpnNetworkManager.configure_gconf(group_hash, client_hash)
26
+ group=ServerGroup.from_xml(SERVER_GROUP_XML)
27
+ client=Client.from_xml(CLIENT_XML)
28
+ assert VpnNetworkManager.configure_gconf(group, client)
27
29
  end
28
30
 
29
31
  def test_ip_to_integer
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-vpc-toolkit
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 7
5
5
  prerelease: false
6
6
  segments:
7
7
  - 2
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 2.1.0
10
+ version: 2.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Dan Prince
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-11 00:00:00 -05:00
18
+ date: 2011-02-06 00:00:00 -05:00
19
19
  default_executable: chef-vpc-toolkit
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -121,15 +121,22 @@ files:
121
121
  - lib/chef-vpc-toolkit/chef_bootstrap/rhel.bash
122
122
  - lib/chef-vpc-toolkit/chef_bootstrap/ubuntu.bash
123
123
  - lib/chef-vpc-toolkit/chef_installer.rb
124
+ - lib/chef-vpc-toolkit/cloud-servers-vpc/client.rb
125
+ - lib/chef-vpc-toolkit/cloud-servers-vpc/connection.rb
126
+ - lib/chef-vpc-toolkit/cloud-servers-vpc/server.rb
127
+ - lib/chef-vpc-toolkit/cloud-servers-vpc/server_group.rb
128
+ - lib/chef-vpc-toolkit/cloud-servers-vpc/ssh_public_key.rb
129
+ - lib/chef-vpc-toolkit/cloud-servers-vpc/vpn_network_interface.rb
124
130
  - lib/chef-vpc-toolkit/cloud_files.bash
125
- - lib/chef-vpc-toolkit/cloud_servers_vpc.rb
126
- - lib/chef-vpc-toolkit/http_util.rb
127
131
  - lib/chef-vpc-toolkit/ssh_util.rb
128
132
  - lib/chef-vpc-toolkit/util.rb
129
133
  - lib/chef-vpc-toolkit/version.rb
130
134
  - lib/chef-vpc-toolkit/vpn_network_manager.rb
135
+ - lib/chef-vpc-toolkit/xml_util.rb
131
136
  - rake/chef_vpc_toolkit.rake
132
- - test/cloud_servers_vpc_test.rb
137
+ - test/client_test.rb
138
+ - test/server_group_test.rb
139
+ - test/server_test.rb
133
140
  - test/ssh_util_test.rb
134
141
  - test/test_helper.rb
135
142
  - test/util_test.rb
@@ -169,8 +176,10 @@ signing_key:
169
176
  specification_version: 3
170
177
  summary: Rake tasks to automate and configure server groups in the cloud with Chef.
171
178
  test_files:
179
+ - test/server_group_test.rb
172
180
  - test/util_test.rb
173
181
  - test/ssh_util_test.rb
174
182
  - test/test_helper.rb
175
- - test/cloud_servers_vpc_test.rb
176
183
  - test/vpn_network_manager_test.rb
184
+ - test/server_test.rb
185
+ - test/client_test.rb
@@ -1,393 +0,0 @@
1
- require 'json'
2
- require 'builder'
3
- require 'rexml/document'
4
- require 'rexml/xpath'
5
-
6
- module ChefVPCToolkit
7
-
8
- module CloudServersVPC
9
-
10
- SERVER_GROUP_CONFIG_FILE = CHEF_VPC_PROJECT + File::SEPARATOR + "config" + File::SEPARATOR + "server_group.json"
11
-
12
- def self.load_public_key
13
-
14
- ssh_dir=ENV['HOME']+File::SEPARATOR+".ssh"+File::SEPARATOR
15
- if File.exists?(ssh_dir+"id_rsa.pub")
16
- pubkey=IO.read(ssh_dir+"id_rsa.pub")
17
- elsif File.exists?(ssh_dir+"id_dsa.pub")
18
- pubkey=IO.read(ssh_dir+"id_dsa.pub")
19
- else
20
- raise "Failed to load SSH key. Please create a SSH public key pair in your HOME directory."
21
- end
22
-
23
- pubkey.chomp
24
-
25
- end
26
-
27
- # generate a Server Group XML from server_group.json
28
- def self.server_group_xml(config_file=SERVER_GROUP_CONFIG_FILE, owner=ENV['USER'])
29
-
30
- json_hash=JSON.parse(IO.read(config_file))
31
-
32
- xml = Builder::XmlMarkup.new
33
- xml.tag! "server-group" do |sg|
34
- sg.name(json_hash["name"])
35
- sg.description(json_hash["description"])
36
- sg.tag! "owner-name", owner
37
- sg.tag! "domain-name", json_hash["domain_name"]
38
- if json_hash["vpn_network"] then
39
- sg.tag! "vpn-network", json_hash["vpn_network"]
40
- else
41
- sg.tag! "vpn-network", "172.19.0.0"
42
- end
43
- if json_hash["vpn_subnet"] then
44
- sg.tag! "vpn-subnet", json_hash["vpn_subnet"]
45
- else
46
- sg.tag! "vpn-subnet", "255.255.128.0"
47
- end
48
- sg.servers("type" => "array") do |servers|
49
- json_hash["servers"].each_pair do |server_name, server_config|
50
- servers.server do |server|
51
- server.name(server_name)
52
- if server_config["description"] then
53
- server.description(server_config["description"])
54
- else
55
- server.description(server_name)
56
- end
57
- server.tag! "flavor-id", server_config["flavor_id"]
58
- server.tag! "image-id", server_config["image_id"]
59
- if server_config["openvpn_server"]
60
- server.tag! "openvpn-server", "true", { "type" => "boolean"}
61
- end
62
- end
63
- end
64
- end
65
- sg.tag! "ssh-public-keys", { "type" => "array"} do |ssh_keys|
66
- ssh_keys.tag! "ssh-public-key" do |ssh_public_key|
67
- ssh_public_key.description "#{ENV['USER']}'s public key"
68
- ssh_public_key.tag! "public-key", self.load_public_key
69
- end
70
- end
71
- end
72
- xml.target!
73
-
74
- end
75
-
76
- def self.server_group_hash(xml)
77
-
78
- hash={}
79
- dom = REXML::Document.new(xml)
80
- REXML::XPath.each(dom, "/server-group") do |sg|
81
-
82
- hash["name"]=sg.elements["name"].text
83
- hash["description"]=sg.elements["description"].text
84
- hash["id"]=sg.elements["id"].text
85
- hash["domain-name"]=sg.elements["domain-name"].text
86
- hash["vpn-network"]=sg.elements["vpn-network"].text
87
- hash["vpn-subnet"]=sg.elements["vpn-subnet"].text
88
- hash["servers"]={}
89
- REXML::XPath.each(dom, "//server") do |server|
90
- server_name=server.elements["name"].text
91
- server_attributes={
92
- "id" => server.elements["id"].text,
93
- "cloud-server-id-number" => server.elements["cloud-server-id-number"].text,
94
- "status" => server.elements["status"].text,
95
- "external-ip-addr" => server.elements["external-ip-addr"].text,
96
- "internal-ip-addr" => server.elements["internal-ip-addr"].text,
97
- "error-message" => server.elements["error-message"].text,
98
- "image-id" => server.elements["image-id"].text,
99
- "retry-count" => server.elements["retry-count"].text,
100
- "openvpn-server" => server.elements["openvpn-server"].text
101
- }
102
- if server.elements["openvpn-server"].text and server.elements["openvpn-server"].text == "true" and server.elements["external-ip-addr"].text then
103
- hash["vpn-gateway"]=server.elements["external-ip-addr"].text
104
- end
105
- hash["servers"].store(server_name, server_attributes)
106
- end
107
- end
108
-
109
- hash
110
-
111
- end
112
-
113
- def self.server_group_xml_for_id(configs, dir, id=nil)
114
-
115
- if id then
116
- xml=HttpUtil.get(
117
- configs["cloud_servers_vpc_url"]+"/server_groups/#{id}.xml",
118
- configs["cloud_servers_vpc_username"],
119
- configs["cloud_servers_vpc_password"]
120
- )
121
- else
122
- recent_hash=CloudServersVPC.most_recent_server_group_hash(dir)
123
- raise "No server group files exist." if recent_hash.nil?
124
- xml=HttpUtil.get(
125
- configs["cloud_servers_vpc_url"]+"/server_groups/#{recent_hash['id']}.xml",
126
- configs["cloud_servers_vpc_username"],
127
- configs["cloud_servers_vpc_password"]
128
- )
129
-
130
- end
131
-
132
- end
133
-
134
- def self.most_recent_server_group_hash(dir_pattern)
135
- server_groups=[]
136
- Dir[dir_pattern].each do |file|
137
- server_groups << CloudServersVPC.server_group_hash(IO.read(file))
138
- end
139
- if server_groups.size > 0 then
140
- server_groups.sort { |a,b| b["id"].to_i <=> a["id"].to_i }[0]
141
- else
142
- nil
143
- end
144
- end
145
-
146
- def self.print_server_group(hash)
147
-
148
- puts "Cloud Group ID: #{hash["id"]}"
149
- puts "name: #{hash["name"]}"
150
- puts "description: #{hash["description"]}"
151
- puts "domain name: #{hash["domain-name"]}"
152
- puts "VPN gateway IP: #{hash["vpn-gateway"]}"
153
- puts "Servers:"
154
- hash["servers"].each_pair do |name, attrs|
155
- puts "\tname: #{name} (id: #{attrs['cloud-server-id-number']})"
156
- puts "\tstatus: #{attrs['status']}"
157
- if attrs["openvpn-server"] and attrs["openvpn-server"] == "true" then
158
- puts "\tOpenVPN server: #{attrs['openvpn-server']}"
159
- end
160
- if attrs["error-message"] then
161
- puts "\tlast error message: #{attrs['error-message']}"
162
- end
163
- puts "\t--"
164
- end
165
-
166
- end
167
-
168
- def self.server_names(hash)
169
-
170
- names=[]
171
-
172
- hash["servers"].each_pair do |name, hash|
173
- if block_given? then
174
- yield name
175
- else
176
- names << name
177
- end
178
- end
179
-
180
- names
181
-
182
- end
183
-
184
- # Return the name of the VPN server within a server group
185
- def self.vpn_server_name(hash)
186
-
187
- hash["servers"].each_pair do |name, hash|
188
- if hash['openvpn-server'] and hash['openvpn-server'] == "true" then
189
- if block_given? then
190
- yield name
191
- else
192
- return name
193
- end
194
- end
195
- end
196
-
197
- end
198
-
199
- # default timeout of 20 minutes
200
- def self.poll_until_online(group_id, timeout=1200)
201
-
202
- configs=Util.load_configs
203
-
204
- online = false
205
- count=0
206
- until online or (count*20) >= timeout.to_i do
207
- count+=1
208
- begin
209
- xml=HttpUtil.get(
210
- configs["cloud_servers_vpc_url"]+"/server_groups/#{group_id}.xml",
211
- configs["cloud_servers_vpc_username"],
212
- configs["cloud_servers_vpc_password"]
213
- )
214
-
215
- hash=CloudServersVPC.server_group_hash(xml)
216
-
217
- online=true
218
- hash["servers"].each_pair do |name, attrs|
219
- if ["Pending", "Rebuilding"].include?(attrs["status"]) then
220
- online=false
221
- end
222
- if attrs["status"] == "Failed" then
223
- raise "Failed to create server group with the following message: #{attrs['error-message']}"
224
- end
225
- end
226
- if not online
227
- yield hash if block_given?
228
- sleep 20
229
- end
230
- rescue EOFError
231
- end
232
- end
233
- if (count*20) >= timeout.to_i then
234
- raise "Timeout waiting for server groups to come online."
235
- end
236
-
237
- end
238
-
239
- def self.os_types(server_group_hash)
240
-
241
- os_types={}
242
- server_group_hash["servers"].each_pair do |name, attrs|
243
- os_type = case attrs["image-id"].to_i
244
- when 51 # Centos 5.5
245
- "centos"
246
- when 187811 # Centos 5.4
247
- "centos"
248
- when 71 # Fedora 14
249
- "fedora"
250
- when 53 # Fedora 13
251
- "fedora"
252
- when 17 # Fedora 12
253
- "fedora"
254
- when 14 # RHEL 5.4
255
- "rhel"
256
- when 62 # RHEL 5.5
257
- "rhel"
258
- when 49 # Ubuntu 10.04
259
- "ubuntu"
260
- when 14362 # Ubuntu 9.10
261
- "ubuntu"
262
- when 8 # Ubuntu 9.04
263
- "ubuntu"
264
- else
265
- "unknown"
266
- end
267
- if block_given? then
268
- yield name, os_type
269
- else
270
- os_types.store(name, os_type)
271
- end
272
- end
273
- os_types
274
-
275
- end
276
-
277
- def self.rebuild(server_group_hash, server_name)
278
-
279
- configs=Util.load_configs
280
-
281
- server_id=nil
282
- image_id=nil
283
- server_group_hash["servers"].each_pair do |name, attrs|
284
- if name == server_name then
285
- raise "Error: Rebuilding the OpenVPN server is not supported at this time." if attrs["openvpn-server"] == "true"
286
- server_id=attrs["id"]
287
- image_id=attrs["image-id"]
288
- end
289
- end
290
- raise "Unable to find server name: #{server_name}" if server_id.nil?
291
-
292
- HttpUtil.post(
293
- configs["cloud_servers_vpc_url"]+"/servers/#{server_id}/rebuild",
294
- {},
295
- configs["cloud_servers_vpc_username"],
296
- configs["cloud_servers_vpc_password"]
297
- )
298
-
299
- end
300
-
301
- def self.client_hash(xml)
302
-
303
- hash={}
304
- dom = REXML::Document.new(xml)
305
- REXML::XPath.each(dom, "/client") do |client|
306
-
307
- hash["name"]=client.elements["name"].text
308
- hash["description"]=client.elements["description"].text
309
- hash["id"]=client.elements["id"].text
310
- hash["status"]=client.elements["status"].text
311
- hash["server-group-id"]=client.elements["server-group-id"].text
312
- hash["vpn-network-interfaces"]=[]
313
- REXML::XPath.each(dom, "//vpn-network-interface") do |vni|
314
- client_attributes={
315
- "id" => vni.elements["id"].text,
316
- "vpn-ip-addr" => vni.elements["vpn-ip-addr"].text,
317
- "ptp-ip-addr" => vni.elements["ptp-ip-addr"].text,
318
- "client-key" => vni.elements["client-key"].text,
319
- "client-cert" => vni.elements["client-cert"].text,
320
- "ca-cert" => vni.elements["ca-cert"].text
321
- }
322
- hash["vpn-network-interfaces"] << client_attributes
323
- end
324
- end
325
-
326
- hash
327
-
328
- end
329
-
330
- def self.poll_client(client_id, timeout=300)
331
-
332
- configs=Util.load_configs
333
-
334
- online = false
335
- count=0
336
- until online or (count*5) >= timeout.to_i do
337
- count+=1
338
- begin
339
- xml=HttpUtil.get(
340
- configs["cloud_servers_vpc_url"]+"/clients/#{client_id}.xml",
341
- configs["cloud_servers_vpc_username"],
342
- configs["cloud_servers_vpc_password"]
343
- )
344
- hash=CloudServersVPC.client_hash(xml)
345
-
346
- if hash["status"] == "Online" then
347
- online = true
348
- else
349
- yield hash if block_given?
350
- sleep 5
351
- end
352
- rescue EOFError
353
- end
354
- end
355
- if (count*20) >= timeout.to_i then
356
- raise "Timeout waiting for client to come online."
357
- end
358
-
359
- end
360
-
361
- def self.client_xml_for_id(configs, dir, id=nil)
362
-
363
- xml=HttpUtil.get(
364
- configs["cloud_servers_vpc_url"]+"/clients/#{id}.xml",
365
- configs["cloud_servers_vpc_username"],
366
- configs["cloud_servers_vpc_password"]
367
- )
368
-
369
- end
370
-
371
- def self.create_client(server_group_hash, client_name)
372
-
373
- configs=Util.load_configs
374
-
375
- xml = Builder::XmlMarkup.new
376
- xml.client do |client|
377
- client.name(client_name)
378
- client.description("Toolkit Client: #{client_name}")
379
- client.tag! "server-group-id", server_group_hash['id']
380
- end
381
-
382
- HttpUtil.post(
383
- configs["cloud_servers_vpc_url"]+"/clients.xml",
384
- xml.target!,
385
- configs["cloud_servers_vpc_username"],
386
- configs["cloud_servers_vpc_password"]
387
- )
388
-
389
- end
390
-
391
- end
392
-
393
- end