smartdc 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. data/.document +5 -0
  2. data/Gemfile +16 -0
  3. data/LICENSE.md +20 -0
  4. data/README.md +87 -0
  5. data/VERSION +1 -0
  6. data/bin/sdc-addmachinemetadata +29 -0
  7. data/bin/sdc-addmachinetag +29 -0
  8. data/bin/sdc-createinstrumentation +28 -0
  9. data/bin/sdc-createkey +33 -0
  10. data/bin/sdc-createmachine +39 -0
  11. data/bin/sdc-createmachinesnapshot +28 -0
  12. data/bin/sdc-deleteinstrumentation +10 -0
  13. data/bin/sdc-deletekey +10 -0
  14. data/bin/sdc-deletemachine +10 -0
  15. data/bin/sdc-deletemachinemetadata +27 -0
  16. data/bin/sdc-deletemachinesnapshot +28 -0
  17. data/bin/sdc-deletemachinetag +27 -0
  18. data/bin/sdc-describeanalytics +11 -0
  19. data/bin/sdc-getdatacenter +11 -0
  20. data/bin/sdc-getdataset +11 -0
  21. data/bin/sdc-getinstrumentation +32 -0
  22. data/bin/sdc-getkey +11 -0
  23. data/bin/sdc-getmachine +11 -0
  24. data/bin/sdc-getmachinemetadata +11 -0
  25. data/bin/sdc-getmachinesnapshot +28 -0
  26. data/bin/sdc-getmachinetag +28 -0
  27. data/bin/sdc-getpackage +11 -0
  28. data/bin/sdc-listdatacenters +11 -0
  29. data/bin/sdc-listdatasets +11 -0
  30. data/bin/sdc-listinstrumentations +11 -0
  31. data/bin/sdc-listkeys +11 -0
  32. data/bin/sdc-listmachines +11 -0
  33. data/bin/sdc-listmachinesnapshots +11 -0
  34. data/bin/sdc-listmachinetags +11 -0
  35. data/bin/sdc-listpackages +11 -0
  36. data/bin/sdc-rebootmachine +10 -0
  37. data/bin/sdc-resizemachine +32 -0
  38. data/bin/sdc-setup +63 -0
  39. data/bin/sdc-startmachine +10 -0
  40. data/bin/sdc-startmachinefromsnapshot +28 -0
  41. data/bin/sdc-stopmachine +10 -0
  42. data/config/fixtures/instrumentation.json +4 -0
  43. data/config/fixtures/key.json +4 -0
  44. data/config/fixtures/tag.json +3 -0
  45. data/lib/cli_helper.rb +12 -0
  46. data/lib/faraday/response/mashify.rb +26 -0
  47. data/lib/faraday/response/parse_json.rb +22 -0
  48. data/lib/smartdc.rb +8 -0
  49. data/lib/smartdc/api/analytics.rb +22 -0
  50. data/lib/smartdc/api/analytics/instrumentations.rb +45 -0
  51. data/lib/smartdc/api/datacenters.rb +21 -0
  52. data/lib/smartdc/api/datasets.rb +21 -0
  53. data/lib/smartdc/api/keys.rb +31 -0
  54. data/lib/smartdc/api/machine/metadata.rb +31 -0
  55. data/lib/smartdc/api/machine/snapshots.rb +37 -0
  56. data/lib/smartdc/api/machine/tags.rb +31 -0
  57. data/lib/smartdc/api/machines.rb +75 -0
  58. data/lib/smartdc/api/packages.rb +21 -0
  59. data/lib/smartdc/client.rb +40 -0
  60. data/lib/smartdc/request.rb +85 -0
  61. data/smartdc.gemspec +138 -0
  62. data/spec/smartdc/api/analytics_spec.rb +32 -0
  63. data/spec/smartdc/api/datacenters_spec.rb +16 -0
  64. data/spec/smartdc/api/datasets_spec.rb +16 -0
  65. data/spec/smartdc/api/keys_spec.rb +32 -0
  66. data/spec/smartdc/api/machine/metadata_spec.rb +42 -0
  67. data/spec/smartdc/api/machine/snapshots_spec.rb +58 -0
  68. data/spec/smartdc/api/machine/tags_spec.rb +48 -0
  69. data/spec/smartdc/api/machines_spec.rb +96 -0
  70. data/spec/smartdc/api/packages_spec.rb +16 -0
  71. data/spec/smartdc/client_spec.rb +45 -0
  72. data/spec/smartdc/request_spec.rb +11 -0
  73. data/spec/smartdc_spec.rb +9 -0
  74. data/spec/spec_helper.rb +12 -0
  75. metadata +259 -0
@@ -0,0 +1,4 @@
1
+ {
2
+ "module": "syscall"
3
+ , "stat": "syscalls"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "name": "sample",
3
+ "key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDBnUxM+7a2f9K3PaKESQlf0YNg/UEXw4CxzLs4aHZciq2neHWeqD22uMIEkqIaYZYZAnbGCCPnz1h8ewk69D4/QVqG4Yw9wR0gEkHMu4xzSrQkCktftVnC0xv4tuxYBWKBu4q+t0R63oOPwzmfnSjcVXf+H6cDRzeBuQYjSaFcqCHIy1ehXfiesb+mdm/hlBA8u1WDZoLi/DELtpkwtX6mNySZCDTGrcua4Xc02ua2olpqj1UIYIZrs9Xyiz5RZP2lPzGMxP0k9lToZQHH1HprABDpEK7MckZbIDHHkoGlPhLEG40H0Wtq9hdgmCIw/rsUweFuwxDn/4BjEhSIBzqn"
4
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "name": "sample"
3
+ }
data/lib/cli_helper.rb ADDED
@@ -0,0 +1,12 @@
1
+ require 'pp'
2
+ require "optparse"
3
+ require 'smartdc'
4
+
5
+ def fixture(name, path='config/fixtures')
6
+ json = File.read(File.join(File.dirname(__FILE__), '..', path, "/#{name}.json"))
7
+ MultiJson.decode(json)
8
+ end
9
+
10
+ def client
11
+ @client ||= Smartdc.new(fixture('config', 'config'))
12
+ end
@@ -0,0 +1,26 @@
1
+ require 'faraday'
2
+
3
+ module Faraday
4
+ class Response::Mashify < Response::Middleware
5
+ dependency 'hashie/mash'
6
+
7
+ class << self
8
+ attr_accessor :mash_class
9
+ end
10
+
11
+ self.mash_class = ::Hashie::Mash
12
+
13
+ def parse(body)
14
+ case body
15
+ when Hash
16
+ self.class.mash_class.new(body)
17
+ when Array
18
+ body.map { |item| item.is_a?(Hash) ? self.class.mash_class.new(item) : item }
19
+ else
20
+ body
21
+ end
22
+ rescue
23
+ body
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,22 @@
1
+ require 'faraday'
2
+
3
+ module Faraday
4
+ class Response::ParseJson < Response::Middleware
5
+ dependency 'multi_json'
6
+
7
+ def parse(body)
8
+ case body
9
+ when ''
10
+ nil
11
+ when 'true'
12
+ true
13
+ when 'false'
14
+ false
15
+ else
16
+ ::MultiJson.decode(body)
17
+ end
18
+ rescue
19
+ body
20
+ end
21
+ end
22
+ end
data/lib/smartdc.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'smartdc/client'
2
+ require 'smartdc/request'
3
+
4
+ module Smartdc
5
+ def self.new(options={})
6
+ Smartdc::Client.new(options)
7
+ end
8
+ end
@@ -0,0 +1,22 @@
1
+ require 'smartdc/api/analytics/instrumentations'
2
+
3
+ module Smartdc
4
+ module Api
5
+ class Analytics
6
+ attr_reader :request, :id
7
+
8
+ def initialize(request, id=nil)
9
+ @request = request
10
+ @id = id
11
+ end
12
+
13
+ def describe
14
+ request.get('my/analytics')
15
+ end
16
+
17
+ def instrumentations(_id=nil)
18
+ Smartdc::Api::Analytics::Instrumentations.new(request, _id)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,45 @@
1
+ module Smartdc::Api
2
+ class Analytics
3
+ class Instrumentations
4
+ attr_reader :request, :id
5
+
6
+ def initialize(request, id)
7
+ @request = request
8
+ @id = id
9
+ end
10
+
11
+ def create(params={})
12
+ request.post('my/analytics/instrumentations/', params)
13
+ end
14
+
15
+ def read
16
+ raise ArgumentError unless id
17
+ request.get('my/analytics/instrumentations/' + id.to_s)
18
+ end
19
+
20
+ def find(params={})
21
+ request.get('my/analytics/instrumentations/', params)
22
+ end
23
+
24
+ def delete
25
+ request.delete('my/analytics/instrumentations/' + id.to_s)
26
+ request.response.status == 204 ? true : false
27
+ end
28
+
29
+ def value
30
+ raise ArgumentError unless id
31
+ request.get('my/analytics/instrumentations/' + id.to_s + '/value/raw')
32
+ end
33
+
34
+ def heatmap(params={})
35
+ raise ArgumentError unless id
36
+ request.get('my/analytics/instrumentations/' + id.to_s + '/value/heatmap/image', params)
37
+ end
38
+
39
+ def heatmap_details(params={})
40
+ raise ArgumentError unless id
41
+ request.get('my/analytics/instrumentations/' + id.to_s + '/value/heatmap/details', params)
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,21 @@
1
+ module Smartdc
2
+ module Api
3
+ class Datacenters
4
+ attr_reader :request, :id
5
+
6
+ def initialize(request, id=nil)
7
+ @request = request
8
+ @id = id
9
+ end
10
+
11
+ def read
12
+ raise ArgumentError unless id
13
+ request.get('my/datacenters/' + id.to_s)
14
+ end
15
+
16
+ def find(params={})
17
+ request.get('my/datacenters', params)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ module Smartdc
2
+ module Api
3
+ class Datasets
4
+ attr_reader :request, :id
5
+
6
+ def initialize(request, id=nil)
7
+ @request = request
8
+ @id = id
9
+ end
10
+
11
+ def read
12
+ raise ArgumentError unless id
13
+ request.get('my/datasets/' + id.to_s)
14
+ end
15
+
16
+ def find(params={})
17
+ request.get('my/datasets', params)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,31 @@
1
+ module Smartdc
2
+ module Api
3
+ class Keys
4
+ attr_reader :request, :id
5
+
6
+ def initialize(request, id=nil)
7
+ @request = request
8
+ @id = id
9
+ end
10
+
11
+ def create(params={})
12
+ request.post('my/keys/', params)
13
+ end
14
+
15
+ def read
16
+ raise ArgumentError unless id
17
+ request.get('my/keys/' + id.to_s)
18
+ end
19
+
20
+ def find(params={})
21
+ request.get('my/keys', params)
22
+ end
23
+
24
+ def delete
25
+ raise ArgumentError unless id
26
+ request.delete('my/keys/' + id.to_s)
27
+ request.response.status == 204 ? true : false
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,31 @@
1
+ module Smartdc::Api
2
+ module Machine
3
+ class Metadata
4
+ attr_reader :request, :id
5
+
6
+ def initialize(request, id1, id)
7
+ @request = request
8
+ @id1 = id1
9
+ @id = id
10
+ end
11
+
12
+ def create(params={})
13
+ request.post('my/machines/' + @id1.to_s + '/metadata/', params)
14
+ end
15
+
16
+ def read
17
+ raise ArgumentError unless id
18
+ request.get('my/machines/' + @id1.to_s + '/metadata/' + id.to_s)
19
+ end
20
+
21
+ def find(params={})
22
+ request.get('my/machines/' + @id1.to_s + '/metadata/', params)
23
+ end
24
+
25
+ def delete
26
+ request.delete('my/machines/' + @id1.to_s + '/metadata/' + id.to_s)
27
+ request.response.status == 204 ? true : false
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,37 @@
1
+ module Smartdc::Api
2
+ module Machine
3
+ class Snapshots
4
+ attr_reader :request, :id
5
+
6
+ def initialize(request, id1, id)
7
+ @request = request
8
+ @id1 = id1
9
+ @id = id
10
+ end
11
+
12
+ def create(params={})
13
+ request.post('my/machines/' + @id1.to_s + '/snapshots/', params)
14
+ end
15
+
16
+ def start
17
+ raise ArgumentError unless id
18
+ request.post('my/machines/' + @id1.to_s + '/snapshots/' + id.to_s)
19
+ request.response.status == 202 ? true : false
20
+ end
21
+
22
+ def read
23
+ raise ArgumentError unless id
24
+ request.get('my/machines/' + @id1.to_s + '/snapshots/' + id.to_s)
25
+ end
26
+
27
+ def find(params={})
28
+ request.get('my/machines/' + @id1.to_s + '/snapshots/', params)
29
+ end
30
+
31
+ def delete
32
+ request.delete('my/machines/' + @id1.to_s + '/snapshots/' + id.to_s)
33
+ request.response.status == 204 ? true : false
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,31 @@
1
+ module Smartdc::Api
2
+ module Machine
3
+ class Tags
4
+ attr_reader :request, :id
5
+
6
+ def initialize(request, id1, id)
7
+ @request = request
8
+ @id1 = id1
9
+ @id = id
10
+ end
11
+
12
+ def create(params={})
13
+ request.post('my/machines/' + @id1.to_s + '/tags/', params)
14
+ end
15
+
16
+ def read
17
+ raise ArgumentError unless id
18
+ request.get('my/machines/' + @id1.to_s + '/tags/' + id.to_s)
19
+ end
20
+
21
+ def find(params={})
22
+ request.get('my/machines/' + @id1.to_s + '/tags/', params)
23
+ end
24
+
25
+ def delete
26
+ request.delete('my/machines/' + @id1.to_s + '/tags/' + id.to_s)
27
+ request.response.status == 204 ? true : false
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,75 @@
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, :id
9
+
10
+ def initialize(request, id=nil)
11
+ @request = request
12
+ @id = id
13
+ end
14
+
15
+ def create(params={})
16
+ request.post('my/machines/', params)
17
+ end
18
+
19
+ def read
20
+ raise ArgumentError unless id
21
+ request.get('my/machines/' + id.to_s)
22
+ end
23
+
24
+ def find(params={})
25
+ request.get('my/machines', params)
26
+ end
27
+
28
+ def delete
29
+ raise ArgumentError unless id
30
+ request.delete('my/machines/' + id.to_s)
31
+ request.response.status == 204 ? true : false
32
+ end
33
+
34
+ def stop
35
+ raise ArgumentError unless id
36
+ request.post('my/machines/' + id.to_s, {'action'=>'stop'})
37
+ request.response.status == 202 ? true : false
38
+ end
39
+
40
+ def start
41
+ raise ArgumentError unless id
42
+ request.post('my/machines/' + id.to_s, {'action'=>'start'})
43
+ request.response.status == 202 ? true : false
44
+ end
45
+
46
+ def reboot
47
+ raise ArgumentError unless id
48
+ request.post('my/machines/' + id.to_s, {'action'=>'reboot'})
49
+ request.response.status == 202 ? true : false
50
+ end
51
+
52
+ def resize(params={})
53
+ raise ArgumentError unless id
54
+ params[:action] = 'resize'
55
+ request.post('my/machines/' + id.to_s, params)
56
+ request.response.status == 202 ? true : false
57
+ end
58
+
59
+ def tags(_id=nil)
60
+ raise ArgumentError unless id
61
+ Smartdc::Api::Machine::Tags.new(request, id, _id)
62
+ end
63
+
64
+ def metadata(_id=nil)
65
+ raise ArgumentError unless id
66
+ Smartdc::Api::Machine::Metadata.new(request, id, _id)
67
+ end
68
+
69
+ def snapshots(_id=nil)
70
+ raise ArgumentError unless id
71
+ Smartdc::Api::Machine::Snapshots.new(request, id, _id)
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,21 @@
1
+ module Smartdc
2
+ module Api
3
+ class Packages
4
+ attr_reader :request, :id
5
+
6
+ def initialize(request, id=nil)
7
+ @request = request
8
+ @id = id
9
+ end
10
+
11
+ def read
12
+ raise ArgumentError unless id
13
+ request.get('my/packages/' + id.to_s)
14
+ end
15
+
16
+ def find(params={})
17
+ request.get('my/packages', params)
18
+ end
19
+ end
20
+ end
21
+ end