rest_connection 0.1.1 → 0.1.2

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.
Files changed (49) hide show
  1. data/README.rdoc +1 -1
  2. data/Rakefile +2 -3
  3. data/VERSION +1 -1
  4. data/git_hooks/post-commit +43 -0
  5. data/git_hooks/pre-commit +98 -14
  6. data/lib/rest_connection.rb +150 -22
  7. data/lib/rest_connection/rightscale/account.rb +2 -0
  8. data/lib/rest_connection/rightscale/alert_spec.rb +1 -5
  9. data/lib/rest_connection/rightscale/alert_spec_subject.rb +21 -0
  10. data/lib/rest_connection/rightscale/audit_entry.rb +2 -0
  11. data/lib/rest_connection/rightscale/child_account.rb +2 -0
  12. data/lib/rest_connection/rightscale/cloud.rb +2 -0
  13. data/lib/rest_connection/rightscale/cloud_account.rb +2 -0
  14. data/lib/rest_connection/rightscale/ec2_ebs_volume.rb +5 -1
  15. data/lib/rest_connection/rightscale/ec2_elastic_ip.rb +2 -0
  16. data/lib/rest_connection/rightscale/ec2_security_group.rb +24 -0
  17. data/lib/rest_connection/rightscale/ec2_ssh_key.rb +2 -0
  18. data/lib/rest_connection/rightscale/executable.rb +2 -0
  19. data/lib/rest_connection/rightscale/instance_type.rb +6 -0
  20. data/lib/rest_connection/rightscale/mc_datacenter.rb +2 -0
  21. data/lib/rest_connection/rightscale/mc_image.rb +2 -0
  22. data/lib/rest_connection/rightscale/mc_instance.rb +2 -0
  23. data/lib/rest_connection/rightscale/mc_instance_type.rb +2 -0
  24. data/lib/rest_connection/rightscale/mc_multi_cloud_image.rb +2 -0
  25. data/lib/rest_connection/rightscale/mc_multi_cloud_image_setting.rb +2 -0
  26. data/lib/rest_connection/rightscale/mc_security_group.rb +62 -0
  27. data/lib/rest_connection/rightscale/mc_server_template_multi_cloud_image.rb +2 -0
  28. data/lib/rest_connection/rightscale/mc_ssh_key.rb +2 -0
  29. data/lib/rest_connection/rightscale/mc_tag.rb +2 -0
  30. data/lib/rest_connection/rightscale/mc_volume.rb +2 -0
  31. data/lib/rest_connection/rightscale/mc_volume_attachment.rb +2 -0
  32. data/lib/rest_connection/rightscale/mc_volume_snapshot.rb +2 -0
  33. data/lib/rest_connection/rightscale/mc_volume_type.rb +2 -0
  34. data/lib/rest_connection/rightscale/monitoring_metric.rb +2 -0
  35. data/lib/rest_connection/rightscale/multi_cloud_image.rb +2 -0
  36. data/lib/rest_connection/rightscale/permission.rb +2 -0
  37. data/lib/rest_connection/rightscale/right_script.rb +3 -0
  38. data/lib/rest_connection/rightscale/rightscale_api_base.rb +51 -4
  39. data/lib/rest_connection/rightscale/rightscale_api_gateway.rb +60 -33
  40. data/lib/rest_connection/rightscale/rightscale_api_resources.rb +5 -0
  41. data/lib/rest_connection/rightscale/s3_bucket.rb +2 -1
  42. data/lib/rest_connection/rightscale/security_group_rule.rb +31 -0
  43. data/lib/rest_connection/rightscale/server_ec2_ebs_volume.rb +40 -0
  44. data/lib/rest_connection/rightscale/session.rb +61 -0
  45. data/lib/rest_connection/rightscale/sqs_queue.rb +22 -0
  46. data/lib/rest_connection/rightscale/tag.rb +2 -0
  47. data/lib/rest_connection/rightscale/task.rb +4 -2
  48. data/lib/rest_connection/rightscale/user.rb +2 -0
  49. metadata +12 -6
@@ -1,5 +1,29 @@
1
1
  module RightScale
2
2
  module Api
3
+ GATEWAY_COOKIE_REFRESH = proc do
4
+ def refresh_cookie
5
+ # login
6
+ ignored, account = @settings[:api_url].split(/\/acct\//) if @settings[:api_url].include?("acct")
7
+ params = {
8
+ "email" => @settings[:user],
9
+ "password" => @settings[:pass],
10
+ "account_href" => "/api/accounts/#{account}"
11
+ }
12
+ @cookie = nil
13
+ resp = post("session", params)
14
+ unless resp.code == "302" || resp.code == "204"
15
+ raise "ERROR: Login failed. #{resp.message}. Code:#{resp.code}"
16
+ end
17
+ # TODO: handle 302 redirects
18
+ @cookie = resp.response['set-cookie']
19
+
20
+ # test session
21
+ resp = get("session")
22
+ raise "ERROR: Invalid session. #{resp["message"]}." unless resp.is_a?(Hash)
23
+ true
24
+ end
25
+ end
26
+
3
27
  module Gateway
4
28
  include RightScale::Api::Base
5
29
 
@@ -17,17 +41,12 @@ module RightScale
17
41
  settings[:common_headers]["X_API_VERSION"] = "1.5"
18
42
  settings[:api_href], account = settings[:api_url].split(/\/acct\//) if settings[:api_url].include?("acct")
19
43
  settings[:extension] = ".json"
20
- unless @@gateway_connection.cookie
21
- # login
22
- params = { "email" => settings[:user], "password" => settings[:pass], "account_href" => "/api/accounts/#{account}" }
23
- resp = @@gateway_connection.post("session", params)
24
- raise "ERROR: Login failed. #{resp.message}. Code:#{resp.code}" unless resp.code == "302" || resp.code == "204"
25
- @@gateway_connection.cookie = resp.response['set-cookie']
26
44
 
27
- # test session
28
- resp = @@gateway_connection.get("session")
29
- raise "ERROR: Invalid session. #{resp["message"]}." unless resp.is_a?(Hash)
45
+ unless @@gateway_connection.respond_to?(:refresh_cookie)
46
+ @@gateway_connection.instance_exec(&(RightScale::Api::GATEWAY_COOKIE_REFRESH))
30
47
  end
48
+
49
+ @@gateway_connection.refresh_cookie unless @@gateway_connection.cookie
31
50
  @@gateway_connection
32
51
  end
33
52
 
@@ -130,23 +149,30 @@ module RightScale
130
149
  end
131
150
 
132
151
  def load(resource)
133
- if resource.is_a?(Class)
134
- param_string = resource.resource_singular_name
135
- class_name = resource
152
+ mod = RightScale::Api::GatewayExtend
153
+ @@gateway_resources ||= Object.constants.map do |const|
154
+ klass = Object.const_get(const)
155
+ (mod === klass ? klass : nil)
156
+ end.compact
157
+ pp @@gateway_resources
158
+ if mod === resource
159
+ klass = resource
136
160
  elsif resource.is_a?(String) or resource.is_a?(Symbol)
137
- param_string = resource
138
- begin
139
- class_name = Kernel.const_get(resource.singularize.camelize)
140
- rescue
141
- class_name = Kernel.const_get("Mc#{resource.singularize.camelize}")
161
+ klass = @@gateway_resources.detect do |const|
162
+ [const.resource_singular_name, const.resource_plural_name].include?(resource.to_s)
142
163
  end
164
+ elsif Class === resource
165
+ raise TypeError.new("#{resource} doesn't extend #{mod}")
166
+ else
167
+ raise TypeError.new("can't convert #{resource.class} into supported Class")
143
168
  end
144
- if self[param_string].nil?
145
- return class_name.load_all(self[param_string.pluralize])
146
- elsif param_string.pluralize == param_string
147
- return class_name.load_all(self[param_string])
169
+
170
+ if self[klass.resource_singular_name]
171
+ return klass.load(self[klass.resource_singular_name])
172
+ elsif self[klass.resource_plural_name]
173
+ return klass.load_all(self[klass.resource_plural_name])
148
174
  else
149
- return class_name.load(self[param_string])
175
+ raise NameError.new("no resource_hrefs found for #{klass}")
150
176
  end
151
177
  end
152
178
  end
@@ -159,17 +185,12 @@ module RightScale
159
185
  settings[:common_headers]["X_API_VERSION"] = "1.5"
160
186
  settings[:api_href], account = settings[:api_url].split(/\/acct\//) if settings[:api_url].include?("acct")
161
187
  settings[:extension] = ".json"
162
- unless @@gateway_connection.cookie
163
- # login
164
- params = { "email" => settings[:user], "password" => settings[:pass], "account_href" => "/api/accounts/#{account}" }
165
- resp = @@gateway_connection.post("session", params)
166
- raise "ERROR: Login failed. #{resp.message}. Code:#{resp.code}" unless resp.code == "302" || resp.code == "204"
167
- @@gateway_connection.cookie = resp.response['set-cookie']
168
188
 
169
- # test session
170
- resp = @@gateway_connection.get("session")
171
- raise "ERROR: Invalid session. #{resp["message"]}." unless resp.is_a?(Hash)
189
+ unless @@gateway_connection.respond_to?(:refresh_cookie)
190
+ @@gateway_connection.instance_exec(&(RightScale::Api::GATEWAY_COOKIE_REFRESH))
172
191
  end
192
+
193
+ @@gateway_connection.refresh_cookie unless @@gateway_connection.cookie
173
194
  @@gateway_connection
174
195
  end
175
196
 
@@ -238,8 +259,14 @@ module RightScale
238
259
  []
239
260
  end
240
261
 
241
- def create(opts)
242
- location = connection.post(self.resource_plural_name, self.resource_singular_name.to_sym => opts)
262
+ def create(*args)
263
+ if args.last.is_a?(Hash)
264
+ opts = args.pop
265
+ else
266
+ raise ArgumentError.new("create requires the last argument to be a Hash")
267
+ end
268
+ url = "#{parse_args(*args)}#{self.resource_plural_name}"
269
+ location = connection.post(url, self.resource_singular_name.to_sym => opts)
243
270
  newrecord = self.new('links' => [ {'rel' => 'self', 'href' => location } ])
244
271
  newrecord.reload
245
272
  newrecord
@@ -20,6 +20,9 @@ require 'rest_connection/rightscale/rightscale_api_gateway'
20
20
  require 'rest_connection/rightscale/rightscale_api_taggable'
21
21
  require 'rest_connection/rightscale/rightscale_api_mc_taggable'
22
22
  require 'rest_connection/rightscale/rightscale_api_mc_input'
23
+ require 'rest_connection/rightscale/alert_spec_subject'
24
+ require 'rest_connection/rightscale/server_ec2_ebs_volume'
25
+ require 'rest_connection/rightscale/sqs_queue'
23
26
  require 'rest_connection/rightscale/executable'
24
27
  require 'rest_connection/rightscale/cloud_account'
25
28
  require 'rest_connection/rightscale/server'
@@ -49,6 +52,7 @@ require 'rest_connection/rightscale/mc_server'
49
52
  require 'rest_connection/rightscale/server_interface'
50
53
  require 'rest_connection/rightscale/mc_instance'
51
54
  require 'rest_connection/rightscale/monitoring_metric'
55
+ require 'rest_connection/rightscale/session'
52
56
  require 'rest_connection/rightscale/mc_multi_cloud_image_setting'
53
57
  require 'rest_connection/rightscale/mc_multi_cloud_image'
54
58
  require 'rest_connection/rightscale/mc_server_template_multi_cloud_image'
@@ -60,6 +64,7 @@ require 'rest_connection/rightscale/multi_cloud_image_cloud_setting_internal'
60
64
  require 'rest_connection/rightscale/multi_cloud_image_internal'
61
65
  require 'rest_connection/rightscale/ec2_server_array'
62
66
  require 'rest_connection/rightscale/mc_server_array'
67
+ require 'rest_connection/rightscale/security_group_rule'
63
68
  require 'rest_connection/rightscale/mc_security_group'
64
69
  require 'rest_connection/rightscale/mc_deployment'
65
70
  require 'rest_connection/rightscale/mc_datacenter'
@@ -17,6 +17,8 @@ class S3Bucket
17
17
  include RightScale::Api::Base
18
18
  extend RightScale::Api::BaseExtend
19
19
 
20
+ deny_methods :update
21
+
20
22
  def self.resource_singular_name
21
23
  "s3_bucket"
22
24
  end
@@ -32,5 +34,4 @@ class S3Bucket
32
34
  def resource_plural_name
33
35
  "s3_buckets"
34
36
  end
35
-
36
37
  end
@@ -0,0 +1,31 @@
1
+ # This file is part of RestConnection
2
+ #
3
+ # RestConnection is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # RestConnection is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with RestConnection. If not, see <http://www.gnu.org/licenses/>.
15
+
16
+ #
17
+ # You must have Beta v1.5 API access to use these internal API calls.
18
+ #
19
+ class SecurityGroupRule
20
+ include RightScale::Api::Gateway
21
+ extend RightScale::Api::GatewayExtend
22
+
23
+ deny_methods :update
24
+
25
+ def self.parse_args(cloud_id=nil, security_group_id=nil)
26
+ if cloud_id.nil? ^ security_group_id.nil?
27
+ raise ArgumentError.new("#{self} requires either 0 arguments, or 2 arguments")
28
+ end
29
+ "clouds/#{cloud_id}/security_groups/#{security_group_id}/"
30
+ end
31
+ end
@@ -0,0 +1,40 @@
1
+ # This file is part of RestConnection
2
+ #
3
+ # RestConnection is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # RestConnection is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with RestConnection. If not, see <http://www.gnu.org/licenses/>.
15
+ #
16
+
17
+ class ServerEc2EbsVolume
18
+ include RightScale::Api::Base
19
+ extend RightScale::Api::BaseExtend
20
+ include RightScale::Api::Taggable
21
+ extend RightScale::Api::TaggableExtend
22
+
23
+ deny_methods :index, :update
24
+
25
+ def resource_plural_name
26
+ "component_ec2_ebs_volumes"
27
+ end
28
+
29
+ def resource_singular_name
30
+ "component_ec2_ebs_volume"
31
+ end
32
+
33
+ def self.resource_plural_name
34
+ "component_ec2_ebs_volumes"
35
+ end
36
+
37
+ def self.resource_singular_name
38
+ "component_ec2_ebs_volume"
39
+ end
40
+ end
@@ -0,0 +1,61 @@
1
+ # This file is part of RestConnection
2
+ #
3
+ # RestConnection is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # RestConnection is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with RestConnection. If not, see <http://www.gnu.org/licenses/>.
15
+
16
+ #
17
+ # You must have Beta v1.5 API access to use these internal API calls.
18
+ #
19
+ class Session
20
+ include RightScale::Api::Gateway
21
+ extend RightScale::Api::GatewayExtend
22
+
23
+ deny_methods :index, :destroy, :update, :show
24
+
25
+ def self.index
26
+ self.new(connection.get(resource_singular_name))
27
+ end
28
+
29
+ def self.create(opts={})
30
+ settings = connection.settings
31
+ ignored, account = settings[:api_url].split(/\/acct\//) if settings[:api_url].include?("acct")
32
+ params = {
33
+ "email" => settings[:user],
34
+ "password" => settings[:pass],
35
+ "account_href" => "/api/accounts/#{account}"
36
+ }.merge(opts)
37
+ resp = connection.post(resource_singular_name, params)
38
+ connection.cookie = resp.response['set-cookie']
39
+ end
40
+
41
+ def self.accounts(opts={})
42
+ settings = connection.settings
43
+ params = {
44
+ "email" => settings[:user],
45
+ "password" => settings[:pass],
46
+ }.merge(opts)
47
+ a = Array.new
48
+ connection.get(resource_singular_name + "/accounts").each do |object|
49
+ a << Account.new(object)
50
+ end
51
+ return a
52
+ end
53
+
54
+ def self.create_instance_session
55
+ # TODO
56
+ end
57
+
58
+ def self.index_instance_session
59
+ # TODO
60
+ end
61
+ end
@@ -0,0 +1,22 @@
1
+ # This file is part of RestConnection
2
+ #
3
+ # RestConnection is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # RestConnection is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with RestConnection. If not, see <http://www.gnu.org/licenses/>.
15
+ #
16
+
17
+ class SqsQueue
18
+ include RightScale::Api::Base
19
+ extend RightScale::Api::BaseExtend
20
+
21
+ deny_methods :update
22
+ end
@@ -17,6 +17,8 @@ class Tag
17
17
  include RightScale::Api::Base
18
18
  extend RightScale::Api::BaseExtend
19
19
 
20
+ deny_methods :index, :create, :destroy, :update, :show
21
+
20
22
  def self.search(resource_name, tags, opts=nil)
21
23
  parameters = { :resource_type => resource_name.to_s, :tags => tags }
22
24
  parameters.merge!(opts) unless opts.nil?
@@ -20,6 +20,8 @@ class Task
20
20
  include RightScale::Api::Gateway
21
21
  extend RightScale::Api::GatewayExtend
22
22
 
23
+ deny_methods :index, :create, :destroy, :update
24
+
23
25
  def self.parse_args(cloud_id, instance_id)
24
26
  "clouds/#{cloud_id}/instances/#{instance_id}/live/"
25
27
  end
@@ -41,7 +43,7 @@ class Task
41
43
  raise "FATAL: Timeout waiting for Executable to complete. State was #{self.summary}" if timeout <= 0
42
44
  end
43
45
 
44
- def wait_for_completed(legacy=nil)
45
- wait_for_state("completed")
46
+ def wait_for_completed(timeout=900)
47
+ wait_for_state("completed", timeout)
46
48
  end
47
49
  end
@@ -25,6 +25,8 @@ class User
25
25
  include RightScale::Api::Gateway
26
26
  extend RightScale::Api::GatewayExtend
27
27
 
28
+ deny_methods :destroy, :update
29
+
28
30
  def self.filters
29
31
  [:email, :first_name, :last_name]
30
32
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rest_connection
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jeremy Deininger
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-12-17 00:00:00 Z
19
+ date: 2012-01-26 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: activesupport
@@ -78,7 +78,7 @@ dependencies:
78
78
  version: "0"
79
79
  type: :runtime
80
80
  version_requirements: *id004
81
- description: provides rest_connection
81
+ description: "Current implemented modules: RightScale API"
82
82
  email:
83
83
  - jeremy@rubyonlinux.org
84
84
  - tw.rodriguez@gmail.com
@@ -102,6 +102,7 @@ files:
102
102
  - examples/cucumber/step_definitions/spot_check_steps.rb
103
103
  - examples/relaunch_deployment.rb
104
104
  - examples/right_scale_ec2_instances_api_test.rb
105
+ - git_hooks/post-commit
105
106
  - git_hooks/post-commit.disabled
106
107
  - git_hooks/post-merge.disabled
107
108
  - git_hooks/pre-commit
@@ -109,6 +110,7 @@ files:
109
110
  - lib/rest_connection/patches.rb
110
111
  - lib/rest_connection/rightscale/account.rb
111
112
  - lib/rest_connection/rightscale/alert_spec.rb
113
+ - lib/rest_connection/rightscale/alert_spec_subject.rb
112
114
  - lib/rest_connection/rightscale/audit_entry.rb
113
115
  - lib/rest_connection/rightscale/child_account.rb
114
116
  - lib/rest_connection/rightscale/cloud.rb
@@ -160,11 +162,15 @@ files:
160
162
  - lib/rest_connection/rightscale/rightscale_api_taggable.rb
161
163
  - lib/rest_connection/rightscale/rs_internal.rb
162
164
  - lib/rest_connection/rightscale/s3_bucket.rb
165
+ - lib/rest_connection/rightscale/security_group_rule.rb
163
166
  - lib/rest_connection/rightscale/server.rb
167
+ - lib/rest_connection/rightscale/server_ec2_ebs_volume.rb
164
168
  - lib/rest_connection/rightscale/server_interface.rb
165
169
  - lib/rest_connection/rightscale/server_internal.rb
166
170
  - lib/rest_connection/rightscale/server_template.rb
167
171
  - lib/rest_connection/rightscale/server_template_internal.rb
172
+ - lib/rest_connection/rightscale/session.rb
173
+ - lib/rest_connection/rightscale/sqs_queue.rb
168
174
  - lib/rest_connection/rightscale/status.rb
169
175
  - lib/rest_connection/rightscale/tag.rb
170
176
  - lib/rest_connection/rightscale/task.rb
@@ -217,6 +223,6 @@ rubyforge_project:
217
223
  rubygems_version: 1.8.10
218
224
  signing_key:
219
225
  specification_version: 3
220
- summary: lib for restful connections to the rightscale api
226
+ summary: Modular RESTful API library
221
227
  test_files: []
222
228