right-scale-api 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/right-scale-api/base.rb +12 -11
- data/lib/right-scale-api/server.rb +54 -3
- data/right-scale-api.gemspec +3 -24
- data/spec/right-scale-api_spec.rb +14 -1
- data/spec/spec_helper.rb +3 -5
- metadata +6 -8
- data/VERSION +0 -1
- data/spec/spec.opts +0 -1
data/lib/right-scale-api/base.rb
CHANGED
@@ -32,10 +32,10 @@ module RightScaleAPI
|
|
32
32
|
# creates a new object on RightScale
|
33
33
|
# @param opts [Hash] attributes of the created object
|
34
34
|
def self.create opts
|
35
|
-
|
36
|
-
|
35
|
+
object_opts = opts.reject{|k,v| ! instance_methods.include? "#{k}="}
|
36
|
+
object = new object_opts
|
37
37
|
query_opts = opts_to_query_opts opts
|
38
|
-
|
38
|
+
|
39
39
|
result = RightScaleAPI::Client.post(object.collection_uri, :body => query_opts)
|
40
40
|
|
41
41
|
if result.code.to_i != 201
|
@@ -47,7 +47,7 @@ module RightScaleAPI
|
|
47
47
|
raise "create failed"
|
48
48
|
end
|
49
49
|
|
50
|
-
new
|
50
|
+
new object_opts.merge(result.merge(:href => result.headers['location']))
|
51
51
|
end
|
52
52
|
|
53
53
|
# The RightScale API name for the class
|
@@ -113,6 +113,14 @@ module RightScaleAPI
|
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
116
|
+
def collection_uri
|
117
|
+
self.class.collection_uri
|
118
|
+
end
|
119
|
+
|
120
|
+
def path
|
121
|
+
"#{collection_uri}/#{id}"
|
122
|
+
end
|
123
|
+
|
116
124
|
protected
|
117
125
|
|
118
126
|
def self.collection_uri uri=nil
|
@@ -122,13 +130,6 @@ module RightScaleAPI
|
|
122
130
|
@collection_uri
|
123
131
|
end
|
124
132
|
|
125
|
-
def collection_uri
|
126
|
-
self.class.collection_uri
|
127
|
-
end
|
128
|
-
|
129
|
-
def path
|
130
|
-
"#{collection_uri}/#{id}"
|
131
|
-
end
|
132
133
|
|
133
134
|
def id_from_href href
|
134
135
|
href.split('/').last
|
@@ -21,7 +21,42 @@ module RightScaleAPI
|
|
21
21
|
type
|
22
22
|
vpc_subnet_href
|
23
23
|
)
|
24
|
+
|
25
|
+
SETTINGS = %w(
|
26
|
+
ec2_ssh_key_href
|
27
|
+
ec2_security_groups_href
|
28
|
+
ec2_instance_type
|
29
|
+
aki_image_href
|
30
|
+
ari_image_href
|
31
|
+
ec2_image_href
|
32
|
+
vpc_subnet_href
|
33
|
+
pricing
|
34
|
+
max_spot_price
|
35
|
+
locked
|
36
|
+
ec2_availability_zone
|
37
|
+
aws_platform
|
38
|
+
dns_name
|
39
|
+
private_dns_name
|
40
|
+
ip_address
|
41
|
+
private_ip_address
|
42
|
+
aws_id
|
43
|
+
cloud_id
|
44
|
+
aws_product_codes
|
45
|
+
)
|
46
|
+
|
47
|
+
SETTINGS.each do |name|
|
48
|
+
module_eval <<-END,__FILE__, __LINE__+1
|
49
|
+
def #{name}
|
50
|
+
@#{name} ||= settings["#{name}"]
|
51
|
+
end
|
52
|
+
END
|
53
|
+
end
|
24
54
|
|
55
|
+
#returns the cloud region the server is in (:us_east,:us_west,:eu,:ap)
|
56
|
+
def region
|
57
|
+
RightScaleAPI::CLOUD_REGIONS.find{|k,v|v == cloud_id}.first
|
58
|
+
end
|
59
|
+
|
25
60
|
# Starts the server
|
26
61
|
def start
|
27
62
|
post '/start'
|
@@ -41,7 +76,21 @@ module RightScaleAPI
|
|
41
76
|
# for info: under Sub-resources on
|
42
77
|
# http://support.rightscale.com/15-References/RightScale_API_Reference_Guide/02-Management/02-Servers
|
43
78
|
def settings
|
44
|
-
get('/settings')['settings']
|
79
|
+
@settings ||= get('/settings')['settings']
|
80
|
+
end
|
81
|
+
|
82
|
+
def reset_settings
|
83
|
+
@settings = nil
|
84
|
+
end
|
85
|
+
|
86
|
+
def reload_settings
|
87
|
+
reset_settings
|
88
|
+
settings
|
89
|
+
end
|
90
|
+
|
91
|
+
def reload!
|
92
|
+
super
|
93
|
+
reload_settings
|
45
94
|
end
|
46
95
|
|
47
96
|
# Is the server operational
|
@@ -69,10 +118,12 @@ module RightScaleAPI
|
|
69
118
|
|
70
119
|
# creates a blank volume and attaches it to the server
|
71
120
|
# @param [Hash] opts Account#create_ec2_ebs_volume's opts +
|
72
|
-
# @option [String] :device device mount point, e.g. /dev/sdk
|
121
|
+
# @option opts [String] :device device mount point, e.g. /dev/sdk
|
122
|
+
# @option opts [String] :ec2_availability_zone (server's) availability zone to create the volume in.
|
123
|
+
|
73
124
|
def attach_blank_volume opts
|
74
125
|
device = opts.delete :device
|
75
|
-
opts = {:ec2_availability_zone =>
|
126
|
+
opts = {:ec2_availability_zone => ec2_availability_zone }.merge opts
|
76
127
|
volume = account.create_ec2_ebs_volume opts
|
77
128
|
attach_volume volume, device
|
78
129
|
end
|
data/right-scale-api.gemspec
CHANGED
@@ -2,11 +2,10 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{right-scale-api}
|
5
|
-
s.version = "0.0.
|
6
|
-
|
5
|
+
s.version = "0.0.6"
|
6
|
+
s.date = %q{2010-11-2}
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Nick Howard"]
|
9
|
-
s.date = %q{2010-09-14}
|
10
9
|
s.description = %q{A client for the RightScale API that hides some of the complexity of the API
|
11
10
|
(It doesn't require passing around hrefs as much). Based on HTTParty
|
12
11
|
}
|
@@ -20,27 +19,7 @@ Gem::Specification.new do |s|
|
|
20
19
|
"LICENSE",
|
21
20
|
"README.md",
|
22
21
|
"Rakefile",
|
23
|
-
"
|
24
|
-
"lib/right-scale-api.rb",
|
25
|
-
"lib/right-scale-api/account.rb",
|
26
|
-
"lib/right-scale-api/alert_spec.rb",
|
27
|
-
"lib/right-scale-api/base.rb",
|
28
|
-
"lib/right-scale-api/client.rb",
|
29
|
-
"lib/right-scale-api/deployment.rb",
|
30
|
-
"lib/right-scale-api/ec2_ebs_snapshot.rb",
|
31
|
-
"lib/right-scale-api/ec2_ebs_volume.rb",
|
32
|
-
"lib/right-scale-api/ec2_elastic_ip.rb",
|
33
|
-
"lib/right-scale-api/ec2_security_group.rb",
|
34
|
-
"lib/right-scale-api/ec2_ssh_key.rb",
|
35
|
-
"lib/right-scale-api/s3_bucket.rb",
|
36
|
-
"lib/right-scale-api/server.rb",
|
37
|
-
"lib/right-scale-api/server_template.rb",
|
38
|
-
"lib/right-scale-api/status.rb",
|
39
|
-
"right-scale-api.gemspec",
|
40
|
-
"spec/right-scale-api_spec.rb",
|
41
|
-
"spec/spec.opts",
|
42
|
-
"spec/spec_helper.rb"
|
43
|
-
]
|
22
|
+
"right-scale-api.gemspec"] + Dir["{lib,spec}/**/*"]
|
44
23
|
s.homepage = %q{http://github.com/baroquebobcat/right-scale-api}
|
45
24
|
s.rdoc_options = ["--charset=UTF-8"]
|
46
25
|
s.require_paths = ["lib"]
|
@@ -12,10 +12,23 @@ describe RightScaleAPI do
|
|
12
12
|
subject { Class.new(RightScaleAPI::Base).new({}) }
|
13
13
|
it { subject.should respond_to(:href) }
|
14
14
|
end
|
15
|
+
|
16
|
+
describe '.create' do
|
17
|
+
before do
|
18
|
+
subject.attributes []
|
19
|
+
RightScaleAPI::Client.stub!(:post).and_return mock('httparty response', :code => 201, :headers => {}, :merge => {})
|
20
|
+
end
|
21
|
+
|
22
|
+
it "doesn't send invalid attrs to the object" do
|
23
|
+
subject.should_not_receive(:new).with hash_including(:foo => 1)
|
24
|
+
subject.should_receive(:new).twice.and_return(mock('base', :collection_uri => ''))
|
25
|
+
|
26
|
+
subject.create :foo => 1, :id => 2
|
27
|
+
end
|
28
|
+
end
|
15
29
|
end
|
16
30
|
|
17
31
|
describe RightScaleAPI::Account do
|
18
|
-
#
|
19
32
|
describe "#create_ec2_ebs_volume" do
|
20
33
|
#when receive a 422
|
21
34
|
#do stuff with error
|
data/spec/spec_helper.rb
CHANGED
@@ -3,9 +3,7 @@
|
|
3
3
|
require 'rubygems'
|
4
4
|
require 'right-scale-api'
|
5
5
|
require 'fakeweb'
|
6
|
-
require '
|
7
|
-
require '
|
6
|
+
require 'rspec'
|
7
|
+
require 'rspec/autorun'
|
8
8
|
|
9
|
-
|
10
|
-
FakeWeb.allow_net_connect = false
|
11
|
-
end
|
9
|
+
FakeWeb.allow_net_connect = false
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: right-scale-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 6
|
10
|
+
version: 0.0.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Nick Howard
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-11-02 00:00:00 -06:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -81,8 +81,7 @@ files:
|
|
81
81
|
- LICENSE
|
82
82
|
- README.md
|
83
83
|
- Rakefile
|
84
|
-
-
|
85
|
-
- lib/right-scale-api.rb
|
84
|
+
- right-scale-api.gemspec
|
86
85
|
- lib/right-scale-api/account.rb
|
87
86
|
- lib/right-scale-api/alert_spec.rb
|
88
87
|
- lib/right-scale-api/base.rb
|
@@ -97,9 +96,8 @@ files:
|
|
97
96
|
- lib/right-scale-api/server.rb
|
98
97
|
- lib/right-scale-api/server_template.rb
|
99
98
|
- lib/right-scale-api/status.rb
|
100
|
-
- right-scale-api.
|
99
|
+
- lib/right-scale-api.rb
|
101
100
|
- spec/right-scale-api_spec.rb
|
102
|
-
- spec/spec.opts
|
103
101
|
- spec/spec_helper.rb
|
104
102
|
has_rdoc: true
|
105
103
|
homepage: http://github.com/baroquebobcat/right-scale-api
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.0.4
|
data/spec/spec.opts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--color
|