rest_connection 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ *.swp
2
+ *.swo
3
+ pkg/*
4
+
5
+ ## RubyMine
6
+ .idea
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,43 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rest_connection (1.0.3)
5
+ activesupport (= 2.3.10)
6
+ highline
7
+ json
8
+ net-ssh (= 2.1.4)
9
+ nokogiri
10
+ rest-client
11
+
12
+ GEM
13
+ remote: http://rubygems.org/
14
+ specs:
15
+ activesupport (2.3.10)
16
+ columnize (0.3.6)
17
+ highline (1.6.15)
18
+ json (1.7.5)
19
+ linecache (0.46)
20
+ rbx-require-relative (> 0.0.4)
21
+ mime-types (1.19)
22
+ net-ssh (2.1.4)
23
+ nokogiri (1.5.5)
24
+ rake (0.8.7)
25
+ rbx-require-relative (0.0.9)
26
+ rest-client (1.6.7)
27
+ mime-types (>= 1.16)
28
+ rspec (1.3.0)
29
+ ruby-debug (0.10.4)
30
+ columnize (>= 0.1)
31
+ ruby-debug-base (~> 0.10.4.0)
32
+ ruby-debug-base (0.10.4)
33
+ linecache (>= 0.3)
34
+
35
+ PLATFORMS
36
+ ruby
37
+
38
+ DEPENDENCIES
39
+ bundler
40
+ rake (= 0.8.7)
41
+ rest_connection!
42
+ rspec (= 1.3.0)
43
+ ruby-debug
data/README.rdoc CHANGED
@@ -4,10 +4,11 @@
4
4
  "gem install rest_connection"
5
5
 
6
6
  ==== Installing from source
7
- "git clone http://github.com/rightscale/rest_connection.git"
8
- "gem install jeweler rspec"
9
- "rake check_dependencies" <- Install any gems listed.
10
- "rake install"
7
+ "git clone git@github.com:rightscale/rest_connection.git"
8
+ "cd rest_connection"
9
+ "gem install rconf"
10
+ "rconf" <- follow any further instructions from rconf
11
+ "bundle install"
11
12
 
12
13
  == Configuration
13
14
 
@@ -47,10 +48,16 @@ Copy the example from GEMHOME/rest_connection/config/rest_api_config.yaml.sample
47
48
 
48
49
  puts my_array.instances.map { |i| i['ip-address'] }
49
50
 
50
- === To cut a new gem and push to rubygems.org
51
+ === To cut a new gem and push to RubyGems.org
51
52
 
52
- Edit VERSION and bump the number
53
- rake gemspec
54
- rake install
55
- visit www.rubygems.org
56
- gem push pkg/rest_connection-0.0.0.gem (use your new version number in this command)
53
+ Edit lib/rest_connection/version.rb and bump the number according to http://semver.org
54
+
55
+ "bundle exec gem build rest_connection.gemspec"
56
+ "ls *.gem" <- verify that gem was built
57
+ "cd /tmp"
58
+ "bundle exec gem install /path/to/local/rest_connection-X.Y.Z.gem" <- replace X.Y.Z with your new version number
59
+ "bundle exec gem uninstall rest_connection"
60
+ "cd -"
61
+ "bundle exec gem push rest_connection-X.Y.Z.gem"
62
+
63
+ Check it out: https://rubygems.org/gems/rest_connection
data/Rakefile CHANGED
@@ -1,17 +1,17 @@
1
- require 'rubygems'
2
- require 'jeweler'
3
- Jeweler::Tasks.new do |gemspec|
4
- gemspec.name = "rest_connection"
5
- gemspec.summary = "Modular RESTful API library"
6
- gemspec.description = "A Modular RESTful API library. Current implemented modules: RightScale API"
7
- gemspec.email = ["daniel.onorato@rightscale.com"]
8
- gemspec.homepage = "http://github.com/rightscale/rest_connection"
9
- gemspec.authors = ["Jeremy Deininger", "Timothy Rodriguez"]
10
- gemspec.add_dependency('activesupport', "=2.3.10")
11
- gemspec.add_dependency('net-ssh', "=2.1.4")
12
- gemspec.add_dependency('json')
13
- gemspec.add_dependency('highline')
14
- gemspec.add_dependency('rest-client')
15
- gemspec.add_dependency('nokogiri')
1
+ require File.expand_path('../lib/rest_connection', __FILE__)
2
+ require 'rake'
3
+ require 'spec/rake/spectask'
4
+
5
+ task :build do
6
+ system "gem build rest_connection.gemspec"
7
+ end
8
+
9
+ task :release => :build do
10
+ system "gem push rest_connection-#{RestConnection::VERSION}.gem"
11
+ end
12
+
13
+ Spec::Rake::SpecTask.new('spec') do |t|
14
+ t.spec_files = Dir.glob('spec/*_spec.rb')
15
+ t.spec_opts << '--format nested'
16
+ t.spec_opts << '--colour'
16
17
  end
17
- Jeweler::GemcutterTasks.new
data/git_hooks/pre-commit CHANGED
@@ -1,5 +1,17 @@
1
1
  #!/bin/bash
2
2
 
3
+ # Setup $stat_flag based on OS type
4
+ mac_unix_name=Darwin
5
+ uname_returned=`uname -a`
6
+ unix_name=${uname_returned:0:${#mac_unix_name}}
7
+ if [ "$unix_name" = "$mac_unix_name" ]; then
8
+ echo "MAC OS \"$mac_unix_name\" detected..."
9
+ stat_flag=-f
10
+ else
11
+ echo "non-MAC OS detected..."
12
+ stat_flag=-c
13
+ fi
14
+
3
15
  echo "Checking for syntax errors..."
4
16
  for FILE in `git diff-index --name-only HEAD --` ; do
5
17
  if test -f $FILE; then
@@ -25,27 +25,36 @@ class Ec2SecurityGroup
25
25
  include RightScale::Api::Base
26
26
  extend RightScale::Api::BaseExtend
27
27
 
28
+ VALID_RULE_TYPES = [
29
+ [:group, :owner],
30
+ [:cidr_ips, :from_port, :protocol, :to_port],
31
+ [:from_port, :group, :owner, :protocol, :to_port],
32
+ ]
33
+
28
34
  # NOTE - Create, Destroy, and Update require "security_manager" permissions
29
35
  # NOTE - Can't remove rules, can only add
30
36
  def add_rule(opts={})
31
- opts.each { |k,v| opts["#{k}".to_sym] = v }
32
- update_types = [
33
- :name => [:owner, :group],
34
- :cidr_ips => [:cidr_ip, :protocol, :from_port, :to_port],
35
- :group => [:owner, :group, :protocol, :from_port, :to_port],
36
- ]
37
- type = (opts[:protocol] ? (opts[:cidr_ip] ? :cidr_ips : :group) : :name)
38
- unless update_types[type].reduce(true) { |b,field| b && opts[field] }
39
- arg_expectation = update_types.values.pretty_inspect
40
- raise ArgumentError.new("add_rule requires one of these groupings: #{arg_expectation}")
41
- end
37
+ rule = {}
38
+ opts.each { |k,v| rule["#{k}".to_sym] = v }
42
39
 
43
- params = {}
44
- update_types[type].each { |field| params[field] = opts[field] }
40
+ unless validate_rule(rule)
41
+ raise ArgumentError.new("add_rule expects one of these valid rule types: #{VALID_RULE_TYPES.to_json}")
42
+ end
45
43
 
44
+ params = {:ec2_security_group => rule}
46
45
  uri = URI.parse(self.href)
47
46
  connection.put(uri.path, params)
48
47
 
49
48
  self.reload
50
49
  end
50
+
51
+ def validate_rule(rule)
52
+ VALID_RULE_TYPES.each do |valid_rule_type|
53
+ if rule.keys.sort_by {|sym| sym.to_s} == valid_rule_type.sort_by {|sym| sym.to_s}
54
+ return true
55
+ end
56
+ end
57
+
58
+ false
59
+ end
51
60
  end
@@ -0,0 +1,4 @@
1
+ # This gem is versioned with the usual X.Y.Z notation
2
+ module RestConnection
3
+ VERSION = '1.0.3'
4
+ end
@@ -0,0 +1,32 @@
1
+ require File.expand_path('../lib/rest_connection/version', __FILE__)
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'rest_connection'
5
+ s.version = RestConnection::VERSION
6
+ s.platform = Gem::Platform::RUBY
7
+ s.date = Time.now.utc.strftime("%Y-%m-%d")
8
+ s.require_path = 'lib'
9
+ s.authors = [ 'RightScale, Inc.' ]
10
+ s.email = [ 'rubygems@rightscale.com' ]
11
+ s.homepage = 'https://github.com/rightscale/rest_connection'
12
+ s.summary = 'A Modular RESTful API library.'
13
+ s.description = %{
14
+ The rest_connection gem simplifies the use of RESTful APIs.
15
+ It currently has support for RightScale API 1.0 and 1.5.
16
+ }
17
+ s.files = `git ls-files`.split(' ')
18
+ s.test_files = `git ls-files spec config`.split(' ')
19
+ s.rubygems_version = '1.8.24'
20
+
21
+ s.add_runtime_dependency 'activesupport', '2.3.10'
22
+ s.add_runtime_dependency 'net-ssh', '2.1.4'
23
+ s.add_runtime_dependency 'json'
24
+ s.add_runtime_dependency 'highline'
25
+ s.add_runtime_dependency 'rest-client'
26
+ s.add_runtime_dependency 'nokogiri'
27
+
28
+ s.add_development_dependency 'rake', '0.8.7'
29
+ s.add_development_dependency 'bundler'
30
+ s.add_development_dependency 'rspec', '1.3.0'
31
+ s.add_development_dependency 'ruby-debug'
32
+ end
@@ -0,0 +1,10 @@
1
+ ruby do
2
+ version 'ree-1.8.7-2012.02'
3
+ rubygems '1.8.24'
4
+ gemset 'rest_connection'
5
+ end
6
+ bundler do
7
+ version '1.2.2'
8
+ exclusions 'deployment'
9
+ bundle_path File.join(ENV["HOME"], '.rightscale_bundle', 'rest_connection')
10
+ end
metadata CHANGED
@@ -1,28 +1,25 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rest_connection
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
5
- prerelease: false
4
+ hash: 17
5
+ prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 2
10
- version: 1.0.2
9
+ - 3
10
+ version: 1.0.3
11
11
  platform: ruby
12
12
  authors:
13
- - Jeremy Deininger
14
- - Timothy Rodriguez
13
+ - RightScale, Inc.
15
14
  autorequire:
16
15
  bindir: bin
17
16
  cert_chain: []
18
17
 
19
- date: 2012-11-29 00:00:00 -08:00
20
- default_executable:
18
+ date: 2012-12-13 00:00:00 Z
21
19
  dependencies:
22
20
  - !ruby/object:Gem::Dependency
23
21
  name: activesupport
24
- prerelease: false
25
- requirement: &id001 !ruby/object:Gem::Requirement
22
+ version_requirements: &id001 !ruby/object:Gem::Requirement
26
23
  none: false
27
24
  requirements:
28
25
  - - "="
@@ -34,11 +31,11 @@ dependencies:
34
31
  - 10
35
32
  version: 2.3.10
36
33
  type: :runtime
37
- version_requirements: *id001
34
+ requirement: *id001
35
+ prerelease: false
38
36
  - !ruby/object:Gem::Dependency
39
37
  name: net-ssh
40
- prerelease: false
41
- requirement: &id002 !ruby/object:Gem::Requirement
38
+ version_requirements: &id002 !ruby/object:Gem::Requirement
42
39
  none: false
43
40
  requirements:
44
41
  - - "="
@@ -50,11 +47,11 @@ dependencies:
50
47
  - 4
51
48
  version: 2.1.4
52
49
  type: :runtime
53
- version_requirements: *id002
50
+ requirement: *id002
51
+ prerelease: false
54
52
  - !ruby/object:Gem::Dependency
55
53
  name: json
56
- prerelease: false
57
- requirement: &id003 !ruby/object:Gem::Requirement
54
+ version_requirements: &id003 !ruby/object:Gem::Requirement
58
55
  none: false
59
56
  requirements:
60
57
  - - ">="
@@ -64,11 +61,11 @@ dependencies:
64
61
  - 0
65
62
  version: "0"
66
63
  type: :runtime
67
- version_requirements: *id003
64
+ requirement: *id003
65
+ prerelease: false
68
66
  - !ruby/object:Gem::Dependency
69
67
  name: highline
70
- prerelease: false
71
- requirement: &id004 !ruby/object:Gem::Requirement
68
+ version_requirements: &id004 !ruby/object:Gem::Requirement
72
69
  none: false
73
70
  requirements:
74
71
  - - ">="
@@ -78,11 +75,11 @@ dependencies:
78
75
  - 0
79
76
  version: "0"
80
77
  type: :runtime
81
- version_requirements: *id004
78
+ requirement: *id004
79
+ prerelease: false
82
80
  - !ruby/object:Gem::Dependency
83
81
  name: rest-client
84
- prerelease: false
85
- requirement: &id005 !ruby/object:Gem::Requirement
82
+ version_requirements: &id005 !ruby/object:Gem::Requirement
86
83
  none: false
87
84
  requirements:
88
85
  - - ">="
@@ -92,11 +89,11 @@ dependencies:
92
89
  - 0
93
90
  version: "0"
94
91
  type: :runtime
95
- version_requirements: *id005
92
+ requirement: *id005
93
+ prerelease: false
96
94
  - !ruby/object:Gem::Dependency
97
95
  name: nokogiri
98
- prerelease: false
99
- requirement: &id006 !ruby/object:Gem::Requirement
96
+ version_requirements: &id006 !ruby/object:Gem::Requirement
100
97
  none: false
101
98
  requirements:
102
99
  - - ">="
@@ -106,23 +103,86 @@ dependencies:
106
103
  - 0
107
104
  version: "0"
108
105
  type: :runtime
109
- version_requirements: *id006
110
- description: "A Modular RESTful API library. Current implemented modules: RightScale API"
106
+ requirement: *id006
107
+ prerelease: false
108
+ - !ruby/object:Gem::Dependency
109
+ name: rake
110
+ version_requirements: &id007 !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - "="
114
+ - !ruby/object:Gem::Version
115
+ hash: 49
116
+ segments:
117
+ - 0
118
+ - 8
119
+ - 7
120
+ version: 0.8.7
121
+ type: :development
122
+ requirement: *id007
123
+ prerelease: false
124
+ - !ruby/object:Gem::Dependency
125
+ name: bundler
126
+ version_requirements: &id008 !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ hash: 3
132
+ segments:
133
+ - 0
134
+ version: "0"
135
+ type: :development
136
+ requirement: *id008
137
+ prerelease: false
138
+ - !ruby/object:Gem::Dependency
139
+ name: rspec
140
+ version_requirements: &id009 !ruby/object:Gem::Requirement
141
+ none: false
142
+ requirements:
143
+ - - "="
144
+ - !ruby/object:Gem::Version
145
+ hash: 27
146
+ segments:
147
+ - 1
148
+ - 3
149
+ - 0
150
+ version: 1.3.0
151
+ type: :development
152
+ requirement: *id009
153
+ prerelease: false
154
+ - !ruby/object:Gem::Dependency
155
+ name: ruby-debug
156
+ version_requirements: &id010 !ruby/object:Gem::Requirement
157
+ none: false
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ hash: 3
162
+ segments:
163
+ - 0
164
+ version: "0"
165
+ type: :development
166
+ requirement: *id010
167
+ prerelease: false
168
+ description: "\n\
169
+ The rest_connection gem simplifies the use of RESTful APIs.\n\
170
+ It currently has support for RightScale API 1.0 and 1.5.\n "
111
171
  email:
112
- - daniel.onorato@rightscale.com
172
+ - rubygems@rightscale.com
113
173
  executables: []
114
174
 
115
175
  extensions: []
116
176
 
117
- extra_rdoc_files:
118
- - LICENSE
119
- - README.rdoc
120
- - README.rdoc.starting.point
177
+ extra_rdoc_files: []
178
+
121
179
  files:
180
+ - .gitignore
181
+ - Gemfile
182
+ - Gemfile.lock
122
183
  - LICENSE
123
184
  - README.rdoc
124
185
  - Rakefile
125
- - VERSION
126
186
  - config/rest_api_config.yaml.sample
127
187
  - examples/README.txt
128
188
  - examples/console.rb
@@ -209,8 +269,10 @@ files:
209
269
  - lib/rest_connection/rightscale/user.rb
210
270
  - lib/rest_connection/rightscale/vpc_dhcp_option.rb
211
271
  - lib/rest_connection/ssh_hax.rb
272
+ - lib/rest_connection/version.rb
212
273
  - log_api_call_parser
213
- - login_to_connection_irb.rb
274
+ - rest_connection.gemspec
275
+ - rest_connection.rconf
214
276
  - spec/ec2_server_array_spec.rb
215
277
  - spec/ec2_ssh_key_internal_spec.rb
216
278
  - spec/image_jockey.rb
@@ -225,9 +287,7 @@ files:
225
287
  - spec/server_template_internal.rb
226
288
  - spec/spec_helper.rb
227
289
  - spec/tag_spec.rb
228
- - README.rdoc.starting.point
229
- has_rdoc: true
230
- homepage: http://github.com/rightscale/rest_connection
290
+ homepage: https://github.com/rightscale/rest_connection
231
291
  licenses: []
232
292
 
233
293
  post_install_message:
@@ -256,9 +316,23 @@ required_rubygems_version: !ruby/object:Gem::Requirement
256
316
  requirements: []
257
317
 
258
318
  rubyforge_project:
259
- rubygems_version: 1.3.7
319
+ rubygems_version: 1.8.24
260
320
  signing_key:
261
321
  specification_version: 3
262
- summary: Modular RESTful API library
263
- test_files: []
264
-
322
+ summary: A Modular RESTful API library.
323
+ test_files:
324
+ - config/rest_api_config.yaml.sample
325
+ - spec/ec2_server_array_spec.rb
326
+ - spec/ec2_ssh_key_internal_spec.rb
327
+ - spec/image_jockey.rb
328
+ - spec/mcserver_spec.rb
329
+ - spec/method_missing_spec.rb
330
+ - spec/multi.rb
331
+ - spec/right_script_internal.rb
332
+ - spec/rs_internal_spec.rb
333
+ - spec/runtests
334
+ - spec/server_internal_spec.rb
335
+ - spec/server_spec.rb
336
+ - spec/server_template_internal.rb
337
+ - spec/spec_helper.rb
338
+ - spec/tag_spec.rb
@@ -1,202 +0,0 @@
1
- = Rest Connection
2
-
3
- The rest_connection gem simplifies the use of RightScale's MultiCloud API. It provides
4
- a simple object model of the API resources, and handles all of the fine details involved
5
- in making HTTP calls and translating their responses.
6
- It is assumed that users are already familiar with the RightScale API:
7
- - API Documentation: http://support.rightscale.com/12-Guides/RightScale_API_1.5
8
- - API Reference Docs: http://support.rightscale.com/api1.5
9
-
10
- == Installation
11
- Ruby 1.8.7 or higher is required.
12
- gem install rest_connection
13
-
14
- == Versioning
15
- The rest_connection gem is versioned using the usual X.Y.Z notation, where X.Y is the
16
- RightScale API version, and Z is the client version. For example, if you want to use
17
- RightScale API 1.5, you should use the latest version of the 1.5 gem. This will ensure
18
- that you get the latest bug fixes for the client that is compatible with that API version.
19
-
20
- == Usage Instructions
21
- New users can start with the following few lines of code and navigate their way around the API by following
22
- the available methods. You can find your account id by logging into the RightScale dashboard (https://my.rightscale.com),
23
- navigate to the Settings > Account Settings page. The account is is at the end of the browser address bar.
24
- require 'rest_connection'
25
- @client = RightApi::Client.new(:email => 'my@email.com', :password => 'my_password', :account_id => 'my_account_id')
26
- puts "Available methods: #{@client.api_methods}"
27
-
28
- The client makes working with and getting to know the API much easier. It spiders the API dynamically to
29
- discover its resources on the fly. At every step, the user has the ability to query api_methods(), which
30
- indicates the potential methods that can be called. The <tt>config/login.yml.example</tt> file provides
31
- details of different login parameters.
32
-
33
- === Making API calls
34
- Essentially, just follow the RightScale API documentation (available from http://support.rightscale.com)
35
- and treat every resource in the paths as objects that can call other objects using the dot (.) operator:
36
-
37
- Examples:
38
- - Index: /api/clouds/:cloud_id/datacenters => @client.clouds(:id => :cloud_id).show.datacenters.index
39
- - Show: /api/clouds/:cloud_id/datacenters/:id => @client.clouds(:id => :cloud_id).show.datacenters(:id => :datacenter_id).show
40
- - Create: /api/deployments/:deployment_id/servers => @client.deployments(:id => :deployment_id).show.servers.create
41
- - Update: /api/deployments/:deployment_id/servers/:id => @client.deployments(:id => :deployment_id).show.servers(:id => :server_id).update
42
- - Destroy: /api/deployments/:deployment_id/servers/:id => @client.deployments(:id => :deployment_id).show.servers(:id => :server_id).destroy
43
- - An action: /api/servers/:server_id/launch => @client.servers(:id => :server_id).show.launch
44
-
45
- As seen above, whenever you need to chain methods, you must call .show before specifying the next method.
46
-
47
- === Parameters
48
- Pass-in parameters to the method that they belong to. Lets say you want to filter on the index for deployments:
49
- @client.deployments.index(:filter => ['name==my_deployment'])
50
- The filter is the parameter for the index call and not the deployment call.
51
-
52
- === Logging HTTP Requests
53
- The HTTP calls made by rest_connection can be logged in two ways:
54
- 1. Log to a file
55
- @client.log('~/rest_connection.log')
56
- 2. Log to SDTOUT
57
- @client.log(STDOUT)
58
-
59
- == Examples
60
- Get a list of all servers (aka doing an Index call)
61
- @client.servers.index
62
-
63
- Get a list of all servers in a deployment
64
- @client.deployments(:id => 'my_deployment_id').show.servers.index
65
-
66
- Get a particular server (aka doing a Show call)
67
- @client.servers(:id => 'my_server_id').show
68
-
69
- Creating a server involves setting up the required parameters, then calling the create method
70
- server_template_href = @client.server_templates.index(:filter => ['name==Base ServerTemplate']).first.href
71
- cloud = @client.clouds(:id => 'my_cloud_id').show
72
- params = { :server => {
73
- :name => 'Test Server',
74
- :deployment_href => @client.deployments(:id => 'my_deployment_id').show.href,
75
- :instance => {
76
- :server_template_href => server_template_href,
77
- :cloud_href => cloud.href,
78
- :security_group_hrefs => [cloud.security_groups.index(:filter => ['name==default']).first.href],
79
- :ssh_key_href => cloud.ssh_keys.index.first.href,
80
- :datacenter_href => cloud.datacenters.index.first.href
81
- }}}
82
- new_server = @client.servers.create(params)
83
- new_server.api_methods
84
-
85
- Launch the newly created server. Inputs are a bit tricky so they have to be set in a long string
86
- inputs = "inputs[][name]=NAME1&inputs[][value]=text:VALUE1&inputs[][name]=NAME2&inputs[][value]=text:VALUE2"
87
- new_server.show.launch(inputs)
88
-
89
- Run a script on the server. The API does not currently expose right_scripts, hence, the script href has
90
- to be retrieved from the dashboard and put in the following href format.
91
- script_href = "right_script_href=/api/right_scripts/382371"
92
- task = new_server.show.current_instance.show.run_executable(script_href + "&inputs[][name]=TEST_NAME&inputs[][value]=text:VALUE1")
93
- task.show.api_methods
94
-
95
- Update the server's name
96
- params = { :server => {:name => 'New Server Name'}}
97
- @client.servers(:id => 'my_server_id').update(params)
98
-
99
- Terminate the server (i.e. shutdown its current_instance)
100
- @client.servers(:id => 'my_server_id').show.terminate
101
-
102
- Destroy the server (i.e. delete it)
103
- @client.servers(:id => 'my_server_id').destroy
104
-
105
- == Object Types
106
- The client returns 3 types of objects:
107
- - <b>Resources</b>: returned when you are querying a collection of resources, e.g.: <tt>client.deployments</tt>
108
- - <b>Resource</b>: returned when you specify an id and therefore a specific resource, e.g.: <tt>@client.deployments(:id => :deployment_id)</tt>
109
- - When the content-type is type=collection then an array of Resource objects will be returned, e.g.: <tt>@client.deployments.index</tt>
110
- - When the content-type is not a collection then a Resource object will be returned, e.g.: <tt>@client.deployments(:id => deployment_id).show</tt>
111
- - <b>ResourceDetail</b>: returned when you do a .show on a Resource, e.g.: <tt>client.deployments(:id => deployment_id).show</tt>
112
- <b>On all 3 types of objects you can query <tt>.api_methods</tt> to see a list of available methods, e.g.: <tt>client.deployments.api_methods</tt></b>
113
-
114
- === Exceptions:
115
- - <tt>inputs.index</tt> will return an array of ResourceDetail objects since you cannot do a .show on an input
116
- - <tt>session.index</tt> will return a ResourceDetail object since you cannot do a .show on a session
117
- - <tt>tags.by_resource, tags.by_tag</tt> will return an array of ResourceDetail objects since you cannot do a .show on a resource_tag
118
- - <tt>monitoring_metrics(:id => :m_m_id).show.data</tt> will return a ResourceDetail object since you cannot do
119
- a .show on a monitoring_metric_data
120
-
121
- == Instance Facing Calls:
122
- The client also supports 'instance facing calls', which use the instance_token to login.
123
- Unlike regular email-password logins, instance-facing-calls are limited in the amount of allowable calls.
124
- Since in most of the cases, the calls are scoped to the instance's cloud (or the instance itself), the cloud_id and
125
- the instance_id will be automatically recorded by the client, so that the user does not need to specify it.
126
-
127
- === Examples
128
- @instance_client = RightApi::Client.new(:instance_token => 'my_token', :account_id => 'my_account_id')
129
- @instance_client.volume_attachments links to /api/clouds/:cloud_id/volume_attachments
130
- @instance_client.volumes_snapshots links to /api/clouds/:cloud_id/volumes_snapshots
131
- @instance_client.volumes_types links to /api/clouds/:cloud_id/volumes_types
132
- @instance_client.volumes links to /api/clouds/:cloud_id/volumes
133
- @instance_client.backups links to /api/backups
134
- @instance_client.live_tasks(:id) links to /api/clouds/:cloud_id/instances/:instance_id/live/tasks/:id
135
-
136
- === Notes
137
- For volume_attachments and volumes_snapshots you can also go through the volume:
138
- @instance_client.volumes(:id => :volume_id).show.volume_attachments
139
- which maps to:
140
- /api/clouds/:cloud_id/volumes/:volume_id/volume_attachment
141
- The instance's volume_attachments can be accessed using:
142
- @instance_client.get_instance.volume_attachments
143
- which maps to:
144
- /api/clouds/:cloud_id/instances/:instance_id/volume_attachments
145
-
146
- Because the cloud_id and the instance_id are automatically added by the client, scripts that work for regular
147
- email-password logins will have to be modified for instance-facing calls. The main reason behind this is the
148
- inability for instance-facing calls to access the clouds resource (i.e.: <tt>@instance_client.clouds(:id=> :cloud_id).show</tt> will fail)
149
-
150
- When you query <tt>api_methods</tt>, it will list all of the methods that one sees with regular email-password logins.
151
- Due to the limiting scope of the instance-facing calls, only a subset of these methods can be called
152
- (see the API Reference Docs for valid methods). If you call a method that instance's are not authorized to access,
153
- you will get a 403 Permission Denied error.
154
-
155
-
156
- = Design Decisions
157
- In the code, we only hard-code CRUD operations for resources. We use the .show and .index methods to make the client
158
- more efficient. Since it dynamically creates methods it needs to query the API at times. The .show and the .index make
159
- it explicit that querying needs to take place. Without them a GET would have to be queried every step of the way
160
- (i.e.: the index call would be client.deployments, and the create call would be client.deployments.create which would
161
- first do an index call).
162
-
163
- <b>In general, when a new API resource is added, you need to indicate in the client whether index, show, create, update
164
- and delete methods are allowed for that resource.</b>
165
-
166
- == Special Cases
167
- === Returning resource_types that are not actual API resources:
168
- - tags:
169
- - by_resource, by_tag: both return a COLLECTION of resource_type = RESOURCE_TAG
170
- - no show or index is defined for that resource_type, therefore return a collection of ResourceDetail objects
171
- - data:
172
- - querying .data for monitoring_metrics:
173
- - no show is defined for that resource_type, therefore return a ResourceDetail object
174
-
175
- === Index call does not act like an index call
176
- - session:
177
- - session.index should act like a show call and not like an index call (since you cannot query show).
178
- Therefore it should return a ResourceDetail object
179
- - inputs
180
- - inputs.index cannot return a collection of Resource objects since .show is not allowed. Therefore it should
181
- return a collection of ResourceDetail objects
182
-
183
- === Having a resource_type that cannot be accurately determined from the URL:
184
- - In server_arrays.show: resource_type = current_instance(s) (although it should be instance(s))
185
- - In multi_cloud_images.show: resource_type = setting(s) (although it should be multi_cloud_image_setting)
186
- Put these special cases in the <tt>RightApi::Helper::INCONSISTENT_RESOURCE_TYPES</tt> hash.
187
-
188
- === Method defined on the generic resource_type itself
189
- - 'instances' => {:multi_terminate => 'do_post', :multi_run_executable => 'do_post'},
190
- - 'inputs' => {:multi_update => 'do_put'},
191
- - 'tags' => {:by_tag => 'do_post', :by_resource => 'do_post', :multi_add => 'do_post', :multi_delete =>'do_post'},
192
- - 'backups' => {:cleanup => 'do_post'}
193
- Put these special cases in the <tt>RightApi::Helper::RESOURCE_TYPE_SPECIAL_ACTIONS</tt> hash.
194
-
195
- === Resources are not linked together
196
- - In ResourceDetail, resource_type = Instance, need live_tasks as a method.
197
-
198
- = Troubleshooting
199
-
200
- == Wrong ruby version
201
-
202
- Ruby 1.8.7 or higher is required.
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 1.0.2
@@ -1,22 +0,0 @@
1
- # A quick way to login to the API and jump into IRB so you can experiment with the connection.
2
- # Add this to your bash profile to make it simpler:
3
- # alias connection='bundle exec ruby login_to_connection_irb.rb'
4
-
5
- require File.expand_path('../lib/rest_connection', __FILE__)
6
- require 'yaml'
7
- require 'irb'
8
-
9
- begin
10
- @connection = RestConnection::Connection.new()
11
- puts "logged-in to the API, use the '@connection' variable to use the connection"
12
- end
13
-
14
- IRB.start
15
-
16
- #
17
- #require 'rubygems'
18
- #require 'rest_connection'
19
- #require 'ruby-debug'
20
- #
21
- #debugger
22
- #puts "done!"