ibm-cloud-sdk 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +3 -0
  3. data/ibm-cloud-sdk.gemspec +1 -0
  4. data/lib/ibm/cloud/sdk.rb +2 -0
  5. data/lib/ibm/cloud/sdk/version.rb +1 -1
  6. data/lib/ibm/cloud/sdk/vpc.rb +128 -0
  7. data/lib/ibm/cloud/sdk/vpc/base_collection.rb +68 -0
  8. data/lib/ibm/cloud/sdk/vpc/base_instance.rb +23 -0
  9. data/lib/ibm/cloud/sdk/vpc/base_vpc.rb +61 -0
  10. data/lib/ibm/cloud/sdk/vpc/cloud_sdk.rb +33 -0
  11. data/lib/ibm/cloud/sdk/vpc/floatingips.rb +20 -0
  12. data/lib/ibm/cloud/sdk/vpc/flowlogcollectors.rb +20 -0
  13. data/lib/ibm/cloud/sdk/vpc/helpers/connection.rb +66 -0
  14. data/lib/ibm/cloud/sdk/vpc/helpers/response.rb +90 -0
  15. data/lib/ibm/cloud/sdk/vpc/ike_policies.rb +24 -0
  16. data/lib/ibm/cloud/sdk/vpc/images.rb +21 -0
  17. data/lib/ibm/cloud/sdk/vpc/instance.rb +36 -0
  18. data/lib/ibm/cloud/sdk/vpc/instance/actions.rb +19 -0
  19. data/lib/ibm/cloud/sdk/vpc/instance/floating_ips.rb +23 -0
  20. data/lib/ibm/cloud/sdk/vpc/instance/network_interfaces.rb +53 -0
  21. data/lib/ibm/cloud/sdk/vpc/instance/profiles.rb +34 -0
  22. data/lib/ibm/cloud/sdk/vpc/instance/volume_attachments.rb +46 -0
  23. data/lib/ibm/cloud/sdk/vpc/instances.rb +20 -0
  24. data/lib/ibm/cloud/sdk/vpc/ipsec_policies.rb +24 -0
  25. data/lib/ibm/cloud/sdk/vpc/keys.rb +43 -0
  26. data/lib/ibm/cloud/sdk/vpc/load_balancer.rb +23 -0
  27. data/lib/ibm/cloud/sdk/vpc/load_balancer/listeners.rb +30 -0
  28. data/lib/ibm/cloud/sdk/vpc/load_balancer/members.rb +23 -0
  29. data/lib/ibm/cloud/sdk/vpc/load_balancer/policies.rb +30 -0
  30. data/lib/ibm/cloud/sdk/vpc/load_balancer/pools.rb +28 -0
  31. data/lib/ibm/cloud/sdk/vpc/load_balancer/rules.rb +25 -0
  32. data/lib/ibm/cloud/sdk/vpc/load_balancers.rb +19 -0
  33. data/lib/ibm/cloud/sdk/vpc/network_acls.rb +39 -0
  34. data/lib/ibm/cloud/sdk/vpc/operating_systems.rb +21 -0
  35. data/lib/ibm/cloud/sdk/vpc/public_gateways.rb +21 -0
  36. data/lib/ibm/cloud/sdk/vpc/regions.rb +35 -0
  37. data/lib/ibm/cloud/sdk/vpc/security_groups.rb +48 -0
  38. data/lib/ibm/cloud/sdk/vpc/subnets.rb +21 -0
  39. data/lib/ibm/cloud/sdk/vpc/volume_profiles.rb +21 -0
  40. data/lib/ibm/cloud/sdk/vpc/volumes.rb +21 -0
  41. data/lib/ibm/cloud/sdk/vpc/vpcs.rb +60 -0
  42. data/lib/ibm/cloud/sdk/vpc/vpn_gateway/connections.rb +35 -0
  43. data/lib/ibm/cloud/sdk/vpc/vpn_gateway/local_cidrs.rb +32 -0
  44. data/lib/ibm/cloud/sdk/vpc/vpn_gateway/peer_cidrs.rb +32 -0
  45. data/lib/ibm/cloud/sdk/vpc/vpn_gateways.rb +25 -0
  46. metadata +57 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d147792b6e2fd5d7ddb2b243cb2993cb606289352883831c6b805c2489c1267b
4
- data.tar.gz: e03cbb041d6aae300f09fa4b6fb1aaaed759b187645deb2e4eeca561307f4520
3
+ metadata.gz: 181a2894e2d8045bea0d2a33cf81570480eee1f668017b8ade96b1801d0465b2
4
+ data.tar.gz: 5399f7e3e4f4b483a72e673d351605cb1f8bb09f216e5fd1a9439742f736aedf
5
5
  SHA512:
6
- metadata.gz: 920c4079d316f6d65dd4fb3b4d9bcb97d06d06b1165f43ba19b3b7c3f1e12dfe1063f2666fdaf26c2252e4fb9949363d804e4678c13f2676531993851da615d4
7
- data.tar.gz: 125f277b64b64c751b5ae932df6d10203b7bbe01417f361667de8e36b942c574eb744e9432eebd3652ef2a21d0b5c34e05e936e3533a34c9f751d64d79bfeb0b
6
+ metadata.gz: 237fd30c5dd4efa622de5be57a2df9e2285dcabc3d15f415d6efb6bec31b36254cbaf6c3cb32a6d8b7113b7e8709e4eddee64736515030e5e3227694dc464b4e
7
+ data.tar.gz: ed36bdf032519bc35c1563f62fe279f6744b3f25b97fef4358ebd689958a48a17a5a1eafbf85f72a3c62e372dfb764b35463cc292eede788b3ad127170664ced
@@ -1,6 +1,9 @@
1
1
  # Changelog
2
2
  All notable changes to the gem ibm-cloud-sdk-ruby will be documented here.
3
3
 
4
+ ## v0.1.4 - 2020-09-17
5
+ - Added support for the IBM Virtual Private Cloud (VPC) service
6
+
4
7
  ## v0.1.3 - 2020-08-31
5
8
  ### Added the following rest api calls for Power System Virtual Server service
6
9
  - Add PowerIaas 'delete_volume' method
@@ -24,4 +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
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
@@ -1,7 +1,7 @@
1
1
  module IBM
2
2
  module Cloud
3
3
  module SDK
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.4"
5
5
  end
6
6
  end
7
7
  end
@@ -0,0 +1,128 @@
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/instances'
13
+ require_relative 'vpc/ipsec_policies'
14
+ require_relative 'vpc/keys'
15
+ require_relative 'vpc/load_balancers'
16
+ require_relative 'vpc/network_acls'
17
+ require_relative 'vpc/operating_systems'
18
+ require_relative 'vpc/public_gateways'
19
+ require_relative 'vpc/regions'
20
+ require_relative 'vpc/security_groups'
21
+ require_relative 'vpc/subnets'
22
+ require_relative 'vpc/volume_profiles'
23
+ require_relative 'vpc/volumes'
24
+ require_relative 'vpc/vpcs'
25
+ require_relative 'vpc/vpn_gateways'
26
+
27
+ module IBM
28
+ module Cloud
29
+ module SDK
30
+ # Container that encapsulates the VPC API.
31
+ class Vpc < BaseVPC
32
+ # Create an API Client object for the VPC IaaS service
33
+ #
34
+ # @param region [String] the IBM Power Cloud instance region
35
+ # @param token [IAMtoken] the IBM Cloud IAM Token object
36
+ # @param logger [Logger] an instance of an instanciated logger.
37
+ def initialize(region, api_key, logger: nil)
38
+ @region = region
39
+ @api_key = api_key
40
+ @token = api_key
41
+
42
+ @logger = logger || Logger.new($stdout)
43
+ end
44
+
45
+ attr_reader :token, :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 instances
71
+ VPC::Instances.new(self)
72
+ end
73
+
74
+ def ipsec_policies
75
+ VPC::IPSecPolicies.new(self)
76
+ end
77
+
78
+ def keys
79
+ VPC::Keys.new(self)
80
+ end
81
+
82
+ def load_balancers
83
+ VPC::LoadBalancers.new(self)
84
+ end
85
+
86
+ def network_acls
87
+ VPC::NetworkACLs.new(self)
88
+ end
89
+
90
+ def operating_systems
91
+ VPC::OperatingSystems.new(self)
92
+ end
93
+
94
+ def public_gateways
95
+ VPC::PublicGateways.new(self)
96
+ end
97
+
98
+ def regions
99
+ VPC::Regions.new(self)
100
+ end
101
+
102
+ def security_groups
103
+ VPC::SecurityGroups.new(self)
104
+ end
105
+
106
+ def subnets
107
+ VPC::Subnets.new(self)
108
+ end
109
+
110
+ def volumes_profiles
111
+ VPC::VolumeProfiles.new(self)
112
+ end
113
+
114
+ def volumes
115
+ VPC::Volumes.new(self)
116
+ end
117
+
118
+ def vpcs
119
+ VPC::Vpcs.new(self)
120
+ end
121
+
122
+ def vpn_gateways
123
+ VPC::VPNGateways.new(self)
124
+ end
125
+ end
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,68 @@
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
+ def initialize(parent, endpoint, array_key: nil, child_class: nil)
10
+ # Setup empty base instance variables.
11
+ @data = nil
12
+ @params = nil
13
+
14
+ array_key ||= endpoint
15
+
16
+ # Set the array key and child class.
17
+ @array_key ||= array_key
18
+ @instance ||= child_class
19
+
20
+ super(parent, endpoint)
21
+ end
22
+
23
+ # Retrieve the collection from the cloud.
24
+ def fetch
25
+ @data ||= get(params: @params)
26
+ @data
27
+ end
28
+
29
+ def all
30
+ response = fetch.subkey(@array_key)
31
+ return response if response.is_a?(Array)
32
+
33
+ raise "#{self.class}.#{__method__} Expecting response to be an Array not a #{response.class}"
34
+ end
35
+
36
+ def params(start: nil, limit: nil, resource_group: nil)
37
+ @params = {}
38
+ @params['start'] = start if start
39
+ @params['limit'] = limit if limit
40
+ @params['resource_group'] = resource_group if resource_group
41
+ self
42
+ end
43
+
44
+ def count
45
+ fetch.subkey('total_count')
46
+ end
47
+
48
+ def limit
49
+ fetch.subkey('limit')
50
+ end
51
+
52
+ def instance(id)
53
+ @instance.new(self, id)
54
+ end
55
+
56
+ def next
57
+ fetch.subkey('next')
58
+ rescue RuntimeError
59
+ nil
60
+ end
61
+
62
+ def create(payload)
63
+ post(payload)
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -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
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
+ @token = parent.token
12
+ @logger = parent.logger
13
+ end
14
+
15
+ attr_reader :endpoint, :token, :logger
16
+
17
+ def adhoc(method: 'get', path: nil, params: {}, payload_type: 'json', payload: {})
18
+ @token.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)
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
+ @token = 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, :token
28
+
29
+ def vpc(region = 'us-east')
30
+ IBM::Cloud::SDK::Vpc.new(region, @token, 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