ibm-cloud-sdk 0.1.6 → 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +20 -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 +117 -9
  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 +28 -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 +77 -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 +3 -3
  27. data/lib/ibm/cloud/sdk/vpc/instance/volume_attachments.rb +3 -3
  28. data/lib/ibm/cloud/sdk/vpc/instance_profiles.rb +3 -3
  29. data/lib/ibm/cloud/sdk/vpc/instances.rb +99 -6
  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 +3 -3
  50. data/lib/ibm/cloud/sdk/vpc/vpn_gateway/peer_cidrs.rb +3 -3
  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 +120 -0
  55. data/lib/ibm/cloud/sdk_http/base_instance.rb +55 -0
  56. data/lib/ibm/cloud/sdk_http/connection.rb +38 -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 -10
  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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 160845336c50ab1c67c274cb62fd5e52af7bf0d6e4b5a4a1b57c4ea3c5eb47db
4
- data.tar.gz: 7762d522d6754815a4e19a927bdcce0d73a8c5a0d204980d44dfdf006d7254d4
3
+ metadata.gz: 336ae42302a72e720775cd6d0c6e193e4a6c9c2b2c4e2858b0c02e5d85e96380
4
+ data.tar.gz: 937ccbcf0d347b0bfaf06f959cf0e96a0aa9ea3816880795da47bfa60d0da3f5
5
5
  SHA512:
6
- metadata.gz: f42fe440d6a3610c94b7336246eda2dfdf6f794afa501480e633563d3a25f2d27bc337ebf41f82b82dad3a3958c2dbbf094244da77021fbe188fffa5cb73d294
7
- data.tar.gz: 7af6df6df99133b619aa62bcc03281dc58f8b1f79c1b26d57b6cbf490dfc85f0dbdd46d41306780d8ead81148d71bf9003b78b787d8d21a64c6974ac0fc546a7
6
+ metadata.gz: 511b9535c80328b92c3e9645a46058f26fda766444ecaf76fd71f8f64ebeea490aaec3284544df68b0cb84bec69dd50f1298dc20d48af17351db6abb60e858bd
7
+ data.tar.gz: 3f1ac1719230d2a8c2ed9e2645d8311c61e7b697dfc36960df9019224392facd5aab3e815ad5fd486ef9a863c935a019e41672c83881c0650a8144901334a8ad
@@ -1,6 +1,26 @@
1
1
  # Changelog
2
2
  All notable changes to the gem ibm-cloud-sdk-ruby will be documented here.
3
3
 
4
+ ## v0.1.11 - 2020-10-28
5
+ - Add start, stop, and reboot actions on VPC instances
6
+
7
+ ## v0.1.10 - 2020-10-08
8
+ - Change VPC http provider to HTTParty
9
+ - Add Tags API and clean up VPC
10
+ - Log ResourceController and IAM calls
11
+
12
+ ## v0.1.9 - 2020-10-02
13
+ - Fix PowerVS Volume Attach/Detach calls
14
+
15
+ ## v0.1.8 - 2020-10-01
16
+ - Add second level instances
17
+
18
+ ## v0.1.7 - 2020-09-28
19
+ - Added Logging in IBM Cloud
20
+ - Add VCR to vpc spec
21
+ - Add exception when status of response is not in 200 range or 404
22
+ - Power IaaS Update docstrings, VM actions volumes
23
+
4
24
  ## v0.1.6 - 2020-09-23
5
25
  - Add PowerIaaS method to get instance info
6
26
  - 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'
@@ -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,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}/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
+
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,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
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ibm/cloud/sdk_http'
4
+
5
+ require_relative 'http/tag_collection'