ibm-cloud-sdk 0.1.3 → 0.1.4

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.
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
@@ -0,0 +1,90 @@
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
+ # Return the raw connection object.
36
+ def connection
37
+ response.connection
38
+ end
39
+
40
+ # Return the content type of the response.
41
+ def content_type
42
+ response.response.mime_type
43
+ end
44
+
45
+ # Return the textual reason.
46
+ def reason
47
+ response.reason
48
+ end
49
+
50
+ # Return the sent url as a string.
51
+ def url
52
+ response.uri.to_s
53
+ end
54
+
55
+ # Return the sent url as a URI class.
56
+ def uri
57
+ response.uri
58
+ end
59
+
60
+ # Verify that the json response is a hash.
61
+ def hash_response
62
+ check_object(Hash)
63
+ end
64
+
65
+ # Verify that the json response is an array.
66
+ def array_response
67
+ check_object(Array)
68
+ end
69
+
70
+ # Find a subkey within the returned response.
71
+ def subkey(key)
72
+ ret = hash_response
73
+ sym_key = key.to_sym
74
+ return ret.fetch(sym_key) if ret.key?(sym_key)
75
+
76
+ raise "Key not found in #{ret}."
77
+ end
78
+
79
+ # Check to see if the returned object is the expected object.
80
+ def check_object(obj)
81
+ ret = json
82
+ return ret if ret.instance_of?(obj)
83
+
84
+ raise "Expected #{obj} in response for #{url}. The returned object is a #{ret.class}."
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
90
+ 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,36 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ require_relative 'instance/actions'
5
+ require_relative 'instance/network_interfaces'
6
+ require_relative 'instance/volume_attachments'
7
+ require_relative 'instance/profiles'
8
+
9
+ module IBM
10
+ module Cloud
11
+ module SDK
12
+ module VPC
13
+ module INSTANCES
14
+ # Work with a single instance.
15
+ class Instance < BaseInstance
16
+ def actions
17
+ Actions.new(self)
18
+ end
19
+
20
+ def network_interfaces
21
+ NetworkInterfaces.new(self)
22
+ end
23
+
24
+ def volume_attachments
25
+ VolumeAttachments.new(self)
26
+ end
27
+
28
+ def profiles
29
+ Profiles.new(self)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ 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,53 @@
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 < BaseVPC
13
+ def initialize(parent)
14
+ super(parent, 'network_interfaces')
15
+ end
16
+
17
+ def all
18
+ get.subkey('network_interfaces')
19
+ # get
20
+ end
21
+
22
+ def update(payload)
23
+ post(payload)
24
+ end
25
+
26
+ def instance(id)
27
+ NetworkInterface.new(self, id)
28
+ end
29
+ end
30
+
31
+ # A single network insterface.
32
+ class NetworkInterface < BaseVPC
33
+ def remove
34
+ delete
35
+ end
36
+
37
+ def details
38
+ get
39
+ end
40
+
41
+ def update(payload)
42
+ patch(payload)
43
+ end
44
+
45
+ def floating_ips
46
+ FloatingIps.new(self)
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,34 @@
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
+ # Work with multiple profiles.
10
+ class Profiles < BaseVPC
11
+ def initialize(parent)
12
+ super(parent, 'instance/profiles')
13
+ end
14
+
15
+ def all
16
+ get
17
+ end
18
+
19
+ def instance(name)
20
+ Profile.new(self, name)
21
+ end
22
+ end
23
+
24
+ # Get a single profile.
25
+ class Profile < BaseVPC
26
+ def details
27
+ get
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,46 @@
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 all attached volumes.
10
+ class VolumeAttachments < BaseVPC
11
+ def initialize(parent)
12
+ super(parent, 'volume_attachments')
13
+ end
14
+
15
+ def all
16
+ get
17
+ end
18
+
19
+ def create(payload)
20
+ post(payload)
21
+ end
22
+
23
+ def instance(id)
24
+ VolumeAttachment.new(self, id)
25
+ end
26
+ end
27
+
28
+ # A single attached volume.
29
+ class VolumeAttachment < BaseVPC
30
+ def details
31
+ get
32
+ end
33
+
34
+ def update(payload)
35
+ patch(payload)
36
+ end
37
+
38
+ def remove
39
+ delete
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,20 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ require_relative('instance')
5
+
6
+ module IBM
7
+ module Cloud
8
+ module SDK
9
+ # Work with VPC instances.
10
+ module VPC
11
+ # Work with multiple VM instances.
12
+ class Instances < BaseCollection
13
+ def initialize(parent)
14
+ super(parent, 'instances', child_class: INSTANCES::Instance)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ 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 IPSecPolicy
9
+ class IPSecPolicies < BaseCollection
10
+ def initialize(parent)
11
+ super(parent, 'ike_policies', child_class: IPSecPolicy)
12
+ end
13
+ end
14
+
15
+ # A single IPSecPolicy
16
+ class IPSecPolicy < BaseInstance
17
+ def connections
18
+ get('connections')
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,43 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ module IBM
5
+ module Cloud
6
+ module SDK
7
+ module VPC
8
+ # A collection of SSH keys.
9
+ class Keys < BaseCollection
10
+ def initialize(parent)
11
+ super(parent, 'keys', child_class: Key)
12
+ end
13
+
14
+ def fetch(resource_id: nil)
15
+ params = {}
16
+ params['resource_group.id'] = resource_id if resource_id
17
+ get(params: params)
18
+ end
19
+
20
+ def all(resource_id = nil)
21
+ fetch(resource_id: resource_id).subkey(@array_key)
22
+ end
23
+
24
+ # :reek:FeatureEnvy
25
+ def create(name, public_key, resource_group: nil, type: nil)
26
+ payload = { name: name, public_key: public_key }
27
+ payload[:resource_group] = resource_group if resource_group
28
+ payload[:type] = type if type
29
+ post(payload)
30
+ end
31
+
32
+ def key(id)
33
+ Key.new(self, id)
34
+ end
35
+ end
36
+
37
+ # A single key.
38
+ class Key < BaseInstance
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end