ibm-cloud-sdk 0.1.5 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +22 -0
  3. data/Gemfile +2 -0
  4. data/ibm-cloud-sdk.gemspec +1 -1
  5. data/lib/ibm/cloud/sdk.rb +3 -1
  6. data/lib/ibm/cloud/sdk/iam.rb +5 -0
  7. data/lib/ibm/cloud/sdk/logging.rb +21 -0
  8. data/lib/ibm/cloud/sdk/null_logger.rb +19 -0
  9. data/lib/ibm/cloud/sdk/power_iaas.rb +125 -10
  10. data/lib/ibm/cloud/sdk/resource_controller.rb +4 -0
  11. data/lib/ibm/cloud/sdk/tags.rb +28 -0
  12. data/lib/ibm/cloud/sdk/tags/http.rb +5 -0
  13. data/lib/ibm/cloud/sdk/tags/http/tag_collection.rb +99 -0
  14. data/lib/ibm/cloud/sdk/version.rb +1 -1
  15. data/lib/ibm/cloud/sdk/vpc.rb +8 -6
  16. data/lib/ibm/cloud/sdk/vpc/floatingips.rb +2 -2
  17. data/lib/ibm/cloud/sdk/vpc/flowlogcollectors.rb +2 -2
  18. data/lib/ibm/cloud/sdk/vpc/http.rb +7 -0
  19. data/lib/ibm/cloud/sdk/vpc/http/vpc_collection.rb +82 -0
  20. data/lib/ibm/cloud/sdk/vpc/http/vpc_http.rb +29 -0
  21. data/lib/ibm/cloud/sdk/vpc/http/vpc_instance.rb +30 -0
  22. data/lib/ibm/cloud/sdk/vpc/ike_policies.rb +2 -2
  23. data/lib/ibm/cloud/sdk/vpc/images.rb +2 -2
  24. data/lib/ibm/cloud/sdk/vpc/instance/actions.rb +2 -2
  25. data/lib/ibm/cloud/sdk/vpc/instance/floating_ips.rb +3 -3
  26. data/lib/ibm/cloud/sdk/vpc/instance/network_interfaces.rb +4 -29
  27. data/lib/ibm/cloud/sdk/vpc/instance/volume_attachments.rb +4 -27
  28. data/lib/ibm/cloud/sdk/vpc/instance_profiles.rb +3 -3
  29. data/lib/ibm/cloud/sdk/vpc/instances.rb +43 -3
  30. data/lib/ibm/cloud/sdk/vpc/ipsec_policies.rb +2 -2
  31. data/lib/ibm/cloud/sdk/vpc/keys.rb +2 -24
  32. data/lib/ibm/cloud/sdk/vpc/load_balancer.rb +1 -1
  33. data/lib/ibm/cloud/sdk/vpc/load_balancer/listeners.rb +2 -2
  34. data/lib/ibm/cloud/sdk/vpc/load_balancer/members.rb +2 -2
  35. data/lib/ibm/cloud/sdk/vpc/load_balancer/policies.rb +2 -2
  36. data/lib/ibm/cloud/sdk/vpc/load_balancer/pools.rb +2 -2
  37. data/lib/ibm/cloud/sdk/vpc/load_balancer/rules.rb +2 -2
  38. data/lib/ibm/cloud/sdk/vpc/load_balancers.rb +1 -1
  39. data/lib/ibm/cloud/sdk/vpc/network_acls.rb +4 -4
  40. data/lib/ibm/cloud/sdk/vpc/operating_systems.rb +2 -2
  41. data/lib/ibm/cloud/sdk/vpc/public_gateways.rb +2 -2
  42. data/lib/ibm/cloud/sdk/vpc/regions.rb +4 -4
  43. data/lib/ibm/cloud/sdk/vpc/security_groups.rb +6 -6
  44. data/lib/ibm/cloud/sdk/vpc/subnets.rb +2 -2
  45. data/lib/ibm/cloud/sdk/vpc/volume_profiles.rb +2 -2
  46. data/lib/ibm/cloud/sdk/vpc/volumes.rb +2 -2
  47. data/lib/ibm/cloud/sdk/vpc/vpcs.rb +6 -6
  48. data/lib/ibm/cloud/sdk/vpc/vpn_gateway/connections.rb +2 -2
  49. data/lib/ibm/cloud/sdk/vpc/vpn_gateway/local_cidrs.rb +2 -2
  50. data/lib/ibm/cloud/sdk/vpc/vpn_gateway/peer_cidrs.rb +2 -2
  51. data/lib/ibm/cloud/sdk/vpc/vpn_gateways.rb +2 -2
  52. data/lib/ibm/cloud/sdk_http.rb +16 -0
  53. data/lib/ibm/cloud/sdk_http/base_collection.rb +121 -0
  54. data/lib/ibm/cloud/sdk_http/base_http_mixin.rb +63 -0
  55. data/lib/ibm/cloud/sdk_http/base_instance.rb +55 -0
  56. data/lib/ibm/cloud/sdk_http/connection.rb +32 -0
  57. data/lib/ibm/cloud/sdk_http/exceptions.rb +31 -0
  58. data/lib/ibm/cloud/sdk_http/has_child.rb +23 -0
  59. data/lib/ibm/cloud/sdk_http/iam_token.rb +53 -0
  60. data/lib/ibm/cloud/sdk_http/sdk_response.rb +132 -0
  61. data/lib/ibm/cloud_sdk.rb +39 -0
  62. metadata +23 -11
  63. data/lib/ibm/cloud/sdk/vpc/base_collection.rb +0 -108
  64. data/lib/ibm/cloud/sdk/vpc/base_instance.rb +0 -23
  65. data/lib/ibm/cloud/sdk/vpc/base_vpc.rb +0 -61
  66. data/lib/ibm/cloud/sdk/vpc/cloud_sdk.rb +0 -33
  67. data/lib/ibm/cloud/sdk/vpc/helpers/connection.rb +0 -66
  68. data/lib/ibm/cloud/sdk/vpc/helpers/response.rb +0 -92
  69. data/lib/ibm/cloud/sdk/vpc/instance.rb +0 -35
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8fe8cad325a98aabb1bd328c04aec7c1c4b7dbda4859d41a85baa51916a40d80
4
- data.tar.gz: e40564d9e168b80623282caa7bb1b4efe5519e16a7757f8ac657ddbf57c0976a
3
+ metadata.gz: 3846f53417aa653151063dfd91b59ea43b1ba3a9d2d53fdb085c8dc7f28bb2ea
4
+ data.tar.gz: 903b21299da1b4d57953b4af2a98d27bc99e34298781b7936deae237641d34c6
5
5
  SHA512:
6
- metadata.gz: 2dabd16a4f84e7c7ade80f0a5d36f0796f15681a53f0f271b01ff6d98b41b00ea249f681c9c402961e53c0a94943c32c18d41e6f1421075be15561ce5c369c7e
7
- data.tar.gz: 90bea5c5ae247170955e937be0fef41c8bd43f0d8749b8a3c08786f25759dd669e5f32e9a35bedada529a5936eb9ae0f06a329df4dcbb99a56c60d2f4dbb7659
6
+ metadata.gz: 9a1284cd63ae075ed1786f5045cb3951e328fb5edfcc95e1d981dd63c72a6ec85ff116102e07fe1317333dcc77305dad3287f312e184a31eb44bc3889303c521
7
+ data.tar.gz: 507dde2d35874cdee345b14c785d941b0b2a40014251ad8262f684f8f0966b050f57bb03e407332c006204344061c4963f4759895ab040d1ed24e5af73acc65d
@@ -1,6 +1,28 @@
1
1
  # Changelog
2
2
  All notable changes to the gem ibm-cloud-sdk-ruby will be documented here.
3
3
 
4
+ ## v0.1.10 - 2020-10-08
5
+ - Change VPC http provider to HTTParty
6
+ - Add Tags API and clean up VPC
7
+ - Log ResourceController and IAM calls
8
+
9
+ ## v0.1.9 - 2020-10-02
10
+ - Fix PowerVS Volume Attach/Detach calls
11
+
12
+ ## v0.1.8 - 2020-10-01
13
+ - Add second level instances
14
+
15
+ ## v0.1.7 - 2020-09-28
16
+ - Added Logging in IBM Cloud
17
+ - Add VCR to vpc spec
18
+ - Add exception when status of response is not in 200 range or 404
19
+ - Power IaaS Update docstrings, VM actions volumes
20
+
21
+ ## v0.1.6 - 2020-09-23
22
+ - Add PowerIaaS method to get instance info
23
+ - Return region specific PowerVS storage types
24
+ - Move VPC instance into instances and add initialization method.
25
+
4
26
  ## v0.1.5 - 2020-09-21
5
27
  - Added Enumerable based pagination support
6
28
  - Move instance profiles
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'
@@ -24,5 +24,5 @@ Gem::Specification.new do |spec|
24
24
  spec.require_paths = ["lib"]
25
25
 
26
26
  spec.add_dependency "rest-client"
27
- spec.add_dependency "http"
27
+ spec.add_dependency "httparty"
28
28
  end
@@ -2,12 +2,14 @@
2
2
  require "json"
3
3
  require "rest-client"
4
4
 
5
+ require 'ibm/cloud_sdk'
6
+
5
7
  require "ibm/cloud/sdk/base_service"
6
8
  require "ibm/cloud/sdk/iam"
7
9
  require "ibm/cloud/sdk/power_iaas"
8
10
  require "ibm/cloud/sdk/resource_controller"
9
11
  require "ibm/cloud/sdk/version"
10
- require "ibm/cloud/sdk/vpc/cloud_sdk"
12
+ require "ibm/cloud/sdk/logging"
11
13
 
12
14
  module IBM
13
15
  module Cloud
@@ -1,13 +1,18 @@
1
+ require_relative 'logging'
2
+
1
3
  module IBM
2
4
  module Cloud
3
5
  module SDK
4
6
  class IAM < BaseService
7
+ include Logging
8
+
5
9
  def endpoint
6
10
  "https://iam.cloud.ibm.com".freeze
7
11
  end
8
12
 
9
13
  def initialize(api_key)
10
14
  @api_key = api_key
15
+ RestClient.log = logger
11
16
  end
12
17
 
13
18
  def get_identity_token
@@ -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,12 +19,23 @@ 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
23
31
 
32
+ # Get Power Cloud Instance information
33
+ #
34
+ # @return [Hash] CloudInstance
35
+ def get_pcloud_instance
36
+ get("cloud-instances/#{guid}")
37
+ end
38
+
24
39
  # Get all PVM instances in an IBM Power Cloud instance
25
40
  #
26
41
  # @return [Array<Hash>] all PVM Instances for this instance
@@ -34,12 +49,15 @@ module IBM
34
49
 
35
50
  # Get an IBM Power Cloud PVM instance
36
51
  #
37
- # @param pvm_instance_id [String] the PVM instance ID
52
+ # @param pvm_instance_id [String] PVM instance ID
38
53
  # @return [Hash] PVM Instances
39
54
  def get_pvm_instance(instance_id)
40
55
  get("cloud-instances/#{guid}/pvm-instances/#{instance_id}")
41
56
  end
42
57
 
58
+ # Perform 'start' action on a PVMInstance
59
+ #
60
+ # @param pvm_instance_id [String] PVM instance ID
43
61
  def start_pvm_instance(instance_id)
44
62
  post(
45
63
  "cloud-instances/#{guid}/pvm-instances/#{instance_id}/action",
@@ -47,6 +65,9 @@ module IBM
47
65
  )
48
66
  end
49
67
 
68
+ # Perform 'stop' action on a PVMInstance
69
+ #
70
+ # @param pvm_instance_id [String] PVM instance ID
50
71
  def stop_pvm_instance(instance_id)
51
72
  post(
52
73
  "cloud-instances/#{guid}/pvm-instances/#{instance_id}/action",
@@ -54,6 +75,22 @@ module IBM
54
75
  )
55
76
  end
56
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
57
94
  def reboot_pvm_instance(instance_id)
58
95
  post(
59
96
  "cloud-instances/#{guid}/pvm-instances/#{instance_id}/action",
@@ -61,10 +98,47 @@ module IBM
61
98
  )
62
99
  end
63
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
64
135
  def create_pvm_instance(instance_hash)
65
136
  post("cloud-instances/#{guid}/pvm-instances", instance_hash.to_json)
66
137
  end
67
138
 
139
+ # Delete a PVM instance
140
+ #
141
+ # @param pvm_instance_id [String] PVM instance ID
68
142
  def delete_pvm_instance(instance_id)
69
143
  delete("cloud-instances/#{guid}/pvm-instances/#{instance_id}")
70
144
  end
@@ -82,7 +156,7 @@ module IBM
82
156
 
83
157
  # Get an IBM Power Cloud image
84
158
  #
85
- # @param image_id [String] The ID of an Image
159
+ # @param image_id [String] Image ID
86
160
  # @return [Hash] Image
87
161
  def get_image(image_id)
88
162
  get("cloud-instances/#{guid}/images/#{image_id}")
@@ -90,6 +164,9 @@ module IBM
90
164
  nil
91
165
  end
92
166
 
167
+ # Delete an image from a cloud instance
168
+ #
169
+ # @param image_id [String] Image ID
93
170
  def delete_image(image_id)
94
171
  delete("cloud-instances/#{guid}/images/#{image_id}")
95
172
  end
@@ -107,7 +184,7 @@ module IBM
107
184
 
108
185
  # Get a specific volume
109
186
  #
110
- # @param volume_id [String] The ID of a volume
187
+ # @param volume_id [String] Image ID
111
188
  # @return [Hash] Volume
112
189
  def get_volume(volume_id)
113
190
  get("cloud-instances/#{guid}/volumes/#{volume_id}")
@@ -115,7 +192,7 @@ module IBM
115
192
 
116
193
  # Delete a volume
117
194
  #
118
- # @param volume_id [String] The ID of a volume
195
+ # @param volume_id [String] Volume ID
119
196
  def delete_volume(volume_id)
120
197
  delete("cloud-instances/#{guid}/volumes/#{volume_id}")
121
198
  end
@@ -128,6 +205,22 @@ module IBM
128
205
  post("cloud-instances/#{guid}/volumes", volume_hash.to_json)
129
206
  end
130
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}/pvm-instances/#{pvm_instance_id}/volumes/#{volume_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}/pvm-instances/#{pvm_instance_id}/volumes/#{volume_id}")
222
+ end
223
+
131
224
  # Get all networks in an IBM Power Cloud instance
132
225
  #
133
226
  # @return [Array<Hash>] all networks for this IBM Power Cloud instance
@@ -140,7 +233,7 @@ module IBM
140
233
 
141
234
  # Get an IBM Power Cloud network
142
235
  #
143
- # @param network_id [String] the network ID
236
+ # @param network_id [String] Network ID
144
237
  # @return [Hash] Network
145
238
  def get_network(network_id)
146
239
  get("cloud-instances/#{guid}/networks/#{network_id}")
@@ -154,42 +247,64 @@ module IBM
154
247
  end
155
248
 
156
249
  # Get a storage types list in IBM Power Cloud.
157
- # note: this mehod to be refactored under the common
250
+ # note: this method to be refactored under the common
158
251
  # IBM::Cloud::SDK::PowerIaas.endpoint when the rest api become available.
159
252
  #
160
- # @return [Hash] StorageType
253
+ # @return [Array<Hash>] StorageType
161
254
  def get_storage_types
162
- JSON.parse(RestClient.get("https://#{region.sub(/-\d$/, '')}.power-iaas.cloud.ibm.com/broker/v1/storage-types", headers))
255
+ JSON.parse(RestClient.get("https://#{region.sub(/-\d$/, '')}.power-iaas.cloud.ibm.com/broker/v1/storage-types", headers))[region]
163
256
  end
164
257
 
258
+ # Create a new network
259
+ #
260
+ # @param network_hash [Hash] New network attributes
261
+ # @return [Hash] Network
165
262
  def create_network(network_hash)
166
263
  post("cloud-instances/#{guid}/networks", network_hash.to_json)
167
264
  end
168
265
 
266
+ # Delete a network
267
+ #
268
+ # @param network_id [String] Network ID
169
269
  def delete_network(network_id)
170
270
  delete("cloud-instances/#{guid}/networks/#{network_id}")
171
271
  end
172
272
 
273
+ # Get all ports for a network
274
+ #
275
+ # @param network_id [String] Network ID
276
+ # @return [Array<Hash>] NetworkPort
173
277
  def get_network_ports(network_id)
174
278
  get("cloud-instances/#{guid}/networks/#{network_id}/ports")["ports"]
175
279
  end
176
280
 
281
+ # List the tenant's SSH Keys
282
+ #
283
+ # @return [Array<Hash>] SSHKey
177
284
  def get_ssh_keys
178
285
  get("tenants/#{tenant}")["sshKeys"]
179
286
  end
180
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
181
293
  def create_key_pair(name, sshkey)
182
294
  payload = {"name" => name, "sshkey" => sshkey}
183
295
  post("tenants/#{tenant}/sshkeys", payload.to_json)
184
296
  end
185
297
 
298
+ # Delete SSH key from the tenant
299
+ #
300
+ # @param sshkey_name [String] SSH Key name
186
301
  def delete_key_pair(name)
187
302
  delete("tenants/#{tenant}/sshkeys/#{name}")
188
303
  end
189
304
 
190
305
  # Get an SAP profile
191
306
  #
192
- # @param sap_profile_id [String] The ID of an SAP profile
307
+ # @param sap_profile_id [String] SAP Profile ID
193
308
  # @return [Hash] SAP profile
194
309
  def get_sap_profile(sap_profile_id)
195
310
  get("cloud-instances/#{guid}/sap/#{sap_profile_id}")
@@ -212,7 +327,7 @@ module IBM
212
327
  # instance is the standard 'PVMInstance' type and can be accessed via
213
328
  # the existing *_pvm_instance methods.
214
329
  #
215
- # @param sap_profile_id [String] The ID of an SAP profile
330
+ # @param sap_profile_id [String] SAP Profile ID
216
331
  # @return [Hash] SAP profile
217
332
  def create_sap_pvm_instance(instance_hash)
218
333
  post("cloud-instances/#{guid}/sap", instance_hash.to_json)
@@ -1,7 +1,10 @@
1
+ require_relative 'logging'
2
+
1
3
  module IBM
2
4
  module Cloud
3
5
  module SDK
4
6
  class ResourceController < BaseService
7
+ include Logging
5
8
  require "ibm/cloud/sdk/resource_controller/resource"
6
9
  def endpoint
7
10
  "https://resource-controller.cloud.ibm.com/v2"
@@ -9,6 +12,7 @@ module IBM
9
12
 
10
13
  def initialize(token)
11
14
  @token = token
15
+ RestClient.log = logger
12
16
  end
13
17
 
14
18
  def get_resource(guid)
@@ -0,0 +1,28 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ require 'ibm/cloud/sdk_http'
5
+ require_relative 'tags/http'
6
+
7
+ module IBM
8
+ module Cloud
9
+ module SDK
10
+ # A collection interface into the Tags API.
11
+ class Tags < TAG::TagCollection
12
+ def initialize(connection, token, logger: nil) # rubocop:disable Lint/MissingSuper
13
+ @token = token
14
+ @connection = connection
15
+
16
+ @logger = logger || Logger.new($stdout, level: :warn)
17
+ @array_key = 'items'
18
+ end
19
+
20
+ attr_reader :logger, :token, :connection
21
+
22
+ def endpoint
23
+ 'https://tags.global-search-tagging.cloud.ibm.com/v3/tags'
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end