smartdc 0.4.0 → 1.0.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/.document +0 -1
- data/.travis.yml +5 -0
- data/Gemfile +7 -10
- data/README.md +42 -69
- data/Rakefile +47 -0
- data/VERSION +1 -1
- data/bin/sdc +327 -0
- data/lib/cli_helper.rb +131 -8
- data/lib/configure.rb +73 -0
- data/lib/smartdc.rb +16 -1
- data/lib/smartdc/api/analytics.rb +29 -7
- data/lib/smartdc/api/analytics/heatmap.rb +20 -0
- data/lib/smartdc/api/datacenters.rb +6 -7
- data/lib/smartdc/api/datasets.rb +6 -7
- data/lib/smartdc/api/keys.rb +10 -11
- data/lib/smartdc/api/machine/metadata.rb +9 -15
- data/lib/smartdc/api/machine/snapshots.rb +16 -16
- data/lib/smartdc/api/machine/tags.rb +11 -12
- data/lib/smartdc/api/machines.rb +23 -23
- data/lib/smartdc/api/packages.rb +7 -8
- data/lib/smartdc/client.rb +14 -18
- data/lib/smartdc/request.rb +41 -51
- data/lib/smartdc/response.rb +24 -0
- data/lib/smartdc/response/raise_error.rb +1 -1
- data/smartdc.gemspec +51 -90
- data/spec/fixtures/analytics.json +26 -0
- data/spec/fixtures/datacenter.json +4 -0
- data/spec/fixtures/datacenters.json +3 -0
- data/spec/fixtures/datasets.json +38 -0
- data/spec/fixtures/keys.json +14 -0
- data/spec/fixtures/machines.json +36 -0
- data/spec/fixtures/packages.json +18 -0
- data/spec/fixtures/snapshots.json +8 -0
- data/spec/fixtures/tag.json +3 -0
- data/spec/spec_helper.rb +3 -12
- data/spec/unit/smartdc/api/analytics_spec.rb +53 -0
- data/spec/unit/smartdc/api/datacenters_spec.rb +31 -0
- data/spec/unit/smartdc/api/datasets_spec.rb +31 -0
- data/spec/unit/smartdc/api/keys_spec.rb +53 -0
- data/spec/unit/smartdc/api/machine/metadata_spec.rb +42 -0
- data/spec/unit/smartdc/api/machine/snapshots_spec.rb +132 -0
- data/spec/unit/smartdc/api/machine/tags_spec.rb +53 -0
- data/spec/unit/smartdc/api/machines_spec.rb +53 -0
- data/spec/unit/smartdc/api/packages_spec.rb +31 -0
- data/spec/{smartdc → unit/smartdc}/client_spec.rb +0 -6
- data/spec/{smartdc_spec.rb → unit/smartdc_spec.rb} +1 -1
- metadata +72 -140
- data/LICENSE.md +0 -20
- data/bin/sdc-addmachinemetadata +0 -29
- data/bin/sdc-addmachinetag +0 -29
- data/bin/sdc-createinstrumentation +0 -27
- data/bin/sdc-createkey +0 -32
- data/bin/sdc-createmachine +0 -39
- data/bin/sdc-createmachinesnapshot +0 -27
- data/bin/sdc-deleteinstrumentation +0 -12
- data/bin/sdc-deletekey +0 -12
- data/bin/sdc-deletemachine +0 -12
- data/bin/sdc-deletemachinemetadata +0 -29
- data/bin/sdc-deletemachinesnapshot +0 -29
- data/bin/sdc-deletemachinetag +0 -29
- data/bin/sdc-describeanalytics +0 -10
- data/bin/sdc-getdatacenter +0 -10
- data/bin/sdc-getdataset +0 -10
- data/bin/sdc-getinstrumentation +0 -31
- data/bin/sdc-getkey +0 -10
- data/bin/sdc-getmachine +0 -12
- data/bin/sdc-getmachinemetadata +0 -12
- data/bin/sdc-getmachinesnapshot +0 -27
- data/bin/sdc-getmachinetag +0 -27
- data/bin/sdc-getpackage +0 -10
- data/bin/sdc-listdatacenters +0 -10
- data/bin/sdc-listdatasets +0 -10
- data/bin/sdc-listinstrumentations +0 -10
- data/bin/sdc-listkeys +0 -10
- data/bin/sdc-listmachines +0 -10
- data/bin/sdc-listmachinesnapshots +0 -10
- data/bin/sdc-listmachinetags +0 -10
- data/bin/sdc-listpackages +0 -10
- data/bin/sdc-rebootmachine +0 -12
- data/bin/sdc-resizemachine +0 -34
- data/bin/sdc-setup +0 -67
- data/bin/sdc-startmachine +0 -12
- data/bin/sdc-startmachinefromsnapshot +0 -29
- data/bin/sdc-stopmachine +0 -12
- data/config/fixtures/instrumentation.json +0 -4
- data/config/fixtures/key.json +0 -4
- data/config/fixtures/tag.json +0 -3
- data/lib/smartdc/api/analytics/instrumentations.rb +0 -44
- data/lib/smartdc/response/mashify.rb +0 -29
- data/lib/smartdc/response/parse_json.rb +0 -26
- data/spec/smartdc/api/analytics_spec.rb +0 -32
- data/spec/smartdc/api/datacenters_spec.rb +0 -16
- data/spec/smartdc/api/datasets_spec.rb +0 -16
- data/spec/smartdc/api/keys_spec.rb +0 -32
- data/spec/smartdc/api/machine/metadata_spec.rb +0 -59
- data/spec/smartdc/api/machine/snapshots_spec.rb +0 -70
- data/spec/smartdc/api/machine/tags_spec.rb +0 -65
- data/spec/smartdc/api/machines_spec.rb +0 -92
- data/spec/smartdc/api/packages_spec.rb +0 -16
- data/spec/smartdc/request_spec.rb +0 -12
data/lib/cli_helper.rb
CHANGED
|
@@ -1,12 +1,135 @@
|
|
|
1
|
-
require '
|
|
2
|
-
require
|
|
1
|
+
require 'thor'
|
|
2
|
+
require 'thor/group'
|
|
3
|
+
require 'terminal-table'
|
|
3
4
|
require 'smartdc'
|
|
5
|
+
require 'configure'
|
|
6
|
+
include Configure
|
|
4
7
|
|
|
5
|
-
def
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
def config(options={})
|
|
9
|
+
cfg = Configure.read
|
|
10
|
+
|
|
11
|
+
if !options.empty?
|
|
12
|
+
options.each do |key, value|
|
|
13
|
+
cfg[key.to_sym] = value
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
cfg
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def sdc(options)
|
|
21
|
+
Smartdc.new(options)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def opt(argument, options={})
|
|
25
|
+
opts = {}
|
|
26
|
+
opts = opts.merge(options)
|
|
27
|
+
opts['raw'] = true if argument.include?('--raw') or argument.include?('-r')
|
|
28
|
+
opts['debug'] = true if argument.include?('--debug') or argument.include?('-d')
|
|
29
|
+
opts
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def output(response, options={})
|
|
33
|
+
if options['raw']
|
|
34
|
+
puts response.body
|
|
35
|
+
else
|
|
36
|
+
if response.status < 300
|
|
37
|
+
if options[:table]
|
|
38
|
+
case options[:table]
|
|
39
|
+
when :h
|
|
40
|
+
puts horizontal(response.content, options)
|
|
41
|
+
when :v
|
|
42
|
+
puts vertical(response.content, options)
|
|
43
|
+
end
|
|
44
|
+
else
|
|
45
|
+
if options[:message]
|
|
46
|
+
puts options[:message]
|
|
47
|
+
else
|
|
48
|
+
puts response.content[options[:only].to_s]
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
else
|
|
52
|
+
puts vertical(response.content)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def horizontal(content, options={})
|
|
58
|
+
if content.empty?
|
|
59
|
+
nil
|
|
60
|
+
else
|
|
61
|
+
options[:include] ||= []
|
|
62
|
+
options[:exclude] ||= []
|
|
63
|
+
rows = []
|
|
64
|
+
headings = nil
|
|
65
|
+
|
|
66
|
+
content.each do |row|
|
|
67
|
+
options[:exclude].each do |col|
|
|
68
|
+
row.delete(col.to_s)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
if !options[:include].empty?
|
|
72
|
+
cols = {}
|
|
73
|
+
options[:include].each do |col|
|
|
74
|
+
cols[col.to_s] = row[col.to_s] if row.key?(col.to_s)
|
|
75
|
+
end
|
|
76
|
+
row = cols
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
rows << row.values
|
|
80
|
+
headings = row.keys if headings.nil?
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
Terminal::Table.new :headings => headings, :rows => rows
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def vertical(content, options={})
|
|
88
|
+
if content.empty?
|
|
89
|
+
nil
|
|
90
|
+
else
|
|
91
|
+
options[:exclude] ||= []
|
|
92
|
+
|
|
93
|
+
options[:exclude].each do |col|
|
|
94
|
+
content.delete(col.to_s)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
rows = []
|
|
98
|
+
content.to_a.each do |row|
|
|
99
|
+
rows << row
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
Terminal::Table.new :headings => ['key','value'], :rows => rows
|
|
103
|
+
end
|
|
8
104
|
end
|
|
9
105
|
|
|
10
|
-
def
|
|
11
|
-
|
|
12
|
-
|
|
106
|
+
def describe(name, content, options)
|
|
107
|
+
if options['all'] or options['output'] == name
|
|
108
|
+
options[:exclude] ||= []
|
|
109
|
+
rows = []
|
|
110
|
+
|
|
111
|
+
content[name].each do |row|
|
|
112
|
+
cols = []
|
|
113
|
+
if options[:cols] == :all
|
|
114
|
+
options[:exclude].each do |col|
|
|
115
|
+
row.delete(col.to_s)
|
|
116
|
+
end
|
|
117
|
+
cols = row.values
|
|
118
|
+
else
|
|
119
|
+
options[:cols].each do |col|
|
|
120
|
+
if col == 'key'
|
|
121
|
+
cols << row[0]
|
|
122
|
+
else
|
|
123
|
+
cols << row[1][col]
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
rows << cols
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
title = options['all'] ? name : nil
|
|
131
|
+
headings = options[:cols] == :all ? content[name][0].keys : options[:cols]
|
|
132
|
+
puts Terminal::Table.new :title => title, :headings => headings, :rows => rows
|
|
133
|
+
puts if options['all']
|
|
134
|
+
end
|
|
135
|
+
end
|
data/lib/configure.rb
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
module Configure
|
|
2
|
+
def self.read()
|
|
3
|
+
begin
|
|
4
|
+
config = {}
|
|
5
|
+
File.open(path, 'r') do |file|
|
|
6
|
+
file.each do |row|
|
|
7
|
+
row.chomp!
|
|
8
|
+
cols = row.split(/\s+=\s+/)
|
|
9
|
+
config[cols[0].to_sym] = cols[1]
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
rescue
|
|
13
|
+
config = {}
|
|
14
|
+
ensure
|
|
15
|
+
return config
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.write(config)
|
|
20
|
+
File.open(path, 'w') do |file|
|
|
21
|
+
config.each do |key, value|
|
|
22
|
+
file.puts "#{key} = #{value}"
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def self.make
|
|
28
|
+
config = self.read
|
|
29
|
+
|
|
30
|
+
puts
|
|
31
|
+
config[:hostname] ||= 'api.example.com'
|
|
32
|
+
print "Hostname (#{config[:hostname]}): "
|
|
33
|
+
stdin = STDIN.gets.chomp.to_s
|
|
34
|
+
config[:hostname] = stdin if !stdin.empty?
|
|
35
|
+
|
|
36
|
+
config[:username] ||= ENV['USER']
|
|
37
|
+
print "Username (#{config[:username]}): "
|
|
38
|
+
stdin = STDIN.gets.chomp.to_s
|
|
39
|
+
config[:username] = stdin if !stdin.empty?
|
|
40
|
+
|
|
41
|
+
config[:password] ||= ''
|
|
42
|
+
print "Password: "
|
|
43
|
+
stdin = STDIN.gets.chomp.to_s
|
|
44
|
+
config[:password] = stdin if !stdin.empty?
|
|
45
|
+
|
|
46
|
+
config[:version] ||= '~6.5 '
|
|
47
|
+
print "Version (#{config[:version]}): "
|
|
48
|
+
stdin = STDIN.gets.chomp.to_s
|
|
49
|
+
config[:version] = stdin if !stdin.empty?
|
|
50
|
+
|
|
51
|
+
puts
|
|
52
|
+
puts "New settings:"
|
|
53
|
+
puts "Hostname: #{config[:hostname]}"
|
|
54
|
+
puts "Username: #{config[:username]}"
|
|
55
|
+
puts "Password:"
|
|
56
|
+
puts "Version: #{config[:version]}"
|
|
57
|
+
puts
|
|
58
|
+
|
|
59
|
+
self.write config
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
private
|
|
63
|
+
|
|
64
|
+
def path
|
|
65
|
+
config = '.sdccfg'
|
|
66
|
+
file = File.join(File.dirname(__FILE__), '..', config)
|
|
67
|
+
if File.exist?(file)
|
|
68
|
+
file
|
|
69
|
+
else
|
|
70
|
+
File.join(ENV["HOME"], config)
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
data/lib/smartdc.rb
CHANGED
|
@@ -1,9 +1,24 @@
|
|
|
1
|
+
require 'pp'
|
|
1
2
|
require 'smartdc/client'
|
|
2
3
|
require 'smartdc/request'
|
|
4
|
+
require 'smartdc/response'
|
|
3
5
|
require 'smartdc/error'
|
|
4
6
|
|
|
5
7
|
module Smartdc
|
|
6
8
|
def self.new(options={})
|
|
7
9
|
Smartdc::Client.new(options)
|
|
8
10
|
end
|
|
9
|
-
|
|
11
|
+
|
|
12
|
+
def self.config=(options={})
|
|
13
|
+
@cli = Smartdc::Client.new(options)
|
|
14
|
+
@config = options
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.config
|
|
18
|
+
@config
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def self.cli
|
|
22
|
+
@cli
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -1,21 +1,43 @@
|
|
|
1
|
-
require 'smartdc/api/analytics/
|
|
1
|
+
require 'smartdc/api/analytics/heatmap'
|
|
2
2
|
|
|
3
3
|
module Smartdc
|
|
4
4
|
module Api
|
|
5
5
|
class Analytics
|
|
6
|
-
attr_reader :request
|
|
6
|
+
attr_reader :request
|
|
7
7
|
|
|
8
|
-
def initialize(
|
|
9
|
-
@request =
|
|
10
|
-
@id = id
|
|
8
|
+
def initialize(options)
|
|
9
|
+
@request = Smartdc::Request.new(options)
|
|
11
10
|
end
|
|
12
11
|
|
|
13
12
|
def describe
|
|
14
13
|
request.get('my/analytics')
|
|
15
14
|
end
|
|
16
15
|
|
|
17
|
-
def
|
|
18
|
-
|
|
16
|
+
def create(raw={})
|
|
17
|
+
request.post('my/analytics/instrumentations/', raw)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def read(id)
|
|
21
|
+
raise ArgumentError unless id
|
|
22
|
+
request.get('my/analytics/instrumentations/' + id.to_s)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def all(query={})
|
|
26
|
+
request.get('my/analytics/instrumentations', query)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def destroy(id)
|
|
30
|
+
request.del('my/analytics/instrumentations/' + id.to_s)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def value(id)
|
|
34
|
+
raise ArgumentError unless id
|
|
35
|
+
request.get('my/analytics/instrumentations/' + id.to_s + '/value/raw')
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def heatmap(id)
|
|
39
|
+
raise ArgumentError unless id
|
|
40
|
+
Smartdc::Api::Analytics::Heatmap.new(request, id)
|
|
19
41
|
end
|
|
20
42
|
end
|
|
21
43
|
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module Smartdc::Api
|
|
2
|
+
class Analytics
|
|
3
|
+
class Heatmap
|
|
4
|
+
attr_reader :request, :id
|
|
5
|
+
|
|
6
|
+
def initialize(request, id)
|
|
7
|
+
@request = request
|
|
8
|
+
@id = id
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def image(query={})
|
|
12
|
+
request.get('my/analytics/instrumentations/' + @id.to_s + '/value/heatmap/image', query)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def details(query={})
|
|
16
|
+
request.get('my/analytics/instrumentations/' + @id.to_s + '/value/heatmap/details', query)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
module Smartdc
|
|
2
2
|
module Api
|
|
3
3
|
class Datacenters
|
|
4
|
-
attr_reader :request
|
|
4
|
+
attr_reader :request
|
|
5
5
|
|
|
6
|
-
def initialize(
|
|
7
|
-
@request =
|
|
8
|
-
@id = id
|
|
6
|
+
def initialize(options)
|
|
7
|
+
@request = Smartdc::Request.new(options)
|
|
9
8
|
end
|
|
10
9
|
|
|
11
|
-
def read
|
|
10
|
+
def read(id)
|
|
12
11
|
raise ArgumentError unless id
|
|
13
12
|
request.get('my/datacenters/' + id.to_s)
|
|
14
13
|
end
|
|
15
14
|
|
|
16
|
-
def
|
|
17
|
-
request.get('my/datacenters',
|
|
15
|
+
def all(query={})
|
|
16
|
+
request.get('my/datacenters', query)
|
|
18
17
|
end
|
|
19
18
|
end
|
|
20
19
|
end
|
data/lib/smartdc/api/datasets.rb
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
module Smartdc
|
|
2
2
|
module Api
|
|
3
3
|
class Datasets
|
|
4
|
-
attr_reader :request
|
|
4
|
+
attr_reader :request
|
|
5
5
|
|
|
6
|
-
def initialize(
|
|
7
|
-
@request =
|
|
8
|
-
@id = id
|
|
6
|
+
def initialize(options)
|
|
7
|
+
@request = Smartdc::Request.new(options)
|
|
9
8
|
end
|
|
10
9
|
|
|
11
|
-
def read
|
|
10
|
+
def read(id)
|
|
12
11
|
raise ArgumentError unless id
|
|
13
12
|
request.get('my/datasets/' + id.to_s)
|
|
14
13
|
end
|
|
15
14
|
|
|
16
|
-
def
|
|
17
|
-
request.get('my/datasets',
|
|
15
|
+
def all(query={})
|
|
16
|
+
request.get('my/datasets', query)
|
|
18
17
|
end
|
|
19
18
|
end
|
|
20
19
|
end
|
data/lib/smartdc/api/keys.rb
CHANGED
|
@@ -1,29 +1,28 @@
|
|
|
1
1
|
module Smartdc
|
|
2
2
|
module Api
|
|
3
3
|
class Keys
|
|
4
|
-
attr_reader :request
|
|
4
|
+
attr_reader :request
|
|
5
5
|
|
|
6
|
-
def initialize(
|
|
7
|
-
@request =
|
|
8
|
-
@id = id
|
|
6
|
+
def initialize(options)
|
|
7
|
+
@request = Smartdc::Request.new(options)
|
|
9
8
|
end
|
|
10
9
|
|
|
11
|
-
def create(
|
|
12
|
-
request.post('my/keys/',
|
|
10
|
+
def create(raw={})
|
|
11
|
+
request.post('my/keys/', raw)
|
|
13
12
|
end
|
|
14
13
|
|
|
15
|
-
def read
|
|
14
|
+
def read(id)
|
|
16
15
|
raise ArgumentError unless id
|
|
17
16
|
request.get('my/keys/' + id.to_s)
|
|
18
17
|
end
|
|
19
18
|
|
|
20
|
-
def
|
|
21
|
-
request.get('my/keys',
|
|
19
|
+
def all(query={})
|
|
20
|
+
request.get('my/keys', query)
|
|
22
21
|
end
|
|
23
22
|
|
|
24
|
-
def
|
|
23
|
+
def destroy(id)
|
|
25
24
|
raise ArgumentError unless id
|
|
26
|
-
request.
|
|
25
|
+
request.del('my/keys/' + id.to_s)
|
|
27
26
|
end
|
|
28
27
|
end
|
|
29
28
|
end
|
|
@@ -1,29 +1,23 @@
|
|
|
1
1
|
module Smartdc::Api
|
|
2
2
|
module Machine
|
|
3
3
|
class Metadata
|
|
4
|
-
attr_reader :request
|
|
4
|
+
attr_reader :request
|
|
5
5
|
|
|
6
|
-
def initialize(
|
|
7
|
-
@request = request
|
|
8
|
-
@id1 = id1
|
|
6
|
+
def initialize(id, options)
|
|
9
7
|
@id = id
|
|
8
|
+
@request = Smartdc::Request.new(options)
|
|
10
9
|
end
|
|
11
10
|
|
|
12
|
-
def create(
|
|
13
|
-
request.post('my/machines/' + @
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def read
|
|
17
|
-
raise ArgumentError unless id
|
|
18
|
-
request.get('my/machines/' + @id1.to_s + '/metadata/' + id.to_s)
|
|
11
|
+
def create(raw={})
|
|
12
|
+
request.post('my/machines/' + @id.to_s + '/metadata/', raw)
|
|
19
13
|
end
|
|
20
14
|
|
|
21
|
-
def
|
|
22
|
-
request.get('my/machines/' + @
|
|
15
|
+
def read(query={})
|
|
16
|
+
request.get('my/machines/' + @id.to_s + '/metadata', query)
|
|
23
17
|
end
|
|
24
18
|
|
|
25
|
-
def
|
|
26
|
-
request.
|
|
19
|
+
def destroy(id=nil)
|
|
20
|
+
request.del('my/machines/' + @id.to_s + '/metadata/' + id.to_s)
|
|
27
21
|
end
|
|
28
22
|
end
|
|
29
23
|
end
|