ibm_sbdtc_rest 0.0.0 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +10 -1
- data/VERSION +1 -1
- data/bin/ibmcloud_admin +160 -19
- data/lib/ibm_cloud_rest/core/address.rb +19 -0
- data/lib/ibm_cloud_rest/core/image.rb +17 -0
- data/lib/ibm_cloud_rest/core/instance.rb +25 -0
- data/lib/ibm_cloud_rest/core/key.rb +11 -0
- data/lib/ibm_cloud_rest/core/request.rb +11 -0
- data/lib/ibm_cloud_rest/core/server.rb +22 -1
- data/lib/ibm_cloud_rest/core/storage.rb +19 -0
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -1,6 +1,15 @@
|
|
1
1
|
= ibm_sbdtc_rest
|
2
2
|
|
3
|
-
|
3
|
+
Manager Client and REST API Lib for IBM Smart Business Development & Test on the IBM Cloud.
|
4
|
+
|
5
|
+
API version: 20090403
|
6
|
+
|
7
|
+
To use this gem, you first need to register an account on https://www.ibm.com/cloud/developer
|
8
|
+
|
9
|
+
== Usage Example for Manager Client
|
10
|
+
|
11
|
+
To list all instances:
|
12
|
+
ibmcloud_admin list instances
|
4
13
|
|
5
14
|
== Note on Patches/Pull Requests
|
6
15
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.1.0
|
data/bin/ibmcloud_admin
CHANGED
@@ -14,14 +14,156 @@ require 'pp'
|
|
14
14
|
|
15
15
|
class IbmCloudAdmin < Thor
|
16
16
|
map "-h" => :help
|
17
|
-
map "
|
17
|
+
map "list" => :list
|
18
|
+
map "instance" => :instance
|
19
|
+
map "image" => :image
|
20
|
+
map "address" => :address
|
21
|
+
map "storage" => :storage
|
22
|
+
map "request" => :request
|
23
|
+
map "key" => :key
|
18
24
|
map "-v" => :version
|
19
|
-
map "--list_instances" => :list_instances
|
20
25
|
|
21
|
-
desc '
|
22
|
-
def
|
23
|
-
|
24
|
-
|
26
|
+
desc 'key [key_name] [operation]', "operation for a specific key"
|
27
|
+
def key(key_name,operation)
|
28
|
+
operation_method = case operation
|
29
|
+
when "list" then :get
|
30
|
+
else nil
|
31
|
+
end
|
32
|
+
if operation_method
|
33
|
+
request = IbmCloudRest::Instance.new
|
34
|
+
json_result=request.send(operation_method.to_sym, key_name)
|
35
|
+
puts JSON.pretty_generate(json_result)
|
36
|
+
else
|
37
|
+
raise 'This operation dos not exists for this object'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
desc 'request [id] [operation]', "operation for a specific request"
|
42
|
+
def request(id,operation)
|
43
|
+
operation_method = case operation
|
44
|
+
when "list" then :get
|
45
|
+
else nil
|
46
|
+
end
|
47
|
+
if operation_method
|
48
|
+
request = IbmCloudRest::Instance.new
|
49
|
+
json_result=request.send(operation_method.to_sym, id)
|
50
|
+
puts JSON.pretty_generate(json_result)
|
51
|
+
else
|
52
|
+
raise 'This operation dos not exists for this object'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
desc 'instance [id] [operation]', "operation for a specific instance"
|
57
|
+
def instance(id,operation)
|
58
|
+
operation_method = case operation
|
59
|
+
when "list" then :get
|
60
|
+
else nil
|
61
|
+
end
|
62
|
+
if operation_method
|
63
|
+
instance = IbmCloudRest::Instance.new
|
64
|
+
json_result=instance.send(operation_method.to_sym, id)
|
65
|
+
puts JSON.pretty_generate(json_result)
|
66
|
+
else
|
67
|
+
raise 'This operation dos not exists for this object'
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
desc 'storage [id] [operation]', "operation for a specific storage"
|
72
|
+
def storage(id,operation)
|
73
|
+
operation_method = case operation
|
74
|
+
when "list" then :get
|
75
|
+
else nil
|
76
|
+
end
|
77
|
+
if operation_method
|
78
|
+
storage = IbmCloudRest::Storage.new
|
79
|
+
json_result=storage.send(operation_method.to_sym, id)
|
80
|
+
puts JSON.pretty_generate(json_result)
|
81
|
+
else
|
82
|
+
raise 'This operation does not exists for this object'
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
desc 'address [id] [operation]', "operation for a specific address"
|
87
|
+
def address(id,operation)
|
88
|
+
operation_method = case operation
|
89
|
+
when "list" then :get
|
90
|
+
else nil
|
91
|
+
end
|
92
|
+
if operation_method
|
93
|
+
address = IbmCloudRest::Address.new
|
94
|
+
json_result=address.send(operation_method.to_sym, id)
|
95
|
+
puts JSON.pretty_generate(json_result)
|
96
|
+
else
|
97
|
+
raise 'This operation dos not exists for this object'
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
desc 'image [id] [operation]', "operation for a specific image"
|
102
|
+
def image(id,operation)
|
103
|
+
operation_method = case operation
|
104
|
+
when "list" then :get
|
105
|
+
else nil
|
106
|
+
end
|
107
|
+
if operation_method
|
108
|
+
image = IbmCloudRest::Image.new
|
109
|
+
json_result=image.send(operation_method.to_sym, id)
|
110
|
+
puts JSON.pretty_generate(json_result)
|
111
|
+
else
|
112
|
+
raise 'This operation does not exists for this object'
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
desc 'list [objects]', "list the current objects of IbmCloudAdmin"
|
118
|
+
def list(objects='instances')
|
119
|
+
list_objects= case objects
|
120
|
+
when "images" then :images
|
121
|
+
when "instances" then :instances
|
122
|
+
when "keys" then :keys
|
123
|
+
when "addresses" then :addresses
|
124
|
+
when "storages" then :storages
|
125
|
+
else nil
|
126
|
+
end
|
127
|
+
if list_objects
|
128
|
+
server = IbmCloudRest.new
|
129
|
+
json_result=server.send(list_objects.to_sym)
|
130
|
+
#puts JSON.pretty_generate(json_result)
|
131
|
+
if objects =~ /instances/
|
132
|
+
puts "Instance List"
|
133
|
+
puts "----------------------------------------------"
|
134
|
+
json_result[objects].each do |e|
|
135
|
+
puts "name: "+e["name"]
|
136
|
+
puts "id: "+e["id"]
|
137
|
+
puts "ip: "+e["ip"]
|
138
|
+
puts "hostname: "+e["hostname"]
|
139
|
+
puts "software_name: "+e["software"][0]["name"]
|
140
|
+
puts "requestId: " +e["requestId"]
|
141
|
+
puts "requestName: " +e["requestName"]
|
142
|
+
puts "imageId: " +e["imageId"]
|
143
|
+
puts "instanceType: " +e["instanceType"]
|
144
|
+
puts "status: "+IbmCloudRest::Instance::STATUS[e["status"]]
|
145
|
+
puts "expirationTime: "+ Time.at((e["expirationTime"].to_i)/1000).to_s
|
146
|
+
puts "----------------------------------------------"
|
147
|
+
end
|
148
|
+
end
|
149
|
+
if objects =~ /images/
|
150
|
+
puts "Image List"
|
151
|
+
puts "----------------------------------------------"
|
152
|
+
json_result[objects].each do |e|
|
153
|
+
puts "name: "+e["name"]
|
154
|
+
puts "id: "+e["id"]
|
155
|
+
puts "description: "+e["description"]
|
156
|
+
puts "platform: "+e["platform"]
|
157
|
+
puts "supportedInstanceTypes: " +e["supportedInstanceTypes"].join('/')
|
158
|
+
puts "state: "+IbmCloudRest::Image::STATES[e["state"]]
|
159
|
+
puts "createdTime: "+ Time.at((e["createdTime"].to_i)/1000).to_s
|
160
|
+
puts "----------------------------------------------"
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
else
|
165
|
+
raise 'This objects does not exists for list command'
|
166
|
+
end
|
25
167
|
end
|
26
168
|
|
27
169
|
desc 'version', "the current version of IbmCloudAdmin"
|
@@ -35,29 +177,28 @@ class IbmCloudAdmin < Thor
|
|
35
177
|
desc 'help', 'help output'
|
36
178
|
def help
|
37
179
|
puts %{
|
38
|
-
Usage: #{$0}
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
--gems Gems to include
|
180
|
+
Usage: #{$0} command [parameters]
|
181
|
+
|
182
|
+
Commands:
|
183
|
+
list List objects(instances, images, keys, storage, addresses)
|
184
|
+
instance [id] [operation] operation for a special instance
|
185
|
+
image [id] [operation] operation for a special image
|
186
|
+
storage [id] [operation] operation for a special storage
|
187
|
+
address [id] [operation] operation for a special address
|
188
|
+
request [id] [operation] operation for a special request
|
189
|
+
key [key_name] [operation] operation for a special key
|
49
190
|
|
50
191
|
IbmCloudAdmin Info:
|
51
192
|
-v, --version Show the IbmCloudAdmin version number and quit.
|
52
|
-
-l, --list Show the various recipes known to IbmCloudAdmin and quit.
|
53
193
|
-h, --help Show this help message and quit.
|
54
194
|
|
55
195
|
General Options:
|
56
196
|
|
57
197
|
Description:
|
58
|
-
|
198
|
+
ibmcloud_admin is used for IBM Cloud Service.
|
59
199
|
|
60
200
|
Example:
|
201
|
+
ibmcloud_admin list instances
|
61
202
|
}
|
62
203
|
end
|
63
204
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module IbmCloudRest
|
2
|
+
class Address
|
3
|
+
STATES=%w[NEW
|
4
|
+
ALLOCATING
|
5
|
+
FREE
|
6
|
+
ATTACHED
|
7
|
+
RELEASING
|
8
|
+
RELEASED
|
9
|
+
FAILED
|
10
|
+
]
|
11
|
+
attr_accessor :uri
|
12
|
+
def initialize(server = 'https://www.ibm.com', base_path= '/cloud/developer/api/rest/20090403/addresses/', uuid_batch_count = 1000)
|
13
|
+
@uri = server+base_path
|
14
|
+
end
|
15
|
+
def get(id)
|
16
|
+
IbmCloudRest.get @uri+id.to_s
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module IbmCloudRest
|
2
|
+
class Image
|
3
|
+
STATES=%w[NEW
|
4
|
+
AVAILABLE
|
5
|
+
UNAVAILABLE
|
6
|
+
DELETED
|
7
|
+
CAPTURING
|
8
|
+
]
|
9
|
+
attr_accessor :uri
|
10
|
+
def initialize(server = 'https://www.ibm.com', base_path= '/cloud/developer/api/rest/20090403/images/', uuid_batch_count = 1000)
|
11
|
+
@uri = server+base_path
|
12
|
+
end
|
13
|
+
def get(id)
|
14
|
+
IbmCloudRest.get @uri+id.to_s
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module IbmCloudRest
|
2
|
+
class Instance
|
3
|
+
STATUS=%w[NEW
|
4
|
+
PROVISIONING
|
5
|
+
FAILED
|
6
|
+
REMOVED
|
7
|
+
REJECTED
|
8
|
+
ACTIVE
|
9
|
+
UNKNOWN
|
10
|
+
DEPROVISIONING
|
11
|
+
RESTARTING
|
12
|
+
STARTING
|
13
|
+
STOPPING
|
14
|
+
STOPPED
|
15
|
+
]
|
16
|
+
attr_accessor :uri, :uuid_batch_count, :available_instances
|
17
|
+
def initialize(server = 'https://www.ibm.com', base_path= '/cloud/developer/api/rest/20090403/instances/', uuid_batch_count = 1000)
|
18
|
+
@uri = server+base_path
|
19
|
+
@uuid_batch_count = uuid_batch_count
|
20
|
+
end
|
21
|
+
def get(id)
|
22
|
+
IbmCloudRest.get @uri+id.to_s
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module IbmCloudRest
|
2
|
+
class Key
|
3
|
+
attr_accessor :uri
|
4
|
+
def initialize(server = 'https://www.ibm.com', base_path= '/cloud/developer/api/rest/20090403/keys/', uuid_batch_count = 1000)
|
5
|
+
@uri = server+base_path
|
6
|
+
end
|
7
|
+
def get(id)
|
8
|
+
IbmCloudRest.get @uri+id.to_s
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module IbmCloudRest
|
2
|
+
class Request
|
3
|
+
attr_accessor :uri
|
4
|
+
def initialize(server = 'https://www.ibm.com', base_path= '/cloud/developer/api/rest/20090403/requests/', uuid_batch_count = 1000)
|
5
|
+
@uri = server+base_path
|
6
|
+
end
|
7
|
+
def get(id)
|
8
|
+
IbmCloudRest.get @uri+id.to_s
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -42,12 +42,33 @@ module IbmCloudRest
|
|
42
42
|
def default_instance
|
43
43
|
available_instances[:default]
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
|
+
# Lists all storages on the server
|
47
|
+
def storages
|
48
|
+
IbmCloudRest.get "#{@uri}/storage"
|
49
|
+
end
|
50
|
+
|
51
|
+
# Lists all addresses on the server
|
52
|
+
|
53
|
+
def addresses
|
54
|
+
IbmCloudRest.get "#{@uri}/addresses"
|
55
|
+
end
|
56
|
+
|
57
|
+
# Lists all keys on the server
|
58
|
+
def keys
|
59
|
+
IbmCloudRest.get "#{@uri}/keys"
|
60
|
+
end
|
61
|
+
|
46
62
|
# Lists all instances on the server
|
47
63
|
def instances
|
48
64
|
IbmCloudRest.get "#{@uri}/instances"
|
49
65
|
end
|
50
66
|
|
67
|
+
# Lists all images on the server
|
68
|
+
def images
|
69
|
+
IbmCloudRest.get "#{@uri}/images"
|
70
|
+
end
|
71
|
+
|
51
72
|
# Returns a IbmCloudRest::instance for the given name
|
52
73
|
def instance(name)
|
53
74
|
IbmCloudRest::instance.new(self, name)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module IbmCloudRest
|
2
|
+
class Storage
|
3
|
+
STATES=%w[NEW
|
4
|
+
CREATING
|
5
|
+
DELETING
|
6
|
+
DELETED
|
7
|
+
UNMOUNTED
|
8
|
+
MOUNTED
|
9
|
+
FAILED
|
10
|
+
]
|
11
|
+
attr_accessor :uri
|
12
|
+
def initialize(server = 'https://www.ibm.com', base_path= '/cloud/developer/api/rest/20090403/storage/', uuid_batch_count = 1000)
|
13
|
+
@uri = server+base_path
|
14
|
+
end
|
15
|
+
def get(id)
|
16
|
+
IbmCloudRest.get @uri+id.to_s
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ibm_sbdtc_rest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Ruan
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-12-
|
12
|
+
date: 2009-12-28 00:00:00 +08:00
|
13
13
|
default_executable: ibmcloud_admin
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|