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
@@ -1,25 +0,0 @@
1
- module Smartdc
2
- class Response
3
- attr_reader :status, :headers, :body, :content
4
-
5
- def initialize(response)
6
- @status = response.status
7
- @headers = response.headers
8
- @body = response.body
9
- self.content = @body
10
- end
11
-
12
- def content=raw
13
- case raw
14
- when nil, ''
15
- @content = nil
16
- when 'true'
17
- @content = true
18
- when 'false'
19
- @content = false
20
- else
21
- @content = JSON.parse(raw)
22
- end
23
- end
24
- end
25
- end
@@ -1,38 +0,0 @@
1
- require 'faraday'
2
-
3
- module Smartdc
4
- class Response
5
- class RaiseError < Faraday::Response::Middleware
6
- def on_complete(env)
7
- case env[:status]
8
- when 400
9
- raise Smartdc::Error::BadRequest, response_values(env)
10
- when 401
11
- raise Smartdc::Error::Unauthorized, response_values(env)
12
- when 403
13
- raise Smartdc::Error::Forbidden, response_values(env)
14
- when 404
15
- raise Smartdc::Error::NotFound, response_values(env)
16
- when 405
17
- raise Smartdc::Error::MethodNotAllowed, response_values(env)
18
- when 406
19
- raise Smartdc::Error::NotAcceptable, response_values(env)
20
- when 409
21
- raise Smartdc::Error::Conflict, response_values(env)
22
- when 500
23
- raise Smartdc::Error::InternalServerError, response_values(env)
24
- when 501
25
- raise Smartdc::Error::NotImplemented, response_values(env)
26
- when 502
27
- raise Smartdc::Error::BadGateway, response_values(env)
28
- when 503
29
- raise Smartdc::Error::ServiceUnavailable, response_values(env)
30
- end
31
- end
32
-
33
- def response_values(env)
34
- {:status => env[:status], :headers => env[:response_headers], :body => env[:body]}
35
- end
36
- end
37
- end
38
- end
@@ -1,26 +0,0 @@
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
- ]
@@ -1,4 +0,0 @@
1
- {
2
- "code": "ResourceMoved",
3
- "message": "Osaka is at https://127.0.0.1"
4
- }
@@ -1,3 +0,0 @@
1
- {
2
- "Osaka": "https://127.0.0.1"
3
- }
@@ -1,38 +0,0 @@
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
- ]
@@ -1,14 +0,0 @@
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
- ]
@@ -1,36 +0,0 @@
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
- ]
@@ -1,18 +0,0 @@
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
- ]
@@ -1,8 +0,0 @@
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
- ]
@@ -1,3 +0,0 @@
1
- {
2
- "k001": "v001"
3
- }
@@ -1,48 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Smartdc::Api::Analytics do
4
-
5
- let(:object) {Object.new}
6
- let(:request) {Smartdc::Request}
7
- let(:analytics) {Smartdc::Api::Analytics.new({})}
8
-
9
- describe ".create" do
10
- it "creates a instrumentation" do
11
- object.stub(:content) {fixture('analytics')[0]}
12
- analytic = object.content
13
- request.stub_chain(:new, :post).with('my/analytics/instrumentations/', analytic) {object}
14
-
15
- expect(analytics.create(analytic).content['id']).to eq(analytic['id'])
16
- end
17
- end
18
-
19
- describe ".read" do
20
- it "returns a instrumentation" do
21
- object.stub(:content) {fixture('analytics')[0]}
22
- id = object.content['id']
23
- request.stub_chain(:new, :get).with('my/analytics/instrumentations/' + id) {object}
24
-
25
- expect(analytics.read(id).content['id']).to eq(id)
26
- end
27
- end
28
-
29
- describe ".all" do
30
- it "returns some instrumentations" do
31
- object.stub(:content) {fixture('analytics')}
32
- request.stub_chain(:new, :get).with('my/analytics/instrumentations', {}) {object}
33
-
34
- expect(analytics.all.content.count).to be > 0
35
- end
36
- end
37
-
38
- describe ".destroy" do
39
- it "returns true when success" do
40
- analytic = fixture('analytics')[0]
41
- object.stub(:status) {204}
42
- request.stub_chain(:new, :del).with('my/analytics/instrumentations/' + analytic['id']) {object}
43
-
44
- expect(analytics.destroy(analytic['id']).status).to eq(204)
45
- end
46
- end
47
-
48
- end
@@ -1,28 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Smartdc::Api::Datacenters do
4
-
5
- let(:object) {Object.new}
6
- let(:request) {Smartdc::Request}
7
- let(:datacenters) {Smartdc::Api::Datacenters.new({})}
8
-
9
- describe ".read" do
10
- it "returns a datacenter" do
11
- object.stub(:content) {fixture('datacenter')}
12
- name = fixture('datacenters').first[0]
13
- request.stub_chain(:new, :get).with('my/datacenters/' + name) {object}
14
-
15
- expect(datacenters.read(name).content['message']).to match(/#{name}/)
16
- end
17
- end
18
-
19
- describe ".all" do
20
- it "returns some datacenter" do
21
- object.stub(:content) {fixture('datacenters')}
22
- request.stub_chain(:new, :get).with('my/datacenters', {}) {object}
23
-
24
- expect(datacenters.all.content.count).to be > 0
25
- end
26
- end
27
-
28
- end
@@ -1,28 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Smartdc::Api::Datasets do
4
-
5
- let(:object) {Object.new}
6
- let(:request) {Smartdc::Request}
7
- let(:datasets) {Smartdc::Api::Datasets.new({})}
8
-
9
- describe ".read" do
10
- it "returns a dataset" do
11
- object.stub(:content) {fixture('datasets')[0]}
12
- id = object.content['id']
13
- request.stub_chain(:new, :get).with('my/datasets/' + id) {object}
14
-
15
- expect(datasets.read(id).content['id']).to eq(id)
16
- end
17
- end
18
-
19
- describe ".all" do
20
- it "returns some datasets" do
21
- object.stub(:content) {fixture('datasets')}
22
- request.stub_chain(:new, :get).with('my/datasets', {}) {object}
23
-
24
- expect(datasets.all.content.count).to be > 0
25
- end
26
- end
27
-
28
- end
@@ -1,48 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Smartdc::Api::Keys do
4
-
5
- let(:object) {Object.new}
6
- let(:request) {Smartdc::Request}
7
- let(:keys) {Smartdc::Api::Keys.new({})}
8
-
9
- describe ".create" do
10
- it "creates a key" do
11
- object.stub(:content) {fixture('keys')[0]}
12
- key = object.content
13
- request.stub_chain(:new, :post).with('my/keys/', key) {object}
14
-
15
- expect(keys.create(key).content['name']).to eq(key['name'])
16
- end
17
- end
18
-
19
- describe ".read" do
20
- it "returns a key" do
21
- object.stub(:content) {fixture('keys')[0]}
22
- name = object.content['name']
23
- request.stub_chain(:new, :get).with('my/keys/' + name) {object}
24
-
25
- expect(keys.read(name).content['name']).to eq(name)
26
- end
27
- end
28
-
29
- describe ".all" do
30
- it "returns some keys" do
31
- object.stub(:content) {fixture('keys')}
32
- request.stub_chain(:new, :get).with('my/keys', {}) {object}
33
-
34
- expect(keys.all.content.count).to be > 1
35
- end
36
- end
37
-
38
- describe ".destroy" do
39
- it "returns true when success" do
40
- key = fixture('keys')[0]
41
- object.stub(:status) {204}
42
- request.stub_chain(:new, :del).with('my/keys/' + key['name']) {object}
43
-
44
- expect(keys.destroy(key['name']).status).to eq(204)
45
- end
46
- end
47
-
48
- end
@@ -1,38 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Smartdc::Api::Machine::Metadata do
4
-
5
- let(:object) {Object.new}
6
- let(:request) {Smartdc::Request}
7
- let(:metadata) {Smartdc::Api::Machine::Metadata.new('id', {})}
8
-
9
- describe ".create" do
10
- it "creates a metadata" do
11
- object.stub(:content) {fixture('tag')}
12
- tag = object.content
13
- request.stub_chain(:new, :post).with('my/machines/id/metadata/', tag) {object}
14
-
15
- expect(metadata.create(tag).content).to eq(tag)
16
- end
17
- end
18
-
19
- describe ".read" do
20
- it "return some metadata" do
21
- object.stub(:content) {fixture('tag')}
22
- request.stub_chain(:new, :get).with('my/machines/id/metadata', {}) {object}
23
-
24
- expect(metadata.read.content.count).to be > 0
25
- end
26
- end
27
-
28
- describe ".destroy" do
29
- it "return a metadata" do
30
- object.stub(:status) {204}
31
- key = fixture('tag').first[0]
32
- request.stub_chain(:new, :del).with('my/machines/id/metadata/' + key) {object}
33
-
34
- expect(metadata.destroy(key).status).to eq(204)
35
- end
36
- end
37
-
38
- end
@@ -1,48 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Smartdc::Api::Machine::Snapshots do
4
-
5
- let(:object) {Object.new}
6
- let(:request) {Smartdc::Request}
7
- let(:snapshots) {Smartdc::Api::Machine::Snapshots.new('id', {})}
8
-
9
- describe ".create" do
10
- it "creates a snapshot" do
11
- object.stub(:content) {fixture('snapshots')[0]}
12
- snapshot = object.content
13
- request.stub_chain(:new, :post).with('my/machines/id/snapshots/', snapshot) {object}
14
-
15
- expect(snapshots.create(snapshot).content['name']).to eq(snapshot['name'])
16
- end
17
- end
18
-
19
- describe ".read" do
20
- it "return a snapshot" do
21
- object.stub(:content) {fixture('snapshots')[0]}
22
- name = object.content['name']
23
- request.stub_chain(:new, :get).with('my/machines/id/snapshots/' + name) {object}
24
-
25
- expect(snapshots.read(name).content['name']).to eq(name)
26
- end
27
- end
28
-
29
- describe ".all" do
30
- it "return some snapshots" do
31
- object.stub(:content) {fixture('snapshots')}
32
- request.stub_chain(:new, :get).with('my/machines/id/snapshots', {}) {object}
33
-
34
- expect(snapshots.all.content.count).to be > 0
35
- end
36
- end
37
-
38
- describe ".destroy" do
39
- it "return a snapshot" do
40
- object.stub(:status) {204}
41
- name = fixture('snapshots')[0]['name']
42
- request.stub_chain(:new, :del).with('my/machines/id/snapshots/' + name) {object}
43
-
44
- expect(snapshots.destroy(name).status).to eq(204)
45
- end
46
- end
47
-
48
- end