ibm-cloud-sdk 0.1.1 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +26 -0
  3. data/README.md +1 -1
  4. data/ibm-cloud-sdk.gemspec +3 -1
  5. data/lib/ibm/cloud/sdk.rb +2 -0
  6. data/lib/ibm/cloud/sdk/power_iaas.rb +70 -1
  7. data/lib/ibm/cloud/sdk/resource_controller.rb +2 -8
  8. data/lib/ibm/cloud/sdk/version.rb +1 -1
  9. data/lib/ibm/cloud/sdk/vpc.rb +132 -0
  10. data/lib/ibm/cloud/sdk/vpc/base_collection.rb +108 -0
  11. data/lib/ibm/cloud/sdk/vpc/base_instance.rb +23 -0
  12. data/lib/ibm/cloud/sdk/vpc/base_vpc.rb +61 -0
  13. data/lib/ibm/cloud/sdk/vpc/cloud_sdk.rb +33 -0
  14. data/lib/ibm/cloud/sdk/vpc/floatingips.rb +20 -0
  15. data/lib/ibm/cloud/sdk/vpc/flowlogcollectors.rb +20 -0
  16. data/lib/ibm/cloud/sdk/vpc/helpers/connection.rb +66 -0
  17. data/lib/ibm/cloud/sdk/vpc/helpers/response.rb +92 -0
  18. data/lib/ibm/cloud/sdk/vpc/ike_policies.rb +24 -0
  19. data/lib/ibm/cloud/sdk/vpc/images.rb +21 -0
  20. data/lib/ibm/cloud/sdk/vpc/instance/actions.rb +19 -0
  21. data/lib/ibm/cloud/sdk/vpc/instance/floating_ips.rb +23 -0
  22. data/lib/ibm/cloud/sdk/vpc/instance/network_interfaces.rb +28 -0
  23. data/lib/ibm/cloud/sdk/vpc/instance/volume_attachments.rb +23 -0
  24. data/lib/ibm/cloud/sdk/vpc/instance_profiles.rb +21 -0
  25. data/lib/ibm/cloud/sdk/vpc/instances.rb +64 -0
  26. data/lib/ibm/cloud/sdk/vpc/ipsec_policies.rb +24 -0
  27. data/lib/ibm/cloud/sdk/vpc/keys.rb +43 -0
  28. data/lib/ibm/cloud/sdk/vpc/load_balancer.rb +23 -0
  29. data/lib/ibm/cloud/sdk/vpc/load_balancer/listeners.rb +30 -0
  30. data/lib/ibm/cloud/sdk/vpc/load_balancer/members.rb +23 -0
  31. data/lib/ibm/cloud/sdk/vpc/load_balancer/policies.rb +30 -0
  32. data/lib/ibm/cloud/sdk/vpc/load_balancer/pools.rb +28 -0
  33. data/lib/ibm/cloud/sdk/vpc/load_balancer/rules.rb +25 -0
  34. data/lib/ibm/cloud/sdk/vpc/load_balancers.rb +19 -0
  35. data/lib/ibm/cloud/sdk/vpc/network_acls.rb +39 -0
  36. data/lib/ibm/cloud/sdk/vpc/operating_systems.rb +21 -0
  37. data/lib/ibm/cloud/sdk/vpc/public_gateways.rb +21 -0
  38. data/lib/ibm/cloud/sdk/vpc/regions.rb +35 -0
  39. data/lib/ibm/cloud/sdk/vpc/security_groups.rb +48 -0
  40. data/lib/ibm/cloud/sdk/vpc/subnets.rb +21 -0
  41. data/lib/ibm/cloud/sdk/vpc/volume_profiles.rb +21 -0
  42. data/lib/ibm/cloud/sdk/vpc/volumes.rb +21 -0
  43. data/lib/ibm/cloud/sdk/vpc/vpcs.rb +60 -0
  44. data/lib/ibm/cloud/sdk/vpc/vpn_gateway/connections.rb +35 -0
  45. data/lib/ibm/cloud/sdk/vpc/vpn_gateway/local_cidrs.rb +32 -0
  46. data/lib/ibm/cloud/sdk/vpc/vpn_gateway/peer_cidrs.rb +32 -0
  47. data/lib/ibm/cloud/sdk/vpc/vpn_gateways.rb +25 -0
  48. metadata +57 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a7558ad49ddda2ac462adadf72b0e41b4b71ecb76549f977763ca474dbc2cdd9
4
- data.tar.gz: ed99310c97b01a7bdbc3b55aba132e9307aceefee82dffb2e74392f74e408f7c
3
+ metadata.gz: 160845336c50ab1c67c274cb62fd5e52af7bf0d6e4b5a4a1b57c4ea3c5eb47db
4
+ data.tar.gz: 7762d522d6754815a4e19a927bdcce0d73a8c5a0d204980d44dfdf006d7254d4
5
5
  SHA512:
6
- metadata.gz: a5975502154c0cbdb3afd8e6010852ae34259ac3d083ded0c1e201d68a12260c1dc01e7d0da74cc40de02e8b612bd26e96fee78f08bac910fc6f058e500a80ab
7
- data.tar.gz: fba093a03b5b51df36e7f3f400c2f8dcfa8ad53c04d611f88c8d637f1d0ca0059b31f652ffa3769ea1cc47bbf2556db7f205c31556f62b39e49cb2bf4e9365ae
6
+ metadata.gz: f42fe440d6a3610c94b7336246eda2dfdf6f794afa501480e633563d3a25f2d27bc337ebf41f82b82dad3a3958c2dbbf094244da77021fbe188fffa5cb73d294
7
+ data.tar.gz: 7af6df6df99133b619aa62bcc03281dc58f8b1f79c1b26d57b6cbf490dfc85f0dbdd46d41306780d8ead81148d71bf9003b78b787d8d21a64c6974ac0fc546a7
@@ -0,0 +1,26 @@
1
+ # Changelog
2
+ All notable changes to the gem ibm-cloud-sdk-ruby will be documented here.
3
+
4
+ ## v0.1.6 - 2020-09-23
5
+ - Add PowerIaaS method to get instance info
6
+ - Return region specific PowerVS storage types
7
+ - Move VPC instance into instances and add initialization method.
8
+
9
+ ## v0.1.5 - 2020-09-21
10
+ - Added Enumerable based pagination support
11
+ - Move instance profiles
12
+ - Improve resource lookup by GUID
13
+ - Add support to create a PowerIaas volume
14
+
15
+ ## v0.1.4 - 2020-09-17
16
+ - Added support for the IBM Virtual Private Cloud (VPC) service
17
+
18
+ ## v0.1.3 - 2020-08-31
19
+ ### Added the following rest api calls for Power System Virtual Server service
20
+ - Add PowerIaas 'delete_volume' method
21
+ - Add PowerVS SAP API calls
22
+ - get list of available system pools within a particular data center
23
+ - get list of all storage type availble in the data center. There may be
24
+ update to the call once PowerVS service updates the storage type rest api
25
+ for Power System Virtual Server service .
26
+
data/README.md CHANGED
@@ -28,5 +28,5 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
28
28
 
29
29
  ## Contributing
30
30
 
31
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ibm-cloud-sdk.
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/IBM-Cloud/ibm-cloud-sdk-ruby.
32
32
 
@@ -11,7 +11,8 @@ Gem::Specification.new do |spec|
11
11
  spec.licenses = %w["Apache-2.0"]
12
12
  spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
13
 
14
- spec.metadata["homepage_uri"] = spec.homepage
14
+ spec.metadata["homepage_uri"] = spec.homepage
15
+ spec.metadata["changelog_uri"] = "https://github.com/IBM-Cloud/ibm-cloud-sdk-ruby/blob/v#{spec.version}/CHANGELOG.md"
15
16
 
16
17
  # Specify which files should be added to the gem when it is released.
17
18
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -23,4 +24,5 @@ Gem::Specification.new do |spec|
23
24
  spec.require_paths = ["lib"]
24
25
 
25
26
  spec.add_dependency "rest-client"
27
+ spec.add_dependency "http"
26
28
  end
@@ -1,3 +1,4 @@
1
+
1
2
  require "json"
2
3
  require "rest-client"
3
4
 
@@ -6,6 +7,7 @@ require "ibm/cloud/sdk/iam"
6
7
  require "ibm/cloud/sdk/power_iaas"
7
8
  require "ibm/cloud/sdk/resource_controller"
8
9
  require "ibm/cloud/sdk/version"
10
+ require "ibm/cloud/sdk/vpc/cloud_sdk"
9
11
 
10
12
  module IBM
11
13
  module Cloud
@@ -18,7 +18,14 @@ module IBM
18
18
  end
19
19
 
20
20
  def endpoint
21
- "https://#{region}.power-iaas.cloud.ibm.com/pcloud/v1"
21
+ "https://#{region.sub(/-\d$/, '')}.power-iaas.cloud.ibm.com/pcloud/v1"
22
+ end
23
+
24
+ # Get Power Cloud Instance information
25
+ #
26
+ # @return [Hash] CloudInstance
27
+ def get_pcloud_instance
28
+ get("cloud-instances/#{guid}")
22
29
  end
23
30
 
24
31
  # Get all PVM instances in an IBM Power Cloud instance
@@ -113,6 +120,21 @@ module IBM
113
120
  get("cloud-instances/#{guid}/volumes/#{volume_id}")
114
121
  end
115
122
 
123
+ # Delete a volume
124
+ #
125
+ # @param volume_id [String] The ID of a volume
126
+ def delete_volume(volume_id)
127
+ delete("cloud-instances/#{guid}/volumes/#{volume_id}")
128
+ end
129
+
130
+ # Create a volume
131
+ #
132
+ # @param volume_hash [Hash] New volume attributes
133
+ # @return [Hash] Volume
134
+ def create_volume(volume_hash)
135
+ post("cloud-instances/#{guid}/volumes", volume_hash.to_json)
136
+ end
137
+
116
138
  # Get all networks in an IBM Power Cloud instance
117
139
  #
118
140
  # @return [Array<Hash>] all networks for this IBM Power Cloud instance
@@ -131,6 +153,22 @@ module IBM
131
153
  get("cloud-instances/#{guid}/networks/#{network_id}")
132
154
  end
133
155
 
156
+ # Get a available system pools list for IBM Power Cloud DC
157
+ #
158
+ # @return [Hash] SystemPool
159
+ def get_system_pool
160
+ get("cloud-instances/#{guid}/system-pools")
161
+ end
162
+
163
+ # Get a storage types list in IBM Power Cloud.
164
+ # note: this mehod to be refactored under the common
165
+ # IBM::Cloud::SDK::PowerIaas.endpoint when the rest api become available.
166
+ #
167
+ # @return [Hash] StorageType
168
+ def get_storage_types
169
+ JSON.parse(RestClient.get("https://#{region.sub(/-\d$/, '')}.power-iaas.cloud.ibm.com/broker/v1/storage-types", headers))[region]
170
+ end
171
+
134
172
  def create_network(network_hash)
135
173
  post("cloud-instances/#{guid}/networks", network_hash.to_json)
136
174
  end
@@ -156,6 +194,37 @@ module IBM
156
194
  delete("tenants/#{tenant}/sshkeys/#{name}")
157
195
  end
158
196
 
197
+ # Get an SAP profile
198
+ #
199
+ # @param sap_profile_id [String] The ID of an SAP profile
200
+ # @return [Hash] SAP profile
201
+ def get_sap_profile(sap_profile_id)
202
+ get("cloud-instances/#{guid}/sap/#{sap_profile_id}")
203
+ end
204
+
205
+ # Get list of all SAP profiles
206
+ #
207
+ # @return [Array<Hash>] all SAP profiles available to this instance
208
+ def get_sap_profiles
209
+ sap_profiles = get("cloud-instances/#{guid}/sap")["profiles"] || []
210
+
211
+ sap_profiles.map do |sap_profile|
212
+ get_sap_profile(sap_profile["profileID"])
213
+ end
214
+ end
215
+
216
+ # Create a new SAP PVM Instance
217
+ #
218
+ # Create a new PVM instance using an SAP profile. The resultant PVM
219
+ # instance is the standard 'PVMInstance' type and can be accessed via
220
+ # the existing *_pvm_instance methods.
221
+ #
222
+ # @param sap_profile_id [String] The ID of an SAP profile
223
+ # @return [Hash] SAP profile
224
+ def create_sap_pvm_instance(instance_hash)
225
+ post("cloud-instances/#{guid}/sap", instance_hash.to_json)
226
+ end
227
+
159
228
  private
160
229
 
161
230
  attr_reader :crn, :guid, :region, :tenant, :token
@@ -2,6 +2,7 @@ module IBM
2
2
  module Cloud
3
3
  module SDK
4
4
  class ResourceController < BaseService
5
+ require "ibm/cloud/sdk/resource_controller/resource"
5
6
  def endpoint
6
7
  "https://resource-controller.cloud.ibm.com/v2"
7
8
  end
@@ -10,15 +11,8 @@ module IBM
10
11
  @token = token
11
12
  end
12
13
 
13
- def get_resources
14
- resources = get("resource_instances")["resources"] || []
15
-
16
- require "ibm/cloud/sdk/resource_controller/resource"
17
- resources.map { |instance| Resource.new(instance) }
18
- end
19
-
20
14
  def get_resource(guid)
21
- get_resources.detect { |resource| resource.guid == guid }
15
+ Resource.new(get("resource_instances/#{guid}"))
22
16
  end
23
17
 
24
18
  private
@@ -1,7 +1,7 @@
1
1
  module IBM
2
2
  module Cloud
3
3
  module SDK
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.6"
5
5
  end
6
6
  end
7
7
  end
@@ -0,0 +1,132 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ require_relative 'vpc/base_vpc'
5
+ require_relative 'vpc/base_collection'
6
+ require_relative 'vpc/base_instance'
7
+
8
+ require_relative 'vpc/floatingips'
9
+ require_relative 'vpc/flowlogcollectors'
10
+ require_relative 'vpc/ike_policies'
11
+ require_relative 'vpc/images'
12
+ require_relative 'vpc/instance_profiles'
13
+ require_relative 'vpc/instances'
14
+ require_relative 'vpc/ipsec_policies'
15
+ require_relative 'vpc/keys'
16
+ require_relative 'vpc/load_balancers'
17
+ require_relative 'vpc/network_acls'
18
+ require_relative 'vpc/operating_systems'
19
+ require_relative 'vpc/public_gateways'
20
+ require_relative 'vpc/regions'
21
+ require_relative 'vpc/security_groups'
22
+ require_relative 'vpc/subnets'
23
+ require_relative 'vpc/volume_profiles'
24
+ require_relative 'vpc/volumes'
25
+ require_relative 'vpc/vpcs'
26
+ require_relative 'vpc/vpn_gateways'
27
+
28
+ module IBM
29
+ module Cloud
30
+ module SDK
31
+ # Container that encapsulates the VPC API.
32
+ class Vpc < BaseVPC
33
+ # Create an API Client object for the VPC IaaS service
34
+ #
35
+ # @param region [String] the IBM Power Cloud instance region
36
+ # @param connection [IBM::Cloud::SDK::VPC::Connection] A connection object.
37
+ # @param logger [Logger] An instance of an instanciated logger.
38
+ def initialize(region, connection, logger: nil)
39
+ @region = region
40
+ @connection = connection
41
+
42
+ @logger = logger || Logger.new($stdout, level: :warn)
43
+ end
44
+
45
+ attr_reader :connection, :logger
46
+ attr_accessor :region
47
+
48
+ # The Region API endpoint.
49
+ def endpoint
50
+ "https://#{region.sub(/-\d$/, '')}.iaas.cloud.ibm.com/v1"
51
+ end
52
+
53
+ # Entry point to the Floating IPs API.
54
+ def floating_ips
55
+ VPC::FloatingIPs.new(self)
56
+ end
57
+
58
+ def flowlog_collectors
59
+ VPC::FlowLogCollectors.new(self)
60
+ end
61
+
62
+ def ike_policies
63
+ VPC::IKEPolicies.new(self)
64
+ end
65
+
66
+ def images
67
+ VPC::Images.new(self)
68
+ end
69
+
70
+ def instance_profiles
71
+ VPC::InstanceProfiles.new(self)
72
+ end
73
+
74
+ def instances
75
+ VPC::Instances.new(self)
76
+ end
77
+
78
+ def ipsec_policies
79
+ VPC::IPSecPolicies.new(self)
80
+ end
81
+
82
+ def keys
83
+ VPC::Keys.new(self)
84
+ end
85
+
86
+ def load_balancers
87
+ VPC::LoadBalancers.new(self)
88
+ end
89
+
90
+ def network_acls
91
+ VPC::NetworkACLs.new(self)
92
+ end
93
+
94
+ def operating_systems
95
+ VPC::OperatingSystems.new(self)
96
+ end
97
+
98
+ def public_gateways
99
+ VPC::PublicGateways.new(self)
100
+ end
101
+
102
+ def regions
103
+ VPC::Regions.new(self)
104
+ end
105
+
106
+ def security_groups
107
+ VPC::SecurityGroups.new(self)
108
+ end
109
+
110
+ def subnets
111
+ VPC::Subnets.new(self)
112
+ end
113
+
114
+ def volumes_profiles
115
+ VPC::VolumeProfiles.new(self)
116
+ end
117
+
118
+ def volumes
119
+ VPC::Volumes.new(self)
120
+ end
121
+
122
+ def vpcs
123
+ VPC::Vpcs.new(self)
124
+ end
125
+
126
+ def vpn_gateways
127
+ VPC::VPNGateways.new(self)
128
+ end
129
+ end
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,108 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ module IBM
5
+ module Cloud
6
+ module SDK
7
+ # Container that encapsulates the VPC API.
8
+ class BaseCollection < BaseVPC
9
+ # This class is used as a base for collection APIs.
10
+ # @param parent [Object] The parent instance in the API chain.
11
+ # @param endpoint [string] A path from the parent to the desired endpoint. In most cases is should be 1 word.
12
+ # @param array_key [string] The key that the API response holds the endpoint data. When nil the endpoint will be used.
13
+ # @param child_class [Object] The Object to be used when instanciating the single instance for this class.
14
+ def initialize(parent, endpoint, array_key: nil, child_class: nil)
15
+ # Setup empty base instance variables.
16
+ @params = nil
17
+
18
+ array_key ||= endpoint
19
+
20
+ # Set the array key and child class.
21
+ @array_key ||= array_key
22
+ @instance ||= child_class
23
+
24
+ super(parent, endpoint)
25
+ end
26
+
27
+ # A chainable method to set query filters on the collection.
28
+ # @example vpc.images.params(limit: 1).all
29
+ #
30
+ # @param start [String] A server-supplied token determining what resource to start the page on.
31
+ # @param limit [Integer] The number of resources to return on a page allowed values are between 1 and 100
32
+ # @param resource_group [String] Filters the collection to resources within one of the resource groups identified in a comma-separated list of resource group identifiers
33
+ # @return [BaseCollection] This class with the param instance variable set.
34
+ def params(start: nil, limit: nil, resource_group: nil)
35
+ @params = {}
36
+ @params[:start] = start if start
37
+ @params[:limit] = limit if limit
38
+ @params[:resource_group] = resource_group if resource_group
39
+ self
40
+ end
41
+
42
+ # Retrieve the collection from the cloud.
43
+ # @return [IBM::Cloud::SDK::VPC::Response] The http response object.
44
+ def fetch
45
+ @data ||= get(params: @params)
46
+ end
47
+
48
+ # Get an iterable for the resource collection.
49
+ # @return [Enumerator] Use standard each, next idioms.
50
+ def all
51
+ each_resource(url)
52
+ end
53
+
54
+ # Fetch all data and return in an array.
55
+ # @return [Array] Hashes of the returned data.
56
+ def data
57
+ all.to_a
58
+ end
59
+
60
+ # Determine if the collection has a total_count key in its response.
61
+ # @return [Boolean]
62
+ def has_count?
63
+ fetch.json&.key?(:total_count)
64
+ end
65
+
66
+ # Get the total count if it exists in the response. Returns nil otherwise.
67
+ # @return [Integer] The total count reuturned by the server.
68
+ def count
69
+ fetch.json&.fetch(:total_count)
70
+ end
71
+
72
+ # A generic post method to create a resource on the collection.
73
+ # @param payload [Hash] A hash of parameters to send to the server.
74
+ # @param payload_type [String] One of the following options json, form, or body.
75
+ # @return [IBM::Cloud::SDK::VPC::Response] The http response object.
76
+ def create(payload, payload_type = 'json')
77
+ adhoc(method: 'post', payload_type: payload_type, payload: payload)
78
+ end
79
+
80
+ # Access a specific instance by either id or name depending on API.
81
+ def instance(id)
82
+ @instance.new(self, id)
83
+ end
84
+
85
+ private
86
+
87
+ # Create a generator that removes the need for pagination.
88
+ def each_resource(url, &block)
89
+ return enum_for(:each_resource, url) unless block_given?
90
+ return unless url
91
+
92
+ response = @connection.adhoc('get', url, metadata(@params)).json
93
+ resources = response.fetch(@array_key.to_sym)
94
+
95
+ resources&.each do |value|
96
+ yield value
97
+ end
98
+ return unless response.key?(:next)
99
+
100
+ next_url = response.dig(:next, :href)
101
+ return unless next_url
102
+
103
+ each_resource(next_url, &block)
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end