cloudservers 0.4.0 → 0.4.1
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/CHANGELOG +9 -0
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/cloudservers.gemspec +4 -3
- data/lib/cloudservers/connection.rb +30 -13
- data/test/cloudservers_servers_test.rb +95 -0
- metadata +6 -5
data/CHANGELOG
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
================================================================================
|
2
|
+
0.4.1 (2011/02/02)
|
3
|
+
================================================================================
|
4
|
+
o Support creation of personalities without using the local filesystem.
|
5
|
+
|
6
|
+
================================================================================
|
7
|
+
0.4.0 (2011/01/05)
|
8
|
+
================================================================================
|
9
|
+
o Configurable :auth_url support. Add constants for Cloud Servers USA and UK.
|
data/Rakefile
CHANGED
@@ -9,7 +9,7 @@ begin
|
|
9
9
|
gemspec.summary = "Rackspace Cloud Servers Ruby API"
|
10
10
|
gemspec.description = "A Ruby API to version 1.0 of the Rackspace Cloud Servers product."
|
11
11
|
gemspec.email = "minter@lunenburg.org"
|
12
|
-
gemspec.homepage = "
|
12
|
+
gemspec.homepage = "https://github.com/rackspace/ruby-cloudservers"
|
13
13
|
gemspec.authors = ["H. Wade Minter","Mike Mayo", "Dan Prince"]
|
14
14
|
gemspec.add_dependency 'json'
|
15
15
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.1
|
data/cloudservers.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{cloudservers}
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["H. Wade Minter", "Mike Mayo", "Dan Prince"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-02-02}
|
13
13
|
s.description = %q{A Ruby API to version 1.0 of the Rackspace Cloud Servers product.}
|
14
14
|
s.email = %q{minter@lunenburg.org}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -17,6 +17,7 @@ Gem::Specification.new do |s|
|
|
17
17
|
"TODO"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
|
+
"CHANGELOG",
|
20
21
|
"COPYING",
|
21
22
|
"README.rdoc",
|
22
23
|
"Rakefile",
|
@@ -38,7 +39,7 @@ Gem::Specification.new do |s|
|
|
38
39
|
"test/cloudservers_servers_test.rb",
|
39
40
|
"test/test_helper.rb"
|
40
41
|
]
|
41
|
-
s.homepage = %q{
|
42
|
+
s.homepage = %q{https://github.com/rackspace/ruby-cloudservers}
|
42
43
|
s.require_paths = ["lib"]
|
43
44
|
s.rubygems_version = %q{1.3.7}
|
44
45
|
s.summary = %q{Rackspace Cloud Servers Ruby API}
|
@@ -150,8 +150,10 @@ module CloudServers
|
|
150
150
|
# API level.
|
151
151
|
#
|
152
152
|
# The "Personality" option allows you to include up to five files, of 10Kb or less in size, that will be placed on the created server.
|
153
|
-
# For :personality,
|
154
|
-
#
|
153
|
+
# For :personality, you may pass either
|
154
|
+
# a. a hash of the form {'local_path' => 'server_path'}. The file contents of the file located at local_path will
|
155
|
+
# be placed at the location identified by server_path on the new server.
|
156
|
+
# b. an array of items like {:path => "/path/on/server", :contents=>"contents of file on server"}
|
155
157
|
#
|
156
158
|
# Returns a CloudServers::Server object. The root password is available in the adminPass instance method.
|
157
159
|
#
|
@@ -329,7 +331,7 @@ module CloudServers
|
|
329
331
|
end
|
330
332
|
@http[server].start
|
331
333
|
rescue
|
332
|
-
raise ConnectionException, "Unable to connect to #{server}"
|
334
|
+
raise CloudServers::Exception::ConnectionException, "Unable to connect to #{server}"
|
333
335
|
end
|
334
336
|
end
|
335
337
|
end
|
@@ -339,17 +341,32 @@ module CloudServers
|
|
339
341
|
return if options.nil?
|
340
342
|
require 'base64'
|
341
343
|
data = []
|
342
|
-
|
343
|
-
options.
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
data
|
349
|
-
itemcount += 1
|
344
|
+
# transform simplified personality option
|
345
|
+
if options.is_a? Hash
|
346
|
+
options.each_pair do |localpath, svrpath|
|
347
|
+
data.push(:path => svrpath, :contents => IO.read(localpath))
|
348
|
+
end
|
349
|
+
else
|
350
|
+
data = options
|
350
351
|
end
|
351
|
-
|
352
|
-
|
352
|
+
|
353
|
+
if data.size > MAX_PERSONALITY_ITEMS
|
354
|
+
raise CloudServers::Exception::TooManyPersonalityItems,
|
355
|
+
"Personality files are limited to a total of #{MAX_PERSONALITY_ITEMS} items"
|
356
|
+
end
|
357
|
+
data.each do |item|
|
358
|
+
path = item[:path]
|
359
|
+
contents = item[:contents]
|
360
|
+
if contents.size > MAX_PERSONALITY_FILE_SIZE
|
361
|
+
raise CloudServers::Exception::PersonalityFileTooLarge,
|
362
|
+
"Data for #{path} exceeds the maximum size of #{MAX_PERSONALITY_FILE_SIZE} bytes"
|
363
|
+
elsif path.size > MAX_SERVER_PATH_LENGTH
|
364
|
+
raise CloudServers::Exception::PersonalityFilePathTooLong,
|
365
|
+
"Server-side path of #{path} exceeds the maximum length of #{MAX_SERVER_PATH_LENGTH} characters"
|
353
366
|
|
367
|
+
end
|
368
|
+
item[:contents] = Base64.encode64(contents)
|
369
|
+
end
|
370
|
+
end
|
354
371
|
end
|
355
372
|
end
|
@@ -1,8 +1,34 @@
|
|
1
1
|
$:.unshift File.dirname(__FILE__)
|
2
2
|
require 'test_helper'
|
3
|
+
require 'tempfile'
|
3
4
|
|
4
5
|
class CloudServersServersTest < Test::Unit::TestCase
|
5
6
|
|
7
|
+
CREATE_SERVER_JSON = %{{
|
8
|
+
"server" : {
|
9
|
+
"id" : 1234,
|
10
|
+
"name" : "sample-server",
|
11
|
+
"imageId" : 2,
|
12
|
+
"flavorId" : 1,
|
13
|
+
"hostId" : "e4d909c290d0fb1ca068ffaddf22cbd0",
|
14
|
+
"adminPass" : "blah",
|
15
|
+
"status" : "BUILD",
|
16
|
+
"progress" : 60,
|
17
|
+
"addresses" : {
|
18
|
+
"public" : [
|
19
|
+
"67.23.10.132"
|
20
|
+
],
|
21
|
+
"private" : [
|
22
|
+
"10.176.42.16"
|
23
|
+
]
|
24
|
+
},
|
25
|
+
"metadata" : {
|
26
|
+
"Racker" : "Fanatical"
|
27
|
+
}
|
28
|
+
}
|
29
|
+
}}
|
30
|
+
|
31
|
+
|
6
32
|
include TestConnection
|
7
33
|
|
8
34
|
def setup
|
@@ -136,6 +162,75 @@ json_response = %{{
|
|
136
162
|
|
137
163
|
end
|
138
164
|
|
165
|
+
def test_create_server_requires_name
|
166
|
+
|
167
|
+
assert_raises(CloudServers::Exception::MissingArgument) do
|
168
|
+
@conn.create_server(:imageId => 2, :flavorId => 2)
|
169
|
+
end
|
170
|
+
|
171
|
+
end
|
172
|
+
|
173
|
+
def test_create_server_requires_image_id
|
174
|
+
|
175
|
+
assert_raises(CloudServers::Exception::MissingArgument) do
|
176
|
+
@conn.create_server(:name => "test1", :flavorId => 2)
|
177
|
+
end
|
178
|
+
|
179
|
+
end
|
180
|
+
|
181
|
+
def test_create_server_requires_flavor_id
|
182
|
+
|
183
|
+
assert_raises(CloudServers::Exception::MissingArgument) do
|
184
|
+
@conn.create_server(:name => "test1", :imageId => 2)
|
185
|
+
end
|
186
|
+
|
187
|
+
end
|
188
|
+
|
189
|
+
def test_create_server_with_local_file_personality
|
190
|
+
|
191
|
+
response = mock()
|
192
|
+
response.stubs(:code => "200", :body => CREATE_SERVER_JSON)
|
193
|
+
@conn.stubs(:csreq).returns(response)
|
194
|
+
|
195
|
+
tmp = Tempfile.open('ruby_cloud_servers')
|
196
|
+
tmp.write("hello")
|
197
|
+
tmp.flush
|
198
|
+
|
199
|
+
server = @conn.create_server(:name => "sample-server", :imageId => 2, :flavorId => 2, :metadata => {'Racker' => 'Fanatical'}, :personality => {tmp.path => '/root/tmp.jpg'})
|
200
|
+
|
201
|
+
assert_equal "blah", server.adminPass
|
202
|
+
|
203
|
+
end
|
204
|
+
|
205
|
+
def test_create_server_with_personalities
|
206
|
+
|
207
|
+
response = mock()
|
208
|
+
response.stubs(:code => "200", :body => CREATE_SERVER_JSON)
|
209
|
+
@conn.stubs(:csreq).returns(response)
|
210
|
+
|
211
|
+
server = @conn.create_server(:name => "sample-server", :imageId => 2, :flavorId => 2, :metadata => {'Racker' => 'Fanatical'}, :personality => [{:path => '/root/hello.txt', :contents => "Hello there!"}, {:path => '/root/.ssh/authorized_keys', :contents => ""}])
|
212
|
+
|
213
|
+
assert_equal "blah", server.adminPass
|
214
|
+
|
215
|
+
end
|
216
|
+
|
217
|
+
def test_too_many_personalities
|
218
|
+
|
219
|
+
personalities=[
|
220
|
+
{:path => "/tmp/test1.txt", :contents => ""},
|
221
|
+
{:path => "/tmp/test2.txt", :contents => ""},
|
222
|
+
{:path => "/tmp/test3.txt", :contents => ""},
|
223
|
+
{:path => "/tmp/test4.txt", :contents => ""},
|
224
|
+
{:path => "/tmp/test5.txt", :contents => ""},
|
225
|
+
{:path => "/tmp/test6.txt", :contents => ""}
|
226
|
+
]
|
227
|
+
|
228
|
+
assert_raises(CloudServers::Exception::TooManyPersonalityItems) do
|
229
|
+
@conn.create_server(:name => "sample-server", :imageId => 2, :flavorId => 2, :metadata => {'Racker' => 'Fanatical'}, :personality => personalities)
|
230
|
+
end
|
231
|
+
|
232
|
+
end
|
233
|
+
|
139
234
|
private
|
140
235
|
def get_test_server
|
141
236
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloudservers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 13
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.4.
|
9
|
+
- 1
|
10
|
+
version: 0.4.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- H. Wade Minter
|
@@ -17,7 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2011-
|
20
|
+
date: 2011-02-02 00:00:00 -05:00
|
21
21
|
default_executable:
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|
@@ -44,6 +44,7 @@ extra_rdoc_files:
|
|
44
44
|
- README.rdoc
|
45
45
|
- TODO
|
46
46
|
files:
|
47
|
+
- CHANGELOG
|
47
48
|
- COPYING
|
48
49
|
- README.rdoc
|
49
50
|
- Rakefile
|
@@ -65,7 +66,7 @@ files:
|
|
65
66
|
- test/cloudservers_servers_test.rb
|
66
67
|
- test/test_helper.rb
|
67
68
|
has_rdoc: true
|
68
|
-
homepage:
|
69
|
+
homepage: https://github.com/rackspace/ruby-cloudservers
|
69
70
|
licenses: []
|
70
71
|
|
71
72
|
post_install_message:
|