ibm-cloud-sdk 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 160845336c50ab1c67c274cb62fd5e52af7bf0d6e4b5a4a1b57c4ea3c5eb47db
4
- data.tar.gz: 7762d522d6754815a4e19a927bdcce0d73a8c5a0d204980d44dfdf006d7254d4
3
+ metadata.gz: 49b6c34b47c964d6025eb8ca01efc3221fe33603c1c56b3e86167925f6132f60
4
+ data.tar.gz: df5e08b1f01c0e05fbec5e8f5887139dde7210be53b2cf538b0357b7efe5f0a1
5
5
  SHA512:
6
- metadata.gz: f42fe440d6a3610c94b7336246eda2dfdf6f794afa501480e633563d3a25f2d27bc337ebf41f82b82dad3a3958c2dbbf094244da77021fbe188fffa5cb73d294
7
- data.tar.gz: 7af6df6df99133b619aa62bcc03281dc58f8b1f79c1b26d57b6cbf490dfc85f0dbdd46d41306780d8ead81148d71bf9003b78b787d8d21a64c6974ac0fc546a7
6
+ metadata.gz: afe2bfaae5cb2a853cd7ba2523a2aed7f0da6f6c319d1c2d730993ab5dc93613e928a423a0a7e0310023e96ad71aaa2f8129b5908d0c767e3679fdae8fa063ec
7
+ data.tar.gz: 91d9e41682d13a1671d63c57fb2a4620b8b5f4d001c055036b7942b60a1e57b9e8a348a4615866851ff09389f6ed868ce7a62eff15b85c7bc8d564559f1180c2
@@ -1,6 +1,12 @@
1
1
  # Changelog
2
2
  All notable changes to the gem ibm-cloud-sdk-ruby will be documented here.
3
3
 
4
+ ## v0.1.7 - 2020-09-28
5
+ - Added Logging in IBM Cloud
6
+ - Add VCR to vpc spec
7
+ - Add exception when status of response is not in 200 range or 404
8
+ - Power IaaS Update docstrings, VM actions volumes
9
+
4
10
  ## v0.1.6 - 2020-09-23
5
11
  - Add PowerIaaS method to get instance info
6
12
  - Return region specific PowerVS storage types
data/Gemfile CHANGED
@@ -5,3 +5,5 @@ gemspec
5
5
 
6
6
  gem "rake", "~> 12.0"
7
7
  gem "rspec", "~> 3.0"
8
+ gem 'vcr'
9
+ gem 'webmock'
@@ -8,6 +8,7 @@ require "ibm/cloud/sdk/power_iaas"
8
8
  require "ibm/cloud/sdk/resource_controller"
9
9
  require "ibm/cloud/sdk/version"
10
10
  require "ibm/cloud/sdk/vpc/cloud_sdk"
11
+ require "ibm/cloud/sdk/logging"
11
12
 
12
13
  module IBM
13
14
  module Cloud
@@ -0,0 +1,21 @@
1
+ require_relative 'null_logger'
2
+
3
+ module IBM
4
+ module Cloud
5
+ module SDK
6
+ class << self
7
+ attr_writer :logger
8
+ end
9
+
10
+ def self.logger
11
+ @logger ||= NullLogger.new
12
+ end
13
+
14
+ module Logging
15
+ def logger
16
+ IBM::Cloud::SDK.logger
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,19 @@
1
+ require "logger"
2
+
3
+ module IBM
4
+ module Cloud
5
+ module SDK
6
+ class NullLogger < Logger
7
+ def initialize(*_args)
8
+ end
9
+
10
+ def add(*_args, &_block)
11
+ end
12
+
13
+ def debug?
14
+ false
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,7 +1,11 @@
1
+ require_relative 'logging'
2
+
1
3
  module IBM
2
4
  module Cloud
3
5
  module SDK
4
6
  class PowerIaas < BaseService
7
+ include Logging
8
+
5
9
  # Create an API Client object for the Power IaaS service
6
10
  #
7
11
  # @param region [String] the IBM Power Cloud instance region
@@ -15,8 +19,12 @@ module IBM
15
19
  @region = region
16
20
  @token = token
17
21
  @tenant = tenant
22
+ RestClient.log = logger
18
23
  end
19
24
 
25
+ # Get the API service Endpoint URL
26
+ #
27
+ # @return [String] Endpoint URL
20
28
  def endpoint
21
29
  "https://#{region.sub(/-\d$/, '')}.power-iaas.cloud.ibm.com/pcloud/v1"
22
30
  end
@@ -41,12 +49,15 @@ module IBM
41
49
 
42
50
  # Get an IBM Power Cloud PVM instance
43
51
  #
44
- # @param pvm_instance_id [String] the PVM instance ID
52
+ # @param pvm_instance_id [String] PVM instance ID
45
53
  # @return [Hash] PVM Instances
46
54
  def get_pvm_instance(instance_id)
47
55
  get("cloud-instances/#{guid}/pvm-instances/#{instance_id}")
48
56
  end
49
57
 
58
+ # Perform 'start' action on a PVMInstance
59
+ #
60
+ # @param pvm_instance_id [String] PVM instance ID
50
61
  def start_pvm_instance(instance_id)
51
62
  post(
52
63
  "cloud-instances/#{guid}/pvm-instances/#{instance_id}/action",
@@ -54,6 +65,9 @@ module IBM
54
65
  )
55
66
  end
56
67
 
68
+ # Perform 'stop' action on a PVMInstance
69
+ #
70
+ # @param pvm_instance_id [String] PVM instance ID
57
71
  def stop_pvm_instance(instance_id)
58
72
  post(
59
73
  "cloud-instances/#{guid}/pvm-instances/#{instance_id}/action",
@@ -61,6 +75,22 @@ module IBM
61
75
  )
62
76
  end
63
77
 
78
+ # Perform 'immediate-shutdown' action on a PVMInstance
79
+ #
80
+ # @param pvm_instance_id [String] PVM instance ID
81
+ def immediate_shutdown_pvm_instance(instance_id)
82
+ post(
83
+ "cloud-instances/#{guid}/pvm-instances/#{instance_id}/action",
84
+ {"action" => "immediate-shutdown"}.to_json
85
+ )
86
+ end
87
+
88
+ # Perform 'reboot' action on a PVMInstance
89
+ #
90
+ # This action has been deprecated and replaced by 'soft-reboot'
91
+ # and 'hard-reboot'
92
+ #
93
+ # @param pvm_instance_id [String] PVM instance ID
64
94
  def reboot_pvm_instance(instance_id)
65
95
  post(
66
96
  "cloud-instances/#{guid}/pvm-instances/#{instance_id}/action",
@@ -68,10 +98,47 @@ module IBM
68
98
  )
69
99
  end
70
100
 
101
+ # Perform 'soft-reboot' action on a PVMInstance
102
+ #
103
+ # @param pvm_instance_id [String] PVM instance ID
104
+ def soft_reboot_pvm_instance(instance_id)
105
+ post(
106
+ "cloud-instances/#{guid}/pvm-instances/#{instance_id}/action",
107
+ {"action" => "soft-reboot"}.to_json
108
+ )
109
+ end
110
+
111
+ # Perform 'hard-reboot' action on a PVMInstance
112
+ #
113
+ # @param pvm_instance_id [String] PVM instance ID
114
+ def hard_reboot_pvm_instance(instance_id)
115
+ post(
116
+ "cloud-instances/#{guid}/pvm-instances/#{instance_id}/action",
117
+ {"action" => "hard-reboot"}.to_json
118
+ )
119
+ end
120
+
121
+ # Perform 'reset-state' action on a PVMInstance
122
+ #
123
+ # @param pvm_instance_id [String] PVM instance ID
124
+ def reset_state_pvm_instance(instance_id)
125
+ post(
126
+ "cloud-instances/#{guid}/pvm-instances/#{instance_id}/action",
127
+ {"action" => "reset-state"}.to_json
128
+ )
129
+ end
130
+
131
+ # Create a new PVM instance
132
+ #
133
+ # @param instance_hash [Hash] New instance attributes
134
+ # @return [Hash] PVMInstance
71
135
  def create_pvm_instance(instance_hash)
72
136
  post("cloud-instances/#{guid}/pvm-instances", instance_hash.to_json)
73
137
  end
74
138
 
139
+ # Delete a PVM instance
140
+ #
141
+ # @param pvm_instance_id [String] PVM instance ID
75
142
  def delete_pvm_instance(instance_id)
76
143
  delete("cloud-instances/#{guid}/pvm-instances/#{instance_id}")
77
144
  end
@@ -89,7 +156,7 @@ module IBM
89
156
 
90
157
  # Get an IBM Power Cloud image
91
158
  #
92
- # @param image_id [String] The ID of an Image
159
+ # @param image_id [String] Image ID
93
160
  # @return [Hash] Image
94
161
  def get_image(image_id)
95
162
  get("cloud-instances/#{guid}/images/#{image_id}")
@@ -97,6 +164,9 @@ module IBM
97
164
  nil
98
165
  end
99
166
 
167
+ # Delete an image from a cloud instance
168
+ #
169
+ # @param image_id [String] Image ID
100
170
  def delete_image(image_id)
101
171
  delete("cloud-instances/#{guid}/images/#{image_id}")
102
172
  end
@@ -114,7 +184,7 @@ module IBM
114
184
 
115
185
  # Get a specific volume
116
186
  #
117
- # @param volume_id [String] The ID of a volume
187
+ # @param volume_id [String] Image ID
118
188
  # @return [Hash] Volume
119
189
  def get_volume(volume_id)
120
190
  get("cloud-instances/#{guid}/volumes/#{volume_id}")
@@ -122,7 +192,7 @@ module IBM
122
192
 
123
193
  # Delete a volume
124
194
  #
125
- # @param volume_id [String] The ID of a volume
195
+ # @param volume_id [String] Volume ID
126
196
  def delete_volume(volume_id)
127
197
  delete("cloud-instances/#{guid}/volumes/#{volume_id}")
128
198
  end
@@ -135,6 +205,22 @@ module IBM
135
205
  post("cloud-instances/#{guid}/volumes", volume_hash.to_json)
136
206
  end
137
207
 
208
+ # Attach a volume
209
+ #
210
+ # @param pvm_instance_id [String] PVM Instance ID
211
+ # @param volume_id [String] Volume ID
212
+ def attach_volume(pvm_instance_id, volume_id)
213
+ post("cloud-instances/#{guid}/volumes/#{volumd_id}")
214
+ end
215
+
216
+ # Detach a volume
217
+ #
218
+ # @param pvm_instance_id [String] PVM Instance ID
219
+ # @param volume_id [String] Volume ID
220
+ def detach_volume(pvm_instance_id, volume_id)
221
+ delete("cloud-instances/#{guid}/volumes/#{volumd_id}")
222
+ end
223
+
138
224
  # Get all networks in an IBM Power Cloud instance
139
225
  #
140
226
  # @return [Array<Hash>] all networks for this IBM Power Cloud instance
@@ -147,7 +233,7 @@ module IBM
147
233
 
148
234
  # Get an IBM Power Cloud network
149
235
  #
150
- # @param network_id [String] the network ID
236
+ # @param network_id [String] Network ID
151
237
  # @return [Hash] Network
152
238
  def get_network(network_id)
153
239
  get("cloud-instances/#{guid}/networks/#{network_id}")
@@ -161,42 +247,64 @@ module IBM
161
247
  end
162
248
 
163
249
  # Get a storage types list in IBM Power Cloud.
164
- # note: this mehod to be refactored under the common
250
+ # note: this method to be refactored under the common
165
251
  # IBM::Cloud::SDK::PowerIaas.endpoint when the rest api become available.
166
252
  #
167
- # @return [Hash] StorageType
253
+ # @return [Array<Hash>] StorageType
168
254
  def get_storage_types
169
255
  JSON.parse(RestClient.get("https://#{region.sub(/-\d$/, '')}.power-iaas.cloud.ibm.com/broker/v1/storage-types", headers))[region]
170
256
  end
171
257
 
258
+ # Create a new network
259
+ #
260
+ # @param network_hash [Hash] New network attributes
261
+ # @return [Hash] Network
172
262
  def create_network(network_hash)
173
263
  post("cloud-instances/#{guid}/networks", network_hash.to_json)
174
264
  end
175
265
 
266
+ # Delete a network
267
+ #
268
+ # @param network_id [String] Network ID
176
269
  def delete_network(network_id)
177
270
  delete("cloud-instances/#{guid}/networks/#{network_id}")
178
271
  end
179
272
 
273
+ # Get all ports for a network
274
+ #
275
+ # @param network_id [String] Network ID
276
+ # @return [Array<Hash>] NetworkPort
180
277
  def get_network_ports(network_id)
181
278
  get("cloud-instances/#{guid}/networks/#{network_id}/ports")["ports"]
182
279
  end
183
280
 
281
+ # List the tenant's SSH Keys
282
+ #
283
+ # @return [Array<Hash>] SSHKey
184
284
  def get_ssh_keys
185
285
  get("tenants/#{tenant}")["sshKeys"]
186
286
  end
187
287
 
288
+ # Add a new SSH key to the tenant
289
+ #
290
+ # @param name [String] User defined name for the SSH key
291
+ # @param sshkey [String] SSH RSA key
292
+ # @return [Hash] SSHKey
188
293
  def create_key_pair(name, sshkey)
189
294
  payload = {"name" => name, "sshkey" => sshkey}
190
295
  post("tenants/#{tenant}/sshkeys", payload.to_json)
191
296
  end
192
297
 
298
+ # Delete SSH key from the tenant
299
+ #
300
+ # @param sshkey_name [String] SSH Key name
193
301
  def delete_key_pair(name)
194
302
  delete("tenants/#{tenant}/sshkeys/#{name}")
195
303
  end
196
304
 
197
305
  # Get an SAP profile
198
306
  #
199
- # @param sap_profile_id [String] The ID of an SAP profile
307
+ # @param sap_profile_id [String] SAP Profile ID
200
308
  # @return [Hash] SAP profile
201
309
  def get_sap_profile(sap_profile_id)
202
310
  get("cloud-instances/#{guid}/sap/#{sap_profile_id}")
@@ -219,7 +327,7 @@ module IBM
219
327
  # instance is the standard 'PVMInstance' type and can be accessed via
220
328
  # the existing *_pvm_instance methods.
221
329
  #
222
- # @param sap_profile_id [String] The ID of an SAP profile
330
+ # @param sap_profile_id [String] SAP Profile ID
223
331
  # @return [Hash] SAP profile
224
332
  def create_sap_pvm_instance(instance_hash)
225
333
  post("cloud-instances/#{guid}/sap", instance_hash.to_json)
@@ -1,7 +1,7 @@
1
1
  module IBM
2
2
  module Cloud
3
3
  module SDK
4
- VERSION = "0.1.6"
4
+ VERSION = "0.1.7"
5
5
  end
6
6
  end
7
7
  end
@@ -4,6 +4,7 @@
4
4
  require_relative 'vpc/base_vpc'
5
5
  require_relative 'vpc/base_collection'
6
6
  require_relative 'vpc/base_instance'
7
+ require_relative 'vpc/exceptions'
7
8
 
8
9
  require_relative 'vpc/floatingips'
9
10
  require_relative 'vpc/flowlogcollectors'
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IBM
4
+ module Cloud
5
+ module SDK
6
+ module VPC
7
+ # Module to contain all custom exception classes.
8
+ module Exceptions
9
+ # An exception for http with a response attribute.
10
+ # @param response [IBM::Cloud::SDK::VPC::Response] The original response object.
11
+ # @param msg [String] A human readable message.
12
+ class ExceptionWithResponse < RuntimeError
13
+ def initialize(response, msg)
14
+ @response = response
15
+ super(msg)
16
+ end
17
+ # @return [IBM::Cloud::SDK::VPC::Response] The response
18
+ attr_reader :response
19
+ end
20
+
21
+ # An exception for http status errors with a response attribute.
22
+ # @param response [IBM::Cloud::SDK::VPC::Response] The original response object.
23
+ class HttpStatusError < ExceptionWithResponse
24
+ def initialize(response)
25
+ msg = "Invalid status #{response.code} for url \"#{response.url}\", #{response.reason}. #{response.body}"
26
+ super(response, msg)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -8,8 +8,10 @@ module IBM
8
8
  module Cloud
9
9
  module SDK
10
10
  module VPC
11
-
12
- # Contols tokens.
11
+ # The Connection object to be used for all HTTP requests.
12
+ # @param api_key [String] The API Key to be used for this account.
13
+ # @param logger [Logger] An instantiated logger instance.
14
+ # @param client [HTTP::Client] An instantiated HTTP client.
13
15
  class Connection
14
16
  def initialize(api_key, logger: nil, client: nil)
15
17
  @api_key = api_key
@@ -20,17 +22,36 @@ module IBM
20
22
 
21
23
  attr_reader :client
22
24
 
25
+ # Send a HTTP request. Checks the validity of the response.
26
+ # @param verb [String] THe HTTP verb to use for this request.
27
+ # @param uri [String] The Full URL to send.
28
+ # @option opts [Hash] :params Parameters for URL encoding parameters.
29
+ # @option opts [Hash] :json Used when sending a hash as application/json content type.
30
+ # @option opts [Hash] :form Used when sending a hash as a form.
31
+ # @option opts [Hash] :headers Used to modify headers for request.
32
+ # @return [IBM::Cloud::SDK::VPC::Response] Wrapped response to query.
33
+ # @raise [IBM::Cloud::SDK::VPC::Exceptions::HttpStatusError] Response code is not either in 200-series or 404.
23
34
  def adhoc(verb, uri, opts = {})
24
- response = @client.auth(@token.authorization_header).request(verb.to_sym, uri, opts)
35
+ unverified_request(verb, uri, opts).raise_for_status?
36
+ end
37
+
38
+ # Send a HTTP request. Don't do any validation checks.
39
+ # @see :adhoc for options.
40
+ def unverified_request(verb, uri, opts = {})
41
+ response = @client.auth(@token.authorization_header).request(verb.to_s.downcase.to_sym, uri, opts)
25
42
  Response.new(response)
26
43
  end
27
44
 
45
+ # Get bearer token string for clients not using the adhoc method.
28
46
  def authorization_header
29
47
  @token.authorization_header
30
48
  end
31
49
  end
32
50
 
33
- # Get a token.
51
+ # The IAM token manager.
52
+ # @param api_key [String] The API Key to be used for this account.
53
+ # @param logger [Logger] An instantiated logger instance.
54
+ # @param client [HTTP::Client] An instantiated HTTP client.
34
55
  class Token
35
56
  def initialize(api_key, logger: nil, client: nil)
36
57
  @api_key = api_key
@@ -39,6 +60,9 @@ module IBM
39
60
  @data = fetch
40
61
  end
41
62
 
63
+ # Retrieve a new access_token from IAM.
64
+ # @return [IBM::Cloud::SDK::VPC::Response] Wrapped response to query.
65
+ # @raise [IBM::Cloud::SDK::VPC::Exceptions::HttpStatusError] Response code is not either in 200-series or 404.
42
66
  def fetch
43
67
  payload = {
44
68
  form: {
@@ -47,14 +71,20 @@ module IBM
47
71
  }
48
72
  }
49
73
  response = HTTP.post('https://iam.cloud.ibm.com/identity/token', payload)
50
- @data = Response.new(response).json
74
+ @data = Response.new(response).raise_for_status?.json
51
75
  end
52
76
 
77
+ # Check to see if the access_token is expired. Fetch a new token if none exists.
78
+ # @return [IBM::Cloud::SDK::VPC::Response] Wrapped response to query.
79
+ # @raise [IBM::Cloud::SDK::VPC::Exceptions::HttpStatusError] Response code is not either in 200-series or 404.
53
80
  def expired?
54
81
  fetch unless @data
55
82
  @data.fetch(:expiration).to_i <= Time.now.to_i + 600
56
83
  end
57
84
 
85
+ # Get a Bearer token string. Before returning check to see if token is expired.
86
+ # @return [String] The Bearer token header used in subsequent requests.
87
+ # @raise [IBM::Cloud::SDK::VPC::Exceptions::HttpStatusError] Response code is not either in 200-series or 404.
58
88
  def authorization_header
59
89
  fetch if expired?
60
90
  "#{@data.fetch(:token_type)} #{@data.fetch(:access_token)}"
@@ -8,82 +8,124 @@ module IBM
8
8
  module SDK
9
9
  module VPC
10
10
  # Encapsulate the HTTP response.
11
+ # @param response [HTTP::Response] The HTTP response object.
11
12
  class Response
12
13
  def initialize(response)
13
14
  @response = response
14
15
  end
15
16
 
17
+ # The raw HTTP response.
18
+ # @return [HTTP::Response]
16
19
  attr_reader :response
17
20
 
18
21
  # Return the response in a hash or array.
22
+ # @return [Hash] When response is a hash.
23
+ # @return [Array] When response is an array.
24
+ # @raise [Exceptions::ExceptionWithResponse] Contents of body is not properly formatted json.
19
25
  def json
20
26
  JSON.parse(body, symbolize_names: true)
21
27
  rescue StandardError
22
- raise "Error while parsing response body. #{response.body}"
28
+ raise Exceptions::ExceptionWithResponse.new(self, "#{url} Error while parsing response body. #{response.body}")
23
29
  end
24
30
 
25
31
  # Return the raw response string.
32
+ # @return [String]
33
+ # @return [nil] Response does not have body method.
26
34
  def body
27
- response.body.to_s
35
+ response&.body.to_s
28
36
  end
29
37
 
30
38
  # Return the response code.
39
+ # @return [Integer] Response has code method.
40
+ # @return [nil] Response does not have code method.
31
41
  def code
32
- response.code
42
+ response&.code
33
43
  end
34
44
 
35
- alias_method :status, :code
45
+ alias status code
36
46
 
37
47
  # Return the raw connection object.
48
+ # @return [HTTP::Connection]
49
+ # @return [nil] Response does not have a connection method.
38
50
  def connection
39
- response.connection
51
+ response&.connection
52
+ end
53
+
54
+ # Chainable method to verify the status code. Raise an exception for non 200-series or 404 status codes.
55
+ # @return [Response] Allows for method to be chainable.
56
+ # @raise [Exceptions::HttpStatusError] Raise if status checks failed.
57
+ def raise_for_status?
58
+ return self if (200..299).include?(code)
59
+ return self if code == 404
60
+
61
+ raise Exceptions::HttpStatusError.new(self)
40
62
  end
41
63
 
42
64
  # Return the content type of the response.
65
+ # @return [String] The mimetype of the response.
66
+ # @return [nil] Response does not have response method that responds to mime_type.
43
67
  def content_type
44
- response.response.mime_type
68
+ response&.response&.mime_type
45
69
  end
46
70
 
47
71
  # Return the textual reason.
72
+ # @return [String] HTTP Reason
73
+ # @return [nil] Response does not have reaspn method that responds.
48
74
  def reason
49
- response.reason
75
+ response&.reason
50
76
  end
51
77
 
52
78
  # Return the sent url as a string.
79
+ # @return [String] Full URL sent
80
+ # @return [nil] Response does not have response method that responds to mime_type.
53
81
  def url
54
- response.uri.to_s
82
+ response&.uri.to_s
55
83
  end
56
84
 
57
85
  # Return the sent url as a URI class.
86
+ # @see https://github.com/httprb/http/blob/master/lib/http/uri.rb URI Class doc.
87
+ # @return [HTTP::URI]
88
+ # @return [nil] Response does not have response method that responds to mime_type.
58
89
  def uri
59
- response.uri
90
+ response&.uri
60
91
  end
61
92
 
62
93
  # Verify that the json response is a hash.
94
+ # @return [Hash] Response from JSON
95
+ # @raise [RuntimeError] JSON object is not a Hash.
63
96
  def hash_response
64
97
  check_object(Hash)
65
98
  end
66
99
 
67
100
  # Verify that the json response is an array.
101
+ # @return [Array] Response from JSON
102
+ # @raise [RuntimeError] JSON object is not a Array.
68
103
  def array_response
69
104
  check_object(Array)
70
105
  end
71
106
 
72
107
  # Find a subkey within the returned response.
108
+ # @param key [String] Name of a first level key.
109
+ # @return [Any] Response from JSON
110
+ # @raise [RuntimeError] JSON object is not a Array.
73
111
  def subkey(key)
74
112
  ret = hash_response
75
113
  sym_key = key.to_sym
76
114
  return ret.fetch(sym_key) if ret.key?(sym_key)
77
115
 
78
- raise "Key #{key} not found in #{ret}."
116
+ msg = "Key #{key} not found in #{ret}."
117
+ raise Exceptions::ExceptionWithResponse.new(self, msg)
79
118
  end
80
119
 
81
120
  # Check to see if the returned object is the expected object.
121
+ # @param obj [Object] The object to test the response against.
122
+ # @raise [Exceptions::ExceptionWithResponse] Parsed JSON is not the expecte class.
82
123
  def check_object(obj)
83
124
  ret = json
84
125
  return ret if ret.instance_of?(obj)
85
126
 
86
- raise "Expected #{obj} in response for #{url}. The returned object is a #{ret.class}."
127
+ msg = "Expected #{obj} in response for #{url}. The returned object is a #{ret.class}."
128
+ raise Exceptions::ExceptionWithResponse.new(self, msg)
87
129
  end
88
130
  end
89
131
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ibm-cloud-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - IBM Cloud Developers
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-09-23 00:00:00.000000000 Z
11
+ date: 2020-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -60,6 +60,8 @@ files:
60
60
  - lib/ibm/cloud/sdk/base_service.rb
61
61
  - lib/ibm/cloud/sdk/iam.rb
62
62
  - lib/ibm/cloud/sdk/iam/token.rb
63
+ - lib/ibm/cloud/sdk/logging.rb
64
+ - lib/ibm/cloud/sdk/null_logger.rb
63
65
  - lib/ibm/cloud/sdk/power_iaas.rb
64
66
  - lib/ibm/cloud/sdk/resource_controller.rb
65
67
  - lib/ibm/cloud/sdk/resource_controller/resource.rb
@@ -69,6 +71,7 @@ files:
69
71
  - lib/ibm/cloud/sdk/vpc/base_instance.rb
70
72
  - lib/ibm/cloud/sdk/vpc/base_vpc.rb
71
73
  - lib/ibm/cloud/sdk/vpc/cloud_sdk.rb
74
+ - lib/ibm/cloud/sdk/vpc/exceptions.rb
72
75
  - lib/ibm/cloud/sdk/vpc/floatingips.rb
73
76
  - lib/ibm/cloud/sdk/vpc/flowlogcollectors.rb
74
77
  - lib/ibm/cloud/sdk/vpc/helpers/connection.rb
@@ -108,7 +111,7 @@ licenses:
108
111
  - '"Apache-2.0"'
109
112
  metadata:
110
113
  homepage_uri: https://github.com/IBM-Cloud/ibm-cloud-sdk-ruby
111
- changelog_uri: https://github.com/IBM-Cloud/ibm-cloud-sdk-ruby/blob/v0.1.6/CHANGELOG.md
114
+ changelog_uri: https://github.com/IBM-Cloud/ibm-cloud-sdk-ruby/blob/v0.1.7/CHANGELOG.md
112
115
  post_install_message:
113
116
  rdoc_options: []
114
117
  require_paths: