rest_connection 0.0.13 → 0.0.14
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/rest_connection.rb +10 -5
- data/lib/rest_connection/rightscale/deployment.rb +9 -0
- data/lib/rest_connection/rightscale/mc_server.rb +39 -0
- data/lib/rest_connection/rightscale/rightscale_api_base.rb +10 -0
- data/lib/rest_connection/rightscale/rightscale_api_gateway.rb +48 -0
- data/lib/rest_connection/rightscale/rightscale_api_internal.rb +8 -2
- data/lib/rest_connection/rightscale/rightscale_api_resources.rb +2 -0
- data/lib/rest_connection/rightscale/rs_internal.rb +8 -2
- data/lib/rest_connection/rightscale/server.rb +2 -2
- data/rest_connection.gemspec +4 -2
- metadata +6 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.14
|
data/lib/rest_connection.rb
CHANGED
@@ -29,7 +29,7 @@ module RestConnection
|
|
29
29
|
# :api_url =>
|
30
30
|
# :user =>
|
31
31
|
# :pass =>
|
32
|
-
attr_accessor :settings
|
32
|
+
attr_accessor :settings, :cookie
|
33
33
|
|
34
34
|
# RestConnection api settings configuration file:
|
35
35
|
# Settings are loaded from a yaml configuration file in users home directory.
|
@@ -48,6 +48,8 @@ module RestConnection
|
|
48
48
|
logger("WARNING: see GEM_HOME/rest_connection/config/rest_api_config.yaml for example config")
|
49
49
|
@settings = {}
|
50
50
|
end
|
51
|
+
@settings[:extension] = ".js"
|
52
|
+
@settings[:api_href] = @settings[:api_url] unless @settings[:api_href]
|
51
53
|
end
|
52
54
|
|
53
55
|
# Main HTTP connection loop. Common settings are set here, then we yield(BASE_URI, OPTIONAL_HEADERS) to other methods for each type of HTTP request: GET, PUT, POST, DELETE
|
@@ -60,16 +62,19 @@ module RestConnection
|
|
60
62
|
# end
|
61
63
|
#
|
62
64
|
def rest_connect(&block)
|
63
|
-
uri = URI.parse(@settings[:
|
65
|
+
uri = URI.parse(@settings[:api_href])
|
64
66
|
http = Net::HTTP.new(uri.host, uri.port)
|
65
67
|
if uri.scheme == 'https'
|
66
68
|
http.use_ssl = true
|
67
69
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
68
70
|
end
|
69
71
|
headers = @settings[:common_headers]
|
72
|
+
headers.merge!("Cookie" => @cookie) if @cookie
|
70
73
|
http.start do |http|
|
71
74
|
req = yield(uri, headers)
|
72
|
-
|
75
|
+
unless @cookie
|
76
|
+
req.basic_auth(@settings[:user], @settings[:pass]) if @settings[:user]
|
77
|
+
end
|
73
78
|
logger("#{req.method}: #{req.path}")
|
74
79
|
logger("\trequest body: #{req.body}") if req.body
|
75
80
|
response, body = http.request(req)
|
@@ -84,7 +89,7 @@ module RestConnection
|
|
84
89
|
def get(href, additional_parameters = "")
|
85
90
|
rest_connect do |base_uri,headers|
|
86
91
|
href = "#{base_uri}/#{href}" unless begins_with_slash(href)
|
87
|
-
new_path = URI.escape(href +
|
92
|
+
new_path = URI.escape(href + @settings[:extension] + "?") + requestify(additional_parameters)
|
88
93
|
Net::HTTP::Get.new(new_path, headers)
|
89
94
|
end
|
90
95
|
end
|
@@ -146,7 +151,7 @@ module RestConnection
|
|
146
151
|
def handle_response(res)
|
147
152
|
if res.code.to_i == 201
|
148
153
|
return res['Location']
|
149
|
-
elsif [200,203,204].detect { |d| d == res.code.to_i }
|
154
|
+
elsif [200,203,204,302].detect { |d| d == res.code.to_i }
|
150
155
|
if res.body
|
151
156
|
begin
|
152
157
|
return JSON.load(res.body)
|
@@ -0,0 +1,39 @@
|
|
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 McServer
|
20
|
+
include RightScale::Api::Gateway
|
21
|
+
extend RightScale::Api::GatewayExtend
|
22
|
+
|
23
|
+
def resource_plural_name
|
24
|
+
"servers"
|
25
|
+
end
|
26
|
+
|
27
|
+
def resource_singular_name
|
28
|
+
"server"
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.resource_plural_name
|
32
|
+
"servers"
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.resource_singular_name
|
36
|
+
"server"
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -20,6 +20,11 @@ module RightScale
|
|
20
20
|
module BaseExtend
|
21
21
|
def connection()
|
22
22
|
@@connection ||= RestConnection::Connection.new
|
23
|
+
settings = @@connection.settings
|
24
|
+
settings[:common_headers]["X_API_VERSION"] = "1.0"
|
25
|
+
settings[:api_href] = settings[:api_url]
|
26
|
+
settings[:extension] = ".js"
|
27
|
+
@@connection
|
23
28
|
end
|
24
29
|
|
25
30
|
def resource_plural_name
|
@@ -121,6 +126,11 @@ module RightScale
|
|
121
126
|
|
122
127
|
def connection()
|
123
128
|
@@connection ||= RestConnection::Connection.new
|
129
|
+
settings = @@connection.settings
|
130
|
+
settings[:common_headers]["X_API_VERSION"] = "1.0"
|
131
|
+
settings[:api_href] = settings[:api_url]
|
132
|
+
settings[:extension] = ".js"
|
133
|
+
@@connection
|
124
134
|
end
|
125
135
|
|
126
136
|
def resource_plural_name
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module RightScale
|
2
|
+
module Api
|
3
|
+
module Gateway
|
4
|
+
def connection
|
5
|
+
@@gateway_connection ||= RestConnection::Connection.new
|
6
|
+
settings = @@gateway_connection.settings
|
7
|
+
settings[:common_headers]["X_API_VERSION"] = "1.5"
|
8
|
+
settings[:api_href], account = settings[:api_url].split(/\/acct\//) if settings[:api_url].include?("acct")
|
9
|
+
settings[:extension] = ""
|
10
|
+
unless @@gateway_connection.cookie
|
11
|
+
# login
|
12
|
+
params = { "email" => settings[:user], "password" => settings[:pass], "account_href" => "/api/accounts/#{account}" }
|
13
|
+
resp = @@gateway_connection.post("session", params)
|
14
|
+
raise "ERROR: Login failed. #{resp.message}. Code:#{resp.code}" unless resp.code == "302" || resp.code == "204"
|
15
|
+
@@gateway_connection.cookie = resp.response['set-cookie']
|
16
|
+
|
17
|
+
# test session
|
18
|
+
resp, data = @@gateway_connection.get("session")
|
19
|
+
raise "ERROR: Invalid session. #{resp.message}. Code:#{resp.code}" unless resp.code == "200"
|
20
|
+
end
|
21
|
+
@@gateway_connection
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
module GatewayExtend
|
26
|
+
def connection
|
27
|
+
@@gateway_connection ||= RestConnection::Connection.new
|
28
|
+
settings = @@gateway_connection.settings
|
29
|
+
settings[:common_headers]["X_API_VERSION"] = "1.5"
|
30
|
+
settings[:api_href], account = settings[:api_url].split(/\/acct\//) if settings[:api_url].include?("acct")
|
31
|
+
settings[:extension] = ""
|
32
|
+
unless @@gateway_connection.cookie
|
33
|
+
# login
|
34
|
+
params = { "email" => settings[:user], "password" => settings[:pass], "account_href" => "/api/accounts/#{account}" }
|
35
|
+
resp = @@gateway_connection.post("session", params)
|
36
|
+
raise "ERROR: Login failed. #{resp.message}. Code:#{resp.code}" unless resp.code == "302" || resp.code == "204"
|
37
|
+
@@gateway_connection.cookie = resp.response['set-cookie']
|
38
|
+
|
39
|
+
# test session
|
40
|
+
resp, data = @@gateway_connection.get("session")
|
41
|
+
raise "ERROR: Invalid session. #{resp.message}. Code:#{resp.code}" unless resp.code == "200"
|
42
|
+
end
|
43
|
+
@@gateway_connection
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
@@ -3,7 +3,10 @@ module RightScale
|
|
3
3
|
module Internal
|
4
4
|
def connection
|
5
5
|
@@little_brother_connection ||= RestConnection::Connection.new
|
6
|
-
|
6
|
+
settings = @@little_brother_connection.settings
|
7
|
+
settings[:common_headers]["X_API_VERSION"] = "0.1"
|
8
|
+
settings[:api_href] = settings[:api_url]
|
9
|
+
settings[:extension] = ".js"
|
7
10
|
@@little_brother_connection
|
8
11
|
end
|
9
12
|
end
|
@@ -11,7 +14,10 @@ module RightScale
|
|
11
14
|
module InternalExtend
|
12
15
|
def connection
|
13
16
|
@@little_brother_connection ||= RestConnection::Connection.new
|
14
|
-
|
17
|
+
settings = @@little_brother_connection.settings
|
18
|
+
settings[:common_headers]["X_API_VERSION"] = "0.1"
|
19
|
+
settings[:api_href] = settings[:api_url]
|
20
|
+
settings[:extension] = ".js"
|
15
21
|
@@little_brother_connection
|
16
22
|
end
|
17
23
|
end
|
@@ -16,6 +16,7 @@
|
|
16
16
|
|
17
17
|
require 'rest_connection/rightscale/rightscale_api_base'
|
18
18
|
require 'rest_connection/rightscale/rightscale_api_internal'
|
19
|
+
require 'rest_connection/rightscale/rightscale_api_gateway'
|
19
20
|
require 'rest_connection/rightscale/executable'
|
20
21
|
require 'rest_connection/rightscale/server'
|
21
22
|
require 'rest_connection/rightscale/deployment'
|
@@ -33,6 +34,7 @@ require 'rest_connection/rightscale/alert_spec'
|
|
33
34
|
require 'rest_connection/rightscale/ec2_ebs_volume'
|
34
35
|
require 'rest_connection/rightscale/ec2_ebs_snapshot'
|
35
36
|
require 'rest_connection/rightscale/server_internal'
|
37
|
+
require 'rest_connection/rightscale/mc_server'
|
36
38
|
require 'rest_connection/rightscale/ec2_ssh_key_internal'
|
37
39
|
require 'rest_connection/rightscale/server_template_internal'
|
38
40
|
require 'rest_connection/rightscale/right_script_internal'
|
@@ -22,13 +22,19 @@ class RsInternal
|
|
22
22
|
|
23
23
|
def connection
|
24
24
|
@@little_brother_connection ||= RestConnection::Connection.new
|
25
|
-
|
25
|
+
settings = @@little_brother_connection.settings
|
26
|
+
settings[:common_headers]["X_API_VERSION"] = "0.1"
|
27
|
+
settings[:api_href] = settings[:api_url]
|
28
|
+
settings[:extension] = ".js"
|
26
29
|
@@little_brother_connection
|
27
30
|
end
|
28
31
|
|
29
32
|
def self.connection
|
30
33
|
@@little_brother_connection ||= RestConnection::Connection.new
|
31
|
-
|
34
|
+
settings = @@little_brother_connection.settings
|
35
|
+
settings[:common_headers]["X_API_VERSION"] = "0.1"
|
36
|
+
settings[:api_href] = settings[:api_url]
|
37
|
+
settings[:extension] = ".js"
|
32
38
|
@@little_brother_connection
|
33
39
|
end
|
34
40
|
|
@@ -184,9 +184,9 @@ class Server
|
|
184
184
|
connection.post(serv_href.path + "/attach_volume", hash)
|
185
185
|
end
|
186
186
|
|
187
|
-
def get_sketchy_data
|
187
|
+
def get_sketchy_data(params = {})
|
188
188
|
serv_href = URI.parse(self.href)
|
189
|
-
@params.merge! connection.get(serv_href.path + "/get_sketchy_data")
|
189
|
+
@params.merge! connection.get(serv_href.path + "/get_sketchy_data", params)
|
190
190
|
end
|
191
191
|
|
192
192
|
def monitoring
|
data/rest_connection.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rest_connection}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.14"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jeremy Deininger"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-12-13}
|
13
13
|
s.description = %q{provides rest_connection}
|
14
14
|
s.email = %q{jeremy@rubyonlinux.org}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -42,12 +42,14 @@ Gem::Specification.new do |s|
|
|
42
42
|
"lib/rest_connection/rightscale/ec2_ssh_key_internal.rb",
|
43
43
|
"lib/rest_connection/rightscale/executable.rb",
|
44
44
|
"lib/rest_connection/rightscale/instance.rb",
|
45
|
+
"lib/rest_connection/rightscale/mc_server.rb",
|
45
46
|
"lib/rest_connection/rightscale/multi_cloud_image.rb",
|
46
47
|
"lib/rest_connection/rightscale/multi_cloud_image_cloud_setting_internal.rb",
|
47
48
|
"lib/rest_connection/rightscale/multi_cloud_image_internal.rb",
|
48
49
|
"lib/rest_connection/rightscale/right_script.rb",
|
49
50
|
"lib/rest_connection/rightscale/right_script_internal.rb",
|
50
51
|
"lib/rest_connection/rightscale/rightscale_api_base.rb",
|
52
|
+
"lib/rest_connection/rightscale/rightscale_api_gateway.rb",
|
51
53
|
"lib/rest_connection/rightscale/rightscale_api_internal.rb",
|
52
54
|
"lib/rest_connection/rightscale/rightscale_api_resources.rb",
|
53
55
|
"lib/rest_connection/rightscale/rs_internal.rb",
|
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:
|
4
|
+
hash: 3
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 14
|
10
|
+
version: 0.0.14
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jeremy Deininger
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-12-13 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -95,12 +95,14 @@ files:
|
|
95
95
|
- lib/rest_connection/rightscale/ec2_ssh_key_internal.rb
|
96
96
|
- lib/rest_connection/rightscale/executable.rb
|
97
97
|
- lib/rest_connection/rightscale/instance.rb
|
98
|
+
- lib/rest_connection/rightscale/mc_server.rb
|
98
99
|
- lib/rest_connection/rightscale/multi_cloud_image.rb
|
99
100
|
- lib/rest_connection/rightscale/multi_cloud_image_cloud_setting_internal.rb
|
100
101
|
- lib/rest_connection/rightscale/multi_cloud_image_internal.rb
|
101
102
|
- lib/rest_connection/rightscale/right_script.rb
|
102
103
|
- lib/rest_connection/rightscale/right_script_internal.rb
|
103
104
|
- lib/rest_connection/rightscale/rightscale_api_base.rb
|
105
|
+
- lib/rest_connection/rightscale/rightscale_api_gateway.rb
|
104
106
|
- lib/rest_connection/rightscale/rightscale_api_internal.rb
|
105
107
|
- lib/rest_connection/rightscale/rightscale_api_resources.rb
|
106
108
|
- lib/rest_connection/rightscale/rs_internal.rb
|