right_api_helper 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
@@ -43,7 +43,7 @@ module RightApiHelper
|
|
43
43
|
ssh_key = nil
|
44
44
|
if ssh_uuid
|
45
45
|
# grab specific ssh key
|
46
|
-
sshkey =
|
46
|
+
sshkey = find_cloud_resource(cloud, :ssh_keys, :by_resource_uid, ssh_uuid)
|
47
47
|
else
|
48
48
|
# grab first key found
|
49
49
|
keys = cloud.show.ssh_keys
|
@@ -78,11 +78,10 @@ module RightApiHelper
|
|
78
78
|
|
79
79
|
def delete_server(name)
|
80
80
|
server = find_server_by_name(name)
|
81
|
-
server.terminate
|
82
81
|
begin
|
82
|
+
server.terminate
|
83
83
|
server_wait_for_state(server, "terminated")
|
84
|
-
rescue
|
85
|
-
|
84
|
+
rescue
|
86
85
|
end
|
87
86
|
server.destroy
|
88
87
|
end
|
@@ -115,6 +114,10 @@ module RightApiHelper
|
|
115
114
|
find_cloud_resource(cloud, :security_groups, :by_name, security_group_name)
|
116
115
|
end
|
117
116
|
|
117
|
+
def find_security_group_by_id(cloud, security_group_uid)
|
118
|
+
find_cloud_resource(cloud, :security_groups, :by_resource_uid, security_group_uid)
|
119
|
+
end
|
120
|
+
|
118
121
|
def find_server_by_name(name)
|
119
122
|
find_resource(:servers, :by_name, name)
|
120
123
|
end
|
@@ -144,7 +147,7 @@ module RightApiHelper
|
|
144
147
|
end
|
145
148
|
|
146
149
|
if name
|
147
|
-
@log.
|
150
|
+
@log.debug "ServerTemplate name detected."
|
148
151
|
# find ServerTemplate by name
|
149
152
|
st_list = list_resources(:server_templates, :by_name, name)
|
150
153
|
revisions = st_list.map { |st| st.revision }
|
@@ -159,7 +162,7 @@ module RightApiHelper
|
|
159
162
|
server_template = st_list.select { |st| st.revision == latest_rev}.first
|
160
163
|
raise RightScaleError, "ERROR: Unable to find ServerTemplate with the name of '#{name}' found " unless server_template
|
161
164
|
else
|
162
|
-
@log.
|
165
|
+
@log.debug "Looking up ServerTemplate by ID."
|
163
166
|
# find ServerTemplate by id
|
164
167
|
server_template = @client.server_templates.index(:id => id)
|
165
168
|
end
|
@@ -348,7 +351,7 @@ module RightApiHelper
|
|
348
351
|
|
349
352
|
def list_subresources(api_resource, subresource, filter_key, filter_value)
|
350
353
|
raise ArgumentError.new("subresource must be a symbol") unless subresource.kind_of?(Symbol)
|
351
|
-
key = filter_key.to_s.
|
354
|
+
key = filter_key.to_s.sub(/by_/,"") # convert :by_name to "name"
|
352
355
|
filter = {}
|
353
356
|
filter = {:filter => ["#{key}==#{filter_value}"]} if filter_value
|
354
357
|
list = api_resource.show.send(subresource).index(filter)
|
@@ -134,7 +134,8 @@ module RightApiHelper
|
|
134
134
|
security_groups ||= ["default"]
|
135
135
|
security_groups.each do |name|
|
136
136
|
group = @api_shim.find_security_group_by_name(@cloud, name)
|
137
|
-
|
137
|
+
group = @api_shim.find_security_group_by_id(@cloud, name) unless group
|
138
|
+
raise RightScaleError, "ERROR: cannot find an security group : #{name}" unless group
|
138
139
|
@sec_groups << group
|
139
140
|
end
|
140
141
|
end
|
@@ -192,7 +193,7 @@ module RightApiHelper
|
|
192
193
|
|
193
194
|
# setup any inputs
|
194
195
|
begin
|
195
|
-
@
|
196
|
+
@api_shim.set_server_inputs(@server, inputs) if inputs && ! inputs.empty?
|
196
197
|
rescue Exception => e
|
197
198
|
raise RightScaleError, "Problem setting inputs. \n #{e.message}\n\n"
|
198
199
|
end
|
data/spec/provisioner_spec.rb
CHANGED