ibm-cloud-sdk 0.1.5 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +22 -0
- data/Gemfile +2 -0
- data/ibm-cloud-sdk.gemspec +1 -1
- data/lib/ibm/cloud/sdk.rb +3 -1
- data/lib/ibm/cloud/sdk/iam.rb +5 -0
- data/lib/ibm/cloud/sdk/logging.rb +21 -0
- data/lib/ibm/cloud/sdk/null_logger.rb +19 -0
- data/lib/ibm/cloud/sdk/power_iaas.rb +125 -10
- data/lib/ibm/cloud/sdk/resource_controller.rb +4 -0
- data/lib/ibm/cloud/sdk/tags.rb +28 -0
- data/lib/ibm/cloud/sdk/tags/http.rb +5 -0
- data/lib/ibm/cloud/sdk/tags/http/tag_collection.rb +99 -0
- data/lib/ibm/cloud/sdk/version.rb +1 -1
- data/lib/ibm/cloud/sdk/vpc.rb +8 -6
- data/lib/ibm/cloud/sdk/vpc/floatingips.rb +2 -2
- data/lib/ibm/cloud/sdk/vpc/flowlogcollectors.rb +2 -2
- data/lib/ibm/cloud/sdk/vpc/http.rb +7 -0
- data/lib/ibm/cloud/sdk/vpc/http/vpc_collection.rb +82 -0
- data/lib/ibm/cloud/sdk/vpc/http/vpc_http.rb +29 -0
- data/lib/ibm/cloud/sdk/vpc/http/vpc_instance.rb +30 -0
- data/lib/ibm/cloud/sdk/vpc/ike_policies.rb +2 -2
- data/lib/ibm/cloud/sdk/vpc/images.rb +2 -2
- data/lib/ibm/cloud/sdk/vpc/instance/actions.rb +2 -2
- data/lib/ibm/cloud/sdk/vpc/instance/floating_ips.rb +3 -3
- data/lib/ibm/cloud/sdk/vpc/instance/network_interfaces.rb +4 -29
- data/lib/ibm/cloud/sdk/vpc/instance/volume_attachments.rb +4 -27
- data/lib/ibm/cloud/sdk/vpc/instance_profiles.rb +3 -3
- data/lib/ibm/cloud/sdk/vpc/instances.rb +43 -3
- data/lib/ibm/cloud/sdk/vpc/ipsec_policies.rb +2 -2
- data/lib/ibm/cloud/sdk/vpc/keys.rb +2 -24
- data/lib/ibm/cloud/sdk/vpc/load_balancer.rb +1 -1
- data/lib/ibm/cloud/sdk/vpc/load_balancer/listeners.rb +2 -2
- data/lib/ibm/cloud/sdk/vpc/load_balancer/members.rb +2 -2
- data/lib/ibm/cloud/sdk/vpc/load_balancer/policies.rb +2 -2
- data/lib/ibm/cloud/sdk/vpc/load_balancer/pools.rb +2 -2
- data/lib/ibm/cloud/sdk/vpc/load_balancer/rules.rb +2 -2
- data/lib/ibm/cloud/sdk/vpc/load_balancers.rb +1 -1
- data/lib/ibm/cloud/sdk/vpc/network_acls.rb +4 -4
- data/lib/ibm/cloud/sdk/vpc/operating_systems.rb +2 -2
- data/lib/ibm/cloud/sdk/vpc/public_gateways.rb +2 -2
- data/lib/ibm/cloud/sdk/vpc/regions.rb +4 -4
- data/lib/ibm/cloud/sdk/vpc/security_groups.rb +6 -6
- data/lib/ibm/cloud/sdk/vpc/subnets.rb +2 -2
- data/lib/ibm/cloud/sdk/vpc/volume_profiles.rb +2 -2
- data/lib/ibm/cloud/sdk/vpc/volumes.rb +2 -2
- data/lib/ibm/cloud/sdk/vpc/vpcs.rb +6 -6
- data/lib/ibm/cloud/sdk/vpc/vpn_gateway/connections.rb +2 -2
- data/lib/ibm/cloud/sdk/vpc/vpn_gateway/local_cidrs.rb +2 -2
- data/lib/ibm/cloud/sdk/vpc/vpn_gateway/peer_cidrs.rb +2 -2
- data/lib/ibm/cloud/sdk/vpc/vpn_gateways.rb +2 -2
- data/lib/ibm/cloud/sdk_http.rb +16 -0
- data/lib/ibm/cloud/sdk_http/base_collection.rb +121 -0
- data/lib/ibm/cloud/sdk_http/base_http_mixin.rb +63 -0
- data/lib/ibm/cloud/sdk_http/base_instance.rb +55 -0
- data/lib/ibm/cloud/sdk_http/connection.rb +32 -0
- data/lib/ibm/cloud/sdk_http/exceptions.rb +31 -0
- data/lib/ibm/cloud/sdk_http/has_child.rb +23 -0
- data/lib/ibm/cloud/sdk_http/iam_token.rb +53 -0
- data/lib/ibm/cloud/sdk_http/sdk_response.rb +132 -0
- data/lib/ibm/cloud_sdk.rb +39 -0
- metadata +23 -11
- data/lib/ibm/cloud/sdk/vpc/base_collection.rb +0 -108
- data/lib/ibm/cloud/sdk/vpc/base_instance.rb +0 -23
- data/lib/ibm/cloud/sdk/vpc/base_vpc.rb +0 -61
- data/lib/ibm/cloud/sdk/vpc/cloud_sdk.rb +0 -33
- data/lib/ibm/cloud/sdk/vpc/helpers/connection.rb +0 -66
- data/lib/ibm/cloud/sdk/vpc/helpers/response.rb +0 -92
- data/lib/ibm/cloud/sdk/vpc/instance.rb +0 -35
@@ -6,14 +6,14 @@ module IBM
|
|
6
6
|
module SDK
|
7
7
|
module VPC
|
8
8
|
# Work with Volume Profiles.
|
9
|
-
class VolumeProfiles <
|
9
|
+
class VolumeProfiles < VPCCollection
|
10
10
|
def initialize(parent)
|
11
11
|
super(parent, 'volume/profiles', child_class: VolumeProfile, array_key: 'profiles')
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
# Work with a single volume profile.
|
16
|
-
class VolumeProfile <
|
16
|
+
class VolumeProfile < VPCInstance
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -6,14 +6,14 @@ module IBM
|
|
6
6
|
module SDK
|
7
7
|
module VPC
|
8
8
|
# Work with a collection of volumes.
|
9
|
-
class Volumes <
|
9
|
+
class Volumes < VPCCollection
|
10
10
|
def initialize(parent)
|
11
11
|
super(parent, 'volumes', child_class: Volume)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
# Work with a single volume.
|
16
|
-
class Volume <
|
16
|
+
class Volume < VPCInstance
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -6,14 +6,14 @@ module IBM
|
|
6
6
|
module SDK
|
7
7
|
module VPC
|
8
8
|
# A list of Vpc
|
9
|
-
class Vpcs <
|
9
|
+
class Vpcs < VPCCollection
|
10
10
|
def initialize(parent)
|
11
11
|
super(parent, 'vpcs', child_class: VpcInstance)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
# A single Vpc
|
16
|
-
class VpcInstance <
|
16
|
+
class VpcInstance < VPCInstance
|
17
17
|
def default_network_acl
|
18
18
|
get('default_network_acl')
|
19
19
|
end
|
@@ -33,25 +33,25 @@ module IBM
|
|
33
33
|
|
34
34
|
module VPCS
|
35
35
|
# A list of Vpc
|
36
|
-
class AddressPrefixes <
|
36
|
+
class AddressPrefixes < VPCCollection
|
37
37
|
def initialize(parent)
|
38
38
|
super(parent, 'address_prefixes', child_class: AddressPrefix)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
42
|
# A single Vpc
|
43
|
-
class AddressPrefix <
|
43
|
+
class AddressPrefix < VPCInstance
|
44
44
|
end
|
45
45
|
|
46
46
|
# A list of Vpc
|
47
|
-
class Routes <
|
47
|
+
class Routes < VPCCollection
|
48
48
|
def initialize(parent)
|
49
49
|
super(parent, 'routes', child_class: Route)
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
53
|
# A single Vpc
|
54
|
-
class Route <
|
54
|
+
class Route < VPCInstance
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
@@ -10,7 +10,7 @@ module IBM
|
|
10
10
|
module VPC
|
11
11
|
module VPNGATEWAY
|
12
12
|
# A list of Connection
|
13
|
-
class Connections <
|
13
|
+
class Connections < VPCCollection
|
14
14
|
def initialize(parent)
|
15
15
|
@array_key = 'connections'
|
16
16
|
@instance = Connection
|
@@ -19,7 +19,7 @@ module IBM
|
|
19
19
|
end
|
20
20
|
|
21
21
|
# A single Connection
|
22
|
-
class Connection <
|
22
|
+
class Connection < VPCInstance
|
23
23
|
def local_cidrs
|
24
24
|
LocalCIDRs.new(self)
|
25
25
|
end
|
@@ -7,7 +7,7 @@ module IBM
|
|
7
7
|
module VPC
|
8
8
|
module VPNGATEWAY
|
9
9
|
# A list of Connection
|
10
|
-
class LocalCIDRs <
|
10
|
+
class LocalCIDRs < VPCCollection
|
11
11
|
def initialize(parent)
|
12
12
|
@array_key = 'local_cidrs'
|
13
13
|
@instance = Connection
|
@@ -20,7 +20,7 @@ module IBM
|
|
20
20
|
end
|
21
21
|
|
22
22
|
# A single Connection
|
23
|
-
class LocalCIDR <
|
23
|
+
class LocalCIDR < VPCInstance
|
24
24
|
def update(payload)
|
25
25
|
put(payload)
|
26
26
|
end
|
@@ -7,7 +7,7 @@ module IBM
|
|
7
7
|
module VPC
|
8
8
|
module VPNGATEWAY
|
9
9
|
# A list of Connection
|
10
|
-
class PeerCIDRs <
|
10
|
+
class PeerCIDRs < VPCCollection
|
11
11
|
def initialize(parent)
|
12
12
|
@array_key = 'peer_cidrs'
|
13
13
|
@instance = Connection
|
@@ -20,7 +20,7 @@ module IBM
|
|
20
20
|
end
|
21
21
|
|
22
22
|
# A single Connection
|
23
|
-
class PeerCIDR <
|
23
|
+
class PeerCIDR < VPCInstance
|
24
24
|
def update(payload)
|
25
25
|
put(payload)
|
26
26
|
end
|
@@ -6,14 +6,14 @@ module IBM
|
|
6
6
|
module SDK
|
7
7
|
module VPC
|
8
8
|
# A list of VPNGateway
|
9
|
-
class VPNGateways <
|
9
|
+
class VPNGateways < VPCCollection
|
10
10
|
def initialize(parent)
|
11
11
|
super(parent, 'vpn_gateways', child_class: VPNGateway)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
# A single VPNGateway
|
16
|
-
class VPNGateway <
|
16
|
+
class VPNGateway < VPCInstance
|
17
17
|
# Get a lisst of connections asssociated with this gateway.
|
18
18
|
def connections
|
19
19
|
VPNGATEWAY::Connections.new(self)
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'sdk_http/connection'
|
4
|
+
require_relative 'sdk_http/exceptions'
|
5
|
+
require_relative 'sdk_http/base_collection'
|
6
|
+
require_relative 'sdk_http/base_instance'
|
7
|
+
require_relative 'sdk_http/sdk_response'
|
8
|
+
require_relative 'sdk_http/iam_token'
|
9
|
+
|
10
|
+
module IBM
|
11
|
+
module Cloud
|
12
|
+
# Module holds basic HTTP functionality.
|
13
|
+
module SDKHTTP
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
# typed: true
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require_relative 'base_http_mixin'
|
5
|
+
require_relative 'has_child'
|
6
|
+
|
7
|
+
module IBM
|
8
|
+
module Cloud
|
9
|
+
module SDKHTTP
|
10
|
+
# Container that encapsulates the VPC API.
|
11
|
+
# This class is used as a base for collection APIs.
|
12
|
+
# @param parent [Object] The parent instance in the API chain.
|
13
|
+
# @param endpoint [string] A path from the parent to the desired endpoint. In most cases is should be 1 word.
|
14
|
+
# @param array_key [string] The key that the API response holds the endpoint data. When nil the endpoint will be used.
|
15
|
+
# @param child_class [Object] The Object to be used when instanciating the single instance for this class.
|
16
|
+
class BaseCollection
|
17
|
+
include BaseHTTPMixin
|
18
|
+
|
19
|
+
def initialize(parent, endpoint, array_key: nil, child_class: nil, child_id: 'id')
|
20
|
+
# Setup empty base instance variables.
|
21
|
+
@params = {}
|
22
|
+
@token = parent.token
|
23
|
+
array_key ||= endpoint
|
24
|
+
|
25
|
+
# Set the array key and child class.
|
26
|
+
@array_key ||= array_key
|
27
|
+
|
28
|
+
@instance ||= child_class
|
29
|
+
@instance_id ||= child_id
|
30
|
+
|
31
|
+
@connection = parent.connection
|
32
|
+
|
33
|
+
(class << self; include ChildMixin; end) if child_class
|
34
|
+
|
35
|
+
@endpoint = parent.url(endpoint)
|
36
|
+
@logger = parent.logger
|
37
|
+
end
|
38
|
+
|
39
|
+
attr_reader :logger, :endpoint, :token, :connection
|
40
|
+
|
41
|
+
# In a Child base class add the possible query parameters for the API and return self to make it chainable.
|
42
|
+
# When implemented usage would be Collection.params(limit: 2).get
|
43
|
+
# @return [BaseCollection] The instanticated class.
|
44
|
+
def params(limit: nil)
|
45
|
+
raise NotImplementedError('Sample only. The params method needs to be customized in child class.')
|
46
|
+
# rubocop:disable Lint/UnreachableCode
|
47
|
+
@params[:limit] = limit if limit
|
48
|
+
self
|
49
|
+
# rubocop:enable Lint/UnreachableCode
|
50
|
+
end
|
51
|
+
|
52
|
+
def reset_params
|
53
|
+
@params.clear
|
54
|
+
end
|
55
|
+
|
56
|
+
# Retrieve the collection from the cloud.
|
57
|
+
# @return [IBM::Cloud::SDK::VPC::Response] The http response object.
|
58
|
+
def fetch
|
59
|
+
@data ||= get
|
60
|
+
end
|
61
|
+
|
62
|
+
# Get an iterable for the resource collection.
|
63
|
+
# @return [Enumerator] Use standard each, next idioms.
|
64
|
+
def all
|
65
|
+
each_resource(url)
|
66
|
+
end
|
67
|
+
|
68
|
+
# Fetch all data and return in an array.
|
69
|
+
# @return [Array] Hashes of the returned data.
|
70
|
+
def data
|
71
|
+
all.to_a
|
72
|
+
end
|
73
|
+
|
74
|
+
# A generic post method to create a resource on the collection.
|
75
|
+
# @param payload [Hash] A hash of parameters to send to the server.
|
76
|
+
# @param payload_type [String] One of the following options json, form, or body.
|
77
|
+
# @return [IBM::Cloud::SDK::VPC::Response] The http response object.
|
78
|
+
def create(payload, payload_type = 'json')
|
79
|
+
adhoc(method: 'post', payload_type: payload_type, payload: payload)
|
80
|
+
end
|
81
|
+
|
82
|
+
private
|
83
|
+
|
84
|
+
# Return a wrapped instance if set.
|
85
|
+
# @param value [Hash] The hash returned from server.
|
86
|
+
def hash_instance(value)
|
87
|
+
return @instance.new(self, data: value, id_key: @instance_id) if @instance
|
88
|
+
|
89
|
+
value
|
90
|
+
end
|
91
|
+
|
92
|
+
# Create a generator that removes the need for pagination.
|
93
|
+
# @param url [String] Full URL to send to server.
|
94
|
+
# @return [Enumerator] Object to page through results.
|
95
|
+
# @yield [BaseInstance] An instance of the instance class.
|
96
|
+
# @yield [Hash] When no BaseInstance set.
|
97
|
+
def each_resource(url, &block)
|
98
|
+
raise NotImplementedError('Sample only. The each_resource method needs to be customized in child class.')
|
99
|
+
# rubocop:disable Lint/UnreachableCode
|
100
|
+
# Sample implementation based on VPC.
|
101
|
+
return enum_for(:each_resource, url) unless block_given?
|
102
|
+
return unless url
|
103
|
+
|
104
|
+
response = get(path: url)
|
105
|
+
resources = response.fetch(@array_key.to_sym)
|
106
|
+
|
107
|
+
resources&.each { |value| yield hash_instance(value) }
|
108
|
+
# VPC has a next key that holds the next URL.
|
109
|
+
return unless response.key?(:next)
|
110
|
+
|
111
|
+
# The next data structure is a hash with a href member.
|
112
|
+
next_url = response.dig(:next, :href)
|
113
|
+
return unless next_url
|
114
|
+
|
115
|
+
each_resource(next_url, &block)
|
116
|
+
# rubocop:enable Lint/UnreachableCode
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'sdk_response'
|
4
|
+
|
5
|
+
module IBM
|
6
|
+
module Cloud
|
7
|
+
# Module holds basic HTTP functionality.
|
8
|
+
module SDKHTTP
|
9
|
+
# Generic methods for accessing VPC.
|
10
|
+
module BaseHTTPMixin
|
11
|
+
@connection = nil
|
12
|
+
|
13
|
+
def adhoc(method: 'get', path: nil, params: {}, payload: {})
|
14
|
+
unchecked_response(method: method, path: path, params: params, payload: payload).raise_for_status!
|
15
|
+
end
|
16
|
+
|
17
|
+
def unchecked_response(method: 'get', path: nil, params: {}, payload: {})
|
18
|
+
@connection.request(method.to_sym, url(path), metadata(params, payload))
|
19
|
+
end
|
20
|
+
|
21
|
+
def get(path: nil, params: {})
|
22
|
+
adhoc(method: 'get', path: path, params: params)
|
23
|
+
end
|
24
|
+
|
25
|
+
attr_reader :endpoint
|
26
|
+
|
27
|
+
def post(payload = {}, path: nil, params: {})
|
28
|
+
adhoc(method: 'post', path: path, params: params, payload: payload)
|
29
|
+
end
|
30
|
+
|
31
|
+
def put(payload = {}, path: nil, params: {})
|
32
|
+
adhoc(method: 'put', path: path, params: params, payload: payload)
|
33
|
+
end
|
34
|
+
|
35
|
+
def patch(payload = {}, path: nil, params: {})
|
36
|
+
adhoc(method: 'patch', path: path, params: params, payload: payload)
|
37
|
+
end
|
38
|
+
|
39
|
+
def delete(path: nil, params: {})
|
40
|
+
adhoc(method: 'delete', path: path, params: params)
|
41
|
+
end
|
42
|
+
|
43
|
+
def metadata(query = nil, payload = nil)
|
44
|
+
@params ||= {}
|
45
|
+
query ||= {}
|
46
|
+
payload ||= {}
|
47
|
+
{
|
48
|
+
query: @params.merge(query),
|
49
|
+
body: payload,
|
50
|
+
headers: { "Authorization": @token.authorization_header }
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
def url(path = nil)
|
55
|
+
return endpoint unless path
|
56
|
+
return path if URI.parse(path).relative? == false
|
57
|
+
|
58
|
+
"#{endpoint}/#{path}"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'forwardable'
|
4
|
+
|
5
|
+
require_relative 'base_http_mixin'
|
6
|
+
|
7
|
+
module IBM
|
8
|
+
module Cloud
|
9
|
+
# Module holds basic HTTP functionality.
|
10
|
+
module SDKHTTP
|
11
|
+
# Container that encapsulates the VPC API.
|
12
|
+
class BaseInstance
|
13
|
+
include BaseHTTPMixin
|
14
|
+
|
15
|
+
def initialize(parent, data: {}, id_key: 'id', endpoint: nil)
|
16
|
+
@data = data
|
17
|
+
|
18
|
+
endpoint ||= data[id_key.to_sym]
|
19
|
+
@connection = parent.connection
|
20
|
+
@token = parent.token
|
21
|
+
@endpoint = parent.url(endpoint)
|
22
|
+
@logger = parent.logger
|
23
|
+
end
|
24
|
+
|
25
|
+
attr_reader :logger, :endpoint, :token, :connection
|
26
|
+
|
27
|
+
# Fetch the instance details for this resource.
|
28
|
+
# @return [SDKResponse] The HTTP response object.
|
29
|
+
def details
|
30
|
+
get.hash_response
|
31
|
+
end
|
32
|
+
|
33
|
+
# Fetch the instance details from the server. Clear current data and save the results.
|
34
|
+
# @return [BaseInstance] This instance for chaining.
|
35
|
+
def refresh
|
36
|
+
@data.replace(details)
|
37
|
+
self
|
38
|
+
end
|
39
|
+
|
40
|
+
# Send an update to the server for this resource.
|
41
|
+
def update(payload)
|
42
|
+
patch(payload)
|
43
|
+
end
|
44
|
+
|
45
|
+
# Send a delete request to the server for this resource.
|
46
|
+
def remove
|
47
|
+
delete
|
48
|
+
end
|
49
|
+
|
50
|
+
extend Forwardable
|
51
|
+
def_delegators :@data, :[], :dig, :each, :each_pair, :fetch, :has_key?, :has_value?, :include?, :index, :inspect, :key?, :keys, :length, :merge, :merge!, :clear, :to_h, :value?, :values, :pretty_print
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'httparty'
|
4
|
+
require_relative 'sdk_response'
|
5
|
+
|
6
|
+
module IBM
|
7
|
+
module Cloud
|
8
|
+
module SDKHTTP
|
9
|
+
# Class to wrap the HTTP Provider implementation.
|
10
|
+
class HTTPConnection
|
11
|
+
include HTTParty
|
12
|
+
|
13
|
+
def initialize(logger)
|
14
|
+
self.class.logger(logger, :debug, :curl)
|
15
|
+
end
|
16
|
+
|
17
|
+
def default_options
|
18
|
+
self.class.default_options
|
19
|
+
end
|
20
|
+
|
21
|
+
def add_proxy(host, port, user, password)
|
22
|
+
self.class.http_proxy(host, port, user, password)
|
23
|
+
end
|
24
|
+
|
25
|
+
def request(method, path, params)
|
26
|
+
response = self.class.send(method.to_sym, path, params)
|
27
|
+
SDKResponse.new(response)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|