smartdc 1.3.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -19
  3. data/.travis.yml +1 -1
  4. data/Gemfile +5 -11
  5. data/README.md +25 -40
  6. data/Rakefile +5 -5
  7. data/bin/sdc +4 -380
  8. data/config.ru +2 -0
  9. data/lib/smartdc.rb +23 -15
  10. data/lib/smartdc/api/analytics.rb +19 -36
  11. data/lib/smartdc/api/analytics/heatmap.rb +6 -15
  12. data/lib/smartdc/api/datacenters.rb +7 -16
  13. data/lib/smartdc/api/images.rb +11 -0
  14. data/lib/smartdc/api/keys.rb +13 -23
  15. data/lib/smartdc/api/machines.rb +26 -60
  16. data/lib/smartdc/api/machines/metadata.rb +15 -0
  17. data/lib/smartdc/api/machines/snapshots.rb +23 -0
  18. data/lib/smartdc/api/machines/tags.rb +19 -0
  19. data/lib/smartdc/api/packages.rb +7 -17
  20. data/lib/smartdc/auth.rb +39 -5
  21. data/lib/smartdc/cli.rb +65 -0
  22. data/lib/smartdc/cli/analytic.rb +52 -0
  23. data/lib/smartdc/cli/datacenter.rb +15 -0
  24. data/lib/smartdc/cli/image.rb +19 -0
  25. data/lib/smartdc/cli/key.rb +26 -0
  26. data/lib/smartdc/cli/machine.rb +79 -0
  27. data/lib/smartdc/cli/machine/metadata.rb +30 -0
  28. data/lib/smartdc/cli/machine/snapshot.rb +38 -0
  29. data/lib/smartdc/cli/machine/tag.rb +33 -0
  30. data/lib/smartdc/cli/package.rb +17 -0
  31. data/lib/smartdc/cli_configure.rb +81 -0
  32. data/lib/smartdc/cli_helper.rb +111 -0
  33. data/lib/smartdc/client.rb +33 -28
  34. data/lib/smartdc/configure.rb +30 -0
  35. data/lib/smartdc/default.rb +35 -0
  36. data/lib/smartdc/version.rb +1 -1
  37. data/smartdc.gemspec +20 -16
  38. data/spec/cassettes/analytics/create.yml +64 -0
  39. data/spec/cassettes/analytics/describe.yml +123 -0
  40. data/spec/cassettes/analytics/destroy.yml +56 -0
  41. data/spec/cassettes/analytics/index.yml +62 -0
  42. data/spec/cassettes/analytics/show.yml +62 -0
  43. data/spec/cassettes/analytics/value.yml +62 -0
  44. data/spec/cassettes/datacenters/index.yml +62 -0
  45. data/spec/cassettes/datacenters/show.yml +64 -0
  46. data/spec/cassettes/images/index.yml +519 -0
  47. data/spec/cassettes/images/show.yml +63 -0
  48. data/spec/cassettes/keys/create.yml +65 -0
  49. data/spec/cassettes/keys/destroy.yml +56 -0
  50. data/spec/cassettes/keys/index.yml +63 -0
  51. data/spec/cassettes/keys/show.yml +63 -0
  52. data/spec/cassettes/machines/create.yml +65 -0
  53. data/spec/cassettes/machines/destroy.yml +56 -0
  54. data/spec/cassettes/machines/index.yml +67 -0
  55. data/spec/cassettes/machines/metadata/destroy.yml +56 -0
  56. data/spec/cassettes/machines/metadata/index.yml +62 -0
  57. data/spec/cassettes/machines/metadata/update.yml +64 -0
  58. data/spec/cassettes/machines/reboot.yml +58 -0
  59. data/spec/cassettes/machines/show.yml +63 -0
  60. data/spec/cassettes/machines/snapshots/create.yml +62 -0
  61. data/spec/cassettes/machines/snapshots/destroy.yml +56 -0
  62. data/spec/cassettes/machines/snapshots/index.yml +62 -0
  63. data/spec/cassettes/machines/snapshots/show.yml +62 -0
  64. data/spec/cassettes/machines/snapshots/start.yml +58 -0
  65. data/spec/cassettes/machines/start.yml +58 -0
  66. data/spec/cassettes/machines/stop.yml +58 -0
  67. data/spec/cassettes/machines/tags/create.yml +64 -0
  68. data/spec/cassettes/machines/tags/destroy.yml +56 -0
  69. data/spec/cassettes/machines/tags/index.yml +62 -0
  70. data/spec/cassettes/machines/tags/show.yml +62 -0
  71. data/spec/cassettes/packages/index.yml +123 -0
  72. data/spec/cassettes/packages/show.yml +63 -0
  73. data/spec/fixtures/config/sdccfg +4 -0
  74. data/spec/fixtures/ssh/id_rsa +27 -0
  75. data/spec/fixtures/ssh/id_rsa.pub +1 -0
  76. data/spec/smartdc/api/analytics_spec.rb +47 -0
  77. data/spec/smartdc/api/datacenters_spec.rb +19 -0
  78. data/spec/smartdc/api/images_spec.rb +19 -0
  79. data/spec/smartdc/api/keys_spec.rb +34 -0
  80. data/spec/smartdc/api/machines/metadata_spec.rb +27 -0
  81. data/spec/smartdc/api/machines/snapshots_spec.rb +38 -0
  82. data/spec/smartdc/api/machines/tags_spec.rb +33 -0
  83. data/spec/smartdc/api/machines_spec.rb +59 -0
  84. data/spec/smartdc/api/packages_spec.rb +19 -0
  85. data/spec/smartdc/auth_spec.rb +25 -0
  86. data/spec/smartdc/cli_configure_spec.rb +32 -0
  87. data/spec/smartdc/client_spec.rb +11 -0
  88. data/spec/smartdc_spec.rb +44 -0
  89. data/spec/spec_helper.rb +25 -8
  90. metadata +176 -83
  91. data/lib/cli_helper.rb +0 -126
  92. data/lib/configure.rb +0 -125
  93. data/lib/smartdc/api/datasets.rb +0 -20
  94. data/lib/smartdc/api/machine/metadata.rb +0 -24
  95. data/lib/smartdc/api/machine/snapshots.rb +0 -35
  96. data/lib/smartdc/api/machine/tags.rb +0 -29
  97. data/lib/smartdc/error.rb +0 -35
  98. data/lib/smartdc/request.rb +0 -83
  99. data/lib/smartdc/response.rb +0 -25
  100. data/lib/smartdc/response/raise_error.rb +0 -38
  101. data/spec/fixtures/analytics.json +0 -26
  102. data/spec/fixtures/datacenter.json +0 -4
  103. data/spec/fixtures/datacenters.json +0 -3
  104. data/spec/fixtures/datasets.json +0 -38
  105. data/spec/fixtures/keys.json +0 -14
  106. data/spec/fixtures/machines.json +0 -36
  107. data/spec/fixtures/packages.json +0 -18
  108. data/spec/fixtures/snapshots.json +0 -8
  109. data/spec/fixtures/tag.json +0 -3
  110. data/spec/unit/smartdc/api/analytics_spec.rb +0 -48
  111. data/spec/unit/smartdc/api/datacenters_spec.rb +0 -28
  112. data/spec/unit/smartdc/api/datasets_spec.rb +0 -28
  113. data/spec/unit/smartdc/api/keys_spec.rb +0 -48
  114. data/spec/unit/smartdc/api/machine/metadata_spec.rb +0 -38
  115. data/spec/unit/smartdc/api/machine/snapshots_spec.rb +0 -48
  116. data/spec/unit/smartdc/api/machine/tags_spec.rb +0 -48
  117. data/spec/unit/smartdc/api/machines_spec.rb +0 -48
  118. data/spec/unit/smartdc/api/packages_spec.rb +0 -28
  119. data/spec/unit/smartdc/client_spec.rb +0 -40
  120. data/spec/unit/smartdc_spec.rb +0 -9
@@ -0,0 +1,2 @@
1
+ require 'cassette-rack'
2
+ run CassetteRack::Engine
@@ -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
- def self.new(options={})
9
- Smartdc::Client.new(options)
10
- end
7
+ class << self
8
+ def configure
9
+ yield Smartdc::Configure
10
+ end
11
11
 
12
- def self.config=(options={})
13
- @cli = Smartdc::Client.new(options)
14
- @config = options
15
- end
12
+ def config
13
+ Smartdc::Configure
14
+ end
16
15
 
17
- def self.config
18
- @config
19
- end
16
+ def client(options={})
17
+ @client = nil unless options.empty?
18
+ @client ||= Smartdc::Client.new(options)
19
+ end
20
20
 
21
- def self.cli
22
- @cli
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
- require 'smartdc/api/analytics/heatmap'
2
-
3
- module Smartdc
4
- module Api
5
- class Analytics
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
- def read(id)
21
- raise ArgumentError unless id
22
- request.get('my/analytics/instrumentations/' + id.to_s)
23
- end
7
+ def create_analytic(body={})
8
+ post 'my/analytics/instrumentations', body
9
+ end
24
10
 
25
- def all(query={})
26
- request.get('my/analytics/instrumentations', query)
27
- end
11
+ def analytic(id)
12
+ get 'my/analytics/instrumentations/' + id.to_s
13
+ end
28
14
 
29
- def destroy(id)
30
- request.del('my/analytics/instrumentations/' + id.to_s)
31
- end
15
+ def destroy_analytic(id)
16
+ delete 'my/analytics/instrumentations/' + id.to_s
17
+ end
32
18
 
33
- def value(id)
34
- raise ArgumentError unless id
35
- request.get('my/analytics/instrumentations/' + id.to_s + '/value/raw')
36
- end
19
+ def value_analytic(id)
20
+ get 'my/analytics/instrumentations/' + id.to_s + '/value/raw'
21
+ end
37
22
 
38
- def heatmap(id)
39
- raise ArgumentError unless id
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
- 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
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
- def details(query={})
16
- request.get('my/analytics/instrumentations/' + @id.to_s + '/value/heatmap/details', query)
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 Api
3
- class Datacenters
4
- attr_reader :request
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
- def all(query={})
16
- request.get('my/datacenters', query)
17
- end
7
+ def datacenter(id)
8
+ get 'my/datacenters/' + id.to_s
18
9
  end
19
10
  end
20
11
  end
@@ -0,0 +1,11 @@
1
+ module Smartdc::Api
2
+ module Images
3
+ def images(params={})
4
+ get 'my/images', params
5
+ end
6
+
7
+ def image(id)
8
+ get 'my/images/' + id.to_s
9
+ end
10
+ end
11
+ end
@@ -1,29 +1,19 @@
1
- module Smartdc
2
- module Api
3
- class Keys
4
- attr_reader :request
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
- def read(id)
15
- raise ArgumentError unless id
16
- request.get('my/keys/' + id.to_s)
17
- end
7
+ def create_key(body={})
8
+ post 'my/keys', body
9
+ end
18
10
 
19
- def all(query={})
20
- request.get('my/keys', query)
21
- end
11
+ def key(id)
12
+ get 'my/keys/' + id.to_s
13
+ end
22
14
 
23
- def destroy(id)
24
- raise ArgumentError unless id
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
@@ -1,70 +1,36 @@
1
- require 'smartdc/api/machine/tags'
2
- require 'smartdc/api/machine/metadata'
3
- require 'smartdc/api/machine/snapshots'
4
-
5
- module Smartdc
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
- def all(query={})
25
- request.get('my/machines', query)
26
- end
7
+ def create_machine(body={})
8
+ post 'my/machines', body
9
+ end
27
10
 
28
- def destroy(id)
29
- raise ArgumentError unless id
30
- request.del('my/machines/' + id.to_s)
31
- end
11
+ def machine(id)
12
+ get 'my/machines/' + id.to_s
13
+ end
32
14
 
33
- def stop(id)
34
- raise ArgumentError unless id
35
- request.post('my/machines/' + id.to_s, {'action'=>'stop'})
36
- end
15
+ def destroy_machine(id)
16
+ delete 'my/machines/' + id.to_s
17
+ end
37
18
 
38
- def start(id)
39
- raise ArgumentError unless id
40
- request.post('my/machines/' + id.to_s, {'action'=>'start'})
41
- end
19
+ def stop_machine(id)
20
+ post 'my/machines/' + id.to_s, {action: :stop}
21
+ end
42
22
 
43
- def reboot(id)
44
- raise ArgumentError unless id
45
- request.post('my/machines/' + id.to_s, {'action'=>'reboot'})
46
- end
23
+ def start_machine(id)
24
+ post 'my/machines/' + id.to_s, {action: :start}
25
+ end
47
26
 
48
- def resize(id, query={})
49
- raise ArgumentError unless id
50
- query['action'] = 'resize'
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
- def tags(id)
55
- raise ArgumentError unless id
56
- Smartdc::Api::Machine::Tags.new(id, @options)
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
@@ -1,21 +1,11 @@
1
- module Smartdc
2
- module Api
3
- class Packages
4
- attr_reader :request
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
- def all(query={})
16
- request.get('my/packages', query)
17
- end
7
+ def package(id)
8
+ get 'my/packages/' + id.to_s
18
9
  end
19
10
  end
20
11
  end
21
-
@@ -1,12 +1,46 @@
1
1
  require 'openssl'
2
2
 
3
3
  module Smartdc
4
- module Auth
5
- def self.sign(request={}, options={})
6
- rsa = OpenSSL::PKey::RSA.new File.read options[:rsa_path]
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
- 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}"
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