smartdc 1.0.1 → 1.1.1
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.
- data/README.md +39 -2
- data/VERSION +1 -1
- data/bin/sdc +81 -25
- data/lib/cli_helper.rb +27 -36
- data/lib/configure.rb +54 -2
- data/lib/smartdc/auth.rb +12 -0
- data/lib/smartdc/request.rb +10 -5
- data/lib/smartdc/response.rb +8 -7
- data/smartdc.gemspec +3 -2
- metadata +4 -3
data/README.md
CHANGED
@@ -1,16 +1,29 @@
|
|
1
1
|
smartdc
|
2
2
|
=======
|
3
3
|
|
4
|
+
```
|
5
|
+
.
|
6
|
+
|
|
7
|
+
.-. .--. .-.| .-.
|
8
|
+
: + : `--.( | (
|
9
|
+
`-' `--' `-'`- `-'
|
10
|
+
|
11
|
+
```
|
12
|
+
|
4
13
|
smartdc is Joyent's [SmartDataCenter](http://www.joyent.com/software/smartdatacenter) client and SmartDataCenter Command Line Interface.
|
5
14
|
[Joyent CloudAPI Documentation](http://apidocs.joyent.com/sdcapidoc/cloudapi/).
|
6
15
|
|
16
|
+
|
7
17
|
## Features
|
18
|
+
|
8
19
|
* Response content is Hash.
|
9
20
|
* Debug output Request and Response.
|
10
21
|
* Output style is Table or JSON.
|
11
22
|
* CLI is sub command style.
|
12
23
|
|
24
|
+
|
13
25
|
## Installation
|
26
|
+
|
14
27
|
```
|
15
28
|
gem install smartdc
|
16
29
|
```
|
@@ -18,17 +31,38 @@ gem install smartdc
|
|
18
31
|
## Usage
|
19
32
|
|
20
33
|
### CLI
|
34
|
+
Invoke interactive configuration.
|
35
|
+
|
21
36
|
```
|
22
37
|
$ sdc init
|
23
|
-
$ sdc key add key_name ~/.ssh/id_rsa.pub
|
24
38
|
$ sdc dataset ls
|
25
39
|
$ sdc package ls
|
26
|
-
$ sdc machine add -e DATASET_URN -p PACKAGE_NAME
|
40
|
+
$ sdc machine add NAME -e DATASET_URN -p PACKAGE_NAME
|
27
41
|
$ sdc machine ls
|
42
|
+
```
|
43
|
+
|
44
|
+
|
45
|
+
#### Output JSON
|
46
|
+
JSON is set to body of response.
|
47
|
+
|
48
|
+
```
|
28
49
|
$ sdc machine ls --raw
|
29
50
|
```
|
30
51
|
|
52
|
+
|
53
|
+
#### Machine use
|
54
|
+
Set to config the Machine uuid.
|
55
|
+
|
56
|
+
```
|
57
|
+
$ sdc machine ls
|
58
|
+
$ sdc machine get UUID
|
59
|
+
$ sdc machine use UUID
|
60
|
+
$ sdc machine get
|
61
|
+
```
|
62
|
+
|
63
|
+
|
31
64
|
### Program
|
65
|
+
Hash is set to content of response.
|
32
66
|
|
33
67
|
```
|
34
68
|
require 'smartdc'
|
@@ -48,7 +82,9 @@ client.machines.all.content.each do |machine|
|
|
48
82
|
end
|
49
83
|
```
|
50
84
|
|
85
|
+
|
51
86
|
## Tests
|
87
|
+
|
52
88
|
```
|
53
89
|
$ rake spec
|
54
90
|
```
|
@@ -57,4 +93,5 @@ $ rake spec
|
|
57
93
|
|
58
94
|
|
59
95
|
## License
|
96
|
+
|
60
97
|
* MIT
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.1.1
|
data/bin/sdc
CHANGED
@@ -8,6 +8,15 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
8
8
|
require 'cli_helper'
|
9
9
|
|
10
10
|
module CLI
|
11
|
+
def self.ip(uuid)
|
12
|
+
res = sdc(config).machines.read(uuid)
|
13
|
+
if res.status == 200
|
14
|
+
res.content['primaryIp']
|
15
|
+
else
|
16
|
+
uuid
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
11
20
|
class Base < Thor
|
12
21
|
class_option :debug, type: :boolean, aliases: '-d', desc: 'Debug output'
|
13
22
|
class_option :raw, type: :boolean, aliases: '-r', desc: 'Raw response body'
|
@@ -33,7 +42,7 @@ module CLI
|
|
33
42
|
|
34
43
|
desc 'del [NAME]', 'Deletes an SSH key by name.'
|
35
44
|
def del(name)
|
36
|
-
output sdc(config(options)).keys.destroy(name), {message: "Key #{name} deleted"}.merge(options)
|
45
|
+
output sdc(config(options)).keys.destroy(name), {message: "Key #{name} deleted."}.merge(options)
|
37
46
|
end
|
38
47
|
end
|
39
48
|
|
@@ -89,8 +98,8 @@ module CLI
|
|
89
98
|
output sdc(config(opt(ARGV, options))).machines.tags(uuid).read(key), {'raw' => true}.merge(opt(ARGV, options))
|
90
99
|
end
|
91
100
|
|
92
|
-
desc '
|
93
|
-
def
|
101
|
+
desc 'set [KEY] [VALUE]', 'Allows you to set the tags for a given machine.'
|
102
|
+
def set(key, value)
|
94
103
|
uuid = options.uuid.nil? ? config[:use_machine] : options.uuid
|
95
104
|
output sdc(config(opt(ARGV, options))).machines.tags(uuid).create({key => value}), {table: :v}.merge(opt(ARGV, options))
|
96
105
|
end
|
@@ -101,28 +110,38 @@ module CLI
|
|
101
110
|
uuid = options.uuid.nil? ? config[:use_machine] : options.uuid
|
102
111
|
if key.nil?
|
103
112
|
if options.all
|
104
|
-
msg = "Machine #{uuid} all tags deleted"
|
113
|
+
msg = "Machine #{CLI.ip(uuid)} all tags deleted."
|
105
114
|
output sdc(config(opt(ARGV, options))).machines.tags(uuid).destroy, {message: msg}.merge(opt(ARGV, options))
|
106
115
|
end
|
107
116
|
else
|
108
|
-
msg = "Machine #{uuid} tag #{key} deleted"
|
117
|
+
msg = "Machine #{CLI.ip(uuid)} tag #{key} deleted."
|
109
118
|
output sdc(config(opt(ARGV, options))).machines.tags(uuid).destroy(key), {message: msg}.merge(opt(ARGV, options))
|
110
119
|
end
|
111
120
|
end
|
112
121
|
end
|
113
122
|
|
114
|
-
class
|
123
|
+
class Meta < CLI::Base
|
115
124
|
class_option :uuid, type: :string, aliases: '-u', desc: 'Machine uuid'
|
116
125
|
|
117
126
|
desc 'ls', 'Returns the complete set of metadata associated with this machine.'
|
127
|
+
method_option :credentials, type: :boolean, aliases: '-c', desc: 'Only output the machine credentials.'
|
118
128
|
def ls
|
119
129
|
uuid = options.uuid.nil? ? config[:use_machine] : options.uuid
|
120
|
-
|
130
|
+
res = sdc(config(opt(ARGV, options))).machines.metadata(uuid).read(options)
|
131
|
+
res.content = res.content['credentials'].to_json if options.credentials
|
132
|
+
output res, {table: :v}.merge(opt(ARGV, options))
|
133
|
+
end
|
134
|
+
|
135
|
+
desc 'set [KEY] [VALUE]', 'Allows you to set the metadata for a given machine.'
|
136
|
+
def set(key, value)
|
137
|
+
uuid = options.uuid.nil? ? config[:use_machine] : options.uuid
|
138
|
+
output sdc(config(opt(ARGV, options))).machines.metadata(uuid).create({key => value}), {table: :v}.merge(opt(ARGV, options))
|
121
139
|
end
|
122
140
|
|
123
|
-
desc '
|
124
|
-
def
|
141
|
+
desc 'push [KEY] [FILE]', 'Push the metadata from file. (user-script or user-data)'
|
142
|
+
def push(key, file)
|
125
143
|
uuid = options.uuid.nil? ? config[:use_machine] : options.uuid
|
144
|
+
value = File.read(file)
|
126
145
|
output sdc(config(opt(ARGV, options))).machines.metadata(uuid).create({key => value}), {table: :v}.merge(opt(ARGV, options))
|
127
146
|
end
|
128
147
|
|
@@ -132,11 +151,11 @@ module CLI
|
|
132
151
|
uuid = options.uuid.nil? ? config[:use_machine] : options.uuid
|
133
152
|
if key.nil?
|
134
153
|
if options.all
|
135
|
-
msg = "Machine #{uuid} all metadata deleted"
|
154
|
+
msg = "Machine #{CLI.ip(uuid)} all metadata deleted."
|
136
155
|
output sdc(config(opt(ARGV, options))).machines.metadata(uuid).destroy, {message: msg}.merge(opt(ARGV, options))
|
137
156
|
end
|
138
157
|
else
|
139
|
-
msg = "Machine #{uuid} metadata #{key} deleted"
|
158
|
+
msg = "Machine #{CLI.ip(uuid)} metadata #{key} deleted."
|
140
159
|
output sdc(config(opt(ARGV, options))).machines.metadata(uuid).destroy(key), {message: msg}.merge(opt(ARGV, options))
|
141
160
|
end
|
142
161
|
end
|
@@ -166,14 +185,14 @@ module CLI
|
|
166
185
|
desc 'del [NAME]', 'Deletes the specified snapshot of a machine.'
|
167
186
|
def del(name)
|
168
187
|
uuid = options.uuid.nil? ? config[:use_machine] : options.uuid
|
169
|
-
msg = "Machine #{uuid} snapshots #{
|
188
|
+
msg = "Machine #{CLI.ip(uuid)} snapshots #{name} deleted."
|
170
189
|
output sdc(config(opt(ARGV, options))).machines.snapshots(uuid).destroy(name), {message: msg}.merge(opt(ARGV, options))
|
171
190
|
end
|
172
191
|
|
173
192
|
desc 'start [NAME]', 'Starts a stopped machine from the referenced snapshot.'
|
174
193
|
def start(name)
|
175
194
|
uuid = options.uuid.nil? ? config[:use_machine] : options.uuid
|
176
|
-
msg = "Machine #{uuid} snapshots #{
|
195
|
+
msg = "Machine #{CLI.ip(uuid)} snapshots #{name} started."
|
177
196
|
output sdc(config(opt(ARGV, options))).machines.snapshots(uuid).start(name), {message: msg}.merge(opt(ARGV, options))
|
178
197
|
end
|
179
198
|
end
|
@@ -183,7 +202,7 @@ module CLI
|
|
183
202
|
method_option :type, type: :string, aliases: '-t', desc: 'virtualmachine or smartmachine'
|
184
203
|
method_option :state, type: :string, aliases: '-s', desc: 'running or stopped'
|
185
204
|
def ls
|
186
|
-
include = [:id, :
|
205
|
+
include = [:id, :dataset, :primaryIp, :state]
|
187
206
|
output sdc(config(options)).machines.all(options), {table: :h, include: include}.merge(options)
|
188
207
|
end
|
189
208
|
|
@@ -203,32 +222,46 @@ module CLI
|
|
203
222
|
desc 'del [UUID]', 'Allows you to completely destroy a machine.'
|
204
223
|
def del(uuid=nil)
|
205
224
|
uuid ||= config[:use_machine]
|
206
|
-
output sdc(config(options)).machines.destroy(uuid), {message: "Machine #{uuid} deleted"}.merge(options)
|
225
|
+
output sdc(config(options)).machines.destroy(uuid), {message: "Machine #{CLI.ip(uuid)} deleted."}.merge(options)
|
207
226
|
end
|
208
227
|
|
209
228
|
desc 'stop [UUID]', 'Allows you to shut down a machine.'
|
229
|
+
method_option :all, type: :boolean, desc: 'All machine stop.'
|
210
230
|
def stop(uuid=nil)
|
211
|
-
|
212
|
-
|
231
|
+
if options.all
|
232
|
+
sdc(config(options)).machines.all({state: 'running'}).content.each do |machine|
|
233
|
+
output sdc(config(options)).machines.stop(machine['id']), {message: "Machine #{machine['primaryIp']} stoped."}.merge(options)
|
234
|
+
end
|
235
|
+
else
|
236
|
+
uuid ||= config[:use_machine]
|
237
|
+
output sdc(config(options)).machines.stop(uuid), {message: "Machine #{CLI.ip(uuid)} stoped."}.merge(options)
|
238
|
+
end
|
213
239
|
end
|
214
240
|
|
215
241
|
desc 'start [UUID]', 'Allows you to boot up a machine.'
|
242
|
+
method_option :all, type: :boolean, desc: 'All machine start.'
|
216
243
|
def start(uuid=nil)
|
217
|
-
|
218
|
-
|
244
|
+
if options.all
|
245
|
+
sdc(config(options)).machines.all({state: 'stopped'}).content.each do |machine|
|
246
|
+
output sdc(config(options)).machines.start(machine['id']), {message: "Machine #{machine['primaryIp']} started."}.merge(options)
|
247
|
+
end
|
248
|
+
else
|
249
|
+
uuid ||= config[:use_machine]
|
250
|
+
output sdc(config(options)).machines.start(uuid), {message: "Machine #{CLI.ip(uuid)} started."}.merge(options)
|
251
|
+
end
|
219
252
|
end
|
220
253
|
|
221
254
|
desc 'reboot [UUID]', 'Allows you to reboot a machine.'
|
222
255
|
def reboot(uuid=nil)
|
223
256
|
uuid ||= config[:use_machine]
|
224
|
-
output sdc(config(options)).machines.reboot(uuid), {message: "Machine #{uuid} reboot"}.merge(options)
|
257
|
+
output sdc(config(options)).machines.reboot(uuid), {message: "Machine #{CLI.ip(uuid)} reboot."}.merge(options)
|
225
258
|
end
|
226
259
|
|
227
260
|
desc 'resize [UUID]', 'Allows you to resize a SmartMachine.'
|
228
261
|
method_option :package, type: :string, aliases: '-p', desc: 'Use a package name returned from ListPackages'
|
229
262
|
def resize(uuid=nil)
|
230
263
|
uuid ||= config[:use_machine]
|
231
|
-
output sdc(config(options)).machines.resize(uuid, {}.merge(options)), {message: "Machine #{uuid} resize"}.merge(options)
|
264
|
+
output sdc(config(options)).machines.resize(uuid, {}.merge(options)), {message: "Machine #{CLI.ip(uuid)} resize."}.merge(options)
|
232
265
|
end
|
233
266
|
|
234
267
|
desc 'use [UUID]', 'Use machine.'
|
@@ -243,7 +276,7 @@ module CLI
|
|
243
276
|
end
|
244
277
|
|
245
278
|
register(Tag, 'tag', 'tag [COMMAND]', 'Machine tag')
|
246
|
-
register(
|
279
|
+
register(Meta, 'meta', 'meta [COMMAND]', 'Machine metadata')
|
247
280
|
register(Snapshot, 'snapshot', 'snapshot [COMMAND]', 'Machine snapshot')
|
248
281
|
end
|
249
282
|
|
@@ -271,7 +304,7 @@ module CLI
|
|
271
304
|
end
|
272
305
|
|
273
306
|
desc 'get [ID]', 'Retrieves the configuration for an instrumentation.'
|
274
|
-
method_option :value, type: :boolean, aliases: '-v', desc: '
|
307
|
+
method_option :value, type: :boolean, aliases: '-v', desc: 'Analytic value.'
|
275
308
|
def get(id)
|
276
309
|
if options[:value]
|
277
310
|
output sdc(config(options)).analytics.value(id), {table: :v}.merge(options)
|
@@ -311,8 +344,31 @@ module CLI
|
|
311
344
|
class Main < Thor
|
312
345
|
desc 'init', 'Sets up an account on a datacenter for use with this CLI.'
|
313
346
|
def init
|
314
|
-
|
315
|
-
|
347
|
+
message = ['Successful configuration.', 'Failed Configuration.']
|
348
|
+
state = 0
|
349
|
+
|
350
|
+
Configure.init
|
351
|
+
res = sdc(config).keys.all
|
352
|
+
if res.status == 200
|
353
|
+
rsa_path = Configure.key(res.content)
|
354
|
+
config = Configure.read
|
355
|
+
if rsa_path
|
356
|
+
raw = {name: config[:use_key], key: File.read(rsa_path)}
|
357
|
+
res = sdc(config).keys.create(raw)
|
358
|
+
state = 1 if res.status != 201
|
359
|
+
config.delete(:password)
|
360
|
+
else
|
361
|
+
config.delete(:password)
|
362
|
+
res = sdc(config).keys.read(config[:use_key])
|
363
|
+
state = 1 if res.status != 200
|
364
|
+
end
|
365
|
+
Configure.write config
|
366
|
+
else
|
367
|
+
state = 1
|
368
|
+
end
|
369
|
+
|
370
|
+
msg = res.content['message'] + '.' if state == 1
|
371
|
+
puts "#{message[state]} #{msg}"
|
316
372
|
end
|
317
373
|
|
318
374
|
register(Key, 'key', 'key [COMMAND]', 'SSH key')
|
data/lib/cli_helper.rb
CHANGED
@@ -55,52 +55,43 @@ def output(response, options={})
|
|
55
55
|
end
|
56
56
|
|
57
57
|
def horizontal(content, options={})
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
options[:exclude].each do |col|
|
68
|
-
row.delete(col.to_s)
|
69
|
-
end
|
58
|
+
options[:include] ||= []
|
59
|
+
options[:exclude] ||= []
|
60
|
+
rows = []
|
61
|
+
headings = nil
|
62
|
+
|
63
|
+
content.each do |row|
|
64
|
+
options[:exclude].each do |col|
|
65
|
+
row.delete(col.to_s)
|
66
|
+
end
|
70
67
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
end
|
76
|
-
row = cols
|
68
|
+
if !options[:include].empty?
|
69
|
+
cols = {}
|
70
|
+
options[:include].each do |col|
|
71
|
+
cols[col.to_s] = row[col.to_s] if row.key?(col.to_s)
|
77
72
|
end
|
78
|
-
|
79
|
-
rows << row.values
|
80
|
-
headings = row.keys if headings.nil?
|
73
|
+
row = cols
|
81
74
|
end
|
82
75
|
|
83
|
-
|
76
|
+
rows << row.values
|
77
|
+
headings = row.keys if headings.nil?
|
84
78
|
end
|
79
|
+
|
80
|
+
Terminal::Table.new :headings => headings, :rows => rows if !content.empty?
|
85
81
|
end
|
86
82
|
|
87
83
|
def vertical(content, options={})
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
options[:exclude].each do |col|
|
94
|
-
content.delete(col.to_s)
|
95
|
-
end
|
84
|
+
options[:exclude] ||= []
|
85
|
+
options[:exclude].each do |col|
|
86
|
+
content.delete(col.to_s)
|
87
|
+
end
|
96
88
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
end
|
101
|
-
|
102
|
-
Terminal::Table.new :headings => ['key','value'], :rows => rows
|
89
|
+
rows = []
|
90
|
+
content.to_a.each do |row|
|
91
|
+
rows << row
|
103
92
|
end
|
93
|
+
|
94
|
+
Terminal::Table.new :headings => ['key','value'], :rows => rows if !content.empty?
|
104
95
|
end
|
105
96
|
|
106
97
|
def describe(name, content, options)
|
data/lib/configure.rb
CHANGED
@@ -24,10 +24,21 @@ module Configure
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
def self.
|
27
|
+
def self.init
|
28
28
|
config = self.read
|
29
29
|
|
30
|
-
|
30
|
+
output = <<EOS
|
31
|
+
.
|
32
|
+
|
|
33
|
+
.-. .--. .-.| .-.
|
34
|
+
: + : `--.( | (
|
35
|
+
`-' `--' `-'`- `-'
|
36
|
+
Smart Data Center Command Line Interface
|
37
|
+
http://apidocs.joyent.com/sdcapidoc/cloudapi/
|
38
|
+
|
39
|
+
EOS
|
40
|
+
puts output
|
41
|
+
|
31
42
|
config[:hostname] ||= 'api.example.com'
|
32
43
|
print "Hostname (#{config[:hostname]}): "
|
33
44
|
stdin = STDIN.gets.chomp.to_s
|
@@ -59,6 +70,47 @@ module Configure
|
|
59
70
|
self.write config
|
60
71
|
end
|
61
72
|
|
73
|
+
def self.key(keys)
|
74
|
+
config = self.read
|
75
|
+
use_key = 0
|
76
|
+
rsa_path = nil
|
77
|
+
|
78
|
+
puts "SSH Key Settings:"
|
79
|
+
keys.each_with_index do |key, i|
|
80
|
+
puts "#{i+1}) #{key['name']}"
|
81
|
+
end
|
82
|
+
|
83
|
+
if !keys.empty?
|
84
|
+
puts "0) Add new key"
|
85
|
+
print "Select SSH key: "
|
86
|
+
stdin = STDIN.gets.chomp.to_s
|
87
|
+
use_key = stdin.to_i if !stdin.empty?
|
88
|
+
end
|
89
|
+
|
90
|
+
if use_key > 0
|
91
|
+
config[:use_key] = keys[use_key-1]['name']
|
92
|
+
else
|
93
|
+
config[:use_key] ||= 'id_rsa'
|
94
|
+
print "Key name (#{config[:use_key]}): "
|
95
|
+
stdin = STDIN.gets.chomp.to_s
|
96
|
+
config[:use_key] = stdin if !stdin.empty?
|
97
|
+
|
98
|
+
rsa_path = File.join(ENV["HOME"], '/.ssh/id_rsa.pub')
|
99
|
+
print "Public key path (#{rsa_path}): "
|
100
|
+
stdin = STDIN.gets.chomp.to_s
|
101
|
+
rsa_path = stdin if !stdin.empty?
|
102
|
+
end
|
103
|
+
|
104
|
+
config[:rsa_path] ||= File.join(ENV["HOME"], '/.ssh/id_rsa')
|
105
|
+
print "Private key path (#{config[:rsa_path]}): "
|
106
|
+
stdin = STDIN.gets.chomp.to_s
|
107
|
+
config[:rsa_path] = stdin if !stdin.empty?
|
108
|
+
puts
|
109
|
+
|
110
|
+
self.write config
|
111
|
+
rsa_path
|
112
|
+
end
|
113
|
+
|
62
114
|
private
|
63
115
|
|
64
116
|
def path
|
data/lib/smartdc/auth.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'openssl'
|
2
|
+
|
3
|
+
module Smartdc
|
4
|
+
module Auth
|
5
|
+
def self.sign(request={}, options={})
|
6
|
+
rsa = OpenSSL::PKey::RSA.new File.read options[:rsa_path]
|
7
|
+
sha256 = OpenSSL::Digest::SHA256.new
|
8
|
+
raw = [rsa.sign(sha256, request[:headers][:date])].pack('m').delete("\r\n")
|
9
|
+
"Signature keyId=\"/#{options[:username]}/keys/#{options[:use_key]}\",algorithm=\"rsa-sha256\" #{raw}"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/smartdc/request.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'faraday'
|
3
|
-
require 'smartdc/
|
3
|
+
require 'smartdc/auth'
|
4
|
+
#require 'smartdc/response/raise_error'
|
4
5
|
|
5
6
|
module Smartdc
|
6
7
|
class Request
|
@@ -25,6 +26,7 @@ module Smartdc
|
|
25
26
|
end
|
26
27
|
|
27
28
|
def request(method, path, query={}, raw={})
|
29
|
+
path = path.gsub(/^my/, @options[:username])
|
28
30
|
res = connection.send(method) do |req|
|
29
31
|
case method
|
30
32
|
when :get
|
@@ -63,16 +65,19 @@ module Smartdc
|
|
63
65
|
:url => 'https://' + @options[:hostname],
|
64
66
|
:ssl => {:verify => false},
|
65
67
|
:headers => {
|
66
|
-
|
67
|
-
'
|
68
|
+
:date => Time.now.gmtime.to_s,
|
69
|
+
'content-type'=>'application/json',
|
70
|
+
'x-api-version' => @options[:version]
|
68
71
|
}
|
69
72
|
}
|
70
73
|
|
74
|
+
options[:headers][:authorization] = Smartdc::Auth::sign(options, @options) if @options[:rsa_path] && !@options[:password]
|
75
|
+
|
71
76
|
Faraday.new(options) do |builder|
|
72
|
-
builder.request :basic_auth, @options[:username], @options[:password]
|
77
|
+
builder.request :basic_auth, @options[:username], @options[:password] if @options[:password]
|
73
78
|
# builder.use Smartdc::Response::RaiseError
|
74
79
|
builder.adapter Faraday.default_adapter
|
75
80
|
end
|
76
81
|
end
|
77
82
|
end
|
78
|
-
end
|
83
|
+
end
|
data/lib/smartdc/response.rb
CHANGED
@@ -1,23 +1,24 @@
|
|
1
1
|
module Smartdc
|
2
2
|
class Response
|
3
|
-
attr_reader :status, :headers, :body
|
3
|
+
attr_reader :status, :headers, :body, :content
|
4
4
|
|
5
5
|
def initialize(response)
|
6
6
|
@status = response.status
|
7
7
|
@headers = response.headers
|
8
8
|
@body = response.body
|
9
|
+
self.content = @body
|
9
10
|
end
|
10
11
|
|
11
|
-
def content
|
12
|
-
case
|
12
|
+
def content=raw
|
13
|
+
case raw
|
13
14
|
when nil, ''
|
14
|
-
nil
|
15
|
+
@content = nil
|
15
16
|
when 'true'
|
16
|
-
true
|
17
|
+
@content = true
|
17
18
|
when 'false'
|
18
|
-
false
|
19
|
+
@content = false
|
19
20
|
else
|
20
|
-
JSON.parse(
|
21
|
+
@content = JSON.parse(raw)
|
21
22
|
end
|
22
23
|
end
|
23
24
|
end
|
data/smartdc.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "smartdc"
|
8
|
-
s.version = "1.
|
8
|
+
s.version = "1.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["ogom"]
|
12
|
-
s.date = "2012-12-
|
12
|
+
s.date = "2012-12-23"
|
13
13
|
s.description = "SmartDataCenter client and SmartDataCenter Command Line Interface."
|
14
14
|
s.email = "ogom@hotmail.co.jp"
|
15
15
|
s.executables = ["sdc"]
|
@@ -37,6 +37,7 @@ Gem::Specification.new do |s|
|
|
37
37
|
"lib/smartdc/api/machine/tags.rb",
|
38
38
|
"lib/smartdc/api/machines.rb",
|
39
39
|
"lib/smartdc/api/packages.rb",
|
40
|
+
"lib/smartdc/auth.rb",
|
40
41
|
"lib/smartdc/client.rb",
|
41
42
|
"lib/smartdc/error.rb",
|
42
43
|
"lib/smartdc/request.rb",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smartdc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -135,6 +135,7 @@ files:
|
|
135
135
|
- lib/smartdc/api/machine/tags.rb
|
136
136
|
- lib/smartdc/api/machines.rb
|
137
137
|
- lib/smartdc/api/packages.rb
|
138
|
+
- lib/smartdc/auth.rb
|
138
139
|
- lib/smartdc/client.rb
|
139
140
|
- lib/smartdc/error.rb
|
140
141
|
- lib/smartdc/request.rb
|
@@ -177,7 +178,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
177
178
|
version: '0'
|
178
179
|
segments:
|
179
180
|
- 0
|
180
|
-
hash: -
|
181
|
+
hash: -4139368408175416003
|
181
182
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
182
183
|
none: false
|
183
184
|
requirements:
|