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.
- data/README.rdoc +1 -1
- data/Rakefile +2 -3
- data/VERSION +1 -1
- data/git_hooks/post-commit +43 -0
- data/git_hooks/pre-commit +98 -14
- data/lib/rest_connection.rb +150 -22
- data/lib/rest_connection/rightscale/account.rb +2 -0
- data/lib/rest_connection/rightscale/alert_spec.rb +1 -5
- data/lib/rest_connection/rightscale/alert_spec_subject.rb +21 -0
- data/lib/rest_connection/rightscale/audit_entry.rb +2 -0
- data/lib/rest_connection/rightscale/child_account.rb +2 -0
- data/lib/rest_connection/rightscale/cloud.rb +2 -0
- data/lib/rest_connection/rightscale/cloud_account.rb +2 -0
- data/lib/rest_connection/rightscale/ec2_ebs_volume.rb +5 -1
- data/lib/rest_connection/rightscale/ec2_elastic_ip.rb +2 -0
- data/lib/rest_connection/rightscale/ec2_security_group.rb +24 -0
- data/lib/rest_connection/rightscale/ec2_ssh_key.rb +2 -0
- data/lib/rest_connection/rightscale/executable.rb +2 -0
- data/lib/rest_connection/rightscale/instance_type.rb +6 -0
- data/lib/rest_connection/rightscale/mc_datacenter.rb +2 -0
- data/lib/rest_connection/rightscale/mc_image.rb +2 -0
- data/lib/rest_connection/rightscale/mc_instance.rb +2 -0
- data/lib/rest_connection/rightscale/mc_instance_type.rb +2 -0
- data/lib/rest_connection/rightscale/mc_multi_cloud_image.rb +2 -0
- data/lib/rest_connection/rightscale/mc_multi_cloud_image_setting.rb +2 -0
- data/lib/rest_connection/rightscale/mc_security_group.rb +62 -0
- data/lib/rest_connection/rightscale/mc_server_template_multi_cloud_image.rb +2 -0
- data/lib/rest_connection/rightscale/mc_ssh_key.rb +2 -0
- data/lib/rest_connection/rightscale/mc_tag.rb +2 -0
- data/lib/rest_connection/rightscale/mc_volume.rb +2 -0
- data/lib/rest_connection/rightscale/mc_volume_attachment.rb +2 -0
- data/lib/rest_connection/rightscale/mc_volume_snapshot.rb +2 -0
- data/lib/rest_connection/rightscale/mc_volume_type.rb +2 -0
- data/lib/rest_connection/rightscale/monitoring_metric.rb +2 -0
- data/lib/rest_connection/rightscale/multi_cloud_image.rb +2 -0
- data/lib/rest_connection/rightscale/permission.rb +2 -0
- data/lib/rest_connection/rightscale/right_script.rb +3 -0
- data/lib/rest_connection/rightscale/rightscale_api_base.rb +51 -4
- data/lib/rest_connection/rightscale/rightscale_api_gateway.rb +60 -33
- data/lib/rest_connection/rightscale/rightscale_api_resources.rb +5 -0
- data/lib/rest_connection/rightscale/s3_bucket.rb +2 -1
- data/lib/rest_connection/rightscale/security_group_rule.rb +31 -0
- data/lib/rest_connection/rightscale/server_ec2_ebs_volume.rb +40 -0
- data/lib/rest_connection/rightscale/session.rb +61 -0
- data/lib/rest_connection/rightscale/sqs_queue.rb +22 -0
- data/lib/rest_connection/rightscale/tag.rb +2 -0
- data/lib/rest_connection/rightscale/task.rb +4 -2
- data/lib/rest_connection/rightscale/user.rb +2 -0
- metadata +12 -6
@@ -0,0 +1,21 @@
|
|
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
|
+
class AlertSpecSubject
|
17
|
+
include RightScale::Api::Base
|
18
|
+
extend RightScale::Api::BaseExtend
|
19
|
+
|
20
|
+
deny_methods :index, :destroy, :update, :show
|
21
|
+
end
|
@@ -21,6 +21,10 @@ class Ec2EbsVolume
|
|
21
21
|
extend RightScale::Api::TaggableExtend
|
22
22
|
|
23
23
|
def attach(params)
|
24
|
-
|
24
|
+
@link = ServerEc2EbsVolume.create(params)
|
25
|
+
end
|
26
|
+
|
27
|
+
def detach
|
28
|
+
@link.destroy if @link
|
25
29
|
end
|
26
30
|
end
|
@@ -16,4 +16,28 @@
|
|
16
16
|
class Ec2SecurityGroup
|
17
17
|
include RightScale::Api::Base
|
18
18
|
extend RightScale::Api::BaseExtend
|
19
|
+
|
20
|
+
# NOTE - Create, Destroy, and Update require "security_manager" permissions
|
21
|
+
# NOTE - Can't remove rules, can only add
|
22
|
+
def add_rule(opts={})
|
23
|
+
opts.each { |k,v| opts["#{k}".to_sym] = v }
|
24
|
+
update_types = [
|
25
|
+
:name => [:owner, :group],
|
26
|
+
:cidr_ips => [:cidr_ip, :protocol, :from_port, :to_port],
|
27
|
+
:group => [:owner, :group, :protocol, :from_port, :to_port],
|
28
|
+
]
|
29
|
+
type = (opts[:protocol] ? (opts[:cidr_ip] ? :cidr_ips : :group) : :name)
|
30
|
+
unless update_types[type].reduce(true) { |b,field| b && opts[field] }
|
31
|
+
arg_expectation = update_types.values.pretty_inspect
|
32
|
+
raise ArgumentError.new("add_rule requires one of these groupings: #{arg_expectation}")
|
33
|
+
end
|
34
|
+
|
35
|
+
params = {}
|
36
|
+
update_types[type].each { |field| params[field] = opts[field] }
|
37
|
+
|
38
|
+
uri = URI.parse(self.href)
|
39
|
+
connection.put(uri.path, params)
|
40
|
+
|
41
|
+
self.reload
|
42
|
+
end
|
19
43
|
end
|
@@ -17,6 +17,8 @@ class Ec2SshKey
|
|
17
17
|
include RightScale::Api::Base
|
18
18
|
extend RightScale::Api::BaseExtend
|
19
19
|
|
20
|
+
deny_methods :index, :update
|
21
|
+
|
20
22
|
def self.create(opts)
|
21
23
|
create_opts = { self.resource_singular_name.to_sym => opts }
|
22
24
|
create_opts['cloud_id'] = opts['cloud_id'] if opts['cloud_id']
|
@@ -2,6 +2,8 @@ class Executable
|
|
2
2
|
include RightScale::Api::Base
|
3
3
|
extend RightScale::Api::BaseExtend
|
4
4
|
|
5
|
+
deny_methods :index, :create, :destroy, :update
|
6
|
+
|
5
7
|
# executable can be EITHER a right_script or recipe
|
6
8
|
# executable example params format:
|
7
9
|
# can have recipes AND right_scripts
|
@@ -20,10 +20,16 @@ class InstanceType
|
|
20
20
|
include RightScale::Api::Gateway
|
21
21
|
extend RightScale::Api::GatewayExtend
|
22
22
|
|
23
|
+
deny_methods :create, :destroy, :update
|
24
|
+
|
23
25
|
def self.parse_args(cloud_id)
|
24
26
|
"clouds/#{cloud_id}/"
|
25
27
|
end
|
26
28
|
|
29
|
+
def self.filters
|
30
|
+
[:cpu_architecture, :description, :name, :resource_uid]
|
31
|
+
end
|
32
|
+
|
27
33
|
def show
|
28
34
|
inst_href = URI.parse(self.href)
|
29
35
|
@params.merge! connection.get(inst_href.path, 'view' => "default")
|
@@ -20,6 +20,8 @@ class McSecurityGroup
|
|
20
20
|
include RightScale::Api::Gateway
|
21
21
|
extend RightScale::Api::GatewayExtend
|
22
22
|
|
23
|
+
deny_methods :update
|
24
|
+
|
23
25
|
def resource_plural_name
|
24
26
|
"security_groups"
|
25
27
|
end
|
@@ -43,4 +45,64 @@ class McSecurityGroup
|
|
43
45
|
def self.filters
|
44
46
|
[:name, :resource_uid]
|
45
47
|
end
|
48
|
+
|
49
|
+
# NOTE: Create & Destroy require "security_manager" permissions
|
50
|
+
def self.create(cloud_id, opts={})
|
51
|
+
url = "#{parse_args(cloud_id)}#{self.resource_plural_name}"
|
52
|
+
location = connection.post(url, self.resource_singular_name.to_sym => opts)
|
53
|
+
newrecord = self.new('links' => [ {'rel' => 'self', 'href' => location } ])
|
54
|
+
|
55
|
+
rules = opts[:rules] || opts["rules"]
|
56
|
+
[rules].flatten.each { |rule_hash| newrecord.add_rule(rule_hash) } if rules
|
57
|
+
|
58
|
+
newrecord.reload
|
59
|
+
newrecord
|
60
|
+
end
|
61
|
+
|
62
|
+
def rules
|
63
|
+
self.load(SecurityGroupRule)
|
64
|
+
end
|
65
|
+
|
66
|
+
def add_rule(opts={})
|
67
|
+
opts.each { |k,v| opts["#{k}".to_sym] = v }
|
68
|
+
fields = [
|
69
|
+
{"1.0" => :owner, "1.5" => :group_owner}, # optional
|
70
|
+
{"1.0" => :group, "1.5" => :group_name}, # optional
|
71
|
+
{"1.0" => :cidr_ip, "1.5" => :cidr_ips}, # optional
|
72
|
+
{"1.0" => :protocol, "1.5" => :protocol}, # "tcp" || "udp" || "icmp"
|
73
|
+
{"1.0" => :from_port, "1.5" => :start_port}, # optional
|
74
|
+
{"1.0" => :to_port, "1.5" => :end_port}, # optional
|
75
|
+
{ "1.5" => :source_type}, # "cidr_ips" || "group"
|
76
|
+
{ "1.5" => :icmp_code}, # optional
|
77
|
+
{ "1.5" => :icmp_type}, # optional
|
78
|
+
{ "1.5" => :security_group_href}, # optional
|
79
|
+
]
|
80
|
+
unless opts[:protocol]
|
81
|
+
raise ArgumentError.new("add_rule requires the 'protocol' option")
|
82
|
+
end
|
83
|
+
params = {
|
84
|
+
:source_type => ((opts[:cidr_ip] || opts[:cidr_ips]) ? "cidr_ips" : "group"),
|
85
|
+
:security_group_href => self.href,
|
86
|
+
:protocol_details => {}
|
87
|
+
}
|
88
|
+
|
89
|
+
fields.each { |ver|
|
90
|
+
next unless val = opts[ver["1.0"]] || opts[ver["1.5"]]
|
91
|
+
if ver["1.5"].to_s =~ /port|icmp/
|
92
|
+
params[:protocol_details][ver["1.5"]] = val
|
93
|
+
else
|
94
|
+
params[ver["1.5"]] = val
|
95
|
+
end
|
96
|
+
}
|
97
|
+
|
98
|
+
SecurityGroupRule.create(params)
|
99
|
+
end
|
100
|
+
|
101
|
+
def remove_rules_by_filters(filters={})
|
102
|
+
rules_to_delete = rules
|
103
|
+
filters.each do |filter,regex|
|
104
|
+
@rules.reject! { |rule| rule[filter] =~ Regexp.new(regex) }
|
105
|
+
end
|
106
|
+
@rules.each { |rule| rule.destroy }
|
107
|
+
end
|
46
108
|
end
|
@@ -17,6 +17,19 @@ require 'active_support/inflector'
|
|
17
17
|
|
18
18
|
module RightScale
|
19
19
|
module Api
|
20
|
+
BASE_COOKIE_REFRESH = proc do
|
21
|
+
def refresh_cookie
|
22
|
+
# login
|
23
|
+
@cookie = nil
|
24
|
+
resp = get("login")
|
25
|
+
unless resp.code == "302" || resp.code == "204"
|
26
|
+
raise "ERROR: Login failed. #{resp.message}. Code:#{resp.code}"
|
27
|
+
end
|
28
|
+
@cookie = resp.response['set-cookie']
|
29
|
+
true
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
20
33
|
module BaseExtend
|
21
34
|
def connection()
|
22
35
|
@@connection ||= RestConnection::Connection.new
|
@@ -24,6 +37,12 @@ module RightScale
|
|
24
37
|
settings[:common_headers]["X_API_VERSION"] = "1.0"
|
25
38
|
settings[:api_href] = settings[:api_url]
|
26
39
|
settings[:extension] = ".js"
|
40
|
+
|
41
|
+
unless @@connection.respond_to?(:refresh_cookie)
|
42
|
+
@@connection.instance_exec(&(RightScale::Api::BASE_COOKIE_REFRESH))
|
43
|
+
end
|
44
|
+
|
45
|
+
@@connection.refresh_cookie unless @@connection.cookie
|
27
46
|
@@connection
|
28
47
|
end
|
29
48
|
|
@@ -59,7 +78,7 @@ module RightScale
|
|
59
78
|
end
|
60
79
|
|
61
80
|
def find_by_nickname(nickname)
|
62
|
-
connection.logger("
|
81
|
+
connection.logger("DEPRECATION WARNING: use of find_by_nickname is deprecated, please use find_by(:nickname) { |n| n == '#{nickname}' } ")
|
63
82
|
self.find_by(:nickname) { |n| n == nickname }
|
64
83
|
end
|
65
84
|
|
@@ -89,7 +108,7 @@ module RightScale
|
|
89
108
|
end
|
90
109
|
|
91
110
|
def find_by_id(id)
|
92
|
-
connection.logger("
|
111
|
+
connection.logger("DEPRECATION WARNING: use of find_by_id is deprecated, please use find(id) ")
|
93
112
|
self.find(id)
|
94
113
|
end
|
95
114
|
|
@@ -100,12 +119,12 @@ module RightScale
|
|
100
119
|
newrecord
|
101
120
|
end
|
102
121
|
|
103
|
-
# filter is only implemented on some api endpoints
|
122
|
+
# filter is only implemented on some api endpoints
|
104
123
|
def find_by_nickname_speed(nickname)
|
105
124
|
self.find_with_filter('nickname' => nickname)
|
106
125
|
end
|
107
126
|
|
108
|
-
# filter is only implemented on some api endpoints
|
127
|
+
# filter is only implemented on some api endpoints
|
109
128
|
def find_with_filter(filter = {})
|
110
129
|
filter_params = []
|
111
130
|
filter.each { |key,val|
|
@@ -160,6 +179,28 @@ module RightScale
|
|
160
179
|
}
|
161
180
|
return (args.empty? ? find_all : ret.flatten.uniq)
|
162
181
|
end
|
182
|
+
|
183
|
+
def deny_methods(*symbols)
|
184
|
+
symbols.map! { |sym| sym.to_sym }
|
185
|
+
if symbols.delete(:index)
|
186
|
+
symbols |= [:find_all, :find_by, :find_by_cloud_id, :find_by_nickname, :find_by_nickname_speed, :find_with_filter]
|
187
|
+
end
|
188
|
+
if symbols.delete(:show)
|
189
|
+
symbols |= [:show, :reload, :find, :find_by_id]
|
190
|
+
end
|
191
|
+
if symbols.delete(:update)
|
192
|
+
symbols |= [:save, :update]
|
193
|
+
end
|
194
|
+
symbols.each do |sym|
|
195
|
+
sym = sym.to_sym
|
196
|
+
eval_str = "undef #{sym.inspect}"
|
197
|
+
if self.respond_to?(sym)
|
198
|
+
instance_eval(eval_str)
|
199
|
+
elsif self.new.respond_to?(sym)
|
200
|
+
class_eval(eval_str)
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
163
204
|
end
|
164
205
|
|
165
206
|
module Base
|
@@ -175,6 +216,12 @@ module RightScale
|
|
175
216
|
settings[:common_headers]["X_API_VERSION"] = "1.0"
|
176
217
|
settings[:api_href] = settings[:api_url]
|
177
218
|
settings[:extension] = ".js"
|
219
|
+
|
220
|
+
unless @@connection.respond_to?(:refresh_cookie)
|
221
|
+
@@connection.instance_exec(&(RightScale::Api::BASE_COOKIE_REFRESH))
|
222
|
+
end
|
223
|
+
|
224
|
+
@@connection.refresh_cookie unless @@connection.cookie
|
178
225
|
@@connection
|
179
226
|
end
|
180
227
|
|