right_gogrid 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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,41 @@
1
+ class TestCredentials
2
+
3
+ @@key = nil
4
+ @@secret = nil
5
+
6
+ def self.key
7
+ @@key
8
+ end
9
+ def self.key=(newval)
10
+ @@key = newval
11
+ end
12
+ def self.secret
13
+ @@secret
14
+ end
15
+ def self.secret=(newval)
16
+ @@secret = newval
17
+ end
18
+
19
+ # Make sure you have environment vars set:
20
+ #
21
+ # export GOGRID_KEY ='your_gogrid_key'
22
+ # export GOGRID_SECRET ='your_gogrid_secret'
23
+ #
24
+ # or you have a file: ~/.rightscale/test_gogrid_credentials.rb with text:
25
+ #
26
+ # TestCredentials.key = 'your_gogrid_key'
27
+ # TestCredentials.secret = 'your_gogrid_secret'
28
+ #
29
+ def self.get_credentials
30
+ Dir.chdir do
31
+ begin
32
+ Dir.chdir('./.rightscale') do
33
+ require 'test_gogrid_credentials'
34
+ end
35
+ rescue Exception => e
36
+ puts "Couldn't chdir to ~/.rightscale: #{e.message}"
37
+ end
38
+ end
39
+ end
40
+
41
+ end
@@ -0,0 +1,103 @@
1
+ # Unit test for Gogrid gem
2
+ # Specify your gogrid account credentials as described in test_credentials.rb
3
+ # Will use the last ip returned by 'list_ips' to create test servers
4
+ require File.dirname(__FILE__) + '/../lib/right_gogrid'
5
+
6
+ class TestRightGogrid < Test::Unit::TestCase
7
+
8
+ TEST_SERVER_NAME = "right_gogrid_awesome_test_server_1234567890"
9
+ TEST_SERVER_IMAGE = "rhel51_64_php"
10
+ TEST_SERVER_RAM = "512MB"
11
+ TEST_SERVER_DESCRIPTION = "Test server"
12
+ ADDED_TEST_SERVER_NAME = "right_gogrid_awesome_added_test_server"
13
+
14
+ def setup
15
+ TestCredentials.get_credentials
16
+ @gogrid = Rightscale::Gogrid.new(TestCredentials.key, TestCredentials.secret)
17
+ end
18
+
19
+ # return a test IP from the list of IPs in the account
20
+ # set default argument to free IP index
21
+ def test_ip(index=258)
22
+ ips = @gogrid.list_ips
23
+ ips[index]["ip"]
24
+ #puts ips.collect {|ip| ip["ip"] + ", " }
25
+ end
26
+
27
+ def add_test_server
28
+ @gogrid.add_server(TEST_SERVER_NAME, TEST_SERVER_IMAGE, TEST_SERVER_RAM, test_ip, TEST_SERVER_DESCRIPTION)
29
+ end
30
+
31
+ def test_01_list_images
32
+ result = @gogrid.list_images
33
+ assert result.is_a?(Array)
34
+ end
35
+
36
+ def test_02_list_servers
37
+ result = @gogrid.list_servers
38
+ assert result.is_a?(Array)
39
+ end
40
+
41
+ def test_03_add_and_delete_server
42
+ result = add_test_server
43
+ assert result.is_a?(Array)
44
+ result = @gogrid.gogrid_get_servers({:names=>[TEST_SERVER_NAME]})
45
+ assert result.is_a?(Array)
46
+ @gogrid.delete_server_by_name(TEST_SERVER_NAME)
47
+ assert result.is_a?(Array)
48
+ end
49
+
50
+ def test_04_power_server
51
+ add_test_server
52
+ result = @gogrid.gogrid_power_server(:name=>TEST_SERVER_NAME,:power=>cycle)
53
+ assert result.is_a?(Array)
54
+ @gogrid.delete_server_by_name(TEST_SERVER_NAME)
55
+ end
56
+
57
+ def test_05_list_support_passwords
58
+ result = @gogrid.list_support_passwords
59
+ assert result.is_a?(Array)
60
+ end
61
+
62
+ def test_06_get_support_password
63
+ passwords = @gogrid.list_support_passwords
64
+ assert !passwords.empty?
65
+ result = @gogrid.get_support_password(passwords[0]=>"id")
66
+ assert result.is_a?(Array)
67
+ end
68
+
69
+ def test_07_list_common_lookup
70
+ result = @gogrid.list_common_lookup
71
+ assert result.is_a?(Array)
72
+ end
73
+
74
+ def test_08_list_loadbalancers
75
+ result = @gogrid.list_loadbalancers
76
+ assert result.is_a?(Array)
77
+ end
78
+
79
+ def test_09_add_and_delete_loadbalancer
80
+ result = @gogrid.add_loadbalancer(
81
+ "Test loadbalancer - delete",
82
+ test_ip(259),
83
+ "80",
84
+ [{:ip => test_ip, :port => "8080"}, {:ip => test_ip, :port => "443"}],
85
+ "Test loadbalancer - delete",
86
+ nil,
87
+ "None")
88
+ assert result.is_a?(Array)
89
+ assert !result.empty?
90
+ balancers = @gogrid.list_loadbalancers
91
+ assert !balancers.empty?
92
+ @gogrid.get_loadbalancer_by_id(balancers.first)
93
+ assert result.is_a?(Array)
94
+ result = @gogrid.delete_loadbalancer(result.first=>"id")
95
+ assert result.is_a?(Array)
96
+ end
97
+
98
+ def test_10_get_myaccount_billing
99
+ result = @gogrid.get_myaccount_billing
100
+ assert result.is_a?(Array)
101
+ end
102
+ end
103
+
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: right_gogrid
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-19 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 GoGrid gem has been designed to provide a robust interface to GoGrid's existing API. == FEATURES/PROBLEMS: - Full programmatic access to the GoGrid API. - Complete error handling: all operations check for errors and report complete error information by raising a GoGridError. - Persistent HTTP connections with robust network-level retry layer using RightHttpConnection). This includes socket timeouts and retries. - Robust HTTP-level retry layer. Certain (user-adjustable) HTTP errors returned by GoGrid are classified as temporary errors. These errors are automaticallly retried using exponentially increasing intervals. The number of retries is user-configurable."
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_gogrid.rb
41
+ - lib/gogrid_base.rb
42
+ - lib/benchmark_fix.rb
43
+ - lib/support.rb
44
+ - test/test_right_gogrid.rb
45
+ has_rdoc: true
46
+ homepage:
47
+ post_install_message:
48
+ rdoc_options:
49
+ - --main
50
+ - README.txt
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ version:
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
65
+ requirements: []
66
+
67
+ rubyforge_project: rightscale
68
+ rubygems_version: 1.3.1
69
+ signing_key:
70
+ specification_version: 2
71
+ summary: Interface classes for the GoGrid API
72
+ test_files:
73
+ - test/test_credentials.rb
74
+ - test/test_right_gogrid.rb