rightresource 0.1.8
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/CHANGELOG +18 -0
- data/LICENSE +22 -0
- data/README.rdoc +16 -0
- data/lib/right_resource/alert_spec.rb +7 -0
- data/lib/right_resource/base.rb +319 -0
- data/lib/right_resource/connection.rb +90 -0
- data/lib/right_resource/core_ext/object/tap.rb +7 -0
- data/lib/right_resource/core_ext/object.rb +3 -0
- data/lib/right_resource/core_ext.rb +3 -0
- data/lib/right_resource/credential.rb +1 -0
- data/lib/right_resource/deployment.rb +15 -0
- data/lib/right_resource/ec2_ebs_snapshot.rb +1 -0
- data/lib/right_resource/ec2_ebs_volume.rb +8 -0
- data/lib/right_resource/ec2_elastic_ip.rb +11 -0
- data/lib/right_resource/ec2_security_group.rb +11 -0
- data/lib/right_resource/ec2_ssh_key.rb +7 -0
- data/lib/right_resource/formats/json_format.rb +26 -0
- data/lib/right_resource/formats/xml_format.rb +26 -0
- data/lib/right_resource/formats.rb +7 -0
- data/lib/right_resource/macro.rb +1 -0
- data/lib/right_resource/multi_cloud_image.rb +27 -0
- data/lib/right_resource/right_script.rb +27 -0
- data/lib/right_resource/s3_bucket.rb +11 -0
- data/lib/right_resource/server.rb +35 -0
- data/lib/right_resource/server_array.rb +20 -0
- data/lib/right_resource/server_template.rb +8 -0
- data/lib/right_resource/status.rb +31 -0
- data/lib/right_resource.rb +39 -0
- metadata +139 -0
data/CHANGELOG
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
commit d849c4772e4a66fff45a794d84832bcfab97cb50
|
2
|
+
Author: Satoshi Ohki <roothybrid7@gmail.com>
|
3
|
+
Date: Thu Oct 28 16:09:42 2010 +0900
|
4
|
+
|
5
|
+
modified: resource action methods support, add: new resource support
|
6
|
+
|
7
|
+
commit 57bc0d37597cee69f30ddba0bc064cb4f4075d49
|
8
|
+
Author: Satoshi Ohki <roothybrid7@gmail.com>
|
9
|
+
Date: Wed Oct 27 17:47:30 2010 +0900
|
10
|
+
|
11
|
+
modified: set fileformat
|
12
|
+
|
13
|
+
commit d57e3180e9d86604c08b3a2cf4b0cb925f2c7b1d
|
14
|
+
Author: Satoshi Ohki <roothybrid7@gmail.com>
|
15
|
+
Date: Mon Oct 25 15:45:29 2010 +0900
|
16
|
+
|
17
|
+
bug fix: centos5.4 older ruby version unsupported method
|
18
|
+
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2010 Satoshi Ohki
|
2
|
+
(The MIT License)
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
'Software'), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
18
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
19
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
20
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
21
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
|
data/README.rdoc
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
= RightScale Resource API wrapper
|
2
|
+
|
3
|
+
== Lisence
|
4
|
+
Author:: Satoshi Ohki <_roothybrid7_@_gmail.com_>
|
5
|
+
Copyright:: Copyright (c) 2010 Satoshi Ohki
|
6
|
+
License:: The MIT License
|
7
|
+
|
8
|
+
== Require packages
|
9
|
+
json
|
10
|
+
rest_client
|
11
|
+
crack
|
12
|
+
|
13
|
+
== install
|
14
|
+
sudo gem install json rest-client crack
|
15
|
+
|
16
|
+
== example
|
@@ -0,0 +1,319 @@
|
|
1
|
+
module RightResource
|
2
|
+
class Base
|
3
|
+
class << self # Define singleton methods
|
4
|
+
def logger=(logger)
|
5
|
+
@logger = logger
|
6
|
+
end
|
7
|
+
|
8
|
+
def logger
|
9
|
+
@logger ||= Logger.new(STDERR)
|
10
|
+
end
|
11
|
+
|
12
|
+
# Set RESTFul client with login authentication for HTTP Methods(Low level)
|
13
|
+
# === Examples
|
14
|
+
# conn = Connection.new do |c|
|
15
|
+
# c.login(:username => "user", :password => "pass", :account => "1")
|
16
|
+
# end
|
17
|
+
# Server.connection = conn
|
18
|
+
def connection=(conn)
|
19
|
+
@connection = conn
|
20
|
+
end
|
21
|
+
|
22
|
+
# Get RESTFul client for HTTP Methods(Low level)
|
23
|
+
# and use in resource api call
|
24
|
+
# === Examples
|
25
|
+
# conn = Server.connection
|
26
|
+
# conn.get("servers?filter=nickname=server1")
|
27
|
+
#
|
28
|
+
# ex. resource api call:
|
29
|
+
# Server.index
|
30
|
+
def connection
|
31
|
+
if defined?(@connection) || superclass == Object
|
32
|
+
raise ArgumentError, "Not set connection object!!" unless @connection
|
33
|
+
@connection
|
34
|
+
else
|
35
|
+
superclass.connection
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Get request and response format type object
|
40
|
+
def format
|
41
|
+
connection.format || RightResource::Formats::JsonFormat
|
42
|
+
end
|
43
|
+
|
44
|
+
# Get response headers via RESTFul client
|
45
|
+
def headers
|
46
|
+
connection.headers || {}
|
47
|
+
end
|
48
|
+
|
49
|
+
# Get response status code
|
50
|
+
def status
|
51
|
+
connection.status || nil
|
52
|
+
end
|
53
|
+
|
54
|
+
# Get resource id in response location header via RESTFul client(create only?)
|
55
|
+
def resource_id
|
56
|
+
connection.resource_id || nil
|
57
|
+
end
|
58
|
+
|
59
|
+
# Get resources by index method
|
60
|
+
# same resources support criteria like filtering.
|
61
|
+
#
|
62
|
+
# === Params
|
63
|
+
# params:: criteria[ex. :filter => "nickname=hoge"](Hash)
|
64
|
+
# === Return
|
65
|
+
# Resource list(Array)
|
66
|
+
#
|
67
|
+
# === Examples
|
68
|
+
# dep = Deployment.index(:filter => ["nickname=payment-dev", "nickname=payment-staging"])
|
69
|
+
#
|
70
|
+
# test = Server.index(:filter => "nickname<>test")
|
71
|
+
#
|
72
|
+
# Criteria unsupport
|
73
|
+
# array = ServerArray.index
|
74
|
+
#
|
75
|
+
# Get first 5 resources
|
76
|
+
# server = Server.index.first(5) # see Array class
|
77
|
+
# Get last resource
|
78
|
+
# server = Server.index.last # see Array class
|
79
|
+
#
|
80
|
+
# Get all operational server's nickname
|
81
|
+
# Server.index.each do |server|
|
82
|
+
# puts server.nickname if server.state = "operational"
|
83
|
+
# end
|
84
|
+
def index(params = {})
|
85
|
+
path = "#{resource_name}s.#{format.extension}#{query_string(params)}"
|
86
|
+
connection.clear
|
87
|
+
instantiate_collection(format.decode(connection.get(path || [])))
|
88
|
+
rescue RestClient::ResourceNotFound
|
89
|
+
nil
|
90
|
+
rescue => e
|
91
|
+
logger.error("#{e.class}: #{e.pretty_inspect}")
|
92
|
+
logger.debug {"Backtrace:\n#{e.backtrace.pretty_inspect}"}
|
93
|
+
ensure
|
94
|
+
logger.debug {"#{__FILE__} #{__LINE__}: #{self.class}\n#{self.pretty_inspect}\n"}
|
95
|
+
end
|
96
|
+
|
97
|
+
# Get resource
|
98
|
+
# === Params
|
99
|
+
# params:: Query Strings(Hash)
|
100
|
+
# === Return
|
101
|
+
# Resource(Object)
|
102
|
+
#
|
103
|
+
# === Example
|
104
|
+
# server_id = 1
|
105
|
+
# Server.show(server_id) #=> #<Server:0x1234...>
|
106
|
+
#
|
107
|
+
# Get deployment resource with server's subresource
|
108
|
+
# Deployment.show(1, :params => {:server_settings => "true"}) #=> #<Deployment:0x12314...>
|
109
|
+
def show(id, params = {})
|
110
|
+
path = element_path(id, nil, params)
|
111
|
+
connection.clear
|
112
|
+
instantiate_record(format.decode(connection.get(path)))
|
113
|
+
rescue RestClient::ResourceNotFound
|
114
|
+
nil
|
115
|
+
rescue => e
|
116
|
+
logger.error("#{e.class}: #{e.pretty_inspect}")
|
117
|
+
logger.debug {"Backtrace:\n#{e.backtrace.pretty_inspect}"}
|
118
|
+
ensure
|
119
|
+
logger.debug {"#{__FILE__} #{__LINE__}: #{self.class}\n#{self.pretty_inspect}\n"}
|
120
|
+
end
|
121
|
+
|
122
|
+
# Create new resource
|
123
|
+
# Example:
|
124
|
+
# params = {
|
125
|
+
# :nickname => "dev",
|
126
|
+
# :deployment_href => "https://my.rightscale.com/api/acct/22329/deployments/59855",
|
127
|
+
# :server_template_href => "https://my.rightscale.com/api/acct/22329/server_templates/76610",
|
128
|
+
# :ec2_availability_zone => "ap-northeast-1a"
|
129
|
+
# }
|
130
|
+
# Server.create(params)
|
131
|
+
def create(params={})
|
132
|
+
#TODO: refactor
|
133
|
+
self.new(params).tap do |resource|
|
134
|
+
resource.save
|
135
|
+
end
|
136
|
+
# path = collection_path
|
137
|
+
# connection.post(path, params)
|
138
|
+
end
|
139
|
+
|
140
|
+
# Update resource
|
141
|
+
def update(id, params={})
|
142
|
+
#TODO: refactor
|
143
|
+
path = element_path(id)
|
144
|
+
connection.put(path, params)
|
145
|
+
end
|
146
|
+
|
147
|
+
# Delete resource
|
148
|
+
# Example:
|
149
|
+
# Server.destory(1)
|
150
|
+
#
|
151
|
+
# server = Server.index(:filter => "aws_id=i-012345")
|
152
|
+
# Server.destory(server.id)
|
153
|
+
def destory(id)
|
154
|
+
path = element_path(id)
|
155
|
+
connection.delete(path)
|
156
|
+
end
|
157
|
+
|
158
|
+
# Get single resource
|
159
|
+
def element_path(id, prefix_options = nil, query_options = nil)
|
160
|
+
"#{resource_name}s/#{id}#{prefix(prefix_options)}.#{format.extension}#{query_string(query_options)}"
|
161
|
+
end
|
162
|
+
|
163
|
+
# Get resource collections
|
164
|
+
def collection_path(prefix_options = nil, query_options = nil)
|
165
|
+
"#{resource_name}s#{prefix(prefix_options)}.#{format.extension}#{query_string(query_options)}"
|
166
|
+
end
|
167
|
+
|
168
|
+
# Get resource name(equals plural of classname)
|
169
|
+
def resource_name
|
170
|
+
name = ""
|
171
|
+
self.name.to_s.split(/::/).last.scan(/([A-Z][^A-Z]*)/).flatten.each_with_index do |str,i|
|
172
|
+
if i > 0
|
173
|
+
name << "_#{str.downcase}"
|
174
|
+
else
|
175
|
+
name << str.downcase
|
176
|
+
end
|
177
|
+
end
|
178
|
+
name
|
179
|
+
end
|
180
|
+
|
181
|
+
def generate_attributes(attributes)
|
182
|
+
raise ArgumentError, "expected an attributes Hash, got #{attributes.pretty_inspect}" unless attributes.is_a?(Hash)
|
183
|
+
attrs = {}
|
184
|
+
attributes.each_pair {|key,value| attrs[key.to_s.gsub('-', '_').to_sym] = value}
|
185
|
+
attrs
|
186
|
+
end
|
187
|
+
|
188
|
+
protected
|
189
|
+
def prefix(options = nil)
|
190
|
+
default = ""
|
191
|
+
unless options.nil?
|
192
|
+
if options.is_a?(String) || options.is_a?(Symbol)
|
193
|
+
default = "/#{options}"
|
194
|
+
elsif options.is_a?(Hash)
|
195
|
+
options.each_pair do |key,value|
|
196
|
+
if value.nil? || value.empty?
|
197
|
+
default << "/#{key}"
|
198
|
+
else
|
199
|
+
default << "/#{key}/#{value}"
|
200
|
+
end
|
201
|
+
end
|
202
|
+
else
|
203
|
+
raise ArgumentError, "expected an Hash, String or Symbol, got #{options.pretty_inspect}"
|
204
|
+
end
|
205
|
+
end
|
206
|
+
default
|
207
|
+
end
|
208
|
+
|
209
|
+
# create querystring by crack to_params method
|
210
|
+
def query_string(options = {})
|
211
|
+
!options.is_a?(Hash) || options.empty? ? "" : '?' + options.to_params
|
212
|
+
end
|
213
|
+
|
214
|
+
# Get resource collection
|
215
|
+
def instantiate_collection(collection)
|
216
|
+
collection.collect! {|record| instantiate_record(record)}
|
217
|
+
end
|
218
|
+
|
219
|
+
# Get a resource and create object
|
220
|
+
def instantiate_record(record)
|
221
|
+
self.new(record)
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
def initialize(attributes={})
|
226
|
+
# sub-resource4json's key name contains '-'
|
227
|
+
# attrs = generate_attributes(attributes)
|
228
|
+
@attributes = {}
|
229
|
+
loads(attributes)
|
230
|
+
if @attributes
|
231
|
+
if self.class.resource_id.nil?
|
232
|
+
@id = @attributes[:href].match(/\d+$/).to_s if @attributes[:href]
|
233
|
+
else
|
234
|
+
@id = self.class.resource_id
|
235
|
+
end
|
236
|
+
load_accessor(@attributes)
|
237
|
+
end
|
238
|
+
yield self if block_given?
|
239
|
+
end
|
240
|
+
attr_accessor :id
|
241
|
+
attr_reader :attributes
|
242
|
+
|
243
|
+
def loads(attributes)
|
244
|
+
raise ArgumentError, "expected an attributes Hash, got #{attributes.pretty_inspect}" unless attributes.is_a?(Hash)
|
245
|
+
attributes.each_pair {|key,value| @attributes[key.to_s.gsub('-', '_').to_sym] = value}
|
246
|
+
self
|
247
|
+
end
|
248
|
+
|
249
|
+
def update_attributes(attributes)
|
250
|
+
loads(attributes) && load_accessor(attributes) && save
|
251
|
+
end
|
252
|
+
|
253
|
+
def load_accessor(attributes)
|
254
|
+
raise ArgumentError, "expected an attributes Hash, got #{attributes.pretty_inspect}" unless attributes.is_a?(Hash)
|
255
|
+
attributes.each_pair do |key, value|
|
256
|
+
instance_variable_set("@#{key}", value) # Initialize instance variables
|
257
|
+
self.class.class_eval do
|
258
|
+
define_method("#{key}=") do |new_value| # ex. obj.key = new_value
|
259
|
+
instance_variable_set("@#{key}", new_value)
|
260
|
+
end
|
261
|
+
define_method(key) do
|
262
|
+
instance_variable_get("@#{key}")
|
263
|
+
end
|
264
|
+
end
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
def new?
|
269
|
+
id.nil?
|
270
|
+
end
|
271
|
+
alias :new_record? :new?
|
272
|
+
|
273
|
+
def save
|
274
|
+
new? ? create : update
|
275
|
+
end
|
276
|
+
|
277
|
+
def destory
|
278
|
+
connection.delete(element_path)
|
279
|
+
end
|
280
|
+
|
281
|
+
protected
|
282
|
+
def connection
|
283
|
+
self.class.connection
|
284
|
+
end
|
285
|
+
|
286
|
+
def update
|
287
|
+
#TODO: refactor hard coding
|
288
|
+
attrs = self.attributes.reject {|key,value| key.to_s == "cloud_id"}
|
289
|
+
pair = URI.decode({resource_name.to_sym => attrs}.to_params).split('&').map {|l| l.split('=')}
|
290
|
+
headers = Hash[*pair.flatten]
|
291
|
+
headers["cloud_id"] = self.attributes[:cloud_id] if self.attributes.has_key?(:cloud_id)
|
292
|
+
connection.put(element_path, headers)
|
293
|
+
end
|
294
|
+
|
295
|
+
def create
|
296
|
+
#TODO: refactor hard coding
|
297
|
+
attrs = self.attributes.reject {|key,value| key.to_s == "cloud_id"}
|
298
|
+
puts attrs.pretty_inspect
|
299
|
+
pair = URI.decode({resource_name.to_sym => attrs}.to_params).split('&').map {|l| l.split('=')}
|
300
|
+
headers = Hash[*pair.flatten]
|
301
|
+
headers["cloud_id"] = self.attributes[:cloud_id] if self.attributes.has_key?(:cloud_id)
|
302
|
+
puts headers.pretty_inspect
|
303
|
+
connection.post(collection_path, headers)
|
304
|
+
self.id = self.class.resource_id
|
305
|
+
end
|
306
|
+
|
307
|
+
def resource_name
|
308
|
+
self.class.resource_name
|
309
|
+
end
|
310
|
+
|
311
|
+
def element_path(prefix_options=nil, query_options=nil)
|
312
|
+
self.class.element_path(self.id, prefix_options, query_options)
|
313
|
+
end
|
314
|
+
|
315
|
+
def collection_path(prefix_options=nil, query_options=nil)
|
316
|
+
self.class.collection_path(prefix_options, query_options)
|
317
|
+
end
|
318
|
+
end
|
319
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
module RightResource
|
2
|
+
class Connection
|
3
|
+
@reraise = false
|
4
|
+
RestClient.log = STDERR
|
5
|
+
|
6
|
+
attr_accessor :api_version, :log, :api, :format, :username, :password, :account, :reraise
|
7
|
+
attr_reader :headers, :resource_id, :response, :status
|
8
|
+
|
9
|
+
# Set RestFul Client Parameters
|
10
|
+
def initialize(params={})
|
11
|
+
@api_version = API_VERSION
|
12
|
+
@api = "https://my.rightscale.com/api/acct/"
|
13
|
+
@format = params[:format] || RightResource::Formats::JsonFormat
|
14
|
+
@logger = params[:logger] || Logger.new(STDERR)
|
15
|
+
yield self if block_given? # RightResource::Connection.new {|conn| ...}
|
16
|
+
end
|
17
|
+
|
18
|
+
def login(params={})
|
19
|
+
@username = params[:username] unless params[:username].nil? || params[:username].empty?
|
20
|
+
@password = params[:password] unless params[:password].nil? || params[:password].empty?
|
21
|
+
@account = params[:account] unless params[:account].nil? || params[:account].empty?
|
22
|
+
@api_object = RestClient::Resource.new("#{@api}#{@account}", @username, @password)
|
23
|
+
rescue => e
|
24
|
+
@logger.error("#{e.class}: #{e.pretty_inspect}")
|
25
|
+
@logger.debug {"Backtrace:\n#{e.backtrace.pretty_inspect}"}
|
26
|
+
raise if self.reraise
|
27
|
+
ensure
|
28
|
+
@logger.debug {"#{__FILE__} #{__LINE__}: #{self.class}\n#{self.pretty_inspect}\n"}
|
29
|
+
end
|
30
|
+
|
31
|
+
def login?
|
32
|
+
@api_object ? true : false
|
33
|
+
end
|
34
|
+
|
35
|
+
def request(path, method="get", headers={})
|
36
|
+
raise "Not Login!!" unless self.login?
|
37
|
+
# if /(.xml|.js)/ =~ path
|
38
|
+
# path = URI.encode(path)
|
39
|
+
# elsif /\?(.*)$/ =~ path
|
40
|
+
# path = URI.encode("#{path}&format=#{@format.extension}")
|
41
|
+
# else
|
42
|
+
# path = URI.encode("#{path}?format=#{@format.extension}")
|
43
|
+
# end
|
44
|
+
unless method.match(/(get|put|post|delete)/)
|
45
|
+
raise "Invalid Action: get|put|post|delete only"
|
46
|
+
end
|
47
|
+
api_version = {:x_api_version => @api_version, :api_version => @api_version}
|
48
|
+
|
49
|
+
@response = @api_object[path].send(method.to_sym, api_version.merge(headers))
|
50
|
+
@status = @response.code
|
51
|
+
@headers = @response.headers
|
52
|
+
@resource_id = @headers[:location].match(/\d+$/).to_s unless @headers[:location].nil?
|
53
|
+
@response.body
|
54
|
+
rescue => e
|
55
|
+
@status = e.http_code
|
56
|
+
@logger.error("#{e.class}: #{e.pretty_inspect}")
|
57
|
+
@logger.debug {"Backtrace:\n#{e.backtrace.pretty_inspect}"}
|
58
|
+
raise if self.reraise
|
59
|
+
ensure
|
60
|
+
@logger.debug {"#{__FILE__} #{__LINE__}: #{self.class}\n#{self.pretty_inspect}\n"}
|
61
|
+
end
|
62
|
+
|
63
|
+
def clear
|
64
|
+
@response = @headers = @resource_id = @status = nil
|
65
|
+
ensure
|
66
|
+
@logger.debug {"#{__FILE__} #{__LINE__}: #{self.class}\n#{self.pretty_inspect}\n"}
|
67
|
+
end
|
68
|
+
|
69
|
+
# HTTP methods
|
70
|
+
# show|index
|
71
|
+
def get(path, headers={})
|
72
|
+
self.request(path, "get", headers)
|
73
|
+
end
|
74
|
+
|
75
|
+
# create
|
76
|
+
def post(path, headers={})
|
77
|
+
self.request(path, "post", headers)
|
78
|
+
end
|
79
|
+
|
80
|
+
# update
|
81
|
+
def put(path, headers={})
|
82
|
+
self.request(path, "put", headers)
|
83
|
+
end
|
84
|
+
|
85
|
+
# destory
|
86
|
+
def delete(path, headers={})
|
87
|
+
self.request(path, "delete", headers)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
class Credential < RightResource::Base; end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class Deployment < RightResource::Base
|
2
|
+
class << self
|
3
|
+
def start_all(id)
|
4
|
+
connection.post(element_path(id, :start_all))
|
5
|
+
end
|
6
|
+
|
7
|
+
def stop_all(id)
|
8
|
+
connection.post(element_path(id, :stop_all))
|
9
|
+
end
|
10
|
+
|
11
|
+
def duplicate(id)
|
12
|
+
connection.post(element_path(id, :duplicate))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
class Ec2EbsSnapshot < RightResource::Base; end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'json/pure'
|
2
|
+
|
3
|
+
module RightResource
|
4
|
+
module Formats
|
5
|
+
module JsonFormat
|
6
|
+
extend self
|
7
|
+
|
8
|
+
def extension
|
9
|
+
"js"
|
10
|
+
end
|
11
|
+
|
12
|
+
def mime_type
|
13
|
+
"application/json"
|
14
|
+
end
|
15
|
+
|
16
|
+
def encode(hash)
|
17
|
+
JSON.generate(hash)
|
18
|
+
end
|
19
|
+
|
20
|
+
def decode(json)
|
21
|
+
JSON.parse(json)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'crack/xml'
|
2
|
+
|
3
|
+
module RightResource
|
4
|
+
module Formats
|
5
|
+
module XmlFormat
|
6
|
+
extend self
|
7
|
+
|
8
|
+
def extension
|
9
|
+
"xml"
|
10
|
+
end
|
11
|
+
|
12
|
+
def mime_type
|
13
|
+
"application/xml"
|
14
|
+
end
|
15
|
+
|
16
|
+
def encode(hash)
|
17
|
+
raise NotImplementedError, "Not Implementated function #{self.class.name}::#{__method__.to_s}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def decode(json)
|
21
|
+
Crack::XML.parse(json)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
class Macro < RightResource::Base; end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class MultiCloudImage < RightResource::Base
|
2
|
+
class << self
|
3
|
+
def create
|
4
|
+
raise NotImplementedError
|
5
|
+
end
|
6
|
+
|
7
|
+
def update(id)
|
8
|
+
raise NotImplementedError
|
9
|
+
end
|
10
|
+
|
11
|
+
def destory(id)
|
12
|
+
raise NotImplementedError
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def create
|
17
|
+
raise NotImplementedError
|
18
|
+
end
|
19
|
+
|
20
|
+
def update(id)
|
21
|
+
raise NotImplementedError
|
22
|
+
end
|
23
|
+
|
24
|
+
def destory(id)
|
25
|
+
raise NotImplementedError
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class RightScript < RightResource::Base
|
2
|
+
class << self
|
3
|
+
def create
|
4
|
+
raise NotImplementedError
|
5
|
+
end
|
6
|
+
|
7
|
+
def update(id)
|
8
|
+
raise NotImplementedError
|
9
|
+
end
|
10
|
+
|
11
|
+
def destory(id)
|
12
|
+
raise NotImplementedError
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def create
|
17
|
+
raise NotImplementedError
|
18
|
+
end
|
19
|
+
|
20
|
+
def update(id)
|
21
|
+
raise NotImplementedError
|
22
|
+
end
|
23
|
+
|
24
|
+
def destory(id)
|
25
|
+
raise NotImplementedError
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
class Server < RightResource::Base
|
2
|
+
class << self
|
3
|
+
def action; end
|
4
|
+
def start(id)
|
5
|
+
connection.post(element_path(id, :start))
|
6
|
+
end
|
7
|
+
|
8
|
+
def stop(id)
|
9
|
+
connection.post(element_path(id, :stop))
|
10
|
+
end
|
11
|
+
|
12
|
+
def reboot(id)
|
13
|
+
connection.post(element_path(id, :reboot))
|
14
|
+
end
|
15
|
+
|
16
|
+
# Run rightscript
|
17
|
+
# location header is status href
|
18
|
+
def run_script(id, params={})
|
19
|
+
raise NotImplementedError
|
20
|
+
end
|
21
|
+
|
22
|
+
def attach_volume(id, params={})
|
23
|
+
raise NotImplementedError
|
24
|
+
end
|
25
|
+
|
26
|
+
def get_sketchy_data(id, params={})
|
27
|
+
raise NotImplementedError
|
28
|
+
end
|
29
|
+
|
30
|
+
def settings(id)
|
31
|
+
path = element_path(id, :settings)
|
32
|
+
format.decode(connection.get(path))
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class ServerArray < RightResource::Base
|
2
|
+
class << self
|
3
|
+
def launch(id)
|
4
|
+
connection.post(element_path(id, :launch))
|
5
|
+
end
|
6
|
+
|
7
|
+
def terminate_all(id)
|
8
|
+
connection.post(element_path(id, :terminate_all))
|
9
|
+
end
|
10
|
+
|
11
|
+
def run_script_on_all(id)
|
12
|
+
raise NotImplementedError
|
13
|
+
end
|
14
|
+
|
15
|
+
def instances(id)
|
16
|
+
path = element_path(id, :instances)
|
17
|
+
format.decode(connection.get(path))
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class Status < RightResource::Base
|
2
|
+
class << self
|
3
|
+
def index(id)
|
4
|
+
raise NotImplementedError
|
5
|
+
end
|
6
|
+
|
7
|
+
def create
|
8
|
+
raise NotImplementedError
|
9
|
+
end
|
10
|
+
|
11
|
+
def update(id)
|
12
|
+
raise NotImplementedError
|
13
|
+
end
|
14
|
+
|
15
|
+
def destory(id)
|
16
|
+
raise NotImplementedError
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def create
|
21
|
+
raise NotImplementedError
|
22
|
+
end
|
23
|
+
|
24
|
+
def update(id)
|
25
|
+
raise NotImplementedError
|
26
|
+
end
|
27
|
+
|
28
|
+
def destory(id)
|
29
|
+
raise NotImplementedError
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'rexml/document'
|
3
|
+
require 'logger'
|
4
|
+
require 'rubygems'
|
5
|
+
|
6
|
+
require 'json/pure'
|
7
|
+
require 'rest_client'
|
8
|
+
require 'crack'
|
9
|
+
|
10
|
+
$:.unshift(File.dirname(__FILE__))
|
11
|
+
# Ruby core extensions
|
12
|
+
require 'right_resource/core_ext'
|
13
|
+
# base class
|
14
|
+
require 'right_resource/connection'
|
15
|
+
require 'right_resource/base'
|
16
|
+
require 'right_resource/formats'
|
17
|
+
# Management API
|
18
|
+
require 'right_resource/deployment'
|
19
|
+
#require 'right_resource/status'
|
20
|
+
require 'right_resource/alert_spec'
|
21
|
+
require 'right_resource/server'
|
22
|
+
require 'right_resource/ec2_ebs_volume'
|
23
|
+
require 'right_resource/ec2_elastic_ip'
|
24
|
+
require 'right_resource/ec2_security_group'
|
25
|
+
require 'right_resource/ec2_ssh_key'
|
26
|
+
require 'right_resource/server_array'
|
27
|
+
require 'right_resource/ec2_ebs_snapshot'
|
28
|
+
require 'right_resource/s3_bucket'
|
29
|
+
#require 'right_resource/tag'
|
30
|
+
# Design API
|
31
|
+
require 'right_resource/server_template'
|
32
|
+
require 'right_resource/right_script'
|
33
|
+
require 'right_resource/multi_cloud_image'
|
34
|
+
require 'right_resource/macro'
|
35
|
+
require 'right_resource/credential'
|
36
|
+
|
37
|
+
module RightResource
|
38
|
+
API_VERSION = "1.0".freeze
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rightresource
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 11
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 8
|
10
|
+
version: 0.1.8
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Satoshi Ohki
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-11-08 00:00:00 +09:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: json
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rest-client
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: crack
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
type: :runtime
|
62
|
+
version_requirements: *id003
|
63
|
+
description: |
|
64
|
+
RightScale Resource API wrapper.
|
65
|
+
|
66
|
+
email: roothybrid7@gmail.com
|
67
|
+
executables: []
|
68
|
+
|
69
|
+
extensions: []
|
70
|
+
|
71
|
+
extra_rdoc_files: []
|
72
|
+
|
73
|
+
files:
|
74
|
+
- CHANGELOG
|
75
|
+
- README.rdoc
|
76
|
+
- LICENSE
|
77
|
+
- lib/right_resource/alert_spec.rb
|
78
|
+
- lib/right_resource/base.rb
|
79
|
+
- lib/right_resource/connection.rb
|
80
|
+
- lib/right_resource/core_ext/object/tap.rb
|
81
|
+
- lib/right_resource/core_ext/object.rb
|
82
|
+
- lib/right_resource/core_ext.rb
|
83
|
+
- lib/right_resource/credential.rb
|
84
|
+
- lib/right_resource/deployment.rb
|
85
|
+
- lib/right_resource/ec2_ebs_snapshot.rb
|
86
|
+
- lib/right_resource/ec2_ebs_volume.rb
|
87
|
+
- lib/right_resource/ec2_elastic_ip.rb
|
88
|
+
- lib/right_resource/ec2_security_group.rb
|
89
|
+
- lib/right_resource/ec2_ssh_key.rb
|
90
|
+
- lib/right_resource/formats/json_format.rb
|
91
|
+
- lib/right_resource/formats/xml_format.rb
|
92
|
+
- lib/right_resource/formats.rb
|
93
|
+
- lib/right_resource/macro.rb
|
94
|
+
- lib/right_resource/multi_cloud_image.rb
|
95
|
+
- lib/right_resource/right_script.rb
|
96
|
+
- lib/right_resource/s3_bucket.rb
|
97
|
+
- lib/right_resource/server.rb
|
98
|
+
- lib/right_resource/server_array.rb
|
99
|
+
- lib/right_resource/server_template.rb
|
100
|
+
- lib/right_resource/status.rb
|
101
|
+
- lib/right_resource.rb
|
102
|
+
has_rdoc: true
|
103
|
+
homepage: https://github.com/satsv/rightresource
|
104
|
+
licenses: []
|
105
|
+
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
none: false
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
hash: 61
|
117
|
+
segments:
|
118
|
+
- 1
|
119
|
+
- 8
|
120
|
+
- 5
|
121
|
+
version: 1.8.5
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
+
none: false
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
hash: 3
|
128
|
+
segments:
|
129
|
+
- 0
|
130
|
+
version: "0"
|
131
|
+
requirements:
|
132
|
+
- none
|
133
|
+
rubyforge_project:
|
134
|
+
rubygems_version: 1.3.7
|
135
|
+
signing_key:
|
136
|
+
specification_version: 3
|
137
|
+
summary: "RightResource: RightScale Resource API wrapper"
|
138
|
+
test_files: []
|
139
|
+
|