cloudservers 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -26,8 +26,11 @@ See the class definitions for documentation on specific methods and operations.
26
26
  require 'rubygems'
27
27
  require 'cloudservers'
28
28
 
29
- # Log into the Cloud Servers system
30
- cs = CloudServers::Connection.new(:username => USERNAME, :api_key => API_KEY)
29
+ # Log into the Cloud Servers
30
+ cs = CloudServers::Connection.new(:username => USERNAME, :api_key => API_KEY)
31
+
32
+ # Log into the Cloud Servers UK
33
+ cs = CloudServers::Connection.new(:username => USERNAME, :api_key => API_KEY, :auth_url => CloudServers::AUTH_UK)
31
34
 
32
35
  # Get a listing of all current servers
33
36
  >> cs.servers
@@ -80,7 +83,7 @@ See the class definitions for documentation on specific methods and operations.
80
83
 
81
84
  == Authors
82
85
 
83
- By H. Wade Minter <wade.minter@rackspace.com> and Mike Mayo <mike.mayo@rackspace.com>
86
+ By H. Wade Minter <minter@lunenburg.org>, Mike Mayo <mike.mayo@rackspace.com>, and Dan Prince <dan.prince@rackspace.com>
84
87
 
85
88
  == License
86
89
 
data/Rakefile CHANGED
@@ -10,7 +10,7 @@ begin
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
12
  gemspec.homepage = "http://github.com/rackspace/cloudservers"
13
- gemspec.authors = ["H. Wade Minter","Mike Mayo","Dan Prince"]
13
+ gemspec.authors = ["H. Wade Minter","Mike Mayo", "Dan Prince"]
14
14
  gemspec.add_dependency 'json'
15
15
  end
16
16
  rescue LoadError
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.4.0
data/cloudservers.gemspec CHANGED
@@ -1,55 +1,53 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{cloudservers}
8
- s.version = "0.3.0"
8
+ s.version = "0.4.0"
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{2010-10-21}
12
+ s.date = %q{2011-01-05}
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 = [
16
16
  "README.rdoc",
17
- "TODO"
17
+ "TODO"
18
18
  ]
19
19
  s.files = [
20
- ".gitignore",
21
- "COPYING",
22
- "README.rdoc",
23
- "Rakefile",
24
- "TODO",
25
- "VERSION",
26
- "cloudservers.gemspec",
27
- "lib/cloudservers.rb",
28
- "lib/cloudservers/authentication.rb",
29
- "lib/cloudservers/connection.rb",
30
- "lib/cloudservers/entity_manager.rb",
31
- "lib/cloudservers/exception.rb",
32
- "lib/cloudservers/flavor.rb",
33
- "lib/cloudservers/image.rb",
34
- "lib/cloudservers/server.rb",
35
- "lib/cloudservers/shared_ip_group.rb",
36
- "test/cloudservers_authentication_test.rb",
37
- "test/cloudservers_connection_test.rb",
38
- "test/cloudservers_exception_test.rb",
39
- "test/cloudservers_servers_test.rb",
40
- "test/test_helper.rb"
20
+ "COPYING",
21
+ "README.rdoc",
22
+ "Rakefile",
23
+ "TODO",
24
+ "VERSION",
25
+ "cloudservers.gemspec",
26
+ "lib/cloudservers.rb",
27
+ "lib/cloudservers/authentication.rb",
28
+ "lib/cloudservers/connection.rb",
29
+ "lib/cloudservers/entity_manager.rb",
30
+ "lib/cloudservers/exception.rb",
31
+ "lib/cloudservers/flavor.rb",
32
+ "lib/cloudservers/image.rb",
33
+ "lib/cloudservers/server.rb",
34
+ "lib/cloudservers/shared_ip_group.rb",
35
+ "test/cloudservers_authentication_test.rb",
36
+ "test/cloudservers_connection_test.rb",
37
+ "test/cloudservers_exception_test.rb",
38
+ "test/cloudservers_servers_test.rb",
39
+ "test/test_helper.rb"
41
40
  ]
42
41
  s.homepage = %q{http://github.com/rackspace/cloudservers}
43
- s.rdoc_options = ["--charset=UTF-8"]
44
42
  s.require_paths = ["lib"]
45
43
  s.rubygems_version = %q{1.3.7}
46
44
  s.summary = %q{Rackspace Cloud Servers Ruby API}
47
45
  s.test_files = [
48
46
  "test/cloudservers_authentication_test.rb",
49
- "test/cloudservers_connection_test.rb",
50
- "test/cloudservers_exception_test.rb",
51
- "test/cloudservers_servers_test.rb",
52
- "test/test_helper.rb"
47
+ "test/cloudservers_connection_test.rb",
48
+ "test/cloudservers_exception_test.rb",
49
+ "test/cloudservers_servers_test.rb",
50
+ "test/test_helper.rb"
53
51
  ]
54
52
 
55
53
  if s.respond_to? :specification_version then
@@ -1,6 +1,6 @@
1
1
  module CloudServers
2
2
  class Authentication
3
-
3
+
4
4
  # Performs an authentication to the Rackspace Cloud authorization servers. Opens a new HTTP connection to the API server,
5
5
  # sends the credentials, and looks for a successful authentication. If it succeeds, it sets the svrmgmthost,
6
6
  # svrmgtpath, svrmgmtport, svrmgmtscheme, authtoken, and authok variables on the connection. If it fails, it raises
@@ -11,9 +11,11 @@ module CloudServers
11
11
  path = '/v1.0'
12
12
  hdrhash = { "X-Auth-User" => connection.authuser, "X-Auth-Key" => connection.authkey }
13
13
  begin
14
- server = Net::HTTP::Proxy(connection.proxy_host, connection.proxy_port).new('auth.api.rackspacecloud.com',443)
15
- server.use_ssl = true
16
- server.verify_mode = OpenSSL::SSL::VERIFY_NONE
14
+ server = Net::HTTP::Proxy(connection.proxy_host, connection.proxy_port).new(connection.auth_host,connection.auth_port)
15
+ if connection.auth_scheme == "https"
16
+ server.use_ssl = true
17
+ server.verify_mode = OpenSSL::SSL::VERIFY_NONE
18
+ end
17
19
  server.start
18
20
  rescue
19
21
  raise CloudServers::Exception::Connection, "Unable to connect to #{server}"
@@ -9,6 +9,9 @@ module CloudServers
9
9
  attr_accessor :svrmgmtpath
10
10
  attr_accessor :svrmgmtport
11
11
  attr_accessor :svrmgmtscheme
12
+ attr_reader :auth_host
13
+ attr_reader :auth_port
14
+ attr_reader :auth_scheme
12
15
  attr_reader :proxy_host
13
16
  attr_reader :proxy_port
14
17
 
@@ -26,6 +29,7 @@ module CloudServers
26
29
  #
27
30
  # :username - Your Rackspace Cloud username *required*
28
31
  # :api_key - Your Rackspace Cloud API key *required*
32
+ # :auth_url - Configurable auth_url endpoint.
29
33
  # :retry_auth - Whether to retry if your auth token expires (defaults to true)
30
34
  # :proxy_host - If you need to connect through a proxy, supply the hostname here
31
35
  # :proxy_port - If you need to connect through a proxy, supply the port here
@@ -34,6 +38,19 @@ module CloudServers
34
38
  def initialize(options = {:retry_auth => true})
35
39
  @authuser = options[:username] || (raise Exception::Authentication, "Must supply a :username")
36
40
  @authkey = options[:api_key] || (raise Exception::Authentication, "Must supply an :api_key")
41
+ @auth_url = options[:auth_url] || @auth_url = CloudServers::AUTH_USA
42
+
43
+ auth_uri=nil
44
+ begin
45
+ auth_uri=URI.parse(@auth_url)
46
+ rescue Exception => e
47
+ raise Exception::InvalidArgument, "Invalid :auth_url parameter: #{e.message}"
48
+ end
49
+ raise Exception::InvalidArgument, "Invalid :auth_url parameter." if auth_uri.nil? or auth_uri.host.nil?
50
+ @auth_host = auth_uri.host
51
+ @auth_port = auth_uri.port
52
+ @auth_scheme = auth_uri.scheme
53
+
37
54
  @retry_auth = options[:retry_auth]
38
55
  @proxy_host = options[:proxy_host]
39
56
  @proxy_port = options[:proxy_port]
@@ -49,6 +49,8 @@ module CloudServers
49
49
  end
50
50
  class MissingArgument < StandardError # :nodoc:
51
51
  end
52
+ class InvalidArgument < StandardError # :nodoc:
53
+ end
52
54
  class TooManyPersonalityItems < StandardError # :nodoc:
53
55
  end
54
56
  class PersonalityFilePathTooLong < StandardError # :nodoc:
@@ -69,9 +71,9 @@ module CloudServers
69
71
  fault = nil
70
72
  info = nil
71
73
  JSON.parse(response.body).each_pair do |key, val|
72
- fault=key
73
- info=val
74
- end
74
+ fault=key
75
+ info=val
76
+ end
75
77
  exception_class = self.const_get(fault[0,1].capitalize+fault[1,fault.length])
76
78
  raise exception_class.new(info["message"], response.code, response.body)
77
79
  rescue NameError
data/lib/cloudservers.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # == Cloud Servers API
4
4
  # ==== Connects Ruby Applications to Rackspace's {Cloud Servers service}[http://www.rackspacecloud.com/cloud_hosting_products/servers]
5
- # By H. Wade Minter <minter@lunenburg.org> and Mike Mayo <mike.mayo@rackspace.com>
5
+ # By H. Wade Minter <minter@lunenburg.org>, Mike Mayo <mike.mayo@rackspace.com>, and Dan Prince <dan.prince@rackspace.com>
6
6
  #
7
7
  # See COPYING for license information.
8
8
  # Copyright (c) 2009, Rackspace US, Inc.
@@ -13,10 +13,13 @@
13
13
  # CloudServers::Connection class.
14
14
  #
15
15
  # The CloudServers class is the base class. Not much of note aside from housekeeping happens here.
16
- # To create a new CloudServers connection, use the CloudServers::Connection.new('user_name', 'api_key') method.
16
+ # To create a new CloudServers connection, use the CloudServers::Connection.new(:username => USERNAME, :api_key => API_KEY)
17
17
 
18
18
  module CloudServers
19
19
 
20
+ AUTH_USA = "https://auth.api.rackspacecloud.com"
21
+ AUTH_UK = "https://lon.auth.api.rackspacecloud.com"
22
+
20
23
  VERSION = IO.read(File.dirname(__FILE__) + '/../VERSION')
21
24
  require 'net/http'
22
25
  require 'net/https'
@@ -1,4 +1,5 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ $:.unshift File.dirname(__FILE__)
2
+ require 'test_helper'
2
3
 
3
4
  class CloudserversAuthenticationTest < Test::Unit::TestCase
4
5
 
@@ -8,7 +9,7 @@ class CloudserversAuthenticationTest < Test::Unit::TestCase
8
9
  server = mock(:use_ssl= => true, :verify_mode= => true, :start => true, :finish => true)
9
10
  server.stubs(:get).returns(response)
10
11
  Net::HTTP.stubs(:new).returns(server)
11
- connection = stub(:authuser => 'bad_user', :authkey => 'bad_key', :authok= => true, :authtoken= => true, :svrmgmthost= => "", :svrmgmtpath= => "", :svrmgmtpath => "", :svrmgmtport= => "", :svrmgmtscheme= => "", :proxy_host => nil, :proxy_port => nil)
12
+ connection = stub(:authuser => 'myuser', :authkey => 'bad_key', :auth_host => "a.b.c", :auth_port => "443", :auth_scheme => "https", :authok= => true, :authtoken= => true, :svrmgmthost= => "", :svrmgmtpath= => "", :svrmgmtpath => "", :svrmgmtport= => "", :svrmgmtscheme= => "", :proxy_host => nil, :proxy_port => nil)
12
13
  result = CloudServers::Authentication.new(connection)
13
14
  assert_equal result.class, CloudServers::Authentication
14
15
  end
@@ -19,7 +20,7 @@ class CloudserversAuthenticationTest < Test::Unit::TestCase
19
20
  server = mock(:use_ssl= => true, :verify_mode= => true, :start => true)
20
21
  server.stubs(:get).returns(response)
21
22
  Net::HTTP.stubs(:new).returns(server)
22
- connection = stub(:authuser => 'bad_user', :authkey => 'bad_key', :authok= => true, :authtoken= => true, :proxy_host => nil, :proxy_port => nil)
23
+ connection = stub(:authuser => 'bad_user', :authkey => 'bad_key', :auth_host => "a.b.c", :auth_port => "443", :auth_scheme => "https", :authok= => true, :authtoken= => true, :proxy_host => nil, :proxy_port => nil)
23
24
  assert_raises(CloudServers::Exception::Authentication) do
24
25
  result = CloudServers::Authentication.new(connection)
25
26
  end
@@ -27,7 +28,7 @@ class CloudserversAuthenticationTest < Test::Unit::TestCase
27
28
 
28
29
  def test_bad_hostname
29
30
  Net::HTTP.stubs(:new).raises(CloudServers::Exception::Connection)
30
- connection = stub(:authuser => 'bad_user', :authkey => 'bad_key', :authok= => true, :authtoken= => true, :proxy_host => nil, :proxy_port => nil)
31
+ connection = stub(:authuser => 'bad_user', :authkey => 'bad_key', :auth_host => "a.b.c", :auth_port => "443", :auth_scheme => "https", :authok= => true, :authtoken= => true, :proxy_host => nil, :proxy_port => nil)
31
32
  assert_raises(CloudServers::Exception::Connection) do
32
33
  result = CloudServers::Authentication.new(connection)
33
34
  end
@@ -1,6 +1,12 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ $:.unshift File.dirname(__FILE__)
2
+ require 'test_helper'
2
3
 
3
4
  class CloudServersConnectionTest < Test::Unit::TestCase
5
+
6
+ def setup
7
+ connection = stub()
8
+ CloudServers::Authentication.stubs(:new).returns(connection)
9
+ end
4
10
 
5
11
  def test_init_connection_no_credentials
6
12
  assert_raises(CloudServers::Exception::Authentication) do
@@ -13,5 +19,21 @@ class CloudServersConnectionTest < Test::Unit::TestCase
13
19
  conn = CloudServers::Connection.new(:username => "test_account")
14
20
  end
15
21
  end
22
+
23
+ def test_init_connection_bad_auth_url
24
+ assert_raises(CloudServers::Exception::InvalidArgument) do
25
+ conn = CloudServers::Connection.new(:username => "test_account", :api_key => "AABBCCDD11", :auth_url => "***")
26
+ end
27
+ end
28
+
29
+ def test_init_connection
30
+ conn = CloudServers::Connection.new(:username => "test_account", :api_key => "AABBCCDD11", :auth_url => "https://a.b.c")
31
+ assert_not_nil conn, "Connection.new returned nil."
32
+ end
33
+
34
+ def test_init_connection_with_custom_auth_url
35
+ conn = CloudServers::Connection.new(:username => "test_account", :api_key => "AABBCCDD11", :auth_url => CloudServers::AUTH_UK)
36
+ assert_not_nil conn, "Connection.new returned nil."
37
+ end
16
38
 
17
39
  end
@@ -1,4 +1,5 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ $:.unshift File.dirname(__FILE__)
2
+ require 'test_helper'
2
3
 
3
4
  class CloudServersExceptionTest < Test::Unit::TestCase
4
5
 
@@ -1,4 +1,5 @@
1
- require File.dirname(__FILE__) + '/test_helper'
1
+ $:.unshift File.dirname(__FILE__)
2
+ require 'test_helper'
2
3
 
3
4
  class CloudServersServersTest < Test::Unit::TestCase
4
5
 
@@ -70,15 +71,15 @@ json_response = %{{
70
71
  def test_get_server
71
72
 
72
73
  server=get_test_server
73
- assert "sample-server", server.name
74
- assert "2", server.imageId
75
- assert "1", server.flavorId
76
- assert "e4d909c290d0fb1ca068ffaddf22cbd0", server.hostId
77
- assert "BUILD", server.status
78
- assert "60", server.progress
79
- assert "67.23.10.132", server.addresses[:public][0]
80
- assert "67.23.10.131", server.addresses[:public][1]
81
- assert "10.176.42.16", server.addresses[:private][1]
74
+ assert_equal "sample-server", server.name
75
+ assert_equal 2, server.imageId
76
+ assert_equal 1, server.flavorId
77
+ assert_equal "e4d909c290d0fb1ca068ffaddf22cbd0", server.hostId
78
+ assert_equal "BUILD", server.status
79
+ assert_equal 60, server.progress
80
+ assert_equal "67.23.10.132", server.addresses[:public][0]
81
+ assert_equal "67.23.10.131", server.addresses[:public][1]
82
+ assert_equal "10.176.42.16", server.addresses[:private][0]
82
83
 
83
84
  end
84
85
 
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: 19
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 3
8
+ - 4
9
9
  - 0
10
- version: 0.3.0
10
+ version: 0.4.0
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: 2010-10-21 00:00:00 -04:00
20
+ date: 2011-01-05 00:00:00 -05:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
@@ -44,7 +44,6 @@ extra_rdoc_files:
44
44
  - README.rdoc
45
45
  - TODO
46
46
  files:
47
- - .gitignore
48
47
  - COPYING
49
48
  - README.rdoc
50
49
  - Rakefile
@@ -70,8 +69,8 @@ homepage: http://github.com/rackspace/cloudservers
70
69
  licenses: []
71
70
 
72
71
  post_install_message:
73
- rdoc_options:
74
- - --charset=UTF-8
72
+ rdoc_options: []
73
+
75
74
  require_paths:
76
75
  - lib
77
76
  required_ruby_version: !ruby/object:Gem::Requirement
data/.gitignore DELETED
@@ -1,2 +0,0 @@
1
- pkg/
2
- doc/