rightresource 0.2.8 → 0.2.9
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.rdoc +0 -3
- data/lib/right_resource/alert_spec.rb +4 -1
- data/lib/right_resource/base.rb +54 -17
- data/lib/right_resource/core_ext/hash/generate_attributes.rb +11 -0
- data/lib/right_resource/core_ext/hash.rb +1 -0
- data/lib/right_resource/core_ext/object.rb +1 -1
- data/lib/right_resource/deployment.rb +9 -10
- data/lib/right_resource/ec2_ebs_volume.rb +11 -3
- data/lib/right_resource/ec2_elastic_ip.rb +2 -7
- data/lib/right_resource/ec2_ssh_key.rb +1 -3
- data/lib/right_resource/multi_cloud_image.rb +2 -23
- data/lib/right_resource/right_script.rb +2 -23
- data/lib/right_resource/s3_bucket.rb +2 -7
- data/lib/right_resource/server.rb +97 -29
- data/lib/right_resource/server_array.rb +26 -5
- data/lib/right_resource/server_template.rb +4 -1
- data/lib/right_resource/status.rb +2 -27
- data/lib/right_resource/tag.rb +66 -0
- data/lib/right_resource.rb +1 -1
- metadata +7 -4
data/README.rdoc
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
class AlertSpec < RightResource::Base
|
2
2
|
class << self
|
3
3
|
def alert_specs_subject(id, params={})
|
4
|
-
|
4
|
+
pair = URI.decode({:alert_specs_subject => params}.to_params).split('&').map {|l| l.split('=')}
|
5
|
+
h = Hash[*pair.flatten]
|
6
|
+
path = "alert_specs_subject"
|
7
|
+
action(:post, path, h)
|
5
8
|
end
|
6
9
|
end
|
7
10
|
end
|
data/lib/right_resource/base.rb
CHANGED
@@ -20,7 +20,7 @@ module RightResource
|
|
20
20
|
|
21
21
|
# Set RESTFul client with login authentication for HTTP Methods(Low level)
|
22
22
|
# === Examples
|
23
|
-
# conn = Connection.new do |c|
|
23
|
+
# conn = RightResource::Connection.new do |c|
|
24
24
|
# c.login(:username => "user", :password => "pass", :account => "1")
|
25
25
|
# end
|
26
26
|
# Deployment.connection = conn
|
@@ -83,6 +83,27 @@ module RightResource
|
|
83
83
|
connection.resource_id || nil
|
84
84
|
end
|
85
85
|
|
86
|
+
# RestFul Method
|
87
|
+
def action(method, path, params={})
|
88
|
+
case method
|
89
|
+
when :get
|
90
|
+
connection.get(path, params)
|
91
|
+
when :post
|
92
|
+
connection.post(path, params)
|
93
|
+
when :put
|
94
|
+
connection.put(path, params)
|
95
|
+
when :delete
|
96
|
+
connection.delete(path, params)
|
97
|
+
end
|
98
|
+
rescue RestClient::ResourceNotFound
|
99
|
+
nil
|
100
|
+
rescue => e
|
101
|
+
logger.error("#{e.class}: #{e.pretty_inspect}")
|
102
|
+
logger.debug {"Backtrace:\n#{e.backtrace.pretty_inspect}"}
|
103
|
+
ensure
|
104
|
+
logger.debug {"#{__FILE__} #{__LINE__}: #{self.class}\n#{self.pretty_inspect}\n"}
|
105
|
+
end
|
106
|
+
|
86
107
|
# Get resources by index method
|
87
108
|
# same resources support criteria like filtering.
|
88
109
|
#
|
@@ -150,14 +171,30 @@ module RightResource
|
|
150
171
|
end
|
151
172
|
|
152
173
|
# Create new resource
|
153
|
-
#
|
174
|
+
# ==== Parameters
|
175
|
+
#
|
176
|
+
# * +params+ - see Examples
|
177
|
+
#
|
178
|
+
# === Examples
|
154
179
|
# params = {
|
155
|
-
# :
|
156
|
-
# :
|
157
|
-
# :
|
158
|
-
# :
|
180
|
+
# :cloud_id => 4, # {1 = us-east; 2 = eu; 3 = us-west, 4 = ap}
|
181
|
+
# :ec2_image_href => "https://my.rightscale.com/api/acct/22329/multi_cloud_images/40840", # AMI image or MultiCloud image
|
182
|
+
# :nickname =>"dev703", # Instance rightscale nickname
|
183
|
+
# :instance_type => 'm1.xlarge',
|
184
|
+
# :assoicate_eip_at_launch => '0',
|
185
|
+
# :deployment_href => "https://my.rightscale.com/api/acct/22329/deployments/63387",
|
186
|
+
# :ec2_availability_zone=>"ap-southeast-1b", # (ex: 'us-east-1a', 'any')
|
187
|
+
# :ec2_ssh_key_href => "https://my.rightscale.com/api/acct/22329/ec2_ssh_keys/240662",
|
188
|
+
# :ec2_security_group =>
|
189
|
+
# ["https://my.rightscale.com/api/acct/22329/ec2_security_groups/170342",
|
190
|
+
# "https://my.rightscale.com/api/acct/22329/ec2_security_groups/170344",
|
191
|
+
# "https://my.rightscale.com/api/acct/22329/ec2_security_groups/170353"],
|
192
|
+
# :server_template_href => "https://my.rightscale.com/api/acct/22329/ec2_server_templates/82665" # rightscale servertemplate
|
159
193
|
# }
|
160
|
-
# Server.create(params)
|
194
|
+
# server_id = Server.create(params).id
|
195
|
+
# settings = Server.settings(server_id)
|
196
|
+
# p settings
|
197
|
+
#
|
161
198
|
def create(params={})
|
162
199
|
#TODO: refactor
|
163
200
|
self.new(params).tap do |resource|
|
@@ -187,12 +224,12 @@ module RightResource
|
|
187
224
|
|
188
225
|
# Get single resource
|
189
226
|
def element_path(id, prefix_options = nil, query_options = nil)
|
190
|
-
"#{resource_name}s/#{id}#{prefix(prefix_options)}
|
227
|
+
"#{resource_name}s/#{id}#{prefix(prefix_options)}#{query_string(query_options)}"
|
191
228
|
end
|
192
229
|
|
193
230
|
# Get resource collections
|
194
231
|
def collection_path(prefix_options = nil, query_options = nil)
|
195
|
-
"#{resource_name}s#{prefix(prefix_options)}
|
232
|
+
"#{resource_name}s#{prefix(prefix_options)}#{query_string(query_options)}"
|
196
233
|
end
|
197
234
|
|
198
235
|
# Get resource name(equals plural of classname)
|
@@ -233,7 +270,7 @@ module RightResource
|
|
233
270
|
raise ArgumentError, "expected an Hash, String or Symbol, got #{options.pretty_inspect}"
|
234
271
|
end
|
235
272
|
end
|
236
|
-
default
|
273
|
+
"#{default}.#{format.extension}"
|
237
274
|
end
|
238
275
|
|
239
276
|
# create querystring by crack to_params method
|
@@ -271,7 +308,7 @@ module RightResource
|
|
271
308
|
|
272
309
|
def loads(attributes)
|
273
310
|
raise ArgumentError, "expected an attributes Hash, got #{attributes.pretty_inspect}" unless attributes.is_a?(Hash)
|
274
|
-
attributes
|
311
|
+
@attributes = attributes.generate_attributes
|
275
312
|
self
|
276
313
|
end
|
277
314
|
|
@@ -316,18 +353,18 @@ module RightResource
|
|
316
353
|
#TODO: refactor hard coding
|
317
354
|
attrs = self.attributes.reject {|key,value| key.to_s == "cloud_id"}
|
318
355
|
pair = URI.decode({resource_name.to_sym => attrs}.to_params).split('&').map {|l| l.split('=')}
|
319
|
-
|
320
|
-
|
321
|
-
connection.put(element_path,
|
356
|
+
h = Hash[*pair.flatten]
|
357
|
+
h["cloud_id"] = self.attributes[:cloud_id] if self.attributes.has_key?(:cloud_id)
|
358
|
+
connection.put(element_path, h)
|
322
359
|
end
|
323
360
|
|
324
361
|
def create
|
325
362
|
#TODO: refactor hard coding
|
326
363
|
attrs = self.attributes.reject {|key,value| key.to_s == "cloud_id"}
|
327
364
|
pair = URI.decode({resource_name.to_sym => attrs}.to_params).split('&').map {|l| l.split('=')}
|
328
|
-
|
329
|
-
|
330
|
-
connection.post(collection_path,
|
365
|
+
h= Hash[*pair.flatten]
|
366
|
+
h["cloud_id"] = self.attributes[:cloud_id] if self.attributes.has_key?(:cloud_id)
|
367
|
+
connection.post(collection_path, h)
|
331
368
|
self.id = self.class.resource_id
|
332
369
|
end
|
333
370
|
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'right_resource/core_ext/hash/generate_attributes'
|
@@ -1,15 +1,14 @@
|
|
1
|
+
# == Define methods
|
2
|
+
# deployment actions (start_all, stop_all, duplicate)
|
3
|
+
# ==== Parameters
|
4
|
+
# * +id+ - RightScale deployment resource id(https://my.rightscale.com/deployments/{id})
|
1
5
|
class Deployment < RightResource::Base
|
2
6
|
class << self
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
connection.post(element_path(id, :stop_all))
|
9
|
-
end
|
10
|
-
|
11
|
-
def duplicate(id)
|
12
|
-
connection.post(element_path(id, :duplicate))
|
7
|
+
[:start_all, :stop_all, :duplicate].each do |act_method|
|
8
|
+
define_method(act_method) do |id|
|
9
|
+
path = element_path(id, act_method).sub(/\.#{format.extension}$/, '')
|
10
|
+
action(:post, path)
|
11
|
+
end
|
13
12
|
end
|
14
13
|
end
|
15
14
|
end
|
@@ -1,8 +1,16 @@
|
|
1
|
+
# == alias_method
|
2
|
+
# * _attach_to_server_ - component_ec2_ebs_volumes
|
1
3
|
class Ec2EbsVolume < RightResource::Base
|
2
4
|
class << self
|
3
|
-
|
4
|
-
|
5
|
-
|
5
|
+
# Eb2Volume attach to server
|
6
|
+
# === Parameters
|
7
|
+
# * +params+ - Hash (keys = [:ec2_ebs_volume_href, :component_href, :device, :mount])
|
8
|
+
def component_ec2_ebs_volumes(params)
|
9
|
+
pair = URI.decode({:component_ec2_ebs_volume => elems}.to_params).split('&').map {|l| l.split('=')}
|
10
|
+
h = Hash[*pair.flatten]
|
11
|
+
path = "component_ec2_ebs_volumes"
|
12
|
+
action(:post, path, h)
|
6
13
|
end
|
14
|
+
alias_method :attach_to_server, :component_ec2_ebs_volumes
|
7
15
|
end
|
8
16
|
end
|
@@ -1,27 +1,6 @@
|
|
1
1
|
class MultiCloudImage < RightResource::Base
|
2
2
|
class << self
|
3
|
-
|
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
|
3
|
+
undef :create, :update, :destory
|
26
4
|
end
|
5
|
+
undef :create, :update, :destory
|
27
6
|
end
|
@@ -1,27 +1,6 @@
|
|
1
1
|
class RightScript < RightResource::Base
|
2
2
|
class << self
|
3
|
-
|
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
|
3
|
+
undef :create, :update, :destory
|
26
4
|
end
|
5
|
+
undef :create, :update, :destory
|
27
6
|
end
|
@@ -1,48 +1,116 @@
|
|
1
|
+
# == define_methods 1
|
2
|
+
# Server Action
|
3
|
+
# * _start_
|
4
|
+
# * _stop_
|
5
|
+
# * _restart_
|
6
|
+
#
|
7
|
+
# === Parameters
|
8
|
+
# * _id_ - RightScale server resource id(https://my.rightscale.com/servers/{id})
|
9
|
+
# === Examples
|
10
|
+
# server_id = Server.index(:filter => "nickname=dev001").first.id
|
11
|
+
# Server.start(server_id)
|
12
|
+
#
|
13
|
+
# == define_methods 2
|
14
|
+
# Server and other resource action
|
15
|
+
# * _run_script_
|
16
|
+
# * _attach_volume_
|
17
|
+
# === Parameters
|
18
|
+
# * _id_ - RightScale server resource id(https://my.rightscale.com/servers/{id})
|
19
|
+
# * _params_ - Hash(ex. :right_script, :ec2_ebs_volume_href, :device)
|
20
|
+
# === Examples
|
21
|
+
# server_id = 1
|
22
|
+
# params = {:ec2_ebs_volume_href => "https://my.rightscale.com/api/acct/##/ec2_ebs_volumes/1", :device => "/dev/sdj"}
|
23
|
+
# Server.attach_volume(server_id, params) # => 204 No Content
|
1
24
|
class Server < RightResource::Base
|
2
25
|
class << self
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
# Server.start(server_id)
|
9
|
-
def start(id)
|
10
|
-
connection.post(element_path(id, :start))
|
11
|
-
end
|
12
|
-
|
13
|
-
# server stop(Starting created instance)
|
14
|
-
def stop(id)
|
15
|
-
connection.post(element_path(id, :stop))
|
26
|
+
[:start, :stop, :reboot].each do |act_method|
|
27
|
+
define_method(act_method) do |id|
|
28
|
+
path = element_path(id, act_method).sub(/\.#{format.extension}$/, '')
|
29
|
+
action(:post, path)
|
30
|
+
end
|
16
31
|
end
|
17
32
|
|
18
|
-
|
19
|
-
|
20
|
-
|
33
|
+
[:run_script, :attach_volume].each do |act_method|
|
34
|
+
define_method(act_method) do |id,params|
|
35
|
+
elems = params.reject {|key,value| key == :right_script} # select server resource params
|
36
|
+
pair = URI.decode({resource_name.to_sym => elems}.to_params).split('&').map {|l| l.split('=')}
|
37
|
+
h = Hash[*pair.flatten]
|
38
|
+
h["right_script"] = params[:right_script] if params.has_key?(:right_script)
|
39
|
+
path = element_path(id, act_method)
|
40
|
+
action(:post, path, h)
|
41
|
+
end
|
21
42
|
end
|
22
43
|
|
23
|
-
#
|
24
|
-
#
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
44
|
+
# Get sampleing data
|
45
|
+
# === Return
|
46
|
+
# Hash (keys # => [:cf, :start, :vars, :lag_time, :end, :data :avg_lag_time])
|
47
|
+
# === Examples
|
48
|
+
# server_id = 848422
|
49
|
+
# params = {:start => -180, :end => -20, :plugin_name => "cpu-0", :plugin_type => "cpu-idle"}
|
50
|
+
# Server.get_sketchy_data(server_id, params)
|
51
|
+
def get_sketchy_data(id, params)
|
52
|
+
path = element_path(id, :get_sketchy_data, params)
|
53
|
+
format.decode(action(:get, path)).generate_attributes
|
31
54
|
end
|
32
55
|
|
33
|
-
|
34
|
-
|
56
|
+
# Get URL of Server monitoring graph
|
57
|
+
# === Examples
|
58
|
+
# * General Graph
|
59
|
+
# Server.monitoring(1)
|
60
|
+
#
|
61
|
+
# * Custumize Graph
|
62
|
+
# server_id = 1
|
63
|
+
# params = {:graph_name => "cpu-0/cpu-idle", :size => "small", :period => "day", :title => "MyCpuGraph", :tz => "JST"}
|
64
|
+
# Server.monitoring(server_id, params)
|
65
|
+
def monitoring(id, params={})
|
66
|
+
if params[:graph_name]
|
67
|
+
prefix_options = params[:graph_name]
|
68
|
+
params.delete(:graph_name)
|
69
|
+
path = element_path(id, :monitoring => prefix_options)
|
70
|
+
else
|
71
|
+
path = element_path(id, :monitoring)
|
72
|
+
end
|
73
|
+
format.decode(action(:get, path, params)).generate_attributes
|
35
74
|
end
|
36
75
|
|
76
|
+
# Get Server settings(Subresource)
|
77
|
+
# === Examples
|
78
|
+
# server_id = Server.index(:filter => "nickname=dev-001").first.id
|
79
|
+
# settings = Server.settings(server_id)
|
37
80
|
def settings(id)
|
38
81
|
path = element_path(id, :settings)
|
39
|
-
|
82
|
+
format.decode(action(:get, path)).generate_attributes
|
83
|
+
end
|
84
|
+
|
85
|
+
# Get status of any running jobs after calling to the servers resource to run_script
|
86
|
+
# === Parameters
|
87
|
+
# * +resource_ref+ - Hash[:id] or Hash[:href](execute run_script method response location header)
|
88
|
+
# (ex. Location: https://my.rightscale.com/api/acct/##/statuses/{id})
|
89
|
+
# === Examples
|
90
|
+
# server_id = 1
|
91
|
+
# right_script_id = 1
|
92
|
+
# Server.run_script(server_id, :right_script => right_script_id)
|
93
|
+
# # => 201 Created, location: https://my.rightscale.com/api/acct/##/statuses/12345
|
94
|
+
#
|
95
|
+
# Server.statuses(:id => Server.resource_id) if Server.status == 201
|
96
|
+
# or
|
97
|
+
# Server.statuses(:href => Server.headers[:location]) if Server.status == 201
|
98
|
+
def statuses(resource_ref)
|
99
|
+
path = element_path(id, :get_sketchy_data, params)
|
100
|
+
format.decode(action(:get, path)).generate_attributes
|
40
101
|
end
|
41
102
|
|
103
|
+
# Get Server tags(server or ec2_current_instance)
|
104
|
+
# === Parameters
|
105
|
+
# * +resource_href+ - server.href or server.ec2_current_href
|
106
|
+
# === Examples
|
107
|
+
# server = Server.show(1)
|
108
|
+
# tags = Server.tags(server.ec2_current_href)
|
109
|
+
# # => [{"name"=>"rs_login:state=active"}, {"name"=>"rs_logging:state=active"}, {"name"=>"rs_monitoring:state=active"}]
|
42
110
|
def tags(resource_href)
|
43
|
-
query_options = {
|
111
|
+
query_options = {:resource_href => resource_href}
|
44
112
|
path = "tags/search.#{format.extension}#{query_string(query_options)}"
|
45
|
-
Hash[*format.decode(
|
113
|
+
Hash[*format.decode(action(:get, path)).collect {|tag|
|
46
114
|
tag['name'].split('=')
|
47
115
|
}.flatten]
|
48
116
|
end
|
@@ -1,21 +1,42 @@
|
|
1
1
|
class ServerArray < RightResource::Base
|
2
2
|
class << self
|
3
|
+
# server array launch
|
4
|
+
# ==== Parameters
|
5
|
+
# * +id+ - RightScale server array resource id(https://my.rightscale.com/server_arrays/{id})
|
6
|
+
#
|
7
|
+
# === Examples
|
8
|
+
# array_id = 1
|
9
|
+
# ServerArray.launch(array_id)
|
3
10
|
def launch(id)
|
4
|
-
|
11
|
+
path = element_path(id, :launch)
|
12
|
+
action(:post, path)
|
5
13
|
end
|
6
14
|
|
15
|
+
# server array terminate all
|
16
|
+
# === Examples
|
17
|
+
# ServerArray.terminate_all(1)
|
18
|
+
# # => {:ec2_instances=>{"failure"=>[],
|
19
|
+
# "success"=>[{"ec2_instance_href"=>"https://my.rightscale.com/api/acct/##/ec2_instances/1367"}]}}
|
7
20
|
def terminate_all(id)
|
8
|
-
|
21
|
+
path = element_path(id, :terminate_all)
|
22
|
+
format.decode(action(:post, path)).generate_attributes
|
9
23
|
end
|
10
24
|
|
11
|
-
|
25
|
+
# Run script on all
|
26
|
+
# === Exception
|
27
|
+
# * +NotImplementedError+
|
28
|
+
def run_script_on_all(id, params)
|
12
29
|
raise NotImplementedError
|
30
|
+
# pair = URI.decode({resource_name.to_sym => params}.to_params).split('&').map {|l| l.split('=')}
|
31
|
+
# h = Hash[*pair.flatten]
|
32
|
+
# path = element_path(id, :run_script_on_all)
|
33
|
+
# action(:post, path, h)
|
13
34
|
end
|
14
35
|
|
15
36
|
def instances(id)
|
16
37
|
path = element_path(id, :instances)
|
17
|
-
result = format.decode(
|
18
|
-
generate_attributes
|
38
|
+
result = format.decode(action(:get, path)).map do |instance|
|
39
|
+
instance.generate_attributes
|
19
40
|
end
|
20
41
|
end
|
21
42
|
end
|
@@ -1,8 +1,11 @@
|
|
1
1
|
class ServerTemplate < RightResource::Base
|
2
2
|
class << self
|
3
|
+
# === Parameters
|
4
|
+
# * _id_ - ServerTemplate id
|
5
|
+
# * _params_ - Hash (keys = [:phase]) ex. 'boot', 'operational', 'decommission'
|
3
6
|
def executables(id, params={})
|
4
7
|
path = element_path(id, :executables, params)
|
5
|
-
|
8
|
+
format.decode(connection.get(path)).map {|x| x.generate_attributes}
|
6
9
|
end
|
7
10
|
end
|
8
11
|
end
|
@@ -1,31 +1,6 @@
|
|
1
1
|
class Status < RightResource::Base
|
2
2
|
class << self
|
3
|
-
|
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
|
3
|
+
undef :index, :create, :update, :destory
|
30
4
|
end
|
5
|
+
undef :create, :update, :destory
|
31
6
|
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# == define_methods
|
2
|
+
# * _set_
|
3
|
+
# * _unset_
|
4
|
+
# === Examples
|
5
|
+
# Set tags for a resource
|
6
|
+
# ec2_href = Server.show(1).current_instance_href
|
7
|
+
# params = {:resource_href => ec2_href, :tags => ["xx99_server:role=dev", "xx99_server:group=dev"]}
|
8
|
+
# Tag.set(params)
|
9
|
+
# puts Tag.status
|
10
|
+
# p Tag.search(:resource_href => ec2_href)
|
11
|
+
# Unset tags for a resource
|
12
|
+
# Tag.unset(params)
|
13
|
+
# puts Tag.status
|
14
|
+
# p Tag.search(:resource_href => ec2_href)
|
15
|
+
class Tag < RightResource::Base
|
16
|
+
class << self
|
17
|
+
undef :index, :show, :create, :update, :destory
|
18
|
+
|
19
|
+
[:set, :unset].each do |act_method|
|
20
|
+
define_method(act_method) do |params|
|
21
|
+
path = "#{get_tag_resource_path(act_method)}"
|
22
|
+
action(:put, path, params)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Search tags for a resource(resource_href in params) or resources matching giving tags
|
27
|
+
# === Parameters
|
28
|
+
# * +params+ - Hash (keys = [:resource_href or :resource_type, :match_all, :tags])
|
29
|
+
# === Return
|
30
|
+
# Array(tags)
|
31
|
+
# === Examples
|
32
|
+
# Get tags for a resource
|
33
|
+
# Tag.search(:resource_href => "/ec2_instances/1")
|
34
|
+
#
|
35
|
+
# Get resources matching tags
|
36
|
+
# param = {:resource_type => "ec2_instance", :tags => ["x99_db:role=*"]}
|
37
|
+
# servers = Tag.search(p).select {|server| server[:state] == "operational"}.map do |resource|
|
38
|
+
# Server.new(resource)
|
39
|
+
# end
|
40
|
+
#
|
41
|
+
# param = {:resource_type => "ec2_instance", :match_all => 'true', :tags => ["x99_db:role=slave"]}
|
42
|
+
# servers = Tag.search(p).select {|server| server[:state] == "operational"}.map do |resource|
|
43
|
+
# Server.new(resource)
|
44
|
+
# end
|
45
|
+
def search(params)
|
46
|
+
path = "#{get_tag_resource_path("search")}.#{format.extension}#{query_string(params)}"
|
47
|
+
result = format.decode(action(:get, path)).map do |tags|
|
48
|
+
tags.generate_attributes
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# === Examples
|
53
|
+
# Tag.taggable_resources
|
54
|
+
def taggable_resources
|
55
|
+
# "#{self.name.to_s.split('::').last}s/#{__method__}" if RUBY_VERSION >= "1.8.7"
|
56
|
+
path = get_tag_resource_path("taggable_resources")
|
57
|
+
RightResource::Formats::XmlFormat.decode(action(:get, path))
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
def get_tag_resource_path(method_name)
|
62
|
+
"#{self.name.to_s.split('::').last.downcase}s/#{method_name}"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
undef :create, :update, :destory
|
66
|
+
end
|
data/lib/right_resource.rb
CHANGED
@@ -27,7 +27,7 @@ require 'right_resource/ec2_ssh_key'
|
|
27
27
|
require 'right_resource/server_array'
|
28
28
|
require 'right_resource/ec2_ebs_snapshot'
|
29
29
|
require 'right_resource/s3_bucket'
|
30
|
-
|
30
|
+
require 'right_resource/tag'
|
31
31
|
# Design API
|
32
32
|
require 'right_resource/server_template'
|
33
33
|
require 'right_resource/right_script'
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rightresource
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 5
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 9
|
10
|
+
version: 0.2.9
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Satoshi Ohki
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-11-
|
18
|
+
date: 2010-11-15 00:00:00 +09:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -80,6 +80,8 @@ files:
|
|
80
80
|
- lib/right_resource/alert_spec.rb
|
81
81
|
- lib/right_resource/base.rb
|
82
82
|
- lib/right_resource/connection.rb
|
83
|
+
- lib/right_resource/core_ext/hash/generate_attributes.rb
|
84
|
+
- lib/right_resource/core_ext/hash.rb
|
83
85
|
- lib/right_resource/core_ext/object/tap.rb
|
84
86
|
- lib/right_resource/core_ext/object.rb
|
85
87
|
- lib/right_resource/core_ext.rb
|
@@ -101,6 +103,7 @@ files:
|
|
101
103
|
- lib/right_resource/server_array.rb
|
102
104
|
- lib/right_resource/server_template.rb
|
103
105
|
- lib/right_resource/status.rb
|
106
|
+
- lib/right_resource/tag.rb
|
104
107
|
- lib/right_resource.rb
|
105
108
|
has_rdoc: true
|
106
109
|
homepage: https://github.com/satsv/rightresource
|