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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +26 -0
- data/README.md +1 -1
- data/ibm-cloud-sdk.gemspec +3 -1
- data/lib/ibm/cloud/sdk.rb +2 -0
- data/lib/ibm/cloud/sdk/power_iaas.rb +70 -1
- data/lib/ibm/cloud/sdk/resource_controller.rb +2 -8
- data/lib/ibm/cloud/sdk/version.rb +1 -1
- data/lib/ibm/cloud/sdk/vpc.rb +132 -0
- data/lib/ibm/cloud/sdk/vpc/base_collection.rb +108 -0
- data/lib/ibm/cloud/sdk/vpc/base_instance.rb +23 -0
- data/lib/ibm/cloud/sdk/vpc/base_vpc.rb +61 -0
- data/lib/ibm/cloud/sdk/vpc/cloud_sdk.rb +33 -0
- data/lib/ibm/cloud/sdk/vpc/floatingips.rb +20 -0
- data/lib/ibm/cloud/sdk/vpc/flowlogcollectors.rb +20 -0
- data/lib/ibm/cloud/sdk/vpc/helpers/connection.rb +66 -0
- data/lib/ibm/cloud/sdk/vpc/helpers/response.rb +92 -0
- data/lib/ibm/cloud/sdk/vpc/ike_policies.rb +24 -0
- data/lib/ibm/cloud/sdk/vpc/images.rb +21 -0
- data/lib/ibm/cloud/sdk/vpc/instance/actions.rb +19 -0
- data/lib/ibm/cloud/sdk/vpc/instance/floating_ips.rb +23 -0
- data/lib/ibm/cloud/sdk/vpc/instance/network_interfaces.rb +28 -0
- data/lib/ibm/cloud/sdk/vpc/instance/volume_attachments.rb +23 -0
- data/lib/ibm/cloud/sdk/vpc/instance_profiles.rb +21 -0
- data/lib/ibm/cloud/sdk/vpc/instances.rb +64 -0
- data/lib/ibm/cloud/sdk/vpc/ipsec_policies.rb +24 -0
- data/lib/ibm/cloud/sdk/vpc/keys.rb +43 -0
- data/lib/ibm/cloud/sdk/vpc/load_balancer.rb +23 -0
- data/lib/ibm/cloud/sdk/vpc/load_balancer/listeners.rb +30 -0
- data/lib/ibm/cloud/sdk/vpc/load_balancer/members.rb +23 -0
- data/lib/ibm/cloud/sdk/vpc/load_balancer/policies.rb +30 -0
- data/lib/ibm/cloud/sdk/vpc/load_balancer/pools.rb +28 -0
- data/lib/ibm/cloud/sdk/vpc/load_balancer/rules.rb +25 -0
- data/lib/ibm/cloud/sdk/vpc/load_balancers.rb +19 -0
- data/lib/ibm/cloud/sdk/vpc/network_acls.rb +39 -0
- data/lib/ibm/cloud/sdk/vpc/operating_systems.rb +21 -0
- data/lib/ibm/cloud/sdk/vpc/public_gateways.rb +21 -0
- data/lib/ibm/cloud/sdk/vpc/regions.rb +35 -0
- data/lib/ibm/cloud/sdk/vpc/security_groups.rb +48 -0
- data/lib/ibm/cloud/sdk/vpc/subnets.rb +21 -0
- data/lib/ibm/cloud/sdk/vpc/volume_profiles.rb +21 -0
- data/lib/ibm/cloud/sdk/vpc/volumes.rb +21 -0
- data/lib/ibm/cloud/sdk/vpc/vpcs.rb +60 -0
- data/lib/ibm/cloud/sdk/vpc/vpn_gateway/connections.rb +35 -0
- data/lib/ibm/cloud/sdk/vpc/vpn_gateway/local_cidrs.rb +32 -0
- data/lib/ibm/cloud/sdk/vpc/vpn_gateway/peer_cidrs.rb +32 -0
- data/lib/ibm/cloud/sdk/vpc/vpn_gateways.rb +25 -0
- metadata +57 -2
@@ -0,0 +1,23 @@
|
|
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 BaseInstance < BaseVPC
|
9
|
+
def details
|
10
|
+
get.hash_response
|
11
|
+
end
|
12
|
+
|
13
|
+
def update(payload)
|
14
|
+
patch(payload)
|
15
|
+
end
|
16
|
+
|
17
|
+
def remove
|
18
|
+
delete
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,61 @@
|
|
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 BaseVPC
|
9
|
+
def initialize(parent, endpoint = nil)
|
10
|
+
@endpoint = parent.url(endpoint)
|
11
|
+
@connection = parent.connection
|
12
|
+
@logger = parent.logger
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_reader :endpoint, :connection, :logger
|
16
|
+
|
17
|
+
def adhoc(method: 'get', path: nil, params: {}, payload_type: 'json', payload: {})
|
18
|
+
@connection.adhoc(method.to_sym, url(path), metadata(params, payload_type, payload))
|
19
|
+
end
|
20
|
+
|
21
|
+
def get(path: nil, params: {})
|
22
|
+
adhoc(method: 'get', path: path, params: params)
|
23
|
+
end
|
24
|
+
|
25
|
+
def post(payload = {}, path: nil, params: {}, type: 'json')
|
26
|
+
adhoc(method: 'post', path: path, params: params, payload: payload, payload_type: type)
|
27
|
+
end
|
28
|
+
|
29
|
+
def put(payload = {}, path: nil, params: {})
|
30
|
+
adhoc(method: 'put', path: path, params: params, payload: payload)
|
31
|
+
end
|
32
|
+
|
33
|
+
def patch(payload = {}, path: nil, params: {})
|
34
|
+
adhoc(method: 'patch', path: path, params: params, payload: payload)
|
35
|
+
end
|
36
|
+
|
37
|
+
def delete(path: nil, params: {})
|
38
|
+
adhoc(method: 'delete', path: path, params: params)
|
39
|
+
end
|
40
|
+
|
41
|
+
def url(path = nil)
|
42
|
+
return endpoint unless path
|
43
|
+
|
44
|
+
"#{endpoint}/#{path}"
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def metadata(params = {}, payload_type = 'json', payload = {})
|
50
|
+
params ||= {}
|
51
|
+
pt = {
|
52
|
+
params: { version: '2020-08-01', generation: 2 }.merge(params)
|
53
|
+
}
|
54
|
+
|
55
|
+
pt[payload_type.to_sym] = payload unless payload.empty?
|
56
|
+
pt
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'http'
|
4
|
+
require 'ibm/cloud/sdk/vpc/helpers/connection'
|
5
|
+
require 'ibm/cloud/sdk/vpc'
|
6
|
+
|
7
|
+
module IBM
|
8
|
+
# Holds the SDK pieces.
|
9
|
+
class CloudSDK
|
10
|
+
def initialize(api_key, logger: nil, options: {})
|
11
|
+
@logger = logger
|
12
|
+
@logger ||= Logger.new($stdout, level: :warn)
|
13
|
+
|
14
|
+
@client = HTTP.use(http_options(options))
|
15
|
+
@connection = IBM::Cloud::SDK::VPC::Connection.new(api_key, logger: @logger, client: @client)
|
16
|
+
end
|
17
|
+
|
18
|
+
def http_options(options = {})
|
19
|
+
options.merge(
|
20
|
+
{
|
21
|
+
logging: { logger: @logger },
|
22
|
+
auto_deflate: {}
|
23
|
+
}
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
attr_reader :logger, :connection
|
28
|
+
|
29
|
+
def vpc(region = 'us-east')
|
30
|
+
IBM::Cloud::SDK::Vpc.new(region, @connection, logger: @logger)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# typed: false
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module IBM
|
5
|
+
module Cloud
|
6
|
+
module SDK
|
7
|
+
module VPC
|
8
|
+
# Class that deals with groups of floating IPs.
|
9
|
+
class FloatingIPs < BaseCollection
|
10
|
+
def initialize(parent)
|
11
|
+
super(parent, 'floating_ips', child_class: FloatingIP)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# Class that deals with a single floating IP.
|
16
|
+
class FloatingIP < BaseInstance; end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# typed: true
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module IBM
|
5
|
+
module Cloud
|
6
|
+
module SDK
|
7
|
+
module VPC
|
8
|
+
# A list of subnets
|
9
|
+
class FlowLogCollectors < BaseCollection
|
10
|
+
def initialize(parent)
|
11
|
+
super(parent, 'flow_log_collectors', child_class: FlowLogCollectors)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# A single subnet
|
16
|
+
class FlowLogCollector < BaseInstance; end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'time'
|
4
|
+
require 'http'
|
5
|
+
require_relative 'response'
|
6
|
+
|
7
|
+
module IBM
|
8
|
+
module Cloud
|
9
|
+
module SDK
|
10
|
+
module VPC
|
11
|
+
|
12
|
+
# Contols tokens.
|
13
|
+
class Connection
|
14
|
+
def initialize(api_key, logger: nil, client: nil)
|
15
|
+
@api_key = api_key
|
16
|
+
@logger = logger
|
17
|
+
@client = client
|
18
|
+
@token = Token.new(api_key, logger: logger, client: client)
|
19
|
+
end
|
20
|
+
|
21
|
+
attr_reader :client
|
22
|
+
|
23
|
+
def adhoc(verb, uri, opts = {})
|
24
|
+
response = @client.auth(@token.authorization_header).request(verb.to_sym, uri, opts)
|
25
|
+
Response.new(response)
|
26
|
+
end
|
27
|
+
|
28
|
+
def authorization_header
|
29
|
+
@token.authorization_header
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Get a token.
|
34
|
+
class Token
|
35
|
+
def initialize(api_key, logger: nil, client: nil)
|
36
|
+
@api_key = api_key
|
37
|
+
@logger = logger
|
38
|
+
@client = client
|
39
|
+
@data = fetch
|
40
|
+
end
|
41
|
+
|
42
|
+
def fetch
|
43
|
+
payload = {
|
44
|
+
form: {
|
45
|
+
grant_type: 'urn:ibm:params:oauth:grant-type:apikey',
|
46
|
+
apikey: @api_key
|
47
|
+
}
|
48
|
+
}
|
49
|
+
response = HTTP.post('https://iam.cloud.ibm.com/identity/token', payload)
|
50
|
+
@data = Response.new(response).json
|
51
|
+
end
|
52
|
+
|
53
|
+
def expired?
|
54
|
+
fetch unless @data
|
55
|
+
@data.fetch(:expiration).to_i <= Time.now.to_i + 600
|
56
|
+
end
|
57
|
+
|
58
|
+
def authorization_header
|
59
|
+
fetch if expired?
|
60
|
+
"#{@data.fetch(:token_type)} #{@data.fetch(:access_token)}"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'time'
|
4
|
+
require 'http'
|
5
|
+
|
6
|
+
module IBM
|
7
|
+
module Cloud
|
8
|
+
module SDK
|
9
|
+
module VPC
|
10
|
+
# Encapsulate the HTTP response.
|
11
|
+
class Response
|
12
|
+
def initialize(response)
|
13
|
+
@response = response
|
14
|
+
end
|
15
|
+
|
16
|
+
attr_reader :response
|
17
|
+
|
18
|
+
# Return the response in a hash or array.
|
19
|
+
def json
|
20
|
+
JSON.parse(body, symbolize_names: true)
|
21
|
+
rescue StandardError
|
22
|
+
raise "Error while parsing response body. #{response.body}"
|
23
|
+
end
|
24
|
+
|
25
|
+
# Return the raw response string.
|
26
|
+
def body
|
27
|
+
response.body.to_s
|
28
|
+
end
|
29
|
+
|
30
|
+
# Return the response code.
|
31
|
+
def code
|
32
|
+
response.code
|
33
|
+
end
|
34
|
+
|
35
|
+
alias_method :status, :code
|
36
|
+
|
37
|
+
# Return the raw connection object.
|
38
|
+
def connection
|
39
|
+
response.connection
|
40
|
+
end
|
41
|
+
|
42
|
+
# Return the content type of the response.
|
43
|
+
def content_type
|
44
|
+
response.response.mime_type
|
45
|
+
end
|
46
|
+
|
47
|
+
# Return the textual reason.
|
48
|
+
def reason
|
49
|
+
response.reason
|
50
|
+
end
|
51
|
+
|
52
|
+
# Return the sent url as a string.
|
53
|
+
def url
|
54
|
+
response.uri.to_s
|
55
|
+
end
|
56
|
+
|
57
|
+
# Return the sent url as a URI class.
|
58
|
+
def uri
|
59
|
+
response.uri
|
60
|
+
end
|
61
|
+
|
62
|
+
# Verify that the json response is a hash.
|
63
|
+
def hash_response
|
64
|
+
check_object(Hash)
|
65
|
+
end
|
66
|
+
|
67
|
+
# Verify that the json response is an array.
|
68
|
+
def array_response
|
69
|
+
check_object(Array)
|
70
|
+
end
|
71
|
+
|
72
|
+
# Find a subkey within the returned response.
|
73
|
+
def subkey(key)
|
74
|
+
ret = hash_response
|
75
|
+
sym_key = key.to_sym
|
76
|
+
return ret.fetch(sym_key) if ret.key?(sym_key)
|
77
|
+
|
78
|
+
raise "Key #{key} not found in #{ret}."
|
79
|
+
end
|
80
|
+
|
81
|
+
# Check to see if the returned object is the expected object.
|
82
|
+
def check_object(obj)
|
83
|
+
ret = json
|
84
|
+
return ret if ret.instance_of?(obj)
|
85
|
+
|
86
|
+
raise "Expected #{obj} in response for #{url}. The returned object is a #{ret.class}."
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# typed: true
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module IBM
|
5
|
+
module Cloud
|
6
|
+
module SDK
|
7
|
+
module VPC
|
8
|
+
# A list of IKEPolicy
|
9
|
+
class IKEPolicies < BaseCollection
|
10
|
+
def initialize(parent)
|
11
|
+
super(parent, 'ike_policies', child_class: IKEPolicy)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# A single IKEPolicy
|
16
|
+
class IKEPolicy < BaseInstance
|
17
|
+
def connections
|
18
|
+
get('connections')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# typed: true
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module IBM
|
5
|
+
module Cloud
|
6
|
+
module SDK
|
7
|
+
module VPC
|
8
|
+
# Work with multiple images.
|
9
|
+
class Images < BaseCollection
|
10
|
+
def initialize(parent)
|
11
|
+
super(parent, 'images', child_class: Image)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# Work with a single image.
|
16
|
+
class Image < BaseInstance
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# typed: true
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module IBM
|
5
|
+
module Cloud
|
6
|
+
module SDK
|
7
|
+
module VPC
|
8
|
+
module INSTANCES
|
9
|
+
# Actions for an instance.
|
10
|
+
class Actions < BaseCollection
|
11
|
+
def initialize(parent)
|
12
|
+
super(parent, 'actions')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# typed: true
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module IBM
|
5
|
+
module Cloud
|
6
|
+
module SDK
|
7
|
+
module VPC
|
8
|
+
module INSTANCES
|
9
|
+
# Get a Floating IP.
|
10
|
+
class FloatingIps < BaseCollection
|
11
|
+
def initialize(parent)
|
12
|
+
super(parent, 'floating_ips', child_class: FloatingIp)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# Get a single floating IP.
|
17
|
+
class FloatingIp < BaseInstance
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# typed: true
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require_relative('floating_ips')
|
5
|
+
|
6
|
+
module IBM
|
7
|
+
module Cloud
|
8
|
+
module SDK
|
9
|
+
module VPC
|
10
|
+
module INSTANCES
|
11
|
+
# All netowrk interfaces.
|
12
|
+
class NetworkInterfaces < BaseCollection
|
13
|
+
def initialize(parent)
|
14
|
+
super(parent, 'network_interfaces', child_class: NetworkInterface)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# A single network insterface.
|
19
|
+
class NetworkInterface < BaseInstance
|
20
|
+
def floating_ips
|
21
|
+
FloatingIps.new(self)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|