smartdc 1.3.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -19
- data/.travis.yml +1 -1
- data/Gemfile +5 -11
- data/README.md +25 -40
- data/Rakefile +5 -5
- data/bin/sdc +4 -380
- data/config.ru +2 -0
- data/lib/smartdc.rb +23 -15
- data/lib/smartdc/api/analytics.rb +19 -36
- data/lib/smartdc/api/analytics/heatmap.rb +6 -15
- data/lib/smartdc/api/datacenters.rb +7 -16
- data/lib/smartdc/api/images.rb +11 -0
- data/lib/smartdc/api/keys.rb +13 -23
- data/lib/smartdc/api/machines.rb +26 -60
- data/lib/smartdc/api/machines/metadata.rb +15 -0
- data/lib/smartdc/api/machines/snapshots.rb +23 -0
- data/lib/smartdc/api/machines/tags.rb +19 -0
- data/lib/smartdc/api/packages.rb +7 -17
- data/lib/smartdc/auth.rb +39 -5
- data/lib/smartdc/cli.rb +65 -0
- data/lib/smartdc/cli/analytic.rb +52 -0
- data/lib/smartdc/cli/datacenter.rb +15 -0
- data/lib/smartdc/cli/image.rb +19 -0
- data/lib/smartdc/cli/key.rb +26 -0
- data/lib/smartdc/cli/machine.rb +79 -0
- data/lib/smartdc/cli/machine/metadata.rb +30 -0
- data/lib/smartdc/cli/machine/snapshot.rb +38 -0
- data/lib/smartdc/cli/machine/tag.rb +33 -0
- data/lib/smartdc/cli/package.rb +17 -0
- data/lib/smartdc/cli_configure.rb +81 -0
- data/lib/smartdc/cli_helper.rb +111 -0
- data/lib/smartdc/client.rb +33 -28
- data/lib/smartdc/configure.rb +30 -0
- data/lib/smartdc/default.rb +35 -0
- data/lib/smartdc/version.rb +1 -1
- data/smartdc.gemspec +20 -16
- data/spec/cassettes/analytics/create.yml +64 -0
- data/spec/cassettes/analytics/describe.yml +123 -0
- data/spec/cassettes/analytics/destroy.yml +56 -0
- data/spec/cassettes/analytics/index.yml +62 -0
- data/spec/cassettes/analytics/show.yml +62 -0
- data/spec/cassettes/analytics/value.yml +62 -0
- data/spec/cassettes/datacenters/index.yml +62 -0
- data/spec/cassettes/datacenters/show.yml +64 -0
- data/spec/cassettes/images/index.yml +519 -0
- data/spec/cassettes/images/show.yml +63 -0
- data/spec/cassettes/keys/create.yml +65 -0
- data/spec/cassettes/keys/destroy.yml +56 -0
- data/spec/cassettes/keys/index.yml +63 -0
- data/spec/cassettes/keys/show.yml +63 -0
- data/spec/cassettes/machines/create.yml +65 -0
- data/spec/cassettes/machines/destroy.yml +56 -0
- data/spec/cassettes/machines/index.yml +67 -0
- data/spec/cassettes/machines/metadata/destroy.yml +56 -0
- data/spec/cassettes/machines/metadata/index.yml +62 -0
- data/spec/cassettes/machines/metadata/update.yml +64 -0
- data/spec/cassettes/machines/reboot.yml +58 -0
- data/spec/cassettes/machines/show.yml +63 -0
- data/spec/cassettes/machines/snapshots/create.yml +62 -0
- data/spec/cassettes/machines/snapshots/destroy.yml +56 -0
- data/spec/cassettes/machines/snapshots/index.yml +62 -0
- data/spec/cassettes/machines/snapshots/show.yml +62 -0
- data/spec/cassettes/machines/snapshots/start.yml +58 -0
- data/spec/cassettes/machines/start.yml +58 -0
- data/spec/cassettes/machines/stop.yml +58 -0
- data/spec/cassettes/machines/tags/create.yml +64 -0
- data/spec/cassettes/machines/tags/destroy.yml +56 -0
- data/spec/cassettes/machines/tags/index.yml +62 -0
- data/spec/cassettes/machines/tags/show.yml +62 -0
- data/spec/cassettes/packages/index.yml +123 -0
- data/spec/cassettes/packages/show.yml +63 -0
- data/spec/fixtures/config/sdccfg +4 -0
- data/spec/fixtures/ssh/id_rsa +27 -0
- data/spec/fixtures/ssh/id_rsa.pub +1 -0
- data/spec/smartdc/api/analytics_spec.rb +47 -0
- data/spec/smartdc/api/datacenters_spec.rb +19 -0
- data/spec/smartdc/api/images_spec.rb +19 -0
- data/spec/smartdc/api/keys_spec.rb +34 -0
- data/spec/smartdc/api/machines/metadata_spec.rb +27 -0
- data/spec/smartdc/api/machines/snapshots_spec.rb +38 -0
- data/spec/smartdc/api/machines/tags_spec.rb +33 -0
- data/spec/smartdc/api/machines_spec.rb +59 -0
- data/spec/smartdc/api/packages_spec.rb +19 -0
- data/spec/smartdc/auth_spec.rb +25 -0
- data/spec/smartdc/cli_configure_spec.rb +32 -0
- data/spec/smartdc/client_spec.rb +11 -0
- data/spec/smartdc_spec.rb +44 -0
- data/spec/spec_helper.rb +25 -8
- metadata +176 -83
- data/lib/cli_helper.rb +0 -126
- data/lib/configure.rb +0 -125
- data/lib/smartdc/api/datasets.rb +0 -20
- data/lib/smartdc/api/machine/metadata.rb +0 -24
- data/lib/smartdc/api/machine/snapshots.rb +0 -35
- data/lib/smartdc/api/machine/tags.rb +0 -29
- data/lib/smartdc/error.rb +0 -35
- data/lib/smartdc/request.rb +0 -83
- data/lib/smartdc/response.rb +0 -25
- data/lib/smartdc/response/raise_error.rb +0 -38
- data/spec/fixtures/analytics.json +0 -26
- data/spec/fixtures/datacenter.json +0 -4
- data/spec/fixtures/datacenters.json +0 -3
- data/spec/fixtures/datasets.json +0 -38
- data/spec/fixtures/keys.json +0 -14
- data/spec/fixtures/machines.json +0 -36
- data/spec/fixtures/packages.json +0 -18
- data/spec/fixtures/snapshots.json +0 -8
- data/spec/fixtures/tag.json +0 -3
- data/spec/unit/smartdc/api/analytics_spec.rb +0 -48
- data/spec/unit/smartdc/api/datacenters_spec.rb +0 -28
- data/spec/unit/smartdc/api/datasets_spec.rb +0 -28
- data/spec/unit/smartdc/api/keys_spec.rb +0 -48
- data/spec/unit/smartdc/api/machine/metadata_spec.rb +0 -38
- data/spec/unit/smartdc/api/machine/snapshots_spec.rb +0 -48
- data/spec/unit/smartdc/api/machine/tags_spec.rb +0 -48
- data/spec/unit/smartdc/api/machines_spec.rb +0 -48
- data/spec/unit/smartdc/api/packages_spec.rb +0 -28
- data/spec/unit/smartdc/client_spec.rb +0 -40
- data/spec/unit/smartdc_spec.rb +0 -9
data/config.ru
ADDED
data/lib/smartdc.rb
CHANGED
@@ -1,24 +1,32 @@
|
|
1
1
|
require 'smartdc/version'
|
2
|
+
require 'smartdc/configure'
|
3
|
+
require 'smartdc/default'
|
2
4
|
require 'smartdc/client'
|
3
|
-
require 'smartdc/request'
|
4
|
-
require 'smartdc/response'
|
5
|
-
require 'smartdc/error'
|
6
5
|
|
7
6
|
module Smartdc
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
class << self
|
8
|
+
def configure
|
9
|
+
yield Smartdc::Configure
|
10
|
+
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
12
|
+
def config
|
13
|
+
Smartdc::Configure
|
14
|
+
end
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
def client(options={})
|
17
|
+
@client = nil unless options.empty?
|
18
|
+
@client ||= Smartdc::Client.new(options)
|
19
|
+
end
|
20
20
|
|
21
|
-
|
22
|
-
|
21
|
+
def root
|
22
|
+
@root ||= File.expand_path('..', File.dirname(__FILE__))
|
23
|
+
end
|
24
|
+
|
25
|
+
def method_missing(method, *args, &block)
|
26
|
+
return super unless client.respond_to?(method)
|
27
|
+
client.send(method, *args, &block)
|
28
|
+
end
|
23
29
|
end
|
24
30
|
end
|
31
|
+
|
32
|
+
Smartdc::Configure.setup
|
@@ -1,44 +1,27 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
attr_reader :request
|
7
|
-
|
8
|
-
def initialize(options)
|
9
|
-
@request = Smartdc::Request.new(options)
|
10
|
-
end
|
11
|
-
|
12
|
-
def describe
|
13
|
-
request.get('my/analytics')
|
14
|
-
end
|
15
|
-
|
16
|
-
def create(raw={})
|
17
|
-
request.post('my/analytics/instrumentations/', raw)
|
18
|
-
end
|
1
|
+
module Smartdc::Api
|
2
|
+
module Analytics
|
3
|
+
def analytics(params={})
|
4
|
+
get 'my/analytics/instrumentations', params
|
5
|
+
end
|
19
6
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
7
|
+
def create_analytic(body={})
|
8
|
+
post 'my/analytics/instrumentations', body
|
9
|
+
end
|
24
10
|
|
25
|
-
|
26
|
-
|
27
|
-
|
11
|
+
def analytic(id)
|
12
|
+
get 'my/analytics/instrumentations/' + id.to_s
|
13
|
+
end
|
28
14
|
|
29
|
-
|
30
|
-
|
31
|
-
|
15
|
+
def destroy_analytic(id)
|
16
|
+
delete 'my/analytics/instrumentations/' + id.to_s
|
17
|
+
end
|
32
18
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
19
|
+
def value_analytic(id)
|
20
|
+
get 'my/analytics/instrumentations/' + id.to_s + '/value/raw'
|
21
|
+
end
|
37
22
|
|
38
|
-
|
39
|
-
|
40
|
-
Smartdc::Api::Analytics::Heatmap.new(request, id)
|
41
|
-
end
|
23
|
+
def describe_analytics(params={})
|
24
|
+
get 'my/analytics', params
|
42
25
|
end
|
43
26
|
end
|
44
27
|
end
|
@@ -1,20 +1,11 @@
|
|
1
1
|
module Smartdc::Api
|
2
|
-
|
3
|
-
|
4
|
-
|
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
|
2
|
+
module Analytics::Heatmap
|
3
|
+
def analytic_image(analytic_id, params={})
|
4
|
+
get 'my/analytics/instrumentations/' + analytic_id.to_s + '/value/heatmap/image', params
|
5
|
+
end
|
14
6
|
|
15
|
-
|
16
|
-
|
17
|
-
end
|
7
|
+
def analytic_details(analytic_id, params={})
|
8
|
+
get 'my/analytics/instrumentations/' + analytic_id.to_s + '/value/heatmap/details', params
|
18
9
|
end
|
19
10
|
end
|
20
11
|
end
|
@@ -1,20 +1,11 @@
|
|
1
|
-
module Smartdc
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
def initialize(options)
|
7
|
-
@request = Smartdc::Request.new(options)
|
8
|
-
end
|
9
|
-
|
10
|
-
def read(id)
|
11
|
-
raise ArgumentError unless id
|
12
|
-
request.get('my/datacenters/' + id.to_s)
|
13
|
-
end
|
1
|
+
module Smartdc::Api
|
2
|
+
module Datacenters
|
3
|
+
def datacenters(params={})
|
4
|
+
get 'my/datacenters', params
|
5
|
+
end
|
14
6
|
|
15
|
-
|
16
|
-
|
17
|
-
end
|
7
|
+
def datacenter(id)
|
8
|
+
get 'my/datacenters/' + id.to_s
|
18
9
|
end
|
19
10
|
end
|
20
11
|
end
|
data/lib/smartdc/api/keys.rb
CHANGED
@@ -1,29 +1,19 @@
|
|
1
|
-
module Smartdc
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
def initialize(options)
|
7
|
-
@request = Smartdc::Request.new(options)
|
8
|
-
end
|
9
|
-
|
10
|
-
def create(raw={})
|
11
|
-
request.post('my/keys/', raw)
|
12
|
-
end
|
1
|
+
module Smartdc::Api
|
2
|
+
module Keys
|
3
|
+
def keys(params={})
|
4
|
+
get 'my/keys', params
|
5
|
+
end
|
13
6
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
7
|
+
def create_key(body={})
|
8
|
+
post 'my/keys', body
|
9
|
+
end
|
18
10
|
|
19
|
-
|
20
|
-
|
21
|
-
|
11
|
+
def key(id)
|
12
|
+
get 'my/keys/' + id.to_s
|
13
|
+
end
|
22
14
|
|
23
|
-
|
24
|
-
|
25
|
-
request.del('my/keys/' + id.to_s)
|
26
|
-
end
|
15
|
+
def destroy_key(id)
|
16
|
+
delete 'my/keys/' + id.to_s
|
27
17
|
end
|
28
18
|
end
|
29
19
|
end
|
data/lib/smartdc/api/machines.rb
CHANGED
@@ -1,70 +1,36 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
module Api
|
7
|
-
class Machines
|
8
|
-
attr_reader :request
|
9
|
-
|
10
|
-
def initialize(options)
|
11
|
-
@options = options
|
12
|
-
@request = Smartdc::Request.new(options)
|
13
|
-
end
|
14
|
-
|
15
|
-
def create(raw={})
|
16
|
-
request.post('my/machines/', raw)
|
17
|
-
end
|
18
|
-
|
19
|
-
def read(id)
|
20
|
-
raise ArgumentError unless id
|
21
|
-
request.get('my/machines/' + id.to_s)
|
22
|
-
end
|
1
|
+
module Smartdc::Api
|
2
|
+
module Machines
|
3
|
+
def machines(params={})
|
4
|
+
get 'my/machines', params
|
5
|
+
end
|
23
6
|
|
24
|
-
|
25
|
-
|
26
|
-
|
7
|
+
def create_machine(body={})
|
8
|
+
post 'my/machines', body
|
9
|
+
end
|
27
10
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
11
|
+
def machine(id)
|
12
|
+
get 'my/machines/' + id.to_s
|
13
|
+
end
|
32
14
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
15
|
+
def destroy_machine(id)
|
16
|
+
delete 'my/machines/' + id.to_s
|
17
|
+
end
|
37
18
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end
|
19
|
+
def stop_machine(id)
|
20
|
+
post 'my/machines/' + id.to_s, {action: :stop}
|
21
|
+
end
|
42
22
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
end
|
23
|
+
def start_machine(id)
|
24
|
+
post 'my/machines/' + id.to_s, {action: :start}
|
25
|
+
end
|
47
26
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
request.post('my/machines/' + id.to_s, query)
|
52
|
-
end
|
27
|
+
def reboot_machine(id)
|
28
|
+
post 'my/machines/' + id.to_s, {action: :reboot}
|
29
|
+
end
|
53
30
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
end
|
58
|
-
|
59
|
-
def metadata(id)
|
60
|
-
raise ArgumentError unless id
|
61
|
-
Smartdc::Api::Machine::Metadata.new(id, @options)
|
62
|
-
end
|
63
|
-
|
64
|
-
def snapshots(id)
|
65
|
-
raise ArgumentError unless id
|
66
|
-
Smartdc::Api::Machine::Snapshots.new(id, @options)
|
67
|
-
end
|
31
|
+
def resize_machine(id, params={})
|
32
|
+
params[:action] = 'resize'
|
33
|
+
post 'my/machines/' + id.to_s, params
|
68
34
|
end
|
69
35
|
end
|
70
36
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Smartdc::Api
|
2
|
+
module Machines::Metadata
|
3
|
+
def machine_metadata(machine_id, params={})
|
4
|
+
get 'my/machines/' + machine_id.to_s + '/metadata', params
|
5
|
+
end
|
6
|
+
|
7
|
+
def update_machine_metadata(machine_id, body={})
|
8
|
+
post 'my/machines/' + machine_id.to_s + '/metadata', body
|
9
|
+
end
|
10
|
+
|
11
|
+
def destroy_machine_metadata(machine_id, key)
|
12
|
+
delete 'my/machines/' + machine_id.to_s + '/metadata/' + key.to_s
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Smartdc::Api
|
2
|
+
module Machines::Snapshots
|
3
|
+
def machine_snapshots(machine_id, params={})
|
4
|
+
get 'my/machines/' + machine_id.to_s + '/snapshots', params
|
5
|
+
end
|
6
|
+
|
7
|
+
def create_machine_snapshot(machine_id, body={})
|
8
|
+
post 'my/machines/' + machine_id.to_s + '/snapshots', body
|
9
|
+
end
|
10
|
+
|
11
|
+
def machine_snapshot(machine_id, name)
|
12
|
+
get 'my/machines/' + machine_id.to_s + '/snapshots/' + name.to_s
|
13
|
+
end
|
14
|
+
|
15
|
+
def destroy_machine_snapshot(machine_id, name)
|
16
|
+
delete 'my/machines/' + machine_id.to_s + '/snapshots/' + name.to_s
|
17
|
+
end
|
18
|
+
|
19
|
+
def start_machine_snapshot(machine_id, name)
|
20
|
+
post 'my/machines/' + machine_id.to_s + '/snapshots/' + name.to_s, {}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Smartdc::Api
|
2
|
+
module Machines::Tags
|
3
|
+
def machine_tags(machine_id, params={})
|
4
|
+
get 'my/machines/' + machine_id.to_s + '/tags', params
|
5
|
+
end
|
6
|
+
|
7
|
+
def create_machine_tag(machine_id, body={})
|
8
|
+
post 'my/machines/' + machine_id.to_s + '/tags', body
|
9
|
+
end
|
10
|
+
|
11
|
+
def machine_tag(machine_id, key)
|
12
|
+
get 'my/machines/' + machine_id.to_s + '/tags/' + key.to_s
|
13
|
+
end
|
14
|
+
|
15
|
+
def destroy_machine_tag(machine_id, key)
|
16
|
+
delete 'my/machines/' + machine_id.to_s + '/tags/' + key.to_s
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/smartdc/api/packages.rb
CHANGED
@@ -1,21 +1,11 @@
|
|
1
|
-
module Smartdc
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
def initialize(options)
|
7
|
-
@request = Smartdc::Request.new(options)
|
8
|
-
end
|
9
|
-
|
10
|
-
def read(id)
|
11
|
-
raise ArgumentError unless id
|
12
|
-
request.get('my/packages/' + id.to_s)
|
13
|
-
end
|
1
|
+
module Smartdc::Api
|
2
|
+
module Packages
|
3
|
+
def packages(params={})
|
4
|
+
get 'my/packages', params
|
5
|
+
end
|
14
6
|
|
15
|
-
|
16
|
-
|
17
|
-
end
|
7
|
+
def package(id)
|
8
|
+
get 'my/packages/' + id.to_s
|
18
9
|
end
|
19
10
|
end
|
20
11
|
end
|
21
|
-
|
data/lib/smartdc/auth.rb
CHANGED
@@ -1,12 +1,46 @@
|
|
1
1
|
require 'openssl'
|
2
2
|
|
3
3
|
module Smartdc
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
class Auth
|
5
|
+
attr_reader :username, :rsa_path, :use_key
|
6
|
+
|
7
|
+
def initialize(options={})
|
8
|
+
@username = options[:username]
|
9
|
+
@rsa_path = options[:rsa_path]
|
10
|
+
@use_key = options[:use_key]
|
11
|
+
end
|
12
|
+
|
13
|
+
def find_key_file
|
14
|
+
path = File.expand_path(self.rsa_path)
|
15
|
+
if File.directory?(path)
|
16
|
+
Dir[File.join(path, '*')].each do |path|
|
17
|
+
return path if File.file?(path) and self.use_key == self.fingerprint(path)
|
18
|
+
end
|
19
|
+
return ''
|
20
|
+
else
|
21
|
+
return path
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def read_key_file(path)
|
26
|
+
OpenSSL::PKey::RSA.new(File.read(File.expand_path(path)), '')
|
27
|
+
end
|
28
|
+
|
29
|
+
def signature(data)
|
30
|
+
rsa = read_key_file(self.find_key_file)
|
7
31
|
sha256 = OpenSSL::Digest::SHA256.new
|
8
|
-
|
9
|
-
"Signature keyId=\"/#{
|
32
|
+
str = [rsa.sign(sha256, data)].pack('m').delete("\r\n")
|
33
|
+
"Signature keyId=\"/#{self.username}/keys/#{self.use_key}\",algorithm=\"rsa-sha256\" #{str}"
|
34
|
+
rescue
|
35
|
+
''
|
36
|
+
end
|
37
|
+
|
38
|
+
def fingerprint(path)
|
39
|
+
rsa = read_key_file(path)
|
40
|
+
str = [7].pack('N') + 'ssh-rsa' + rsa.public_key.e.to_s(0) + rsa.public_key.n.to_s(0)
|
41
|
+
OpenSSL::Digest::MD5.hexdigest(str).scan(/../).join(':')
|
42
|
+
rescue
|
43
|
+
''
|
10
44
|
end
|
11
45
|
end
|
12
46
|
end
|