right-scale-api 0.0.3 → 0.0.4
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/README.md +19 -2
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/right-scale-api.rb +5 -0
- data/lib/right-scale-api/account.rb +31 -1
- data/lib/right-scale-api/base.rb +14 -3
- data/lib/right-scale-api/ec2_ebs_volume.rb +23 -17
- data/lib/right-scale-api/ec2_ssh_key.rb +2 -0
- data/lib/right-scale-api/s3_bucket.rb +5 -0
- data/lib/right-scale-api/server.rb +17 -4
- data/right-scale-api.gemspec +8 -7
- data/spec/right-scale-api_spec.rb +27 -3
- data/spec/spec_helper.rb +5 -3
- metadata +20 -6
data/README.md
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
RightScale API Gem
|
2
2
|
=======================
|
3
3
|
|
4
|
-
A client library for the RightScale API.
|
4
|
+
A client library for the RightScale API. Still under development, but it has enough written to be useful.
|
5
|
+
|
6
|
+
There aren't any tests yet and it doesn't fully cover all the object types RightScale's API supports.
|
5
7
|
|
6
8
|
RightScale's [API Docs]("http://support.rightscale.com/15-References/RightScale_API_Reference_Guide")
|
7
9
|
|
@@ -36,4 +38,19 @@ Usage Examples
|
|
36
38
|
#we do this as an update, because rightscale's api doesn't let you set this on create (as of May 2010)
|
37
39
|
server.update :associate_eip_at_launch => true,
|
38
40
|
:ec2_elastic_ip => ip
|
39
|
-
server.start
|
41
|
+
server.start
|
42
|
+
|
43
|
+
#### Create a Deployment
|
44
|
+
|
45
|
+
account.create_deployment :nickname => 'foo',
|
46
|
+
:description => 'foo bar baz'
|
47
|
+
#### Show all Servers
|
48
|
+
account.servers
|
49
|
+
#### Show an individual server
|
50
|
+
account.servers.find {|server| server.id ==}
|
51
|
+
|
52
|
+
## Contributions Welcome
|
53
|
+
|
54
|
+
Fork away.
|
55
|
+
|
56
|
+
Needs tests, filling out the object types, etc.
|
data/Rakefile
CHANGED
@@ -12,7 +12,7 @@ begin
|
|
12
12
|
gem.email = "ndh@baroquebobcat.com"
|
13
13
|
gem.homepage = "http://github.com/baroquebobcat/right-scale-api"
|
14
14
|
gem.authors = ["Nick Howard"]
|
15
|
-
gem.add_dependency "httparty"
|
15
|
+
gem.add_dependency "httparty", "~> 0.6.0"
|
16
16
|
gem.add_dependency "activesupport"
|
17
17
|
gem.add_development_dependency "rspec", ">= 1.2.9"
|
18
18
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
data/lib/right-scale-api.rb
CHANGED
@@ -1,10 +1,15 @@
|
|
1
1
|
require 'yaml'
|
2
2
|
require 'httparty'
|
3
3
|
require 'active_support/core_ext'
|
4
|
+
require 'active_support/multibyte'
|
4
5
|
|
5
6
|
module RightScaleAPI
|
6
7
|
API_VERSION = '1.0'
|
7
8
|
BASE_URI = "https://my.rightscale.com/"
|
9
|
+
|
10
|
+
def self.login *args
|
11
|
+
Client.login *args
|
12
|
+
end
|
8
13
|
end
|
9
14
|
|
10
15
|
require File.dirname(__FILE__) + '/right-scale-api/client'
|
@@ -22,19 +22,49 @@ module RightScaleAPI
|
|
22
22
|
:ec2_elastic_ips,
|
23
23
|
:ec2_security_groups,
|
24
24
|
:server_templates,
|
25
|
-
:servers
|
25
|
+
:servers,
|
26
|
+
:s3_buckets
|
26
27
|
|
28
|
+
# Creates a Deployment
|
29
|
+
# @param [Hash] opts deployment attributes
|
30
|
+
# @option opts [String] :nickname The nickname of the deployment
|
31
|
+
# @option opts [String] :description The description of the deployment
|
32
|
+
# @option opts [String :default_ec2_availability_zone the default availability zone for the deployment e.g. us-east-1a
|
33
|
+
# @option opts [String] :default_vpc_subnet_href
|
34
|
+
def create_deployment opts
|
35
|
+
Deployment.create opts.merge :account => self
|
36
|
+
end
|
37
|
+
|
38
|
+
# Creates an EC2 EBS Elastic IP
|
39
|
+
# @param [Hash] opts ip attributes
|
40
|
+
# @option opts [String] :nickname The nickname of the ip
|
41
|
+
# @option opts [Fixnum] :cloud_id the cloud identifier default 1 (1 = us-east; 2 = eu; 3 = us-west, 4 = ap)
|
27
42
|
def create_ec2_elastic_ip opts
|
28
43
|
Ec2ElasticIp.create opts.merge :account => self
|
29
44
|
end
|
30
45
|
|
46
|
+
# Creates an EC2 EBS Volume
|
47
|
+
# @param [Hash] opts volume attributes
|
48
|
+
# @option opts [String] :nickname The nickname of the volume
|
49
|
+
# @option opts [String] :description
|
50
|
+
# @option opts [Fixnum] :aws_size The size of the volume in gigabytes*
|
51
|
+
# @option opts [String] :ec2_availability_zone name of the availability zone e.g. us-east-1a*
|
31
52
|
def create_ec2_ebs_volume opts
|
32
53
|
Ec2EbsVolume.create opts.merge :account => self
|
33
54
|
end
|
34
55
|
|
56
|
+
# Creates an EC2 Instance
|
57
|
+
# @param [Hash] opts server attributes
|
58
|
+
# @option [RightScaleAPI::ServerTemplate] opts :server_template the server template to use*
|
59
|
+
# @option [[RightScaleAPI::Deployment] opts :deployment
|
35
60
|
def create_server opts
|
36
61
|
Server.create opts.merge :account => self
|
37
62
|
end
|
63
|
+
|
64
|
+
# Gets an EC2 ssh key.
|
65
|
+
# Currently you can't get a list of ssh keys through the API, so you need to get the id through the web interface.
|
66
|
+
# https://my.rightscale.com/clouds/1/ec2_ssh_keys
|
67
|
+
# @param id the id of the ssh key to get
|
38
68
|
def get_ec2_ssh_key id
|
39
69
|
Ec2SshKey.new get("/ec2_ssh_keys/#{id}").merge :id => id, :account => self
|
40
70
|
end
|
data/lib/right-scale-api/base.rb
CHANGED
@@ -3,7 +3,8 @@ module RightScaleAPI
|
|
3
3
|
|
4
4
|
attr_accessor :id, :href
|
5
5
|
|
6
|
-
#attributes that directly correspond to the api's
|
6
|
+
# attributes that directly correspond to the api's
|
7
|
+
# @param [Array<Symbol>] attrs a list of attributes an object type has
|
7
8
|
def self.attributes attrs=nil
|
8
9
|
if attrs
|
9
10
|
@attributes ||= Base.attributes
|
@@ -24,10 +25,14 @@ module RightScaleAPI
|
|
24
25
|
|
25
26
|
attributes [:tags, :created_at, :updated_at,:errors, :nickname]
|
26
27
|
|
28
|
+
# gets an object by id
|
29
|
+
# @param id [Fixnum]
|
27
30
|
def self.get id
|
28
31
|
new :id => id
|
29
32
|
end
|
30
33
|
|
34
|
+
# creates a new object on RightScale
|
35
|
+
# @param opts [Hash] attributes of the created object
|
31
36
|
def self.create opts
|
32
37
|
object = new opts
|
33
38
|
|
@@ -43,10 +48,11 @@ module RightScaleAPI
|
|
43
48
|
puts result.inspect
|
44
49
|
raise "create failed"
|
45
50
|
end
|
46
|
-
|
47
|
-
new opts.merge(result.merge(:href =>
|
51
|
+
|
52
|
+
new opts.merge(result.merge(:href => result.headers['location']))
|
48
53
|
end
|
49
54
|
|
55
|
+
# The RightScale API name for the class
|
50
56
|
def self.api_name
|
51
57
|
name.demodulize.underscore
|
52
58
|
end
|
@@ -61,10 +67,13 @@ module RightScaleAPI
|
|
61
67
|
end
|
62
68
|
end
|
63
69
|
|
70
|
+
# Updates the object with the passed attributes
|
71
|
+
# @param [Hash] attrs the updated attributes
|
64
72
|
def update attrs
|
65
73
|
put '', :body => {self.class.api_name => self.class.opts_to_query_opts(attrs)}
|
66
74
|
end
|
67
75
|
|
76
|
+
# tells the API to delete the object
|
68
77
|
def destroy
|
69
78
|
delete ''
|
70
79
|
end
|
@@ -94,10 +103,12 @@ module RightScaleAPI
|
|
94
103
|
send_request :delete, *args
|
95
104
|
end
|
96
105
|
|
106
|
+
# the objects uri on rightscale
|
97
107
|
def uri
|
98
108
|
RightScaleAPI::Client.base_uri + path
|
99
109
|
end
|
100
110
|
|
111
|
+
# Reload the attributes of the object
|
101
112
|
def reload!
|
102
113
|
get('')[self.class.api_name].each do |attr, value|
|
103
114
|
self.send :"#{attr}=",value
|
@@ -1,7 +1,9 @@
|
|
1
1
|
module RightScaleAPI
|
2
|
-
|
2
|
+
# EC2 EBS Volume
|
3
|
+
# See http://support.rightscale.com/15-References/RightScale_API_Reference_Guide/02-Management/05-EC2_EBS_Volumes
|
4
|
+
class Ec2EbsVolume < Account::SubResource
|
3
5
|
|
4
|
-
|
6
|
+
attributes %w(
|
5
7
|
description
|
6
8
|
ec2_availability_zone
|
7
9
|
aws_attached_at
|
@@ -11,21 +13,25 @@ class Ec2EbsVolume < Account::SubResource
|
|
11
13
|
aws_size
|
12
14
|
aws_status
|
13
15
|
created_at
|
14
|
-
|
16
|
+
)
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
18
|
+
# Attaches the volume to a server
|
19
|
+
# @param [RightScaleAPI::Server] server the server to attach the volume to
|
20
|
+
# @param [String] device the device to mount the volume as e.g. /dev/sdk
|
21
|
+
# @param [String] mount when to mount the device. Usually 'boot'
|
22
|
+
def attach_to_server server, device, mount
|
23
|
+
account.post '/component_ec2_ebs_volumes', :body => {
|
24
|
+
:component_ec2_ebs_volume => {
|
25
|
+
:ec2_ebs_volume_href => uri,
|
26
|
+
:component_href => server.href,
|
27
|
+
:device => device,
|
28
|
+
:mount => mount
|
29
|
+
}
|
30
|
+
}
|
31
|
+
end
|
26
32
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
33
|
+
def collection_uri
|
34
|
+
account.path + "/ec2_ebs_volumes"
|
35
|
+
end
|
36
|
+
end
|
31
37
|
end
|
@@ -22,27 +22,39 @@ module RightScaleAPI
|
|
22
22
|
type
|
23
23
|
vpc_subnet_href
|
24
24
|
)
|
25
|
-
|
25
|
+
|
26
|
+
# Starts the server
|
26
27
|
def start
|
27
28
|
post '/start'
|
28
29
|
end
|
29
30
|
|
31
|
+
# Stops the server
|
30
32
|
def stop
|
31
33
|
post '/stop'
|
32
34
|
end
|
33
35
|
|
36
|
+
# Reboots the server
|
34
37
|
def reboot
|
35
38
|
post '/reboot'
|
36
39
|
end
|
37
40
|
|
41
|
+
# Server Settings
|
42
|
+
# for info: under Sub-resources on
|
43
|
+
# http://support.rightscale.com/15-References/RightScale_API_Reference_Guide/02-Management/02-Servers
|
38
44
|
def settings
|
39
45
|
get('/settings')['settings']
|
40
46
|
end
|
41
47
|
|
42
|
-
|
48
|
+
# Is the server operational
|
49
|
+
def operational?
|
43
50
|
state == 'operational'
|
44
51
|
end
|
52
|
+
|
53
|
+
alias :running? :operational?
|
45
54
|
|
55
|
+
# Attach a volume to the server
|
56
|
+
# @param [RightScaleAPI::Ec2EbsVolume] volume the volume to attach
|
57
|
+
# @param [String] device the device to attach it as e.g. /dev/sdk
|
46
58
|
def attach_volume volume, device
|
47
59
|
if running?
|
48
60
|
post '/attach_volume', :query => {
|
@@ -56,8 +68,9 @@ module RightScaleAPI
|
|
56
68
|
end
|
57
69
|
end
|
58
70
|
|
59
|
-
#
|
60
|
-
#
|
71
|
+
# creates a blank volume and attaches it to the server
|
72
|
+
# @param [Hash] opts Account#create_ec2_ebs_volume's opts +
|
73
|
+
# @option [String] :device device mount point, e.g. /dev/sdk
|
61
74
|
def attach_blank_volume opts
|
62
75
|
device = opts.delete :device
|
63
76
|
opts = {:ec2_availability_zone => 'us-east-1a'}.merge opts #default to the server's avail zone
|
data/right-scale-api.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{right-scale-api}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Nick Howard"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-09-14}
|
13
13
|
s.description = %q{A client for the RightScale API that hides some of the complexity of the API
|
14
14
|
(It doesn't require passing around hrefs as much). Based on HTTParty
|
15
15
|
}
|
@@ -35,6 +35,7 @@ Gem::Specification.new do |s|
|
|
35
35
|
"lib/right-scale-api/ec2_elastic_ip.rb",
|
36
36
|
"lib/right-scale-api/ec2_security_group.rb",
|
37
37
|
"lib/right-scale-api/ec2_ssh_key.rb",
|
38
|
+
"lib/right-scale-api/s3_bucket.rb",
|
38
39
|
"lib/right-scale-api/server.rb",
|
39
40
|
"lib/right-scale-api/server_template.rb",
|
40
41
|
"lib/right-scale-api/status.rb",
|
@@ -46,7 +47,7 @@ Gem::Specification.new do |s|
|
|
46
47
|
s.homepage = %q{http://github.com/baroquebobcat/right-scale-api}
|
47
48
|
s.rdoc_options = ["--charset=UTF-8"]
|
48
49
|
s.require_paths = ["lib"]
|
49
|
-
s.rubygems_version = %q{1.3.
|
50
|
+
s.rubygems_version = %q{1.3.7}
|
50
51
|
s.summary = %q{A RightScale API gem that doesn't suck.(mostly)}
|
51
52
|
s.test_files = [
|
52
53
|
"spec/right-scale-api_spec.rb",
|
@@ -57,17 +58,17 @@ Gem::Specification.new do |s|
|
|
57
58
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
58
59
|
s.specification_version = 3
|
59
60
|
|
60
|
-
if Gem::Version.new(Gem::
|
61
|
-
s.add_runtime_dependency(%q<httparty>, ["
|
61
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
62
|
+
s.add_runtime_dependency(%q<httparty>, ["~> 0.6.0"])
|
62
63
|
s.add_runtime_dependency(%q<activesupport>, [">= 0"])
|
63
64
|
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
64
65
|
else
|
65
|
-
s.add_dependency(%q<httparty>, ["
|
66
|
+
s.add_dependency(%q<httparty>, ["~> 0.6.0"])
|
66
67
|
s.add_dependency(%q<activesupport>, [">= 0"])
|
67
68
|
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
68
69
|
end
|
69
70
|
else
|
70
|
-
s.add_dependency(%q<httparty>, ["
|
71
|
+
s.add_dependency(%q<httparty>, ["~> 0.6.0"])
|
71
72
|
s.add_dependency(%q<activesupport>, [">= 0"])
|
72
73
|
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
73
74
|
end
|
@@ -1,7 +1,31 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
|
-
describe
|
4
|
-
it
|
5
|
-
|
3
|
+
describe RightScaleAPI do
|
4
|
+
it { should respond_to(:login) }
|
5
|
+
|
6
|
+
describe RightScaleAPI::Base do
|
7
|
+
subject { Class.new RightScaleAPI::Base }
|
8
|
+
|
9
|
+
it { should respond_to(:collection_uri) }
|
10
|
+
|
11
|
+
describe 'instance' do
|
12
|
+
subject { Class.new(RightScaleAPI::Base).new({}) }
|
13
|
+
it { subject.should respond_to(:href) }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe RightScaleAPI::Account do
|
18
|
+
#
|
19
|
+
describe "#create_ec2_ebs_volume" do
|
20
|
+
#when receive a 422
|
21
|
+
#do stuff with error
|
22
|
+
#missing ec2_avaliability_zone
|
23
|
+
# Error:Unknown availability zone '' for the cloud AWS US-East
|
24
|
+
#missing aws_size
|
25
|
+
# Error:MissingParameter: The request must contain the parameter size/snapshot
|
26
|
+
end
|
27
|
+
describe "#create_server" do
|
28
|
+
#@parsed_response={"errors"=>{"error"=>["Server template can't be blank", "Deployment can't be blank"]}}
|
29
|
+
end
|
6
30
|
end
|
7
31
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
#$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
#$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
require 'rubygems'
|
3
4
|
require 'right-scale-api'
|
5
|
+
require 'fakeweb'
|
4
6
|
require 'spec'
|
5
7
|
require 'spec/autorun'
|
6
8
|
|
7
9
|
Spec::Runner.configure do |config|
|
8
|
-
|
10
|
+
FakeWeb.allow_net_connect = false
|
9
11
|
end
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: right-scale-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Nick Howard
|
@@ -14,28 +15,34 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-
|
18
|
+
date: 2010-09-14 00:00:00 -06:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
22
|
name: httparty
|
22
23
|
prerelease: false
|
23
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
24
26
|
requirements:
|
25
|
-
- -
|
27
|
+
- - ~>
|
26
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 7
|
27
30
|
segments:
|
28
31
|
- 0
|
29
|
-
|
32
|
+
- 6
|
33
|
+
- 0
|
34
|
+
version: 0.6.0
|
30
35
|
type: :runtime
|
31
36
|
version_requirements: *id001
|
32
37
|
- !ruby/object:Gem::Dependency
|
33
38
|
name: activesupport
|
34
39
|
prerelease: false
|
35
40
|
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
36
42
|
requirements:
|
37
43
|
- - ">="
|
38
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 3
|
39
46
|
segments:
|
40
47
|
- 0
|
41
48
|
version: "0"
|
@@ -45,9 +52,11 @@ dependencies:
|
|
45
52
|
name: rspec
|
46
53
|
prerelease: false
|
47
54
|
requirement: &id003 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
48
56
|
requirements:
|
49
57
|
- - ">="
|
50
58
|
- !ruby/object:Gem::Version
|
59
|
+
hash: 13
|
51
60
|
segments:
|
52
61
|
- 1
|
53
62
|
- 2
|
@@ -84,6 +93,7 @@ files:
|
|
84
93
|
- lib/right-scale-api/ec2_elastic_ip.rb
|
85
94
|
- lib/right-scale-api/ec2_security_group.rb
|
86
95
|
- lib/right-scale-api/ec2_ssh_key.rb
|
96
|
+
- lib/right-scale-api/s3_bucket.rb
|
87
97
|
- lib/right-scale-api/server.rb
|
88
98
|
- lib/right-scale-api/server_template.rb
|
89
99
|
- lib/right-scale-api/status.rb
|
@@ -101,23 +111,27 @@ rdoc_options:
|
|
101
111
|
require_paths:
|
102
112
|
- lib
|
103
113
|
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
104
115
|
requirements:
|
105
116
|
- - ">="
|
106
117
|
- !ruby/object:Gem::Version
|
118
|
+
hash: 3
|
107
119
|
segments:
|
108
120
|
- 0
|
109
121
|
version: "0"
|
110
122
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
+
none: false
|
111
124
|
requirements:
|
112
125
|
- - ">="
|
113
126
|
- !ruby/object:Gem::Version
|
127
|
+
hash: 3
|
114
128
|
segments:
|
115
129
|
- 0
|
116
130
|
version: "0"
|
117
131
|
requirements: []
|
118
132
|
|
119
133
|
rubyforge_project:
|
120
|
-
rubygems_version: 1.3.
|
134
|
+
rubygems_version: 1.3.7
|
121
135
|
signing_key:
|
122
136
|
specification_version: 3
|
123
137
|
summary: A RightScale API gem that doesn't suck.(mostly)
|