ibm-cloud-sdk 0.1.6 → 0.1.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +20 -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 +117 -9
- 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 +28 -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 +77 -2
- data/lib/ibm/cloud/sdk/vpc/instance/floating_ips.rb +3 -3
- data/lib/ibm/cloud/sdk/vpc/instance/network_interfaces.rb +3 -3
- data/lib/ibm/cloud/sdk/vpc/instance/volume_attachments.rb +3 -3
- data/lib/ibm/cloud/sdk/vpc/instance_profiles.rb +3 -3
- data/lib/ibm/cloud/sdk/vpc/instances.rb +99 -6
- 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 +3 -3
- data/lib/ibm/cloud/sdk/vpc/vpn_gateway/peer_cidrs.rb +3 -3
- 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 +120 -0
- data/lib/ibm/cloud/sdk_http/base_instance.rb +55 -0
- data/lib/ibm/cloud/sdk_http/connection.rb +38 -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 -10
- 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
@@ -5,16 +5,16 @@ module IBM
|
|
5
5
|
module Cloud
|
6
6
|
module SDK
|
7
7
|
module VPC
|
8
|
-
module
|
8
|
+
module INSTANCE
|
9
9
|
# Get a Floating IP.
|
10
|
-
class FloatingIps <
|
10
|
+
class FloatingIps < VPCCollection
|
11
11
|
def initialize(parent)
|
12
12
|
super(parent, 'floating_ips', child_class: FloatingIp)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
# Get a single floating IP.
|
17
|
-
class FloatingIp <
|
17
|
+
class FloatingIp < VPCInstance
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -7,16 +7,16 @@ module IBM
|
|
7
7
|
module Cloud
|
8
8
|
module SDK
|
9
9
|
module VPC
|
10
|
-
module
|
10
|
+
module INSTANCE
|
11
11
|
# All netowrk interfaces.
|
12
|
-
class NetworkInterfaces <
|
12
|
+
class NetworkInterfaces < VPCCollection
|
13
13
|
def initialize(parent)
|
14
14
|
super(parent, 'network_interfaces', child_class: NetworkInterface)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
# A single network insterface.
|
19
|
-
class NetworkInterface <
|
19
|
+
class NetworkInterface < VPCInstance
|
20
20
|
def floating_ips
|
21
21
|
FloatingIps.new(self)
|
22
22
|
end
|
@@ -5,16 +5,16 @@ module IBM
|
|
5
5
|
module Cloud
|
6
6
|
module SDK
|
7
7
|
module VPC
|
8
|
-
module
|
8
|
+
module INSTANCE
|
9
9
|
# Get all attached volumes.
|
10
|
-
class VolumeAttachments <
|
10
|
+
class VolumeAttachments < VPCCollection
|
11
11
|
def initialize(parent)
|
12
12
|
super(parent, 'volume_attachments', child_class: VolumeAttachment)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
# A single attached volume.
|
17
|
-
class VolumeAttachment <
|
17
|
+
class VolumeAttachment < VPCInstance
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -6,14 +6,14 @@ module IBM
|
|
6
6
|
module SDK
|
7
7
|
module VPC
|
8
8
|
# Work with multiple profiles.
|
9
|
-
class InstanceProfiles <
|
9
|
+
class InstanceProfiles < VPCCollection
|
10
10
|
def initialize(parent)
|
11
|
-
super(parent, 'instance/profiles', child_class:
|
11
|
+
super(parent, 'instance/profiles', child_class: InstanceProfile, array_key: 'profiles')
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
# Get a single profile.
|
16
|
-
class
|
16
|
+
class InstanceProfile < VPCInstance
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -11,7 +11,7 @@ module IBM
|
|
11
11
|
# Work with VPC instances.
|
12
12
|
module VPC
|
13
13
|
# Work with multiple VM instances.
|
14
|
-
class Instances <
|
14
|
+
class Instances < VPCCollection
|
15
15
|
def initialize(parent)
|
16
16
|
super(parent, 'instances', child_class: Instance)
|
17
17
|
end
|
@@ -37,26 +37,119 @@ module IBM
|
|
37
37
|
end
|
38
38
|
|
39
39
|
# Work with a single instance.
|
40
|
-
class Instance <
|
40
|
+
class Instance < VPCInstance
|
41
|
+
TRANSITIONAL_STATES = %w[pausing pending restarting resuming starting stopping].freeze
|
42
|
+
ERROR_STATE = 'failed'
|
43
|
+
RUNNING_STATE = 'running'
|
44
|
+
STOPPED_STATES = %w[stopped paused].freeze
|
45
|
+
|
46
|
+
# The id of this VM.
|
47
|
+
def id
|
48
|
+
@data[:id]
|
49
|
+
end
|
50
|
+
|
51
|
+
# The name of this VM.
|
52
|
+
def name
|
53
|
+
@data[:name]
|
54
|
+
end
|
55
|
+
|
56
|
+
# The status of the virtual server instance. Possible values: [failed,paused,pausing,pending,restarting,resuming,running,starting,stopped,stopping]
|
57
|
+
def status
|
58
|
+
@data[:status]
|
59
|
+
end
|
60
|
+
|
61
|
+
# Whether the state of the VM is in failed state.
|
62
|
+
# @return [Boolean]
|
63
|
+
def failed?
|
64
|
+
status == ERROR_STATE
|
65
|
+
end
|
66
|
+
|
67
|
+
# Whether the state of the VM is in the started state.
|
68
|
+
# @return [Boolean]
|
69
|
+
def started?
|
70
|
+
status == RUNNING_STATE
|
71
|
+
end
|
72
|
+
|
73
|
+
# Whether the state of the VM is in a stopped or paused state.
|
74
|
+
# @return [Boolean]
|
75
|
+
def stopped?
|
76
|
+
STOPPED_STATES.include?(status)
|
77
|
+
end
|
78
|
+
|
79
|
+
# Whether the state of the VM is in a transitional state.
|
80
|
+
# @return [Boolean]
|
81
|
+
def transitional?
|
82
|
+
TRANSITIONAL_STATES.include?(status)
|
83
|
+
end
|
84
|
+
|
85
|
+
# Interact with instance actions.
|
86
|
+
# @return [INSTANCE::Actions]
|
41
87
|
def actions
|
42
88
|
INSTANCE::Actions.new(self)
|
43
89
|
end
|
44
90
|
|
91
|
+
# Interact with instance network interfaces.
|
92
|
+
# @return [INSTANCE::NetworkInterfaces]
|
45
93
|
def network_interfaces
|
46
94
|
INSTANCE::NetworkInterfaces.new(self)
|
47
95
|
end
|
48
96
|
|
97
|
+
# Interact with instance volume attachements.
|
98
|
+
# @return [INSTANCE::VolumeAttachments]
|
49
99
|
def volume_attachments
|
50
100
|
INSTANCE::VolumeAttachments.new(self)
|
51
101
|
end
|
52
102
|
|
53
|
-
|
54
|
-
INSTANCE::Profiles.new(self)
|
55
|
-
end
|
56
|
-
|
103
|
+
# Return the data used for initializing this VM.
|
57
104
|
def initialization
|
58
105
|
adhoc(method: 'get', path: 'initialization').json
|
59
106
|
end
|
107
|
+
|
108
|
+
# Wait for the VM instance to be in a stable state.
|
109
|
+
# @param sleep_time [Integer] The time to sleep between refreshes.
|
110
|
+
# @param timeout [Integer] The number of seconds before raising an error.
|
111
|
+
# @param block [Proc] A block to test against. Must return a boolean.
|
112
|
+
# @raise [RuntimeError] Instance goes into failed state.
|
113
|
+
# @raise [RuntimeError] Timeout has been reached.
|
114
|
+
def wait_for!(sleep_time: 5, timeout: 600, &block)
|
115
|
+
@logger.info("Starting wait for instance #{id}. Starts in state #{status}.")
|
116
|
+
loop do
|
117
|
+
refresh
|
118
|
+
raise "VM #{id} is in a failed state." if failed?
|
119
|
+
break if block.call(self)
|
120
|
+
|
121
|
+
timeout = sleep_counter(sleep_time, timeout)
|
122
|
+
raise "Time out while waiting #{id} to be stable." if timeout <= 0
|
123
|
+
end
|
124
|
+
@logger.info("Finished wait for instance #{id}. Ends in state #{status}.")
|
125
|
+
end
|
126
|
+
|
127
|
+
# Wait for the VM instance to be have a started status.
|
128
|
+
# @param sleep_time [Integer] The time to sleep between refreshes.
|
129
|
+
# @param timeout [Integer] The number of seconds before raising an error.
|
130
|
+
# @raise [RuntimeError] Instance goes into failed state.
|
131
|
+
# @raise [RuntimeError] Timeout has been reached.
|
132
|
+
def wait_for_started!(sleep_time: 5, timeout: 600)
|
133
|
+
wait_for!(sleep_time: sleep_time, timeout: timeout, &:started?)
|
134
|
+
end
|
135
|
+
|
136
|
+
# Wait for the VM instance to be have a stopped status.
|
137
|
+
# @param sleep_time [Integer] The time to sleep between refreshes.
|
138
|
+
# @param timeout [Integer] The number of seconds before raising an error.
|
139
|
+
# @raise [RuntimeError] Instance goes into failed state.
|
140
|
+
# @raise [RuntimeError] Timeout has been reached.
|
141
|
+
def wait_for_stopped!(sleep_time: 5, timeout: 600)
|
142
|
+
wait_for!(sleep_time: sleep_time, timeout: timeout, &:stopped?)
|
143
|
+
end
|
144
|
+
|
145
|
+
private
|
146
|
+
|
147
|
+
# Sleep for the specificed time and decrement timout by that number.
|
148
|
+
# @return [Integer] The current timeout.
|
149
|
+
def sleep_counter(sleep_time, timeout)
|
150
|
+
sleep sleep_time
|
151
|
+
timeout - sleep_time
|
152
|
+
end
|
60
153
|
end
|
61
154
|
end
|
62
155
|
end
|
@@ -6,14 +6,14 @@ module IBM
|
|
6
6
|
module SDK
|
7
7
|
module VPC
|
8
8
|
# A list of IPSecPolicy
|
9
|
-
class IPSecPolicies <
|
9
|
+
class IPSecPolicies < VPCCollection
|
10
10
|
def initialize(parent)
|
11
11
|
super(parent, 'ike_policies', child_class: IPSecPolicy)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
# A single IPSecPolicy
|
16
|
-
class IPSecPolicy <
|
16
|
+
class IPSecPolicy < VPCInstance
|
17
17
|
def connections
|
18
18
|
get('connections')
|
19
19
|
end
|
@@ -6,36 +6,14 @@ module IBM
|
|
6
6
|
module SDK
|
7
7
|
module VPC
|
8
8
|
# A collection of SSH keys.
|
9
|
-
class Keys <
|
9
|
+
class Keys < VPCCollection
|
10
10
|
def initialize(parent)
|
11
11
|
super(parent, 'keys', child_class: Key)
|
12
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
13
|
end
|
36
14
|
|
37
15
|
# A single key.
|
38
|
-
class Key <
|
16
|
+
class Key < VPCInstance
|
39
17
|
end
|
40
18
|
end
|
41
19
|
end
|
@@ -9,7 +9,7 @@ module IBM
|
|
9
9
|
module VPC
|
10
10
|
module LOADBALANCER
|
11
11
|
# A list of Listener
|
12
|
-
class Listeners <
|
12
|
+
class Listeners < VPCCollection
|
13
13
|
def initialize(parent)
|
14
14
|
@array_key = 'listeners'
|
15
15
|
@instance = Listener
|
@@ -18,7 +18,7 @@ module IBM
|
|
18
18
|
end
|
19
19
|
|
20
20
|
# A single Listener
|
21
|
-
class Listener <
|
21
|
+
class Listener < VPCInstance
|
22
22
|
def policies
|
23
23
|
LOADBALANCER::Policies.new(self)
|
24
24
|
end
|
@@ -6,7 +6,7 @@ module IBM
|
|
6
6
|
module SDK
|
7
7
|
module VPC
|
8
8
|
# A list of Member
|
9
|
-
class Members <
|
9
|
+
class Members < VPCCollection
|
10
10
|
def initialize(parent)
|
11
11
|
@array_key = 'members'
|
12
12
|
@instance = Member
|
@@ -15,7 +15,7 @@ module IBM
|
|
15
15
|
end
|
16
16
|
|
17
17
|
# A single Member
|
18
|
-
class Member <
|
18
|
+
class Member < VPCInstance
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
@@ -9,7 +9,7 @@ module IBM
|
|
9
9
|
module VPC
|
10
10
|
module LOADBALANCER
|
11
11
|
# A list of Policies
|
12
|
-
class Policies <
|
12
|
+
class Policies < VPCCollection
|
13
13
|
def initialize(parent)
|
14
14
|
@array_key = 'policies'
|
15
15
|
@instance = Policy
|
@@ -18,7 +18,7 @@ module IBM
|
|
18
18
|
end
|
19
19
|
|
20
20
|
# A single Policy
|
21
|
-
class Policy <
|
21
|
+
class Policy < VPCInstance
|
22
22
|
def rules
|
23
23
|
Rules.new(self)
|
24
24
|
end
|
@@ -8,7 +8,7 @@ module IBM
|
|
8
8
|
module SDK
|
9
9
|
module VPC
|
10
10
|
# A list of Pool
|
11
|
-
class Pools <
|
11
|
+
class Pools < VPCCollection
|
12
12
|
def initialize(parent)
|
13
13
|
@array_key = 'pools'
|
14
14
|
@instance = Pool
|
@@ -17,7 +17,7 @@ module IBM
|
|
17
17
|
end
|
18
18
|
|
19
19
|
# A single Pool
|
20
|
-
class Pool <
|
20
|
+
class Pool < VPCInstance
|
21
21
|
def members
|
22
22
|
Members.new(self)
|
23
23
|
end
|
@@ -7,7 +7,7 @@ module IBM
|
|
7
7
|
module VPC
|
8
8
|
module LOADBALANCER
|
9
9
|
# A list of Rule
|
10
|
-
class Rules <
|
10
|
+
class Rules < VPCCollection
|
11
11
|
def initialize(parent)
|
12
12
|
@array_key = 'rules'
|
13
13
|
@instance = Rule
|
@@ -16,7 +16,7 @@ module IBM
|
|
16
16
|
end
|
17
17
|
|
18
18
|
# A single Rule
|
19
|
-
class Rule <
|
19
|
+
class Rule < VPCInstance
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
@@ -6,14 +6,14 @@ module IBM
|
|
6
6
|
module SDK
|
7
7
|
module VPC
|
8
8
|
# A list of NetworkACL
|
9
|
-
class NetworkACLs <
|
9
|
+
class NetworkACLs < VPCCollection
|
10
10
|
def initialize(parent)
|
11
11
|
super(parent, 'network_acls', child_class: NetworkACL)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
# A single NetworkACL
|
16
|
-
class NetworkACL <
|
16
|
+
class NetworkACL < VPCInstance
|
17
17
|
def rules
|
18
18
|
NETWORKACL::Rules.new(self)
|
19
19
|
end
|
@@ -21,7 +21,7 @@ module IBM
|
|
21
21
|
|
22
22
|
module NETWORKACL
|
23
23
|
# A list of NetworkACL
|
24
|
-
class Rules <
|
24
|
+
class Rules < VPCCollection
|
25
25
|
def initialize(parent)
|
26
26
|
@array_key = 'network_acls'
|
27
27
|
@instance = NetworkACL
|
@@ -30,7 +30,7 @@ module IBM
|
|
30
30
|
end
|
31
31
|
|
32
32
|
# A single NetworkACL
|
33
|
-
class Rule <
|
33
|
+
class Rule < VPCInstance
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
@@ -6,14 +6,14 @@ module IBM
|
|
6
6
|
module SDK
|
7
7
|
module VPC
|
8
8
|
# A list of OperatingSystem
|
9
|
-
class OperatingSystems <
|
9
|
+
class OperatingSystems < VPCCollection
|
10
10
|
def initialize(parent)
|
11
11
|
super(parent, 'operating_systems', child_class: OperatingSystem)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
# A single OperatingSystem
|
16
|
-
class OperatingSystem <
|
16
|
+
class OperatingSystem < 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 PublicGateway
|
9
|
-
class PublicGateways <
|
9
|
+
class PublicGateways < VPCCollection
|
10
10
|
def initialize(parent)
|
11
11
|
super(parent, 'public_gateways', child_class: PublicGateway)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
# A single PublicGateway
|
16
|
-
class PublicGateway <
|
16
|
+
class PublicGateway < VPCInstance
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|