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,40 @@
1
+ require 'smartdc/api/keys'
2
+ require 'smartdc/api/datacenters'
3
+ require 'smartdc/api/datasets'
4
+ require 'smartdc/api/packages'
5
+ require 'smartdc/api/machines'
6
+ require 'smartdc/api/analytics'
7
+
8
+ module Smartdc
9
+ class Client
10
+ attr_reader :request
11
+
12
+ def initialize(options={})
13
+ @request ||= Smartdc::Request.new(options)
14
+ end
15
+
16
+ def keys(id=nil)
17
+ Smartdc::Api::Keys.new(request, id)
18
+ end
19
+
20
+ def datacenters(id=nil)
21
+ Smartdc::Api::Datacenters.new(request, id)
22
+ end
23
+
24
+ def datasets(id=nil)
25
+ Smartdc::Api::Datasets.new(request, id)
26
+ end
27
+
28
+ def packages(id=nil)
29
+ Smartdc::Api::Packages.new(request, id)
30
+ end
31
+
32
+ def machines(id=nil)
33
+ Smartdc::Api::Machines.new(request, id)
34
+ end
35
+
36
+ def analytics(id=nil)
37
+ Smartdc::Api::Analytics.new(request, id)
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,85 @@
1
+ require 'hashie/mash'
2
+ require 'multi_json'
3
+ require 'faraday'
4
+ require 'faraday/response/mashify'
5
+ require 'faraday/response/parse_json'
6
+
7
+ module Smartdc
8
+ class Request
9
+ attr_reader :url, :version, :response, :username, :password
10
+ attr_accessor :return_variable
11
+
12
+ def initialize(options)
13
+ @url = options['url']
14
+ @version = options['version']
15
+ @username = options['username']
16
+ @password = options['password']
17
+ end
18
+
19
+ def get(path, params={})
20
+ request(:get, path, params)
21
+ end
22
+
23
+ def post(path, params={})
24
+ request(:post, path, params)
25
+ end
26
+
27
+ def put(path, params={})
28
+ request(:put, path, params)
29
+ end
30
+
31
+ def delete(path, params={})
32
+ request(:delete, path, params)
33
+ end
34
+
35
+ private
36
+ def request(method, path, params={})
37
+ @response = connection.send(method) do |request|
38
+ case method
39
+ when :get
40
+ request.url path, params
41
+ when :post, :put
42
+ request.path = path
43
+ request.body = MultiJson.encode(params) unless params.empty?
44
+ when :delete
45
+ request.url path
46
+ request.headers = {'content-length'=>'0'}
47
+ end
48
+ end
49
+ @response.body
50
+ end
51
+
52
+ def connection
53
+ case return_variable
54
+ when 'mash', nil
55
+ middleware = 3
56
+ when 'hash'
57
+ middleware = 2
58
+ when 'json'
59
+ middleware = 1
60
+ else
61
+ middleware = 0
62
+ end
63
+
64
+ options = {
65
+ :url => url,
66
+ :ssl => {:verify => false},
67
+ :headers => {
68
+ 'authorization' => basic_auth(username, password),
69
+ 'X-Api-Version' => version
70
+ }
71
+ }
72
+
73
+ Faraday.new(options) do |builder|
74
+ builder.use Faraday::Request::JSON
75
+ builder.use Faraday::Response::Mashify if middleware > 2
76
+ builder.use Faraday::Response::ParseJson if middleware > 1
77
+ builder.adapter Faraday.default_adapter
78
+ end
79
+ end
80
+
81
+ def basic_auth(username, password)
82
+ 'Basic ' + Base64.encode64("#{username}:#{password}").gsub!("\n", '')
83
+ end
84
+ end
85
+ end
data/smartdc.gemspec ADDED
@@ -0,0 +1,138 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "smartdc"
8
+ s.version = "0.3.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["ogom"]
12
+ s.date = "2011-12-03"
13
+ s.description = "smartdc is SmartDataCenter Public API."
14
+ s.email = "ogom@hotmail.co.jp"
15
+ s.executables = ["sdc-addmachinemetadata", "sdc-addmachinetag", "sdc-createinstrumentation", "sdc-createkey", "sdc-createmachine", "sdc-createmachinesnapshot", "sdc-deleteinstrumentation", "sdc-deletekey", "sdc-deletemachine", "sdc-deletemachinemetadata", "sdc-deletemachinesnapshot", "sdc-deletemachinetag", "sdc-describeanalytics", "sdc-getdatacenter", "sdc-getdataset", "sdc-getinstrumentation", "sdc-getkey", "sdc-getmachine", "sdc-getmachinemetadata", "sdc-getmachinesnapshot", "sdc-getmachinetag", "sdc-getpackage", "sdc-listdatacenters", "sdc-listdatasets", "sdc-listinstrumentations", "sdc-listkeys", "sdc-listmachines", "sdc-listmachinesnapshots", "sdc-listmachinetags", "sdc-listpackages", "sdc-rebootmachine", "sdc-resizemachine", "sdc-setup", "sdc-startmachine", "sdc-startmachinefromsnapshot", "sdc-stopmachine"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE.md",
18
+ "README.md"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ "Gemfile",
23
+ "LICENSE.md",
24
+ "README.md",
25
+ "VERSION",
26
+ "bin/sdc-addmachinemetadata",
27
+ "bin/sdc-addmachinetag",
28
+ "bin/sdc-createinstrumentation",
29
+ "bin/sdc-createkey",
30
+ "bin/sdc-createmachine",
31
+ "bin/sdc-createmachinesnapshot",
32
+ "bin/sdc-deleteinstrumentation",
33
+ "bin/sdc-deletekey",
34
+ "bin/sdc-deletemachine",
35
+ "bin/sdc-deletemachinemetadata",
36
+ "bin/sdc-deletemachinesnapshot",
37
+ "bin/sdc-deletemachinetag",
38
+ "bin/sdc-describeanalytics",
39
+ "bin/sdc-getdatacenter",
40
+ "bin/sdc-getdataset",
41
+ "bin/sdc-getinstrumentation",
42
+ "bin/sdc-getkey",
43
+ "bin/sdc-getmachine",
44
+ "bin/sdc-getmachinemetadata",
45
+ "bin/sdc-getmachinesnapshot",
46
+ "bin/sdc-getmachinetag",
47
+ "bin/sdc-getpackage",
48
+ "bin/sdc-listdatacenters",
49
+ "bin/sdc-listdatasets",
50
+ "bin/sdc-listinstrumentations",
51
+ "bin/sdc-listkeys",
52
+ "bin/sdc-listmachines",
53
+ "bin/sdc-listmachinesnapshots",
54
+ "bin/sdc-listmachinetags",
55
+ "bin/sdc-listpackages",
56
+ "bin/sdc-rebootmachine",
57
+ "bin/sdc-resizemachine",
58
+ "bin/sdc-setup",
59
+ "bin/sdc-startmachine",
60
+ "bin/sdc-startmachinefromsnapshot",
61
+ "bin/sdc-stopmachine",
62
+ "config/fixtures/instrumentation.json",
63
+ "config/fixtures/key.json",
64
+ "config/fixtures/tag.json",
65
+ "lib/cli_helper.rb",
66
+ "lib/faraday/response/mashify.rb",
67
+ "lib/faraday/response/parse_json.rb",
68
+ "lib/smartdc.rb",
69
+ "lib/smartdc/api/analytics.rb",
70
+ "lib/smartdc/api/analytics/instrumentations.rb",
71
+ "lib/smartdc/api/datacenters.rb",
72
+ "lib/smartdc/api/datasets.rb",
73
+ "lib/smartdc/api/keys.rb",
74
+ "lib/smartdc/api/machine/metadata.rb",
75
+ "lib/smartdc/api/machine/snapshots.rb",
76
+ "lib/smartdc/api/machine/tags.rb",
77
+ "lib/smartdc/api/machines.rb",
78
+ "lib/smartdc/api/packages.rb",
79
+ "lib/smartdc/client.rb",
80
+ "lib/smartdc/request.rb",
81
+ "smartdc.gemspec",
82
+ "spec/smartdc/api/analytics_spec.rb",
83
+ "spec/smartdc/api/datacenters_spec.rb",
84
+ "spec/smartdc/api/datasets_spec.rb",
85
+ "spec/smartdc/api/keys_spec.rb",
86
+ "spec/smartdc/api/machine/metadata_spec.rb",
87
+ "spec/smartdc/api/machine/snapshots_spec.rb",
88
+ "spec/smartdc/api/machine/tags_spec.rb",
89
+ "spec/smartdc/api/machines_spec.rb",
90
+ "spec/smartdc/api/packages_spec.rb",
91
+ "spec/smartdc/client_spec.rb",
92
+ "spec/smartdc/request_spec.rb",
93
+ "spec/smartdc_spec.rb",
94
+ "spec/spec_helper.rb"
95
+ ]
96
+ s.homepage = "http://github.com/ogom/ruby-smartdc"
97
+ s.licenses = ["MIT"]
98
+ s.require_paths = ["lib"]
99
+ s.rubygems_version = "1.8.10"
100
+ s.summary = "SmartDataCenter CloudApi client by ruby."
101
+
102
+ if s.respond_to? :specification_version then
103
+ s.specification_version = 3
104
+
105
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
106
+ s.add_runtime_dependency(%q<faraday>, ["~> 0.7.5"])
107
+ s.add_runtime_dependency(%q<hashie>, ["~> 1.2.0"])
108
+ s.add_runtime_dependency(%q<multi_json>, ["~> 1.0.3"])
109
+ s.add_runtime_dependency(%q<multipart-post>, ["~> 1.1.3"])
110
+ s.add_development_dependency(%q<rspec>, ["~> 2.7.0"])
111
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
112
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
113
+ s.add_development_dependency(%q<rcov>, [">= 0"])
114
+ s.add_development_dependency(%q<uuid>, ["~> 2.3.4"])
115
+ else
116
+ s.add_dependency(%q<faraday>, ["~> 0.7.5"])
117
+ s.add_dependency(%q<hashie>, ["~> 1.2.0"])
118
+ s.add_dependency(%q<multi_json>, ["~> 1.0.3"])
119
+ s.add_dependency(%q<multipart-post>, ["~> 1.1.3"])
120
+ s.add_dependency(%q<rspec>, ["~> 2.7.0"])
121
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
122
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
123
+ s.add_dependency(%q<rcov>, [">= 0"])
124
+ s.add_dependency(%q<uuid>, ["~> 2.3.4"])
125
+ end
126
+ else
127
+ s.add_dependency(%q<faraday>, ["~> 0.7.5"])
128
+ s.add_dependency(%q<hashie>, ["~> 1.2.0"])
129
+ s.add_dependency(%q<multi_json>, ["~> 1.0.3"])
130
+ s.add_dependency(%q<multipart-post>, ["~> 1.1.3"])
131
+ s.add_dependency(%q<rspec>, ["~> 2.7.0"])
132
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
133
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
134
+ s.add_dependency(%q<rcov>, [">= 0"])
135
+ s.add_dependency(%q<uuid>, ["~> 2.3.4"])
136
+ end
137
+ end
138
+
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Smartdc::Api::instrumentations" do
4
+ before(:all) do
5
+ @fixture = fixture('instrumentation')
6
+ @instrumentation = client.analytics.instrumentations.create @fixture
7
+ end
8
+
9
+ describe ".create" do
10
+ it "should return a instrumentation" do
11
+ @instrumentation.module.should eq @fixture['module']
12
+ end
13
+ end
14
+
15
+ describe ".read" do
16
+ it "should return a instrumentation" do
17
+ client.analytics.instrumentations(@instrumentation.id).read.module.should eq @fixture['module']
18
+ end
19
+ end
20
+
21
+ describe ".find" do
22
+ it "should return some instrumentations" do
23
+ client.analytics.instrumentations.find.count.should > 0
24
+ end
25
+ end
26
+
27
+ describe ".delete" do
28
+ it "should return true when success" do
29
+ client.analytics.instrumentations(@instrumentation.id).delete.should be_true
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Smartdc::Api::Datacenters" do
4
+ describe ".find" do
5
+ it "should return some datacenters" do
6
+ client.datacenters.find.count.should > 0
7
+ end
8
+ end
9
+
10
+ describe ".read" do
11
+ it "should return a datacenter" do
12
+ datacenters = client.datacenters.find
13
+ client.datacenters(datacenters.first[0]).read[:message].should match(/#{datacenters.first[0]}/)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Smartdc::Api::Datasets" do
4
+ describe ".find" do
5
+ it "should return some datasets" do
6
+ client.datasets.find.count.should > 0
7
+ end
8
+ end
9
+
10
+ describe ".read" do
11
+ it "should return a dataset" do
12
+ datasets = client.datasets.find
13
+ client.datasets(datasets[0].id).read.id.should eq datasets[0].id
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Smartdc::Api::Keys" do
4
+ before(:all) do
5
+ @key = fixture('key')
6
+ end
7
+
8
+ describe ".create" do
9
+ it "should return a key" do
10
+ key = client.keys.create @key
11
+ key.name.should eq @key['name']
12
+ end
13
+ end
14
+
15
+ describe ".read" do
16
+ it "should return a key" do
17
+ client.keys(@key['name']).read.name.should eq @key['name']
18
+ end
19
+ end
20
+
21
+ describe ".find" do
22
+ it "should return some keys" do
23
+ client.keys.find.count.should > 0
24
+ end
25
+ end
26
+
27
+ describe ".delete" do
28
+ it "should return true when success" do
29
+ client.keys(@key['name']).delete.should be_true
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Smartdc::Api::Machine::Metadata" do
4
+ before(:all) do
5
+ @name = UUID.new.generate
6
+ machine = {
7
+ 'name' => @name,
8
+ 'dataset' => client.datasets.find[0].urn
9
+ }
10
+ @machine = client.machines.create machine
11
+ @fixture = fixture('tag')
12
+ end
13
+
14
+ describe ".create" do
15
+ it "should return a tag" do
16
+ tag = client.machines(@machine.id).metadata.create @fixture
17
+ tag.name.should eq @fixture['name']
18
+ end
19
+ end
20
+
21
+ describe ".find" do
22
+ it "should return some metadata" do
23
+ client.machines(@machine.id).metadata.find.count.should > 0
24
+ end
25
+ end
26
+
27
+ describe ".delete" do
28
+ it "should return true when success" do
29
+ client.machines(@machine.id).metadata('name').delete.should be_true
30
+ end
31
+ end
32
+
33
+ after(:all) do
34
+ machine = client.machines(@machine.id)
35
+ machine.stop
36
+ 8.times do |i|
37
+ break if machine.read.state == 'stopped'
38
+ sleep i
39
+ end
40
+ client.machines(@machine.id).delete
41
+ end
42
+ end
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Smartdc::Api::Machine::Snapshots" do
4
+ before(:all) do
5
+ @fixture = fixture('tag')
6
+ @name = UUID.new.generate
7
+ machine = {
8
+ 'name' => @name,
9
+ 'dataset' => client.datasets.find[0].urn # this is smartmachine
10
+ }
11
+ @machine = client.machines.create machine
12
+ machine = client.machines(@machine.id)
13
+ 8.times do |i|
14
+ break if machine.read.state == 'running'
15
+ sleep i
16
+ end
17
+ machine.stop
18
+ 8.times do |i|
19
+ break if machine.read.state == 'stopped'
20
+ sleep i
21
+ end
22
+ end
23
+
24
+ describe ".create" do
25
+ it "should return a snapshot" do
26
+ snapshot = client.machines(@machine.id).snapshots.create @fixture
27
+ snapshot.name.should eq @fixture['name']
28
+ end
29
+ end
30
+
31
+ describe ".read" do
32
+ it "should return a snapshot" do
33
+ client.machines(@machine.id).snapshots('sample').read.name.should eq @fixture['name']
34
+ end
35
+ end
36
+
37
+ describe ".find" do
38
+ it "should return some snapshots" do
39
+ client.machines(@machine.id).snapshots.find.count.should > 0
40
+ end
41
+ end
42
+
43
+ describe ".delete" do
44
+ it "should return true when success" do
45
+ client.machines(@machine.id).snapshots('sample').delete.should be_true
46
+ end
47
+ end
48
+
49
+ after(:all) do
50
+ machine = client.machines(@machine.id)
51
+ machine.stop
52
+ 8.times do |i|
53
+ break if machine.read.state == 'stopped'
54
+ sleep i
55
+ end
56
+ client.machines(@machine.id).delete
57
+ end
58
+ end