smartdc 0.4.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. data/.document +0 -1
  2. data/.travis.yml +5 -0
  3. data/Gemfile +7 -10
  4. data/README.md +42 -69
  5. data/Rakefile +47 -0
  6. data/VERSION +1 -1
  7. data/bin/sdc +327 -0
  8. data/lib/cli_helper.rb +131 -8
  9. data/lib/configure.rb +73 -0
  10. data/lib/smartdc.rb +16 -1
  11. data/lib/smartdc/api/analytics.rb +29 -7
  12. data/lib/smartdc/api/analytics/heatmap.rb +20 -0
  13. data/lib/smartdc/api/datacenters.rb +6 -7
  14. data/lib/smartdc/api/datasets.rb +6 -7
  15. data/lib/smartdc/api/keys.rb +10 -11
  16. data/lib/smartdc/api/machine/metadata.rb +9 -15
  17. data/lib/smartdc/api/machine/snapshots.rb +16 -16
  18. data/lib/smartdc/api/machine/tags.rb +11 -12
  19. data/lib/smartdc/api/machines.rb +23 -23
  20. data/lib/smartdc/api/packages.rb +7 -8
  21. data/lib/smartdc/client.rb +14 -18
  22. data/lib/smartdc/request.rb +41 -51
  23. data/lib/smartdc/response.rb +24 -0
  24. data/lib/smartdc/response/raise_error.rb +1 -1
  25. data/smartdc.gemspec +51 -90
  26. data/spec/fixtures/analytics.json +26 -0
  27. data/spec/fixtures/datacenter.json +4 -0
  28. data/spec/fixtures/datacenters.json +3 -0
  29. data/spec/fixtures/datasets.json +38 -0
  30. data/spec/fixtures/keys.json +14 -0
  31. data/spec/fixtures/machines.json +36 -0
  32. data/spec/fixtures/packages.json +18 -0
  33. data/spec/fixtures/snapshots.json +8 -0
  34. data/spec/fixtures/tag.json +3 -0
  35. data/spec/spec_helper.rb +3 -12
  36. data/spec/unit/smartdc/api/analytics_spec.rb +53 -0
  37. data/spec/unit/smartdc/api/datacenters_spec.rb +31 -0
  38. data/spec/unit/smartdc/api/datasets_spec.rb +31 -0
  39. data/spec/unit/smartdc/api/keys_spec.rb +53 -0
  40. data/spec/unit/smartdc/api/machine/metadata_spec.rb +42 -0
  41. data/spec/unit/smartdc/api/machine/snapshots_spec.rb +132 -0
  42. data/spec/unit/smartdc/api/machine/tags_spec.rb +53 -0
  43. data/spec/unit/smartdc/api/machines_spec.rb +53 -0
  44. data/spec/unit/smartdc/api/packages_spec.rb +31 -0
  45. data/spec/{smartdc → unit/smartdc}/client_spec.rb +0 -6
  46. data/spec/{smartdc_spec.rb → unit/smartdc_spec.rb} +1 -1
  47. metadata +72 -140
  48. data/LICENSE.md +0 -20
  49. data/bin/sdc-addmachinemetadata +0 -29
  50. data/bin/sdc-addmachinetag +0 -29
  51. data/bin/sdc-createinstrumentation +0 -27
  52. data/bin/sdc-createkey +0 -32
  53. data/bin/sdc-createmachine +0 -39
  54. data/bin/sdc-createmachinesnapshot +0 -27
  55. data/bin/sdc-deleteinstrumentation +0 -12
  56. data/bin/sdc-deletekey +0 -12
  57. data/bin/sdc-deletemachine +0 -12
  58. data/bin/sdc-deletemachinemetadata +0 -29
  59. data/bin/sdc-deletemachinesnapshot +0 -29
  60. data/bin/sdc-deletemachinetag +0 -29
  61. data/bin/sdc-describeanalytics +0 -10
  62. data/bin/sdc-getdatacenter +0 -10
  63. data/bin/sdc-getdataset +0 -10
  64. data/bin/sdc-getinstrumentation +0 -31
  65. data/bin/sdc-getkey +0 -10
  66. data/bin/sdc-getmachine +0 -12
  67. data/bin/sdc-getmachinemetadata +0 -12
  68. data/bin/sdc-getmachinesnapshot +0 -27
  69. data/bin/sdc-getmachinetag +0 -27
  70. data/bin/sdc-getpackage +0 -10
  71. data/bin/sdc-listdatacenters +0 -10
  72. data/bin/sdc-listdatasets +0 -10
  73. data/bin/sdc-listinstrumentations +0 -10
  74. data/bin/sdc-listkeys +0 -10
  75. data/bin/sdc-listmachines +0 -10
  76. data/bin/sdc-listmachinesnapshots +0 -10
  77. data/bin/sdc-listmachinetags +0 -10
  78. data/bin/sdc-listpackages +0 -10
  79. data/bin/sdc-rebootmachine +0 -12
  80. data/bin/sdc-resizemachine +0 -34
  81. data/bin/sdc-setup +0 -67
  82. data/bin/sdc-startmachine +0 -12
  83. data/bin/sdc-startmachinefromsnapshot +0 -29
  84. data/bin/sdc-stopmachine +0 -12
  85. data/config/fixtures/instrumentation.json +0 -4
  86. data/config/fixtures/key.json +0 -4
  87. data/config/fixtures/tag.json +0 -3
  88. data/lib/smartdc/api/analytics/instrumentations.rb +0 -44
  89. data/lib/smartdc/response/mashify.rb +0 -29
  90. data/lib/smartdc/response/parse_json.rb +0 -26
  91. data/spec/smartdc/api/analytics_spec.rb +0 -32
  92. data/spec/smartdc/api/datacenters_spec.rb +0 -16
  93. data/spec/smartdc/api/datasets_spec.rb +0 -16
  94. data/spec/smartdc/api/keys_spec.rb +0 -32
  95. data/spec/smartdc/api/machine/metadata_spec.rb +0 -59
  96. data/spec/smartdc/api/machine/snapshots_spec.rb +0 -70
  97. data/spec/smartdc/api/machine/tags_spec.rb +0 -65
  98. data/spec/smartdc/api/machines_spec.rb +0 -92
  99. data/spec/smartdc/api/packages_spec.rb +0 -16
  100. data/spec/smartdc/request_spec.rb +0 -12
@@ -0,0 +1,26 @@
1
+ [
2
+ {
3
+ "module": "syscall",
4
+ "stat": "syscalls",
5
+ "predicate": {},
6
+ "decomposition": [],
7
+ "value-dimension": 1,
8
+ "value-arity": "scalar",
9
+ "enabled": true,
10
+ "retention-time": 600,
11
+ "idle-max": 3600,
12
+ "transformations": {},
13
+ "nsources": 1,
14
+ "granularity": 1,
15
+ "persist-data": false,
16
+ "crtime": 1355245051112,
17
+ "value-scope": "interval",
18
+ "id": "3",
19
+ "uris": [
20
+ {
21
+ "uri": "/ogom/analytics/instrumentations/3/value/raw",
22
+ "name": "value_raw"
23
+ }
24
+ ]
25
+ }
26
+ ]
@@ -0,0 +1,4 @@
1
+ {
2
+ "code": "ResourceMoved",
3
+ "message": "Osaka is at https://127.0.0.1"
4
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "Osaka": "https://127.0.0.1"
3
+ }
@@ -0,0 +1,38 @@
1
+ [
2
+ {
3
+ "id": "141194fa-dd77-11e0-8539-27dd8d8264b8",
4
+ "urn": "sdc:sdc:smartos64:1.4.7",
5
+ "name": "smartos64",
6
+ "os": "smartos",
7
+ "type": "smartmachine",
8
+ "description": "Base template to build other templates on",
9
+ "default": false,
10
+ "requirements": {},
11
+ "version": "1.4.7",
12
+ "created": "2011-11-21T04:48:58+00:00"
13
+ },
14
+ {
15
+ "id": "f8ea0bb8-dd75-11e0-87c3-af5352ad3bd6",
16
+ "urn": "sdc:sdc:smartos:1.4.7",
17
+ "name": "smartos",
18
+ "os": "smartos",
19
+ "type": "smartmachine",
20
+ "description": "Base template to build other templates on",
21
+ "default": false,
22
+ "requirements": {},
23
+ "version": "1.4.7",
24
+ "created": "2011-10-22T07:23:19+00:00"
25
+ },
26
+ {
27
+ "id": "41da9c2e-7175-11e0-bb9f-536983f41cd8",
28
+ "urn": "sdc:sdc:nodejs:1.1.4",
29
+ "name": "nodejs",
30
+ "os": "smartos",
31
+ "type": "smartmachine",
32
+ "description": "Node.js git-deploy PaaS dataset",
33
+ "default": false,
34
+ "requirements": {},
35
+ "version": "1.1.4",
36
+ "created": "2011-09-26T01:42:34+00:00"
37
+ }
38
+ ]
@@ -0,0 +1,14 @@
1
+ [
2
+ {
3
+ "name": "K001",
4
+ "key": "ssh-rsa AAA123 K001",
5
+ "created": "2012-12-12T23:59:01+00:00",
6
+ "updated": "2012-12-12T23:59:02+00:00"
7
+ },
8
+ {
9
+ "name": "K002",
10
+ "key": "ssh-rsa AAA456 K002",
11
+ "created": "2012-12-12T23:59:03+00:00",
12
+ "updated": "2012-12-12T23:59:04+00:00"
13
+ }
14
+ ]
@@ -0,0 +1,36 @@
1
+ [
2
+ {
3
+ "id": "abc",
4
+ "name": "M001",
5
+ "type": "smartmachine",
6
+ "state": "running",
7
+ "dataset": "sdc:sdc:smartos:1.5.1",
8
+ "ips": [
9
+ "192.168.1.2"
10
+ ],
11
+ "memory": 512,
12
+ "disk": 10240,
13
+ "metadata": {},
14
+ "created": "2012-12-12T23:59:01+00:00",
15
+ "updated": "2012-12-12T23:59:02+00:00",
16
+ "primaryIp": "192.168.1.2"
17
+ },
18
+ {
19
+ "id": "def",
20
+ "name": "M002",
21
+ "type": "virtualmachine",
22
+ "state": "running",
23
+ "dataset": "sdc:sdc:ubuntu10.04:0.1.0",
24
+ "ips": [
25
+ "192.168.1.3"
26
+ ],
27
+ "memory": 256,
28
+ "disk": 10240,
29
+ "metadata": {
30
+ "root_authorized_keys": "ssh-rsa AAA123 K001\n"
31
+ },
32
+ "created": "2012-12-12T23:59:03+00:00",
33
+ "updated": "2012-12-12T23:59:04+00:00",
34
+ "primaryIp": "192.168.1.3"
35
+ }
36
+ ]
@@ -0,0 +1,18 @@
1
+ [
2
+ {
3
+ "name": "regular_256",
4
+ "memory": 256,
5
+ "disk": 5120,
6
+ "vcpus": 1,
7
+ "swap": 512,
8
+ "default": true
9
+ },
10
+ {
11
+ "name": "regular_512",
12
+ "memory": 512,
13
+ "disk": 10240,
14
+ "vcpus": 1,
15
+ "swap": 1024,
16
+ "default": false
17
+ }
18
+ ]
@@ -0,0 +1,8 @@
1
+ [
2
+ {
3
+ "name": "s001",
4
+ "state": "success",
5
+ "created": "2012-12-12T23:59:01+00:00",
6
+ "updated": "2012-12-12T23:59:02+00:00"
7
+ }
8
+ ]
@@ -0,0 +1,3 @@
1
+ {
2
+ "k001": "v001"
3
+ }
data/spec/spec_helper.rb CHANGED
@@ -1,18 +1,9 @@
1
1
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
2
  $LOAD_PATH.unshift(File.dirname(__FILE__))
3
3
  require 'rspec'
4
- require 'uuid'
5
4
  require 'cli_helper'
6
5
 
7
- # Requires supporting files with custom matchers and macros, etc,
8
- # in ./support/ and its subdirectories.
9
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
10
-
11
- RSpec.configure do |config|
12
- end
13
-
14
- def client
15
- @client ||= Smartdc.new(fixture('config', 'config'))
16
- @client.format = 'mash'
17
- @client
6
+ def fixture(name)
7
+ path = File.join(File.dirname(__FILE__), './fixtures', "/#{name}.json")
8
+ JSON.parse(File.read(path))
18
9
  end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Smartdc::Api::Analytics" do
4
+
5
+ before(:all) do
6
+ @object = Object.new
7
+ @request = Smartdc::Request
8
+ end
9
+
10
+ describe ".create" do
11
+ it "should return a instrumentation" do
12
+ @object.stub(:content) {fixture('analytics')[0]}
13
+ analytic = @object.content
14
+ @request.stub_chain(:new, :post).with('my/analytics/instrumentations/', analytic) {@object}
15
+
16
+ analytics = Smartdc::Api::Analytics.new({})
17
+ analytics.create(analytic).content['id'].should == analytic['id']
18
+ end
19
+ end
20
+
21
+ describe ".read" do
22
+ it "should return a instrumentation" do
23
+ @object.stub(:content) {fixture('analytics')[0]}
24
+ id = @object.content['id']
25
+ @request.stub_chain(:new, :get).with('my/analytics/instrumentations/' + id) {@object}
26
+
27
+ analytics = Smartdc::Api::Analytics.new({})
28
+ analytics.read(id).content['id'].should == id
29
+ end
30
+ end
31
+
32
+ describe ".all" do
33
+ it "should return some instrumentations" do
34
+ @object.stub(:content) {fixture('analytics')}
35
+ @request.stub_chain(:new, :get).with('my/analytics/instrumentations', {}) {@object}
36
+
37
+ analytics = Smartdc::Api::Analytics.new({})
38
+ analytics.all.content.count.should > 0
39
+ end
40
+ end
41
+
42
+ describe ".delete" do
43
+ it "should return true when success" do
44
+ analytic = fixture('analytics')[0]
45
+ @object.stub(:status) {204}
46
+ @request.stub_chain(:new, :del).with('my/analytics/instrumentations/' + analytic['id']) {@object}
47
+
48
+ analytics = Smartdc::Api::Analytics.new({})
49
+ analytics.destroy(analytic['id']).status.should == 204
50
+ end
51
+ end
52
+
53
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Smartdc::Api::Datacenters" do
4
+
5
+ before(:all) do
6
+ @object = Object.new
7
+ @request = Smartdc::Request
8
+ end
9
+
10
+ describe ".read" do
11
+ it "should return a datacenter" do
12
+ @object.stub(:content) {fixture('datacenter')}
13
+ name = fixture('datacenters').first[0]
14
+ @request.stub_chain(:new, :get).with('my/datacenters/' + name) {@object}
15
+
16
+ datacenters = Smartdc::Api::Datacenters.new({})
17
+ datacenters.read(name).content['message'].should match(/#{name}/)
18
+ end
19
+ end
20
+
21
+ describe ".all" do
22
+ it "should return some datacenter" do
23
+ @object.stub(:content) {fixture('datacenters')}
24
+ @request.stub_chain(:new, :get).with('my/datacenters', {}) {@object}
25
+
26
+ datacenters = Smartdc::Api::Datacenters.new({})
27
+ datacenters.all.content.count.should > 0
28
+ end
29
+ end
30
+
31
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Smartdc::Api::Datasets" do
4
+
5
+ before(:all) do
6
+ @object = Object.new
7
+ @request = Smartdc::Request
8
+ end
9
+
10
+ describe ".read" do
11
+ it "should return a dataset" do
12
+ @object.stub(:content) {fixture('datasets')[0]}
13
+ id = @object.content['id']
14
+ @request.stub_chain(:new, :get).with('my/datasets/' + id) {@object}
15
+
16
+ datasets = Smartdc::Api::Datasets.new({})
17
+ datasets.read(id).content['id'].should == id
18
+ end
19
+ end
20
+
21
+ describe ".all" do
22
+ it "should return some datasets" do
23
+ @object.stub(:content) {fixture('datasets')}
24
+ @request.stub_chain(:new, :get).with('my/datasets', {}) {@object}
25
+
26
+ datasets = Smartdc::Api::Datasets.new({})
27
+ datasets.all.content.count.should > 0
28
+ end
29
+ end
30
+
31
+ end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Smartdc::Api::Keys" do
4
+
5
+ before(:all) do
6
+ @object = Object.new
7
+ @request = Smartdc::Request
8
+ end
9
+
10
+ describe ".create" do
11
+ it "should return a key" do
12
+ @object.stub(:content) {fixture('keys')[0]}
13
+ key = @object.content
14
+ @request.stub_chain(:new, :post).with('my/keys/', key) {@object}
15
+
16
+ keys = Smartdc::Api::Keys.new({})
17
+ keys.create(key).content['name'].should == key['name']
18
+ end
19
+ end
20
+
21
+ describe ".read" do
22
+ it "should return a key" do
23
+ @object.stub(:content) {fixture('keys')[0]}
24
+ name = @object.content['name']
25
+ @request.stub_chain(:new, :get).with('my/keys/' + name) {@object}
26
+
27
+ keys = Smartdc::Api::Keys.new({})
28
+ keys.read(name).content['name'].should == name
29
+ end
30
+ end
31
+
32
+ describe ".all" do
33
+ it "should return some keys" do
34
+ @object.stub(:content) {fixture('keys')}
35
+ @request.stub_chain(:new, :get).with('my/keys', {}) {@object}
36
+
37
+ keys = Smartdc::Api::Keys.new({})
38
+ keys.all.content.count.should > 0
39
+ end
40
+ end
41
+
42
+ describe ".delete" do
43
+ it "should return true when success" do
44
+ key = fixture('keys')[0]
45
+ @object.stub(:status) {204}
46
+ @request.stub_chain(:new, :del).with('my/keys/' + key['name']) {@object}
47
+
48
+ keys = Smartdc::Api::Keys.new({})
49
+ keys.destroy(key['name']).status.should == 204
50
+ end
51
+ end
52
+
53
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Smartdc::Api::Machine::Metadata" do
4
+
5
+ before(:all) do
6
+ @object = Object.new
7
+ @request = Smartdc::Request
8
+ end
9
+
10
+ describe ".create" do
11
+ it "should return a metadata" do
12
+ @object.stub(:content) {fixture('tag')}
13
+ tag = @object.content
14
+ @request.stub_chain(:new, :post).with('my/machines/id/metadata/', tag) {@object}
15
+
16
+ metadata = Smartdc::Api::Machine::Metadata.new('id', {})
17
+ metadata.create(tag).content.should == tag
18
+ end
19
+ end
20
+
21
+ describe ".read" do
22
+ it "should return some metadata" do
23
+ @object.stub(:content) {fixture('tag')}
24
+ @request.stub_chain(:new, :get).with('my/machines/id/metadata', {}) {@object}
25
+
26
+ metadata = Smartdc::Api::Machine::Metadata.new('id', {})
27
+ metadata.read.content.count.should > 0
28
+ end
29
+ end
30
+
31
+ describe ".delete" do
32
+ it "should return a metadata" do
33
+ @object.stub(:status) {204}
34
+ key = fixture('tag').first[0]
35
+ @request.stub_chain(:new, :del).with('my/machines/id/metadata/' + key) {@object}
36
+
37
+ metadata = Smartdc::Api::Machine::Metadata.new('id', {})
38
+ metadata.destroy(key).status.should == 204
39
+ end
40
+ end
41
+
42
+ end
@@ -0,0 +1,132 @@
1
+
2
+ require 'spec_helper'
3
+
4
+ describe "Smartdc::Api::Machine::Snapshots" do
5
+
6
+ before(:all) do
7
+ @object = Object.new
8
+ @request = Smartdc::Request
9
+ end
10
+
11
+ describe ".create" do
12
+ it "should return a snapshot" do
13
+ @object.stub(:content) {fixture('snapshots')[0]}
14
+ snapshot = @object.content
15
+ @request.stub_chain(:new, :post).with('my/machines/id/snapshots/', snapshot) {@object}
16
+
17
+ snapshots = Smartdc::Api::Machine::Snapshots.new('id', {})
18
+ snapshots.create(snapshot).content['name'].should == snapshot['name']
19
+ end
20
+ end
21
+
22
+ describe ".read" do
23
+ it "should return a snapshot" do
24
+ @object.stub(:content) {fixture('snapshots')[0]}
25
+ name = @object.content['name']
26
+ @request.stub_chain(:new, :get).with('my/machines/id/snapshots/' + name) {@object}
27
+
28
+ snapshots = Smartdc::Api::Machine::Snapshots.new('id', {})
29
+ snapshots.read(name).content['name'].should == name
30
+ end
31
+ end
32
+
33
+ describe ".all" do
34
+ it "should return some snapshots" do
35
+ @object.stub(:content) {fixture('snapshots')}
36
+ @request.stub_chain(:new, :get).with('my/machines/id/snapshots', {}) {@object}
37
+
38
+ snapshots = Smartdc::Api::Machine::Snapshots.new('id', {})
39
+ snapshots.all.content.count.should > 0
40
+ end
41
+ end
42
+
43
+ describe ".delete" do
44
+ it "should return a snapshot" do
45
+ @object.stub(:status) {204}
46
+ name = fixture('snapshots')[0]['name']
47
+ @request.stub_chain(:new, :del).with('my/machines/id/snapshots/' + name) {@object}
48
+
49
+ snapshots = Smartdc::Api::Machine::Snapshots.new('id', {})
50
+ snapshots.destroy(name).status.should == 204
51
+ end
52
+ end
53
+
54
+ end
55
+
56
+
57
+
58
+
59
+
60
+
61
+
62
+
63
+ # require 'spec_helper'
64
+
65
+ # describe "Smartdc::Api::Machine::Snapshots" do
66
+ # before(:all) do
67
+ # @fixture = fixture('tag')
68
+ # @name = UUID.new.generate
69
+ # client.datasets.find.each do |dataset|
70
+ # if dataset.type == "smartmachine"
71
+ # @dataset_urn = dataset.urn
72
+ # break
73
+ # end
74
+ # end
75
+
76
+ # machine = {
77
+ # 'name' => @name,
78
+ # 'dataset' => @dataset_urn
79
+ # }
80
+ # @machine = client.machines.create machine
81
+ # machine = client.machines(@machine.id)
82
+ # 88.times do |i|
83
+ # break if machine.read.state == 'running'
84
+ # sleep i
85
+ # end
86
+ # 88.times do |i|
87
+ # break if machine.read.state == 'running'
88
+ # sleep i
89
+ # end
90
+ # machine.stop
91
+ # 88.times do |i|
92
+ # break if machine.read.state == 'stopped'
93
+ # sleep i
94
+ # end
95
+ # end
96
+
97
+ # describe ".create" do
98
+ # it "should return a snapshot" do
99
+ # snapshot = client.machines(@machine.id).snapshots.create @fixture
100
+ # snapshot.name.should eq @fixture['name']
101
+ # end
102
+ # end
103
+
104
+ # describe ".read" do
105
+ # it "should return a snapshot" do
106
+ # client.machines(@machine.id).snapshots('sample').read.name.should eq @fixture['name']
107
+ # end
108
+ # end
109
+
110
+ # describe ".find" do
111
+ # it "should return some snapshots" do
112
+ # client.machines(@machine.id).snapshots.find.count.should > 0
113
+ # end
114
+ # end
115
+
116
+ # describe ".delete" do
117
+ # it "should return true when success" do
118
+ # client.machines(@machine.id).snapshots('sample').delete.should be_nil
119
+ # end
120
+ # end
121
+
122
+ # after(:all) do
123
+ # sleep 8
124
+ # machine = client.machines(@machine.id)
125
+ # machine.stop
126
+ # 88.times do |i|
127
+ # break if machine.read.state == 'stopped'
128
+ # sleep i
129
+ # end
130
+ # client.machines(@machine.id).delete
131
+ # end
132
+ # end