ibm-cloud-sdk 0.1.0
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 +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/Gemfile +7 -0
- data/README.md +32 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/ibm-cloud-sdk.gemspec +25 -0
- data/lib/ibm-cloud-sdk.rb +1 -0
- data/lib/ibm/cloud/sdk.rb +16 -0
- data/lib/ibm/cloud/sdk/base_service.rb +37 -0
- data/lib/ibm/cloud/sdk/iam.rb +38 -0
- data/lib/ibm/cloud/sdk/iam/token.rb +22 -0
- data/lib/ibm/cloud/sdk/power_iaas.rb +173 -0
- data/lib/ibm/cloud/sdk/resource_controller.rb +36 -0
- data/lib/ibm/cloud/sdk/resource_controller/resource.rb +33 -0
- data/lib/ibm/cloud/sdk/version.rb +7 -0
- metadata +74 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 20e66e3c2588ddaf738a31e2f6c7e4f04b1664c4bbeb8c3819515b5df0b0bf4a
|
4
|
+
data.tar.gz: 7f2921c6b950773077d71ce80f8ed6dc68fedcb583df4b6d63467177b40a15be
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5fb192e3f61c316392ba61cca0583ec2838ae7e909e2a544eb7572672a527797b3c442b077f8f7ac5124469db36e22a79cfe6fd25d30855a8697620d2beffc0f
|
7
|
+
data.tar.gz: 4ff41931a8647133664a7ba9842b8858bd2920736a94472cf227fb9d229336b18e3c26a1d8b0fe9ce7616b6f88f052a00a809befd5e821415e1bac64a94ab928
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# IBM::Cloud::SDK
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem 'ibm-cloud-sdk'
|
9
|
+
```
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle install
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install ibm-cloud-sdk
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Development
|
24
|
+
|
25
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
26
|
+
|
27
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ibm-cloud-sdk.
|
32
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ibm/cloud/sdk"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative 'lib/ibm/cloud/sdk/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "ibm-cloud-sdk"
|
5
|
+
spec.version = IBM::Cloud::SDK::VERSION
|
6
|
+
spec.authors = ["IBM Cloud Developers"]
|
7
|
+
|
8
|
+
spec.summary = %q{IBM Cloud API Ruby gem.}
|
9
|
+
spec.description = %q{A Ruby gem for interacting with the various IBM Cloud services.}
|
10
|
+
spec.homepage = "https://github.com/IBM-Cloud/ibm-cloud-sdk-ruby"
|
11
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
12
|
+
|
13
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
14
|
+
|
15
|
+
# Specify which files should be added to the gem when it is released.
|
16
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
17
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
18
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_dependency "rest-client"
|
25
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require "ibm/cloud/sdk"
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "json"
|
2
|
+
require "rest-client"
|
3
|
+
|
4
|
+
require "ibm/cloud/sdk/base_service"
|
5
|
+
require "ibm/cloud/sdk/iam"
|
6
|
+
require "ibm/cloud/sdk/power_iaas"
|
7
|
+
require "ibm/cloud/sdk/resource_controller"
|
8
|
+
require "ibm/cloud/sdk/version"
|
9
|
+
|
10
|
+
module IBM
|
11
|
+
module Cloud
|
12
|
+
module SDK
|
13
|
+
class Error < StandardError; end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module IBM
|
2
|
+
module Cloud
|
3
|
+
module SDK
|
4
|
+
class BaseService
|
5
|
+
def self.endpoint
|
6
|
+
raise NotImplementedError
|
7
|
+
end
|
8
|
+
|
9
|
+
def endpoint
|
10
|
+
raise NotImplementedError
|
11
|
+
end
|
12
|
+
|
13
|
+
def delete(path)
|
14
|
+
JSON.parse(RestClient.delete(url(path), headers))
|
15
|
+
end
|
16
|
+
|
17
|
+
def get(path)
|
18
|
+
JSON.parse(RestClient.get(url(path), headers))
|
19
|
+
end
|
20
|
+
|
21
|
+
def post(path, payload)
|
22
|
+
JSON.parse(RestClient.post(url(path), payload, headers))
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def url(path)
|
28
|
+
"#{endpoint}/#{path}"
|
29
|
+
end
|
30
|
+
|
31
|
+
def headers
|
32
|
+
{"Authorization" => token.authorization_header}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module IBM
|
2
|
+
module Cloud
|
3
|
+
module SDK
|
4
|
+
class IAM < BaseService
|
5
|
+
def endpoint
|
6
|
+
"https://iam.cloud.ibm.com".freeze
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(api_key)
|
10
|
+
@api_key = api_key
|
11
|
+
end
|
12
|
+
|
13
|
+
def get_identity_token
|
14
|
+
payload = {
|
15
|
+
:grant_type => "urn:ibm:params:oauth:grant-type:apikey",
|
16
|
+
:apikey => api_key
|
17
|
+
}
|
18
|
+
|
19
|
+
result = post("identity/token", payload)
|
20
|
+
|
21
|
+
require "ibm/cloud/sdk/iam/token"
|
22
|
+
Token.new(*result.values_at("token_type", "access_token"))
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
attr_reader :api_key
|
28
|
+
|
29
|
+
def headers
|
30
|
+
{
|
31
|
+
"Content-Type" => "application/x-www-form-urlencoded",
|
32
|
+
"Accept" => "application/json"
|
33
|
+
}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module IBM
|
2
|
+
module Cloud
|
3
|
+
module SDK
|
4
|
+
class IAM
|
5
|
+
class Token
|
6
|
+
def initialize(token_type, access_token)
|
7
|
+
@token_type = token_type
|
8
|
+
@access_token = access_token
|
9
|
+
end
|
10
|
+
|
11
|
+
def authorization_header
|
12
|
+
"#{token_type} #{access_token}"
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
attr_reader :access_token, :token_type
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,173 @@
|
|
1
|
+
module IBM
|
2
|
+
module Cloud
|
3
|
+
module SDK
|
4
|
+
class PowerIaas < BaseService
|
5
|
+
# Create an API Client object for the Power IaaS service
|
6
|
+
#
|
7
|
+
# @param region [String] the IBM Power Cloud instance region
|
8
|
+
# @param guid [String] the IBM Power Cloud instance GUID
|
9
|
+
# @param token [IAMtoken] the IBM Cloud IAM Token object
|
10
|
+
# @param crn [String] the IBM Power Cloud instance CRN
|
11
|
+
# @param tenant [String] the IBM Power Cloud account ID
|
12
|
+
def initialize(region, guid, token, crn, tenant)
|
13
|
+
@crn = crn
|
14
|
+
@guid = guid
|
15
|
+
@region = region
|
16
|
+
@token = token
|
17
|
+
@tenant = tenant
|
18
|
+
end
|
19
|
+
|
20
|
+
def endpoint
|
21
|
+
"https://#{region}.power-iaas.cloud.ibm.com/pcloud/v1"
|
22
|
+
end
|
23
|
+
|
24
|
+
# Get all PVM instances in an IBM Power Cloud instance
|
25
|
+
#
|
26
|
+
# @return [Array<Hash>] all PVM Instances for this instance
|
27
|
+
def get_pvm_instances
|
28
|
+
pvm_instances = get("cloud-instances/#{guid}/pvm-instances")["pvmInstances"] || []
|
29
|
+
|
30
|
+
pvm_instances.map do |pvm_instance|
|
31
|
+
get_pvm_instance(pvm_instance["pvmInstanceID"])
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Get an IBM Power Cloud PVM instance
|
36
|
+
#
|
37
|
+
# @param pvm_instance_id [String] the PVM instance ID
|
38
|
+
# @return [Hash] PVM Instances
|
39
|
+
def get_pvm_instance(instance_id)
|
40
|
+
get("cloud-instances/#{guid}/pvm-instances/#{instance_id}")
|
41
|
+
end
|
42
|
+
|
43
|
+
def start_pvm_instance(instance_id)
|
44
|
+
post(
|
45
|
+
"cloud-instances/#{guid}/pvm-instances/#{instance_id}/action",
|
46
|
+
{"action" => "start"}.to_json
|
47
|
+
)
|
48
|
+
end
|
49
|
+
|
50
|
+
def stop_pvm_instance(instance_id)
|
51
|
+
post(
|
52
|
+
"cloud-instances/#{guid}/pvm-instances/#{instance_id}/action",
|
53
|
+
{"action" => "stop"}.to_json
|
54
|
+
)
|
55
|
+
end
|
56
|
+
|
57
|
+
def reboot_pvm_instance(instance_id)
|
58
|
+
post(
|
59
|
+
"cloud-instances/#{guid}/pvm-instances/#{instance_id}/action",
|
60
|
+
{"action" => "reboot"}.to_json
|
61
|
+
)
|
62
|
+
end
|
63
|
+
|
64
|
+
def create_pvm_instance(instance_hash)
|
65
|
+
post("cloud-instances/#{guid}/pvm-instances", instance_hash.to_json)
|
66
|
+
end
|
67
|
+
|
68
|
+
def delete_pvm_instance(instance_id)
|
69
|
+
delete("cloud-instances/#{guid}/pvm-instances/#{instance_id}")
|
70
|
+
end
|
71
|
+
|
72
|
+
# Get all images in an IBM Power Cloud instance
|
73
|
+
#
|
74
|
+
# @return [Array<Hash>] all Images for this instance
|
75
|
+
def get_images
|
76
|
+
images = get("cloud-instances/#{guid}/images")["images"] || []
|
77
|
+
|
78
|
+
images.map do |image|
|
79
|
+
get_image(image["imageID"])
|
80
|
+
end.compact
|
81
|
+
end
|
82
|
+
|
83
|
+
# Get an IBM Power Cloud image
|
84
|
+
#
|
85
|
+
# @param image_id [String] The ID of an Image
|
86
|
+
# @return [Hash] Image
|
87
|
+
def get_image(image_id)
|
88
|
+
get("cloud-instances/#{guid}/images/#{image_id}")
|
89
|
+
rescue
|
90
|
+
nil
|
91
|
+
end
|
92
|
+
|
93
|
+
def delete_image(image_id)
|
94
|
+
delete("cloud-instances/#{guid}/images/#{image_id}")
|
95
|
+
end
|
96
|
+
|
97
|
+
# List all the volumes.
|
98
|
+
#
|
99
|
+
# @return [Array<Hash>] all volumes for this instance
|
100
|
+
def get_volumes
|
101
|
+
volumes = get("cloud-instances/#{guid}/volumes")["volumes"] || []
|
102
|
+
|
103
|
+
volumes.map do |volume|
|
104
|
+
get_volume(volume["volumeID"])
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
# Get a specific volume
|
109
|
+
#
|
110
|
+
# @param volume_id [String] The ID of a volume
|
111
|
+
# @return [Hash] Volume
|
112
|
+
def get_volume(volume_id)
|
113
|
+
get("cloud-instances/#{guid}/volumes/#{volume_id}")
|
114
|
+
end
|
115
|
+
|
116
|
+
# Get all networks in an IBM Power Cloud instance
|
117
|
+
#
|
118
|
+
# @return [Array<Hash>] all networks for this IBM Power Cloud instance
|
119
|
+
def get_networks
|
120
|
+
networks = get("cloud-instances/#{guid}/networks")["networks"] || []
|
121
|
+
networks.map do |network|
|
122
|
+
get_network(network["networkID"])
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
# Get an IBM Power Cloud network
|
127
|
+
#
|
128
|
+
# @param network_id [String] the network ID
|
129
|
+
# @return [Hash] Network
|
130
|
+
def get_network(network_id)
|
131
|
+
get("cloud-instances/#{guid}/networks/#{network_id}")
|
132
|
+
end
|
133
|
+
|
134
|
+
def create_network(network_hash)
|
135
|
+
post("cloud-instances/#{guid}/networks", network_hash.to_json)
|
136
|
+
end
|
137
|
+
|
138
|
+
def delete_network(network_id)
|
139
|
+
delete("cloud-instances/#{guid}/networks/#{network_id}")
|
140
|
+
end
|
141
|
+
|
142
|
+
def get_network_ports(network_id)
|
143
|
+
get("cloud-instances/#{guid}/networks/#{network_id}/ports")["ports"]
|
144
|
+
end
|
145
|
+
|
146
|
+
def get_ssh_keys
|
147
|
+
get("tenants/#{tenant}")["sshKeys"]
|
148
|
+
end
|
149
|
+
|
150
|
+
def create_key_pair(name, sshkey)
|
151
|
+
payload = {"name" => name, "sshkey" => sshkey}
|
152
|
+
post("tenants/#{tenant}/sshkeys", payload.to_json)
|
153
|
+
end
|
154
|
+
|
155
|
+
def delete_key_pair(name)
|
156
|
+
delete("tenants/#{tenant}/sshkeys/#{name}")
|
157
|
+
end
|
158
|
+
|
159
|
+
private
|
160
|
+
|
161
|
+
attr_reader :crn, :guid, :region, :tenant, :token
|
162
|
+
|
163
|
+
def headers
|
164
|
+
{
|
165
|
+
'Authorization' => token.authorization_header,
|
166
|
+
'CRN' => crn,
|
167
|
+
'Content-Type' => 'application/json'
|
168
|
+
}
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module IBM
|
2
|
+
module Cloud
|
3
|
+
module SDK
|
4
|
+
class ResourceController < BaseService
|
5
|
+
def endpoint
|
6
|
+
"https://resource-controller.cloud.ibm.com/v2"
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(token)
|
10
|
+
@token = token
|
11
|
+
end
|
12
|
+
|
13
|
+
def get_resources
|
14
|
+
resources = get("resource_instances")["resources"] || []
|
15
|
+
|
16
|
+
require "ibm/cloud/sdk/resource_controller/resource"
|
17
|
+
resources.map { |instance| Resource.new(instance) }
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_resource(guid)
|
21
|
+
get_resources.detect { |resource| resource.guid == guid }
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
attr_reader :token
|
27
|
+
|
28
|
+
def headers
|
29
|
+
{
|
30
|
+
"Authorization" => token.authorization_header
|
31
|
+
}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module IBM
|
2
|
+
module Cloud
|
3
|
+
module SDK
|
4
|
+
class ResourceController
|
5
|
+
class Resource
|
6
|
+
def initialize(instance)
|
7
|
+
@instance = instance
|
8
|
+
end
|
9
|
+
|
10
|
+
def account_id
|
11
|
+
instance["account_id"]
|
12
|
+
end
|
13
|
+
|
14
|
+
def crn
|
15
|
+
instance["crn"]
|
16
|
+
end
|
17
|
+
|
18
|
+
def guid
|
19
|
+
instance["guid"]
|
20
|
+
end
|
21
|
+
|
22
|
+
def region_id
|
23
|
+
instance["region_id"]
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
attr_reader :instance
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ibm-cloud-sdk
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- IBM Cloud Developers
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-08-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: A Ruby gem for interacting with the various IBM Cloud services.
|
28
|
+
email:
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- ".gitignore"
|
34
|
+
- ".rspec"
|
35
|
+
- ".travis.yml"
|
36
|
+
- Gemfile
|
37
|
+
- README.md
|
38
|
+
- Rakefile
|
39
|
+
- bin/console
|
40
|
+
- bin/setup
|
41
|
+
- ibm-cloud-sdk.gemspec
|
42
|
+
- lib/ibm-cloud-sdk.rb
|
43
|
+
- lib/ibm/cloud/sdk.rb
|
44
|
+
- lib/ibm/cloud/sdk/base_service.rb
|
45
|
+
- lib/ibm/cloud/sdk/iam.rb
|
46
|
+
- lib/ibm/cloud/sdk/iam/token.rb
|
47
|
+
- lib/ibm/cloud/sdk/power_iaas.rb
|
48
|
+
- lib/ibm/cloud/sdk/resource_controller.rb
|
49
|
+
- lib/ibm/cloud/sdk/resource_controller/resource.rb
|
50
|
+
- lib/ibm/cloud/sdk/version.rb
|
51
|
+
homepage: https://github.com/IBM-Cloud/ibm-cloud-sdk-ruby
|
52
|
+
licenses: []
|
53
|
+
metadata:
|
54
|
+
homepage_uri: https://github.com/IBM-Cloud/ibm-cloud-sdk-ruby
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: 2.3.0
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
requirements: []
|
70
|
+
rubygems_version: 3.1.3
|
71
|
+
signing_key:
|
72
|
+
specification_version: 4
|
73
|
+
summary: IBM Cloud API Ruby gem.
|
74
|
+
test_files: []
|