rightresource 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,463 @@
1
+ === 0.0.1 2010-11-23
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
5
+
6
+ commit dd59bf61c82aad05d90b35c3286cdefb65830277
7
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
8
+ Date: Wed Nov 24 08:58:24 2010 +0900
9
+
10
+ refactor: recursive convert attrs, update method
11
+
12
+ * recursive convert resource attributes
13
+ * update method support
14
+ * add fixtures of resource attributes
15
+
16
+ commit 2cab626e7cf166a62787415261d479b9b2bb31ce
17
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
18
+ Date: Mon Nov 15 02:41:29 2010 +0900
19
+
20
+ refactor: method chain
21
+
22
+ commit b1add55c13950a7f8085f97b9c91216d7a7d07fa
23
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
24
+ Date: Mon Nov 15 01:51:48 2010 +0900
25
+
26
+ versionup: v0.2.9
27
+
28
+ commit c206b7201b88b7864c60b3e5b64192d8ba794523
29
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
30
+ Date: Mon Nov 15 01:42:34 2010 +0900
31
+
32
+ refactor and add: tag resource, undef method
33
+
34
+ core_ext class Hash: generate_attributes(key: String2Symbol and '-'2'_')
35
+ add tag resource api
36
+ refactor: undef not use method
37
+
38
+ commit 716ea66791a7ca9bf284fa2f854258c82d1df6ae
39
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
40
+ Date: Sun Nov 14 15:30:09 2010 +0900
41
+
42
+ add: resource method, base class method: action(RestFul)
43
+
44
+ commit 241c072da738d41fa543b5218093555a66a798ae
45
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
46
+ Date: Sat Nov 13 11:45:40 2010 +0900
47
+
48
+ refactor: remove methods
49
+
50
+ commit cdaba1c34a4605eb4c89504057b9b417bd32f3e7
51
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
52
+ Date: Sat Nov 13 11:41:25 2010 +0900
53
+
54
+ add: action method support
55
+
56
+ commit f546e00d9c35a87324df05d910335d4a8a7d4a1c
57
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
58
+ Date: Fri Nov 12 18:44:02 2010 +0900
59
+
60
+ modified: Resource.create comment
61
+
62
+ commit d7c446c190dcf8a2d78cf74f56826e845dc7f946
63
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
64
+ Date: Fri Nov 12 17:39:43 2010 +0900
65
+
66
+ bug fix: tab, space
67
+
68
+ commit a33ccde253c9a3c8b03db5f393814b7d75f9888a
69
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
70
+ Date: Fri Nov 12 16:24:47 2010 +0900
71
+
72
+ v0.2.6->v0.2.7
73
+
74
+ commit a91118256ed82fc436fcca827eaa95b6b5e1515a
75
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
76
+ Date: Fri Nov 12 16:21:13 2010 +0900
77
+
78
+ add: Search server's tag support
79
+
80
+ Search servers's resource tag(server's href or current instance's href)
81
+ created by Nimai Malle
82
+
83
+ commit b87729b4595f09914110ebe61e9467502ec51b10
84
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
85
+ Date: Wed Nov 10 11:43:01 2010 +0900
86
+
87
+ version up
88
+
89
+ commit d27ae1037c75900c384339ca4e320ecd1e2fb8b2
90
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
91
+ Date: Wed Nov 10 10:49:37 2010 +0900
92
+
93
+ bug fix: format
94
+
95
+ commit 99838b47518bee172be4d649917ebf4744f250f7
96
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
97
+ Date: Wed Nov 10 09:02:39 2010 +0900
98
+
99
+ modified: variable inherit
100
+
101
+ commit be4cedc3556840f6ec25914b86f7579c3736e668
102
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
103
+ Date: Tue Nov 9 22:06:56 2010 +0900
104
+
105
+ bug fix: mistake except api returns array, collect hash
106
+
107
+ commit b46cf20bc72fe2580a46f95fdd1425e03754a01c
108
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
109
+ Date: Tue Nov 9 22:06:21 2010 +0900
110
+
111
+ bug fix: mistake except api returns array, collect hash
112
+
113
+ commit 9e2e4fc1932a5b97a237513356f4bbf673a9fe92
114
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
115
+ Date: Tue Nov 9 21:14:44 2010 +0900
116
+
117
+ bug fix: mistake expect hash of api returns, collect array
118
+
119
+ commit 8b7698d66db112037c338f0d2eb19fb886e36fbd
120
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
121
+ Date: Tue Nov 9 09:39:05 2010 +0900
122
+
123
+ modified: logger level debug -> warn
124
+
125
+ commit 789c239a8df5f385d23eb871b2d739e6ddbb6953
126
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
127
+ Date: Mon Nov 8 22:24:03 2010 +0900
128
+
129
+ version up: v0.2.1 -> v0.2.2
130
+
131
+ commit eebbb4fe3a7608053ae852efb703c5946f120acb
132
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
133
+ Date: Mon Nov 8 22:22:44 2010 +0900
134
+
135
+ modified: add rdoc in gem
136
+
137
+ commit b916804a3dd3e123ba1be9f35d6562d69d6b8c9e
138
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
139
+ Date: Mon Nov 8 19:56:38 2010 +0900
140
+
141
+ modified: convert subresources hash key string2symbol
142
+
143
+ commit 61e1bea412912a3833f8dee9327fd050a9e188b5
144
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
145
+ Date: Mon Nov 8 15:46:18 2010 +0900
146
+
147
+ bug fix: method, rdoc commentout
148
+
149
+ commit 779ab906e6b6da686312472e6f95e401d2221a3c
150
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
151
+ Date: Mon Nov 8 11:55:02 2010 +0900
152
+
153
+ bug fix: gems name mistake
154
+
155
+ commit 2e01389ef942886ab3fddc4644d419b6d4acc009
156
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
157
+ Date: Mon Nov 8 11:48:02 2010 +0900
158
+
159
+ bug fix: gems name mistake
160
+
161
+ commit 5c52c7e1c68dc16439e0f474f96a558909300994
162
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
163
+ Date: Mon Nov 8 10:24:42 2010 +0900
164
+
165
+ modified: when create resource, except modified cloud_id
166
+
167
+ commit f15a75f72ea9a46650710b813af6ac901dacdfc2
168
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
169
+ Date: Mon Nov 8 10:24:03 2010 +0900
170
+
171
+ modified: when create resource, except modified cloud_id
172
+
173
+ commit 07a8076ca9e7e96a8afb1d78d9bdad9791c3d1e2
174
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
175
+ Date: Mon Nov 8 09:33:01 2010 +0900
176
+
177
+ modified: support create, update method and bug fix
178
+
179
+ commit 68e3311ec100f324604780c86acbcb062731104d
180
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
181
+ Date: Mon Nov 8 01:06:40 2010 +0900
182
+
183
+ add: license paragraph, rename README
184
+
185
+ commit 28bd894a086b37db7ef7d70629c482d8f7aa960b
186
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
187
+ Date: Sun Nov 7 17:14:47 2010 +0900
188
+
189
+ modified: Rakefile, add tags(ctag) ignore
190
+
191
+ commit 59d47437af3ec0cc30dfe3962b2e047b28910d59
192
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
193
+ Date: Sun Nov 7 13:49:31 2010 +0900
194
+
195
+ modified: change rdoc template, gem_spec
196
+
197
+ rdoc template: sdoc
198
+ gem spec: add dependency, homepage
199
+
200
+ commit c1ff829ce7f3c0c7490eb44096d156bdf5d443df
201
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
202
+ Date: Sun Nov 7 13:47:58 2010 +0900
203
+
204
+ modified: remove pp
205
+
206
+ commit 26d3c47926c470f7ff59b85eb18048a5521a7a9a
207
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
208
+ Date: Sun Nov 7 02:37:49 2010 +0900
209
+
210
+ modified: ignore rdoc, gem package, rake rdoc task
211
+
212
+ commit 333ff220e8b23e1c84d64ed49a5b4249455d0cad
213
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
214
+ Date: Sat Nov 6 22:11:55 2010 +0900
215
+
216
+ modified: version string freeze
217
+
218
+ commit ee0f54b418407c0d5b47ca95325b61ca21765be9
219
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
220
+ Date: Sat Nov 6 21:39:38 2010 +0900
221
+
222
+ add: require class[logger, pp]
223
+
224
+ commit 9fdf9ceb21b4a6afbb048409e4f9970bfd3a1679
225
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
226
+ Date: Fri Nov 5 19:45:19 2010 +0900
227
+
228
+ add: refactor
229
+
230
+ commit 57bb16f2eb05204451c33bfa7279f91d52b899b2
231
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
232
+ Date: Fri Nov 5 09:23:49 2010 +0900
233
+
234
+ remove file
235
+
236
+ commit 88c2967f94153efeaeca8c228442f8d97a9d80c4
237
+ Merge: 3589cb8 5b828d3
238
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
239
+ Date: Fri Nov 5 09:20:55 2010 +0900
240
+
241
+ refactor and merge core_ext
242
+
243
+ commit 5b828d35d4ea6dec7631e590cda28913692f5f3f
244
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
245
+ Date: Thu Nov 4 21:03:40 2010 +0900
246
+
247
+ add: core_ext
248
+
249
+ commit 42dc61051ed11387601b9784cb57a544eca151a8
250
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
251
+ Date: Thu Nov 4 19:03:24 2010 +0900
252
+
253
+ add: core_ext.rb
254
+
255
+ commit 9fe0b4c667964d7f843daf2042d218a02908e15d
256
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
257
+ Date: Thu Nov 4 18:57:49 2010 +0900
258
+
259
+ add: tap method[ruby version < 1.9]
260
+
261
+ commit 380247af7cc6fb245d86b8d1cc73ce06ae536afd
262
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
263
+ Date: Thu Nov 4 16:43:35 2010 +0900
264
+
265
+ yield self
266
+
267
+ commit 3589cb8714651238b2476887a0837c10639c4f53
268
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
269
+ Date: Sun Oct 31 15:47:09 2010 +0900
270
+
271
+ modified: require rubygems line moved
272
+
273
+ commit 423b213c07790437efab7df2d45d59b9129eb710
274
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
275
+ Date: Sun Oct 31 15:37:18 2010 +0900
276
+
277
+ modified: require rubygems line moved
278
+
279
+ commit 218b8b4e725abf9587c6fd8e7f971d1f0e3d8cb0
280
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
281
+ Date: Fri Oct 29 16:56:36 2010 +0900
282
+
283
+ add: new resource
284
+
285
+ commit 604c0253080c7f413a6604832b14e83ce707dd63
286
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
287
+ Date: Fri Oct 29 09:00:57 2010 +0900
288
+
289
+ work temporary
290
+
291
+ commit 3aa0346177961835477556fe49de2a1528c8d907
292
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
293
+ Date: Thu Oct 28 16:11:59 2010 +0900
294
+
295
+ version up gem: 0.1.3
296
+
297
+ commit c8b69bafb25444c1b1c6073c67ba049430938db8
298
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
299
+ Date: Thu Oct 28 16:11:16 2010 +0900
300
+
301
+ versionup
302
+
303
+ commit d849c4772e4a66fff45a794d84832bcfab97cb50
304
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
305
+ Date: Thu Oct 28 16:09:42 2010 +0900
306
+
307
+ modified: resource action methods support, add: new resource support
308
+
309
+ commit 31dbd90d8a156cd157889f301ddf0d4f13a3c6da
310
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
311
+ Date: Wed Oct 27 18:08:15 2010 +0900
312
+
313
+ modified: version up
314
+
315
+ commit 57bc0d37597cee69f30ddba0bc064cb4f4075d49
316
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
317
+ Date: Wed Oct 27 17:47:30 2010 +0900
318
+
319
+ modified: set fileformat
320
+
321
+ commit 6f3cd28a2f77d8f8af61fd6d8655aba9f3ae9c08
322
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
323
+ Date: Mon Oct 25 21:38:34 2010 +0900
324
+
325
+ bug fix: future method: __method__ in v1.8.5
326
+
327
+ commit 0134f9b10bfe6a81180227a2748f43b53238028d
328
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
329
+ Date: Mon Oct 25 15:48:10 2010 +0900
330
+
331
+ Modified: changelog
332
+
333
+ commit badcf624cb6a23d15376eb4f823d576749f169e0
334
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
335
+ Date: Mon Oct 25 15:45:29 2010 +0900
336
+
337
+ bug fix: centos5.4 older ruby version unsupported method
338
+
339
+ commit 885ac3a4b65d5d30b3dbd3a49f881622d2aaf05f
340
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
341
+ Date: Mon Oct 25 02:48:57 2010 +0900
342
+
343
+ modified: return self in server_array#instances for method chain
344
+
345
+ commit 3c786aa835b932847905011077114424aac1449d
346
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
347
+ Date: Mon Oct 25 01:30:44 2010 +0900
348
+
349
+ refactor: require packages
350
+
351
+ commit 2727106d0b8da35d0fbdbb22c8ee9a079e2ff29d
352
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
353
+ Date: Mon Oct 25 01:14:54 2010 +0900
354
+
355
+ bug fix: path
356
+
357
+ commit 82d890712462641a994218ec465536f8e982ce2d
358
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
359
+ Date: Mon Oct 25 01:04:11 2010 +0900
360
+
361
+ Removed: oldfile
362
+
363
+ commit fbb08ecd98bbff3f175abef37e638511a33c4be8
364
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
365
+ Date: Mon Oct 25 01:03:03 2010 +0900
366
+
367
+ Add: Gem package files
368
+
369
+ commit 80ed530ecc702592a322d9dccc1b4d371c8fd282
370
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
371
+ Date: Mon Oct 25 01:01:31 2010 +0900
372
+
373
+ modified: version removed
374
+
375
+ commit ad32eecc7696eaf83fdb9d36fbc9cb11f692cc0d
376
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
377
+ Date: Mon Oct 25 01:00:17 2010 +0900
378
+
379
+ modified: rdoc author removed
380
+
381
+ commit 304b5a8adba3666528189844b611f474e09f58f8
382
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
383
+ Date: Mon Oct 25 00:41:32 2010 +0900
384
+
385
+ Add: library's git ignore
386
+
387
+ commit 1cf40878bbec32276548643a128bee222dadfaa8
388
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
389
+ Date: Mon Oct 25 00:09:45 2010 +0900
390
+
391
+ remove testcode from git
392
+
393
+ commit 5275ce543458d7f8152b8f67f2639ee441e3b40f
394
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
395
+ Date: Mon Oct 25 00:07:55 2010 +0900
396
+
397
+ test directory ignore
398
+
399
+ commit 67ef25b9db2ecb7f82fd19491d111a5f457a8439
400
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
401
+ Date: Sun Oct 24 23:43:26 2010 +0900
402
+
403
+ Add: format processor
404
+
405
+ commit b3fa7b84f7a17608ebd45236bb07650c129ff657
406
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
407
+ Date: Sun Oct 24 21:44:00 2010 +0900
408
+
409
+ bug fix: matchobject.to_s
410
+
411
+ commit 4b9f9e9be62ffc16bdc7a4b2a057a664ed68a736
412
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
413
+ Date: Sun Oct 24 16:34:18 2010 +0900
414
+
415
+ Add: require file
416
+
417
+ commit 2a0c86ae94cd2ab226083d6348de2282163b6f4a
418
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
419
+ Date: Sun Oct 24 15:14:06 2010 +0900
420
+
421
+ Add: deployments API
422
+
423
+ commit c09397ebc384163da1c057cb26285ea6e68bf5b9
424
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
425
+ Date: Sun Oct 24 14:57:56 2010 +0900
426
+
427
+ Modified: Split Child class to new file
428
+
429
+ commit 5c9eb46b61e1b5d329c70498e18a2f672ad1e72d
430
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
431
+ Date: Sun Oct 24 14:53:16 2010 +0900
432
+
433
+ Add: server subresource
434
+
435
+ commit 32ba81fd72a083854f5f57e7deb408315a1601a8
436
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
437
+ Date: Sun Oct 24 14:52:55 2010 +0900
438
+
439
+ Add: server subresource
440
+
441
+ commit 0807bc50ac59d185d1c634e8af7221572273f6bb
442
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
443
+ Date: Sun Oct 24 12:04:16 2010 +0900
444
+
445
+ Add: alert specifications
446
+
447
+ commit 4652139b64d1ce26be444063907b25b17180fa0d
448
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
449
+ Date: Sun Oct 24 11:52:31 2010 +0900
450
+
451
+ Add: package include module and class file
452
+
453
+ commit 1098221342df77d6a12ea5cfabe84bdc208112e4
454
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
455
+ Date: Sun Oct 24 10:55:27 2010 +0900
456
+
457
+ move libfile to directory
458
+
459
+ commit e30dfd47a4c37f68a28fb03d523174ee5131159a
460
+ Author: Satoshi Ohki <roothybrid7@gmail.com>
461
+ Date: Sun Oct 24 10:51:48 2010 +0900
462
+
463
+ rename package
data/README.rdoc CHANGED
@@ -1,13 +1,50 @@
1
- = RightScale Resource API wrapper
1
+ = right_resource
2
2
 
3
- == Lisence
4
- Author:: Satoshi Ohki <_roothybrid7_@_gmail.com_>
5
- Copyright:: Copyright (c) 2010 Satoshi Ohki
6
- License:: The MIT License
3
+ * http://github.com/#{github_username}/#{project_name}
7
4
 
8
- == Require packages
5
+ == DESCRIPTION:
6
+
7
+ RightScale Resource API wrapper
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * list of features or problems
12
+
13
+ == SYNOPSIS:
14
+
15
+
16
+ == REQUIREMENTS:
17
+
18
+ * list of requirements
9
19
  json
10
- rest_client
20
+ rest-client
11
21
  crack
12
22
 
13
- == example
23
+ == INSTALL:
24
+
25
+ * sudo gem install rightresource
26
+
27
+ == LICENSE:
28
+
29
+ (The MIT License)
30
+
31
+ Copyright (c) 2010 Satoshi Ohki
32
+
33
+ Permission is hereby granted, free of charge, to any person obtaining
34
+ a copy of this software and associated documentation files (the
35
+ 'Software'), to deal in the Software without restriction, including
36
+ without limitation the rights to use, copy, modify, merge, publish,
37
+ distribute, sublicense, and/or sell copies of the Software, and to
38
+ permit persons to whom the Software is furnished to do so, subject to
39
+ the following conditions:
40
+
41
+ The above copyright notice and this permission notice shall be
42
+ included in all copies or substantial portions of the Software.
43
+
44
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
45
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
46
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
47
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
48
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
49
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
50
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,5 +1,7 @@
1
1
  module RightResource
2
2
  class Base
3
+ @@non_rs_params = [:cloud_id,] # Non RightScale parameters(ex. ec2 api request parameters)
4
+
3
5
  class << self # Define singleton methods
4
6
  # Set Logger object
5
7
  # === Examples
@@ -74,8 +76,8 @@ module RightResource
74
76
  end
75
77
 
76
78
  # Get response status code
77
- def status
78
- connection.status || nil
79
+ def status_code
80
+ connection.status_code || nil
79
81
  end
80
82
 
81
83
  # Get resource id in response location header via RESTFul client(create only?)
@@ -95,11 +97,10 @@ module RightResource
95
97
  when :delete
96
98
  connection.delete(path, params)
97
99
  end
98
- rescue RestClient::ResourceNotFound
99
- nil
100
100
  rescue => e
101
101
  logger.error("#{e.class}: #{e.pretty_inspect}")
102
102
  logger.debug {"Backtrace:\n#{e.backtrace.pretty_inspect}"}
103
+ nil
103
104
  ensure
104
105
  logger.debug {"#{__FILE__} #{__LINE__}: #{self.class}\n#{self.pretty_inspect}\n"}
105
106
  end
@@ -135,12 +136,15 @@ module RightResource
135
136
  def index(params = {})
136
137
  path = "#{resource_name}s.#{format.extension}#{query_string(params)}"
137
138
  connection.clear
138
- instantiate_collection(format.decode(connection.get(path || [])))
139
- rescue RestClient::ResourceNotFound
140
- nil
139
+ result = format.decode(connection.get(path || [])).map do |resource|
140
+ correct_attributes(resource)
141
+ resource
142
+ end
143
+ instantiate_collection(result)
141
144
  rescue => e
142
145
  logger.error("#{e.class}: #{e.pretty_inspect}")
143
146
  logger.debug {"Backtrace:\n#{e.backtrace.pretty_inspect}"}
147
+ []
144
148
  ensure
145
149
  logger.debug {"#{__FILE__} #{__LINE__}: #{self.class}\n#{self.pretty_inspect}\n"}
146
150
  end
@@ -160,12 +164,16 @@ module RightResource
160
164
  def show(id, params = {})
161
165
  path = element_path(id, nil, params)
162
166
  connection.clear
163
- instantiate_record(format.decode(connection.get(path)))
164
- rescue RestClient::ResourceNotFound
165
- nil
167
+ result = format.decode(connection.get(path)).tap do |resource|
168
+ correct_attributes(resource)
169
+ resource[:id] = resource[:href].match(/[0-9]+$/).to_s.to_i
170
+ resource
171
+ end
172
+ instantiate_record(result)
166
173
  rescue => e
167
174
  logger.error("#{e.class}: #{e.pretty_inspect}")
168
175
  logger.debug {"Backtrace:\n#{e.backtrace.pretty_inspect}"}
176
+ nil
169
177
  ensure
170
178
  logger.debug {"#{__FILE__} #{__LINE__}: #{self.class}\n#{self.pretty_inspect}\n"}
171
179
  end
@@ -178,38 +186,35 @@ module RightResource
178
186
  # === Examples
179
187
  # params = {
180
188
  # :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
189
+ # :ec2_image_href => "https://my.rightscale.com/api/acct/###/multi_cloud_images/40840", # AMI image or MultiCloud image
182
190
  # :nickname =>"dev703", # Instance rightscale nickname
183
191
  # :instance_type => 'm1.xlarge',
184
192
  # :assoicate_eip_at_launch => '0',
185
- # :deployment_href => "https://my.rightscale.com/api/acct/22329/deployments/63387",
193
+ # :deployment_href => "https://my.rightscale.com/api/acct/###/deployments/63387",
186
194
  # :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",
195
+ # :ec2_ssh_key_href => "https://my.rightscale.com/api/acct/###/ec2_ssh_keys/240662",
188
196
  # :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
197
+ # ["https://my.rightscale.com/api/acct/###/ec2_security_groups/170342",
198
+ # "https://my.rightscale.com/api/acct/###/ec2_security_groups/170344",
199
+ # "https://my.rightscale.com/api/acct/###/ec2_security_groups/170353"],
200
+ # :server_template_href => "https://my.rightscale.com/api/acct/###/ec2_server_templates/82665" # rightscale servertemplate
193
201
  # }
194
202
  # server_id = Server.create(params).id
195
203
  # settings = Server.settings(server_id)
196
204
  # p settings
197
205
  #
198
206
  def create(params={})
199
- #TODO: refactor
200
207
  self.new(params).tap do |resource|
201
208
  resource.save
202
209
  end
203
- # path = collection_path
204
- # connection.post(path, params)
205
210
  end
206
211
 
207
212
  # Update resource
208
- def update(id, params={})
209
- #TODO: refactor
210
- path = element_path(id)
211
- connection.put(path, params)
212
- end
213
+ # def update(id, params={})
214
+ # #TODO: refactor
215
+ # path = element_path(id)
216
+ # connection.put(path, params)
217
+ # end
213
218
 
214
219
  # Delete resource
215
220
  # Example:
@@ -245,11 +250,31 @@ module RightResource
245
250
  name
246
251
  end
247
252
 
248
- def generate_attributes(attributes)
249
- raise ArgumentError, "expected an attributes Hash, got #{attributes.pretty_inspect}" unless attributes.is_a?(Hash)
250
- attrs = {}
251
- attributes.each_pair {|key,value| attrs[key.to_s.gsub('-', '_').to_sym] = value}
252
- attrs
253
+ # Correct attributes(Correct hash keys recursively)
254
+ # '-'(dash) is included but not '_'(under score) in AWS Parameter keys.
255
+ # On the other hand '_'(under score) is included in RightScale Parameter keys
256
+ # e.g. Hash["ip-address"] -> Hash[:ip_address], Hash["deployment_href"] -> Hash[:deployment_href]
257
+ def correct_attributes(attributes)
258
+ return unless attributes.is_a?(Hash)
259
+
260
+ attributes.alter_keys
261
+ attributes.each do |key,value| # recursive
262
+ attributes[key] =
263
+ case value
264
+ when Array
265
+ value.map do |attrs|
266
+ if attrs.is_a?(Hash)
267
+ correct_attributes(attrs)
268
+ else
269
+ attrs.dup rescue attrs
270
+ end
271
+ end
272
+ when Hash
273
+ correct_attributes(value)
274
+ else
275
+ value.dup rescue value
276
+ end
277
+ end
253
278
  end
254
279
 
255
280
  protected
@@ -289,11 +314,34 @@ module RightResource
289
314
  end
290
315
  end
291
316
 
317
+ attr_accessor :id, :attributes
318
+
319
+ # If no schema has been defined for the class (see
320
+ # <tt>ActiveResource::schema=</tt>), the default automatic schema is
321
+ # generated from the current instance's attributes
322
+ def schema
323
+ # self.class.schema || self.attributes
324
+ end
325
+
326
+ # This is a list of known attributes for this resource. Either
327
+ # gathered from the provided <tt>schema</tt>, or from the attributes
328
+ # set on this instance after it has been fetched from the remote system.
329
+ def known_attributes
330
+ # self.class.known_attributes + self.attributes.keys.map(&:to_s)
331
+ end
332
+
333
+ # Duplicate resource
334
+ def dup
335
+ self.class.new.tap do |resource|
336
+ resource.attributes = @attributes.reject {|key,value| key == :href}
337
+ resource.load_accessor(resource.attributes)
338
+ end
339
+ end
340
+
292
341
  def initialize(attributes={})
293
342
  # sub-resource4json's key name contains '-'
294
- # attrs = generate_attributes(attributes)
295
343
  @attributes = {}
296
- loads(attributes)
344
+ load_attributes(attributes)
297
345
  if @attributes
298
346
  if self.class.resource_id.nil?
299
347
  @id = @attributes[:href].match(/\d+$/).to_s if @attributes[:href]
@@ -304,16 +352,15 @@ module RightResource
304
352
  end
305
353
  yield self if block_given?
306
354
  end
307
- attr_accessor :id, :attributes
308
355
 
309
- def loads(attributes)
356
+ def load_attributes(attributes)
310
357
  raise ArgumentError, "expected an attributes Hash, got #{attributes.pretty_inspect}" unless attributes.is_a?(Hash)
311
- @attributes = attributes.generate_attributes
358
+ @attributes = self.class.correct_attributes(attributes)
312
359
  self
313
360
  end
314
361
 
315
362
  def update_attributes(attributes)
316
- loads(attributes) && load_accessor(attributes) && save
363
+ load_attributes(attributes) && load_accessor(attributes) && save
317
364
  end
318
365
 
319
366
  def load_accessor(attributes)
@@ -344,28 +391,48 @@ module RightResource
344
391
  connection.delete(element_path)
345
392
  end
346
393
 
394
+ # For checking <tt>respond_to?</tt> without searching the attributes (which is faster).
395
+ alias_method :respond_to_without_attributes?, :respond_to?
396
+
397
+ # A method to determine if an object responds to a message (e.g., a method call). In Active Resource, a Person object with a
398
+ # +name+ attribute can answer <tt>true</tt> to <tt>my_person.respond_to?(:name)</tt>, <tt>my_person.respond_to?(:name=)</tt>, and
399
+ # <tt>my_person.respond_to?(:name?)</tt>.
400
+ def respond_to?(method, include_priv = false)
401
+ method_name = method.to_s
402
+ if attributes.nil?
403
+ super
404
+ # elsif known_attributes.include?(method_name)
405
+ # true
406
+ elsif method_name =~ /(?:=|\?)$/ && attributes.include?($`)
407
+ true
408
+ else
409
+ # super must be called at the end of the method, because the inherited respond_to?
410
+ # would return true for generated readers, even if the attribute wasn't present
411
+ super
412
+ end
413
+ end
414
+
347
415
  protected
348
416
  def connection
349
417
  self.class.connection
350
418
  end
351
419
 
352
420
  def update
353
- #TODO: refactor hard coding
354
- attrs = self.attributes.reject {|key,value| key.to_s == "cloud_id"}
421
+ attrs = self.attributes.reject {|key,value| @@non_rs_params.include?(key.to_sym) || value.nil?}
355
422
  pair = URI.decode({resource_name.to_sym => attrs}.to_params).split('&').map {|l| l.split('=')}
356
423
  h = Hash[*pair.flatten]
357
- h["cloud_id"] = self.attributes[:cloud_id] if self.attributes.has_key?(:cloud_id)
424
+ @@non_rs_params.each {|key| h[key.to_s] = self.attributes[key] if self.attributes.has_key?(key) && self.attributes[key]}
358
425
  connection.put(element_path, h)
359
426
  end
360
427
 
361
428
  def create
362
- #TODO: refactor hard coding
363
- attrs = self.attributes.reject {|key,value| key.to_s == "cloud_id"}
429
+ attrs = self.attributes.reject {|key,value| @@non_rs_params.include?(key.to_sym) || value.nil?}
364
430
  pair = URI.decode({resource_name.to_sym => attrs}.to_params).split('&').map {|l| l.split('=')}
365
431
  h= Hash[*pair.flatten]
366
- h["cloud_id"] = self.attributes[:cloud_id] if self.attributes.has_key?(:cloud_id)
432
+ @@non_rs_params.each {|key| h[key.to_s] = self.attributes[key] if self.attributes.has_key?(key) && self.attributes[key]}
367
433
  connection.post(collection_path, h)
368
434
  self.id = self.class.resource_id
435
+ self.href = self.class.headers[:location]
369
436
  end
370
437
 
371
438
  def resource_name
@@ -379,5 +446,24 @@ module RightResource
379
446
  def collection_path(prefix_options=nil, query_options=nil)
380
447
  self.class.collection_path(prefix_options, query_options)
381
448
  end
449
+
450
+ private
451
+ def method_missing(method_symbol, *arguments) #:nodoc:
452
+ method_name = method_symbol.to_s
453
+
454
+ if method_name =~ /(=|\?)$/
455
+ case $1
456
+ when "="
457
+ attributes[$`.to_sym] = arguments.first
458
+ when "?"
459
+ attributes[$`.to_sym]
460
+ end
461
+ else
462
+ return attributes[method_symbol] if attributes.include?(method_symbol)
463
+ # not set right now but we know about it
464
+ # return nil if known_attributes.include?(method_name)
465
+ super
466
+ end
467
+ end
382
468
  end
383
469
  end
@@ -1,14 +1,13 @@
1
1
  module RightResource
2
2
  class Connection
3
- @reraise = false
4
-
5
- attr_accessor :api_version, :log, :api, :format, :username, :password, :account, :reraise, :logger
6
- attr_reader :headers, :resource_id, :response, :status
3
+ attr_accessor :api_version, :log, :url, :api, :format, :username, :password, :account, :logger
4
+ attr_reader :headers, :resource_id, :response, :status_code, :timeout, :open_timeout
7
5
 
8
6
  # Set RestFul Client Parameters
9
7
  def initialize(params={})
10
8
  @api_version = API_VERSION
11
- @api = "https://my.rightscale.com/api/acct/"
9
+ @url = params[:url] || "https://my.rightscale.com"
10
+ @api = "#{@url}/api/acct/"
12
11
  @format = params[:format] || RightResource::Formats::JsonFormat
13
12
  @logger = params[:logger] || Logger.new(STDERR).tap {|l| l.level = Logger::WARN}
14
13
  RestClient.log = STDERR if @logger.level == Logger::DEBUG # HTTP request/response log
@@ -21,14 +20,16 @@ module RightResource
21
20
  # conn = Connection.new
22
21
  # conn.login(params)
23
22
  def login(params={})
24
- @username = params[:username] unless params[:username].nil? || params[:username].empty?
25
- @password = params[:password] unless params[:password].nil? || params[:password].empty?
26
- @account = params[:account] unless params[:account].nil? || params[:account].empty?
27
- @api_object = RestClient::Resource.new("#{@api}#{@account}", @username, @password)
23
+ @username = params[:username] if params[:username]
24
+ @password = params[:password] if params[:password]
25
+ @account = params[:account] if params[:account]
26
+ @open_timeout = params[:open_timeout] || 10 # Connection.timeout
27
+ @timeout = params[:timeout] || 60 # Response.read.timeout
28
+ req_opts = {:user => @username, :password => @password, :open_timeout => @open_timeout, :timeout => @timeout}
29
+ @api_object = RestClient::Resource.new("#{@api}#{@account}", req_opts)
28
30
  rescue => e
29
31
  @logger.error("#{e.class}: #{e.pretty_inspect}")
30
32
  @logger.debug {"Backtrace:\n#{e.backtrace.pretty_inspect}"}
31
- raise if self.reraise
32
33
  ensure
33
34
  @logger.debug {"#{__FILE__} #{__LINE__}: #{self.class}\n#{self.pretty_inspect}\n"}
34
35
  end
@@ -51,24 +52,24 @@ module RightResource
51
52
  raise "Invalid Action: get|put|post|delete only"
52
53
  end
53
54
  api_version = {:x_api_version => @api_version, :api_version => @api_version}
54
-
55
- @response = @api_object[path].send(method.to_sym, api_version.merge(headers))
56
- @status = @response.code
55
+ @response = @api_object[path].__send__(method.to_sym, api_version.merge(headers))
56
+ @status_code = @response.code
57
57
  @headers = @response.headers
58
58
  @resource_id = @headers[:location].match(/\d+$/).to_s unless @headers[:location].nil?
59
59
  @response.body
60
+ rescue Timeout::Error => e
61
+ raise TimeoutError.new(e.message)
60
62
  rescue => e
61
- @status = e.http_code
63
+ @status_code = e.http_code
62
64
  @logger.error("#{e.class}: #{e.pretty_inspect}")
63
65
  @logger.debug {"Backtrace:\n#{e.backtrace.pretty_inspect}"}
64
- raise if self.reraise
65
66
  ensure
66
67
  @logger.debug {"#{__FILE__} #{__LINE__}: #{self.class}\n#{self.pretty_inspect}\n"}
67
68
  end
68
69
 
69
70
  # Resource clear
70
71
  def clear
71
- @response = @headers = @resource_id = @status = nil
72
+ @response = @headers = @resource_id = @status_code = nil
72
73
  ensure
73
74
  @logger.debug {"#{__FILE__} #{__LINE__}: #{self.class}\n#{self.pretty_inspect}\n"}
74
75
  end
@@ -1,8 +1,8 @@
1
1
  class Hash
2
- def generate_attributes
2
+ def alter_keys
3
3
  attrs = {}
4
4
  self.each_pair {|key,value| attrs[key.to_s.gsub('-', '_').to_sym] = value}
5
- self.clear.merge!(attrs) if attrs
5
+ self.clear.merge!(attrs).rehash if attrs
6
6
  self
7
7
  end
8
8
  end
@@ -1 +1 @@
1
- require 'right_resource/core_ext/hash/generate_attributes'
1
+ require 'right_resource/core_ext/hash/alter_keys'
@@ -6,7 +6,7 @@ class Deployment < RightResource::Base
6
6
  class << self
7
7
  [:start_all, :stop_all, :duplicate].each do |act_method|
8
8
  define_method(act_method) do |id|
9
- path = element_path(id, act_method).sub(/\.#{format.extension}$/, '')
9
+ path = element_path(id, act_method).sub(/\.#{format.extension}$/, '') # response empty and format xml only
10
10
  action(:post, path)
11
11
  end
12
12
  end
@@ -1,6 +1,3 @@
1
1
  class Ec2ElasticIp < RightResource::Base
2
- class << self
3
- undef :update
4
- end
5
2
  undef :update
6
3
  end
@@ -1,5 +1,3 @@
1
- require 'json/pure'
2
-
3
1
  module RightResource
4
2
  module Formats
5
3
  module JsonFormat
@@ -1,5 +1,3 @@
1
- require 'crack/xml'
2
-
3
1
  module RightResource
4
2
  module Formats
5
3
  module XmlFormat
@@ -17,8 +15,8 @@ module RightResource
17
15
  raise NotImplementedError, "Not Implementated function #{self.class.name}::#{__method__.to_s}"
18
16
  end
19
17
 
20
- def decode(json)
21
- Crack::XML.parse(json)
18
+ def decode(xml)
19
+ Crack::XML.parse(xml)
22
20
  end
23
21
  end
24
22
  end
@@ -1,6 +1,6 @@
1
1
  class MultiCloudImage < RightResource::Base
2
2
  class << self
3
- undef :create, :update, :destory
3
+ undef :create, :destory
4
4
  end
5
5
  undef :create, :update, :destory
6
6
  end
@@ -1,6 +1,6 @@
1
1
  class RightScript < RightResource::Base
2
2
  class << self
3
- undef :create, :update, :destory
3
+ undef :create, :destory
4
4
  end
5
5
  undef :create, :update, :destory
6
6
  end
@@ -1,6 +1,3 @@
1
1
  class S3Bucket < RightResource::Base
2
- class << self
3
- undef :update
4
- end
5
2
  undef :update
6
3
  end
@@ -25,7 +25,7 @@ class Server < RightResource::Base
25
25
  class << self
26
26
  [:start, :stop, :reboot].each do |act_method|
27
27
  define_method(act_method) do |id|
28
- path = element_path(id, act_method).sub(/\.#{format.extension}$/, '')
28
+ path = element_path(id, act_method).sub(/\.#{format.extension}$/, '') # can't include json extension in request
29
29
  action(:post, path)
30
30
  end
31
31
  end
@@ -50,7 +50,7 @@ class Server < RightResource::Base
50
50
  # Server.get_sketchy_data(server_id, params)
51
51
  def get_sketchy_data(id, params)
52
52
  path = element_path(id, :get_sketchy_data, params)
53
- format.decode(action(:get, path)).generate_attributes
53
+ format.decode(action(:get, path)).tap {|resource| correct_attributes(resource)}
54
54
  end
55
55
 
56
56
  # Get URL of Server monitoring graph
@@ -70,7 +70,7 @@ class Server < RightResource::Base
70
70
  else
71
71
  path = element_path(id, :monitoring)
72
72
  end
73
- format.decode(action(:get, path, params)).generate_attributes
73
+ format.decode(action(:get, path, params)).tap {|resource| correct_attributes(resource)}
74
74
  end
75
75
 
76
76
  # Get Server settings(Subresource)
@@ -79,25 +79,7 @@ class Server < RightResource::Base
79
79
  # settings = Server.settings(server_id)
80
80
  def settings(id)
81
81
  path = element_path(id, :settings)
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
82
+ format.decode(action(:get, path)).tap {|resource| correct_attributes(resource)}
101
83
  end
102
84
 
103
85
  # Get Server tags(server or ec2_current_instance)
@@ -106,7 +88,7 @@ class Server < RightResource::Base
106
88
  # === Examples
107
89
  # server = Server.show(1)
108
90
  # tags = Server.tags(server.ec2_current_href)
109
- # # => [{"name"=>"rs_login:state=active"}, {"name"=>"rs_logging:state=active"}, {"name"=>"rs_monitoring:state=active"}]
91
+ # # => [{"rs_login:state" => "active"}, {"name"=>"rs_logging:state=active"}, {"name"=>"rs_monitoring:state=active"}]
110
92
  def tags(resource_href)
111
93
  query_options = {:resource_href => resource_href}
112
94
  path = "tags/search.#{format.extension}#{query_string(query_options)}"
@@ -19,24 +19,35 @@ class ServerArray < RightResource::Base
19
19
  # "success"=>[{"ec2_instance_href"=>"https://my.rightscale.com/api/acct/##/ec2_instances/1367"}]}}
20
20
  def terminate_all(id)
21
21
  path = element_path(id, :terminate_all)
22
- format.decode(action(:post, path)).generate_attributes
22
+ format.decode(action(:post, path)).tap {|resource| correct_attributes(resource)}
23
23
  end
24
24
 
25
- # Run script on all
26
- # === Exception
27
- # * +NotImplementedError+
25
+ # Run script on all(Response format is only xml)
26
+ # === Examples
27
+ # RightResource::Base.connection = RightResource::Connection.new do |c|
28
+ # c.login(:username => "user", :password => "pass", :account => "1")
29
+ # end
30
+ # array_id = 1
31
+ # scripts_params = {
32
+ # :right_script_href => "#{RightResource::Base.connection.api}###/right_scripts/261296",
33
+ # :server_template_hrefs => ["#{RightResource::Base.connection.api}###/server_templates/83632"],
34
+ # }
35
+ #
36
+ # ServerArray.run_script_on_all(array_id, scripts_params)
37
+ # => {:audit_entries=>
38
+ # [{:href=>"https://my.rightscale.com/api/acct/###/audit_entries/44723645"},
39
+ # {:href=>"https://my.rightscale.com/api/acct/###/audit_entries/44723646"}]}
28
40
  def run_script_on_all(id, params)
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)
41
+ pair = URI.decode({resource_name.to_sym => params}.to_params).split('&').map {|l| l.split('=')}
42
+ h = Hash[*pair.flatten]
43
+ path = element_path(id, :run_script_on_all).sub(/\.#{format.extension}$/, '') # xml only
44
+ RightResource::Formats::XmlFormat.decode(action(:post, path, h)).tap {|resource| correct_attributes(resource)}
34
45
  end
35
46
 
36
47
  def instances(id)
37
48
  path = element_path(id, :instances)
38
- result = format.decode(action(:get, path)).map do |instance|
39
- instance.generate_attributes
49
+ format.decode(action(:get, path)).map do |instance|
50
+ correct_attributes(instance)
40
51
  end
41
52
  end
42
53
  end
@@ -2,10 +2,10 @@ class ServerTemplate < RightResource::Base
2
2
  class << self
3
3
  # === Parameters
4
4
  # * _id_ - ServerTemplate id
5
- # * _params_ - Hash (keys = [:phase]) ex. 'boot', 'operational', 'decommission'
5
+ # * _params_ - Hash (keys = [:phase]) ex. 'boot', 'operational', 'decommission' if not defined, all phases
6
6
  def executables(id, params={})
7
7
  path = element_path(id, :executables, params)
8
- format.decode(connection.get(path)).map {|x| x.generate_attributes}
8
+ format.decode(connection.get(path)).map {|resource| correct_attributes(resource)}
9
9
  end
10
10
  end
11
11
  end
@@ -1,6 +1,6 @@
1
1
  class Status < RightResource::Base
2
2
  class << self
3
- undef :index, :create, :update, :destory
3
+ undef :index, :create, :destory
4
4
  end
5
5
  undef :create, :update, :destory
6
6
  end
@@ -3,18 +3,18 @@
3
3
  # * _unset_
4
4
  # === Examples
5
5
  # Set tags for a resource
6
- # ec2_href = Server.show(1).current_instance_href
6
+ # ec2_href = Server.show(1)[:current_instance_href]
7
7
  # params = {:resource_href => ec2_href, :tags => ["xx99_server:role=dev", "xx99_server:group=dev"]}
8
8
  # Tag.set(params)
9
- # puts Tag.status
9
+ # puts Tag.status_code
10
10
  # p Tag.search(:resource_href => ec2_href)
11
11
  # Unset tags for a resource
12
12
  # Tag.unset(params)
13
- # puts Tag.status
13
+ # puts Tag.status_code
14
14
  # p Tag.search(:resource_href => ec2_href)
15
15
  class Tag < RightResource::Base
16
16
  class << self
17
- undef :index, :show, :create, :update, :destory
17
+ undef :index, :show, :create, :destory
18
18
 
19
19
  [:set, :unset].each do |act_method|
20
20
  define_method(act_method) do |params|
@@ -25,7 +25,7 @@ class Tag < RightResource::Base
25
25
 
26
26
  # Search tags for a resource(resource_href in params) or resources matching giving tags
27
27
  # === Parameters
28
- # * +params+ - Hash (keys = [:resource_href or :resource_type, :match_all, :tags])
28
+ # * +params+ - Hash (keys = [:resource_href or :resource_type, :match_all(exact match), :tags])
29
29
  # === Return
30
30
  # Array(tags)
31
31
  # === Examples
@@ -44,9 +44,27 @@ class Tag < RightResource::Base
44
44
  # end
45
45
  def search(params)
46
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
47
+ result = format.decode(action(:get, path)).map do |resource|
48
+ correct_attributes(resource)
49
+ resource
49
50
  end
51
+ if params.has_key?(:resource_href)
52
+ result
53
+ else
54
+ if params[:resource_type] == "ec2_instance"
55
+ resource_name = "Server"
56
+ else
57
+ resource_name = params[:resource_type].split(/-/).map {|r| r.capitalize}.join
58
+ end
59
+ klass = const_get(resource_name)
60
+ klass.instantiate_collection(result)
61
+ end
62
+ rescue => e
63
+ logger.error("#{e.class}: #{e.pretty_inspect}")
64
+ logger.debug {"Backtrace:\n#{e.backtrace.pretty_inspect}"}
65
+ []
66
+ ensure
67
+ logger.debug {"#{__FILE__} #{__LINE__}: #{self.class}\n#{self.pretty_inspect}\n"}
50
68
  end
51
69
 
52
70
  # === Examples
@@ -54,7 +72,7 @@ class Tag < RightResource::Base
54
72
  def taggable_resources
55
73
  # "#{self.name.to_s.split('::').last}s/#{__method__}" if RUBY_VERSION >= "1.8.7"
56
74
  path = get_tag_resource_path("taggable_resources")
57
- RightResource::Formats::XmlFormat.decode(action(:get, path))
75
+ RightResource::Formats::XmlFormat.decode(action(:get, path)).tap {|resource| correct_attributes(resource)}
58
76
  end
59
77
 
60
78
  private
@@ -4,11 +4,13 @@ require 'logger'
4
4
  require 'pp'
5
5
  require 'rubygems'
6
6
 
7
- require 'json/pure'
7
+ require 'json'
8
8
  require 'rest_client'
9
9
  require 'crack'
10
10
 
11
- $:.unshift(File.dirname(__FILE__))
11
+ $:.unshift(File.dirname(__FILE__)) unless
12
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
13
+
12
14
  # Ruby core extensions
13
15
  require 'right_resource/core_ext'
14
16
  # base class
@@ -36,5 +38,6 @@ require 'right_resource/macro'
36
38
  require 'right_resource/credential'
37
39
 
38
40
  module RightResource
39
- API_VERSION = "1.0".freeze
41
+ VERSION = '0.3.1'
42
+ API_VERSION = "1.0"
40
43
  end
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: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 0
10
- version: 0.3.0
9
+ - 1
10
+ version: 0.3.1
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-15 00:00:00 +09:00
18
+ date: 2010-11-24 00:00:00 +09:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -74,13 +74,13 @@ extensions: []
74
74
  extra_rdoc_files:
75
75
  - README.rdoc
76
76
  files:
77
- - CHANGELOG
77
+ - History.txt
78
78
  - README.rdoc
79
79
  - LICENSE
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
83
+ - lib/right_resource/core_ext/hash/alter_keys.rb
84
84
  - lib/right_resource/core_ext/hash.rb
85
85
  - lib/right_resource/core_ext/object/tap.rb
86
86
  - lib/right_resource/core_ext/object.rb
data/CHANGELOG DELETED
@@ -1,18 +0,0 @@
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
-