right_slicehost 0.1.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/History.txt +4 -0
- data/Manifest.txt +11 -0
- data/README.txt +47 -0
- data/Rakefile +37 -0
- data/lib/benchmark_fix.rb +39 -0
- data/lib/right_slicehost.rb +601 -0
- data/lib/slicehost_base.rb +604 -0
- data/lib/support.rb +111 -0
- data/test/_test_credentials.rb +27 -0
- data/test/_test_helper.rb +5 -0
- data/test/test_right_slicehost.rb +57 -0
- metadata +75 -0
data/lib/support.rb
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
# If ActiveSupport is loaded, then great - use it. But we don't
|
2
|
+
# want a dependency on it, so if it's not present, define the few
|
3
|
+
# extensions that we want to use...
|
4
|
+
unless defined? ActiveSupport::CoreExtensions
|
5
|
+
# These are ActiveSupport-;like extensions to do a few handy things in the gems
|
6
|
+
# Derived from ActiveSupport, so the AS copyright notice applies:
|
7
|
+
#
|
8
|
+
#
|
9
|
+
#
|
10
|
+
# Copyright (c) 2005 David Heinemeier Hansson
|
11
|
+
#
|
12
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
13
|
+
# a copy of this software and associated documentation files (the
|
14
|
+
# "Software"), to deal in the Software without restriction, including
|
15
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
16
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
17
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
18
|
+
# the following conditions:
|
19
|
+
#
|
20
|
+
# The above copyright notice and this permission notice shall be
|
21
|
+
# included in all copies or substantial portions of the Software.
|
22
|
+
#
|
23
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
24
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
25
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
26
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
27
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
28
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
29
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
30
|
+
#++
|
31
|
+
#
|
32
|
+
#
|
33
|
+
class String #:nodoc:
|
34
|
+
|
35
|
+
# Constantize tries to find a declared constant with the name specified
|
36
|
+
# in the string. It raises a NameError when the name is not in CamelCase
|
37
|
+
# or is not initialized.
|
38
|
+
#
|
39
|
+
# Examples
|
40
|
+
# "Module".constantize #=> Module
|
41
|
+
# "Class".constantize #=> Class
|
42
|
+
def constantize()
|
43
|
+
unless /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/ =~ self
|
44
|
+
raise NameError, "#{self.inspect} is not a valid constant name!"
|
45
|
+
end
|
46
|
+
|
47
|
+
Object.module_eval("::#{$1}", __FILE__, __LINE__)
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
class Object #:nodoc:
|
54
|
+
# "", " ", nil, [], and {} are blank
|
55
|
+
def blank?
|
56
|
+
if respond_to?(:empty?) && respond_to?(:strip)
|
57
|
+
empty? or strip.empty?
|
58
|
+
elsif respond_to?(:empty?)
|
59
|
+
empty?
|
60
|
+
else
|
61
|
+
!self
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
class NilClass #:nodoc:
|
67
|
+
def blank?
|
68
|
+
true
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
class FalseClass #:nodoc:
|
73
|
+
def blank?
|
74
|
+
true
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
class TrueClass #:nodoc:
|
79
|
+
def blank?
|
80
|
+
false
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
class Array #:nodoc:
|
85
|
+
alias_method :blank?, :empty?
|
86
|
+
end
|
87
|
+
|
88
|
+
class Hash #:nodoc:
|
89
|
+
alias_method :blank?, :empty?
|
90
|
+
|
91
|
+
# Return a new hash with all keys converted to symbols.
|
92
|
+
def symbolize_keys
|
93
|
+
inject({}) do |options, (key, value)|
|
94
|
+
options[key.to_sym] = value
|
95
|
+
options
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
class String #:nodoc:
|
101
|
+
def blank?
|
102
|
+
empty? || strip.empty?
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
class Numeric #:nodoc:
|
107
|
+
def blank?
|
108
|
+
false
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class TestSlicehostCredentials
|
2
|
+
|
3
|
+
@@password = nil
|
4
|
+
|
5
|
+
def self.password
|
6
|
+
@@password
|
7
|
+
end
|
8
|
+
def self.password=(newval)
|
9
|
+
@@password = newval
|
10
|
+
end
|
11
|
+
|
12
|
+
# Make sure you have environment vars set:
|
13
|
+
#
|
14
|
+
# export SLICEHOST_PASSWORD='your_slicehost_password'
|
15
|
+
#
|
16
|
+
# or you have a file: ~/.rightscale/test_slicehost_credentials.rb with text:
|
17
|
+
#
|
18
|
+
# TestSlicehostCredentials.password = 'your_slicehost_password'
|
19
|
+
#
|
20
|
+
def self.get_credentials
|
21
|
+
begin
|
22
|
+
require '~/.rightscale/test_slicehost_credentials'
|
23
|
+
rescue Exception => e
|
24
|
+
puts e.message
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/_test_helper"
|
2
|
+
|
3
|
+
class TestSlicehost < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@sls= Rightscale::Slicehost.new(TestSlicehostCredentials.password)
|
7
|
+
end
|
8
|
+
|
9
|
+
def do_test_api_call(api_call)
|
10
|
+
# test an API call without params (should return mass of items)
|
11
|
+
items = nil
|
12
|
+
assert_nothing_raised(Rightscale::SlicehostError) do
|
13
|
+
items = @sls.__send__(api_call)
|
14
|
+
end
|
15
|
+
assert items.is_a?(Array)
|
16
|
+
# test an API call with item id (should return a single item)
|
17
|
+
if items.size > 0
|
18
|
+
item = nil
|
19
|
+
assert_nothing_raised(Rightscale::SlicehostError) do
|
20
|
+
item = @sls.__send__(api_call, items.first[:sls_id])
|
21
|
+
end
|
22
|
+
assert item.is_a?(Hash)
|
23
|
+
assert_equal items.first, item
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def do_test_caching(api_call)
|
28
|
+
# first call - nothing should be raised
|
29
|
+
assert_nothing_raised(Rightscale::SlicehostError) do
|
30
|
+
@sls.__send__(api_call)
|
31
|
+
end
|
32
|
+
# second call - must hit a cache
|
33
|
+
assert_raise(Rightscale::SlicehostNoChange) do
|
34
|
+
@sls.__send__(api_call)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_01_lists
|
39
|
+
do_test_api_call(:list_images)
|
40
|
+
do_test_api_call(:list_flavors)
|
41
|
+
do_test_api_call(:list_backups)
|
42
|
+
do_test_api_call(:list_slices)
|
43
|
+
do_test_api_call(:list_zones)
|
44
|
+
do_test_api_call(:list_records)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_02_caching
|
48
|
+
@sls.params[:cache] = true
|
49
|
+
do_test_caching(:list_images)
|
50
|
+
do_test_caching(:list_flavors)
|
51
|
+
do_test_caching(:list_backups)
|
52
|
+
do_test_caching(:list_slices)
|
53
|
+
do_test_caching(:list_zones)
|
54
|
+
do_test_caching(:list_records)
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: right_slicehost
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- RightScale, Inc.
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-02-20 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: right_http_connection
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.2.4
|
24
|
+
version:
|
25
|
+
description: "== DESCRIPTION: The RightScale Slicehost gem has been designed to provide a robust interface to Slicehost's existing API. == FEATURES/PROBLEMS: - Full programmatic access to the Slicehost API. - Complete error handling: all operations check for errors and report complete error information by raising a SlicehostError. - Persistent HTTP connections with robust network-level retry layer using Rightscale::HttpConnection. This includes socket timeouts and retries. - Robust HTTP-level retry layer. Certain (user-adjustable) HTTP errors returned by Slicehost are classified as temporary errors. These errors are automaticallly retried using exponentially increasing intervals. The number of retries is user-configurable. == INSTALL:"
|
26
|
+
email: rubygems@rightscale.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- History.txt
|
33
|
+
- Manifest.txt
|
34
|
+
- README.txt
|
35
|
+
files:
|
36
|
+
- History.txt
|
37
|
+
- Manifest.txt
|
38
|
+
- README.txt
|
39
|
+
- Rakefile
|
40
|
+
- lib/right_slicehost.rb
|
41
|
+
- lib/slicehost_base.rb
|
42
|
+
- lib/benchmark_fix.rb
|
43
|
+
- lib/support.rb
|
44
|
+
- test/test_right_slicehost.rb
|
45
|
+
- test/_test_helper.rb
|
46
|
+
- test/_test_credentials.rb
|
47
|
+
has_rdoc: true
|
48
|
+
homepage:
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options:
|
51
|
+
- --main
|
52
|
+
- README.txt
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: "0"
|
60
|
+
version:
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: "0"
|
66
|
+
version:
|
67
|
+
requirements: []
|
68
|
+
|
69
|
+
rubyforge_project: rightscale
|
70
|
+
rubygems_version: 1.3.1
|
71
|
+
signing_key:
|
72
|
+
specification_version: 2
|
73
|
+
summary: Interface classes for the Slicehost API
|
74
|
+
test_files:
|
75
|
+
- test/test_right_slicehost.rb
|