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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 43aca47bac65dbbea7f700de8a255dad549a2c4c
4
+ data.tar.gz: f08ee46200f3a180d6275d64ff3a8d441bf1d045
5
+ SHA512:
6
+ metadata.gz: d59373cf0eed55bf36af8aa155fedf954c5c5e02c7b9516b87de3e2b034756be6037b0b29edffe32978118faf00d04a394e04fc8c0dc0d1f06d0787e729dddd0
7
+ data.tar.gz: 5f5299ad3d49c477b8367188f9440c70b38116e6294ae34caa81cac367d03c31bf3c0c602af5f29fe123f92547e6d6c63b724f2659b39604284b1dc64012868e
data/.gitignore CHANGED
@@ -1,24 +1,6 @@
1
- *.gem
2
- *.rbc
3
1
  .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
2
  pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
3
  tmp
18
-
19
- .DS_Store
20
4
  .rspec
21
5
  .sdccfg
22
- .sdccfg.*
23
-
24
- sftp-config.json
6
+ Gemfile.lock
@@ -1,6 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - 2.1.0
3
4
  - 2.0.0
4
- - 1.9.3
5
5
  gemfile:
6
6
  - Gemfile
data/Gemfile CHANGED
@@ -1,17 +1,11 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
- gem "rake"
4
-
5
- group :development do
6
- gem "bundler"
7
- end
3
+ gemspec
8
4
 
9
5
  group :test do
10
- gem "rspec", ">= 2.11"
6
+ gem 'rspec'
11
7
  end
12
8
 
13
- group :runtime do
14
- gem "faraday", "~> 0.8"
15
- gem "thor", "~> 0.18"
16
- gem "terminal-table", "~> 1.4"
9
+ group :development, :test do
10
+ gem 'webmock'
17
11
  end
data/README.md CHANGED
@@ -3,27 +3,16 @@ smartdc
3
3
 
4
4
  [![Gem Version](https://badge.fury.io/rb/smartdc.png)](https://rubygems.org/gems/smartdc) [![Build Status](https://travis-ci.org/ogom/ruby-smartdc.png?branch=master)](https://travis-ci.org/ogom/ruby-smartdc)
5
5
 
6
+ [Joyent CloudAPI](https://apidocs.joyent.com/cloudapi/) client and command line interface.
7
+
6
8
  ```
7
9
  .
8
10
  |
9
11
  .-. .--. .-.| .-.
10
- : + : `--.( | (
12
+ : + : `--.( | (
11
13
  `-' `--' `-'`- `-'
12
-
13
14
  ```
14
15
 
15
- smartdc is Joyent's [SmartDataCenter](http://www.joyent.com/software/smartdatacenter) client and SDC Command Line Interface.
16
- [Joyent CloudAPI Documentation](http://apidocs.joyent.com/sdcapidoc/cloudapi/).
17
-
18
-
19
- ## Features
20
-
21
- * Response content is Hash.
22
- * Debug output Request and Response.
23
- * Output style is Table or JSON.
24
- * CLI is sub command style.
25
-
26
-
27
16
  ## Installation
28
17
 
29
18
  ```
@@ -33,57 +22,53 @@ gem install smartdc
33
22
  ## Usage
34
23
 
35
24
  ### CLI
25
+
36
26
  Invoke interactive configuration.
37
27
 
28
+ #### Creates machine
29
+
38
30
  ```
39
31
  $ sdc init
40
- $ sdc dataset ls
41
- $ sdc package ls
42
- $ sdc machine add NAME -e DATASET_URN -p PACKAGE_NAME
43
- $ sdc machine ls
32
+ $ sdc image list
33
+ $ sdc package list
34
+ $ sdc machine add NAME -i IMAGE_ID -p PACKAGE_ID
35
+ $ sdc machine list
44
36
  ```
45
37
 
46
-
47
38
  #### Output JSON
39
+
48
40
  JSON is set to body of response.
49
41
 
50
42
  ```
51
- $ sdc machine ls --raw
43
+ $ sdc machine list --raw
52
44
  ```
53
45
 
46
+ #### Use machine
54
47
 
55
- #### Machine use
56
48
  Set to config the Machine uuid.
57
49
 
58
50
  ```
59
- $ sdc machine ls
60
- $ sdc machine get UUID
61
- $ sdc machine use UUID
62
- $ sdc machine get
51
+ $ sdc machine list
52
+ $ sdc machine show MACHINE_ID
53
+ $ sdc machine use MACHINE_ID
54
+ $ sdc machine show
63
55
  ```
64
56
 
57
+ #### Receives machine
65
58
 
66
- ### Program
67
59
  Hash is set to content of response.
68
60
 
69
61
  ```
70
62
  require 'smartdc'
71
63
 
72
- client = Smartdc.new({
73
- hostname: 'example.com',
74
- username: 'auth_user',
75
- password: 'auth_pass',
76
- version: '~6.5'
77
- })
78
-
79
- client.machines.all.content.each do |machine|
80
- p "#{machine['name']} is state at #{machine['state']}."
81
-
82
- # Stop machine
83
- p client.machines.stop(machine['id']).status
64
+ Smartdc.configure do |config|
65
+ config.url = 'https://example.com'
66
+ config.username = 'user'
67
+ config.use_key = '4c:02:f3:b2:09:fb:29:dd:41:97:da:80:bc:69:6c:f8'
84
68
  end
85
- ```
86
69
 
70
+ Smartdc.machines.content
71
+ ```
87
72
 
88
73
  ## Tests
89
74
 
@@ -91,6 +76,6 @@ end
91
76
  $ rake spec
92
77
  ```
93
78
 
94
- ## License
79
+ ## License
95
80
 
96
81
  * MIT
data/Rakefile CHANGED
@@ -1,9 +1,9 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
2
 
3
- require 'rspec/core'
4
3
  require 'rspec/core/rake_task'
5
- RSpec::Core::RakeTask.new(:spec) do |spec|
6
- spec.pattern = FileList['spec/**/*_spec.rb']
4
+ RSpec::Core::RakeTask.new(:spec) do |task|
5
+ task.rspec_opts = ['--color', '--format', 'doc']
7
6
  end
8
7
 
9
- task :default => :spec
8
+ task test: :spec
9
+ task default: :spec
data/bin/sdc CHANGED
@@ -1,383 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
- #
3
- # sdc
4
- # Copyright(c) 2012 ogom
5
- # MIT Licensed
6
- #
7
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
8
- require 'cli_helper'
9
2
 
10
- module CLI
11
- def self.ip(uuid)
12
- res = sdc(config).machines.read(uuid)
13
- if res.status == 200
14
- res.content['primaryIp']
15
- else
16
- uuid
17
- end
18
- end
3
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
4
+ require 'smartdc'
5
+ require 'smartdc/cli'
19
6
 
20
- class Base < Thor
21
- class_option :debug, type: :boolean, aliases: '-d', desc: 'Debug output'
22
- class_option :raw, type: :boolean, aliases: '-r', desc: 'Raw response body'
23
- end
24
-
25
- class Key < CLI::Base
26
- desc 'ls', 'Lists all public keys we have on record for the specified account.'
27
- def ls
28
- output sdc(config(options)).keys.all, {table: :h, exclude: [:key]}.merge(options)
29
- end
30
-
31
- desc 'get [NAME]', 'Retrieves an individual key record.'
32
- def get(name)
33
- output sdc(config(options)).keys.read(name), {only: :key}.merge(options)
34
- end
35
-
36
- desc 'add [NAME] [FILE]', 'Uploads a new OpenSSH key to SmartDataCenter.'
37
- def add(name, file)
38
- raw = {name: name}
39
- raw[:key] = File.read(file)
40
- output sdc(config(options)).keys.create(raw), {table: :v, exclude: [:key]}.merge(options)
41
- end
42
-
43
- desc 'del [NAME]', 'Deletes an SSH key by name.'
44
- def del(name)
45
- output sdc(config(options)).keys.destroy(name), {message: "Key #{name} deleted."}.merge(options)
46
- end
47
- end
48
-
49
- class Datacenter < CLI::Base
50
- desc 'ls', 'Provides a list of all datacenters this cloud is aware of.'
51
- def ls
52
- output sdc(config(options)).datacenters.all, {table: :v}.merge(options)
53
- end
54
-
55
- desc 'get [NAME]', 'Gets an individual datacenter by name.'
56
- def get(name)
57
- output sdc(config(options)).datacenters.read(name), {table: :v}.merge(options)
58
- end
59
- end
60
-
61
- class Dataset < CLI::Base
62
- desc 'ls', 'Provides a list of datasets available in this datacenter.'
63
- def ls
64
- include = [:id, :name, :urn, :version, :os]
65
- output sdc(config(options)).datasets.all, {table: :h, include: include}.merge(options)
66
- end
67
-
68
- desc 'get [ID]', 'Gets an individual dataset by id.'
69
- def get(id)
70
- output sdc(config(options)).datasets.read(id), {table: :v}.merge(options)
71
- end
72
- end
73
-
74
- class Package < CLI::Base
75
- desc 'ls', 'Provides a list of packages available in this datacenter.'
76
- def ls
77
- output sdc(config(options)).packages.all, {table: :h}.merge(options)
78
- end
79
-
80
- desc 'get [NAME]', 'Gets a package by name.'
81
- def get(name)
82
- output sdc(config(options)).packages.read(name), {table: :v}.merge(options)
83
- end
84
- end
85
-
86
- class Tag < CLI::Base
87
- class_option :uuid, type: :string, aliases: '-u', desc: 'Machine uuid'
88
-
89
- desc 'ls', 'Returns the complete set of tags associated with this machine.'
90
- def ls
91
- uuid = options.uuid.nil? ? config[:use_machine] : options.uuid
92
- output sdc(config(opt(ARGV, options))).machines.tags(uuid).all, {table: :v}.merge(opt(ARGV, options))
93
- end
94
-
95
- desc 'get [KEY]', 'Returns the value for a single tag on this machine.'
96
- def get(key)
97
- uuid = options.uuid.nil? ? config[:use_machine] : options.uuid
98
- output sdc(config(opt(ARGV, options))).machines.tags(uuid).read(key), {'raw' => true}.merge(opt(ARGV, options))
99
- end
100
-
101
- desc 'set [KEY] [VALUE]', 'Allows you to set the tags for a given machine.'
102
- def set(key, value)
103
- uuid = options.uuid.nil? ? config[:use_machine] : options.uuid
104
- output sdc(config(opt(ARGV, options))).machines.tags(uuid).create({key => value}), {table: :v}.merge(opt(ARGV, options))
105
- end
106
-
107
- desc 'del [KEY]', 'Deletes tag from this machine.'
108
- method_option :all, type: :boolean, desc: 'All tags delete.'
109
- def del(key=nil)
110
- uuid = options.uuid.nil? ? config[:use_machine] : options.uuid
111
- if key.nil?
112
- if options.all
113
- msg = "Machine #{CLI.ip(uuid)} all tags deleted."
114
- output sdc(config(opt(ARGV, options))).machines.tags(uuid).destroy, {message: msg}.merge(opt(ARGV, options))
115
- end
116
- else
117
- msg = "Machine #{CLI.ip(uuid)} tag #{key} deleted."
118
- output sdc(config(opt(ARGV, options))).machines.tags(uuid).destroy(key), {message: msg}.merge(opt(ARGV, options))
119
- end
120
- end
121
- end
122
-
123
- class Meta < CLI::Base
124
- class_option :uuid, type: :string, aliases: '-u', desc: 'Machine uuid'
125
-
126
- desc 'ls', 'Returns the complete set of metadata associated with this machine.'
127
- method_option :credentials, type: :boolean, aliases: '-c', desc: 'Only output the machine credentials.'
128
- def ls
129
- uuid = options.uuid.nil? ? config[:use_machine] : options.uuid
130
- res = sdc(config(opt(ARGV, options))).machines.metadata(uuid).read(options)
131
- res.content = res.content['credentials'].to_json if options.credentials
132
- output res, {table: :v}.merge(opt(ARGV, options))
133
- end
134
-
135
- desc 'set [KEY] [VALUE]', 'Allows you to set the metadata for a given machine.'
136
- def set(key, value)
137
- uuid = options.uuid.nil? ? config[:use_machine] : options.uuid
138
- output sdc(config(opt(ARGV, options))).machines.metadata(uuid).create({key => value}), {table: :v}.merge(opt(ARGV, options))
139
- end
140
-
141
- desc 'push [KEY] [FILE]', 'Push the metadata from file. (user-script or user-data)'
142
- def push(key, file)
143
- uuid = options.uuid.nil? ? config[:use_machine] : options.uuid
144
- value = File.read(file)
145
- output sdc(config(opt(ARGV, options))).machines.metadata(uuid).create({key => value}), {table: :v}.merge(opt(ARGV, options))
146
- end
147
-
148
- desc 'del [KEY]', 'Deletes metadata key from this machine.'
149
- method_option :all, type: :boolean, desc: 'All metadata delete.'
150
- def del(key=nil)
151
- uuid = options.uuid.nil? ? config[:use_machine] : options.uuid
152
- if key.nil?
153
- if options.all
154
- msg = "Machine #{CLI.ip(uuid)} all metadata deleted."
155
- output sdc(config(opt(ARGV, options))).machines.metadata(uuid).destroy, {message: msg}.merge(opt(ARGV, options))
156
- end
157
- else
158
- msg = "Machine #{CLI.ip(uuid)} metadata #{key} deleted."
159
- output sdc(config(opt(ARGV, options))).machines.metadata(uuid).destroy(key), {message: msg}.merge(opt(ARGV, options))
160
- end
161
- end
162
- end
163
-
164
- class Snapshot < CLI::Base
165
- class_option :uuid, type: :string, aliases: '-u', desc: 'Machine uuid'
166
-
167
- desc 'ls', 'Lists all snapshots taken for a given machine.'
168
- def ls
169
- uuid = options.uuid.nil? ? config[:use_machine] : options.uuid
170
- output sdc(config(opt(ARGV, options))).machines.snapshots(uuid).all, {table: :h}.merge(opt(ARGV, options))
171
- end
172
-
173
- desc 'get [NAME]', 'Gets the state of the named snapshot.'
174
- def get(name)
175
- uuid = options.uuid.nil? ? config[:use_machine] : options.uuid
176
- output sdc(config(opt(ARGV, options))).machines.snapshots(uuid).read(name), {table: :v}.merge(opt(ARGV, options))
177
- end
178
-
179
- desc 'add [NAME]', 'Allows you to take a snapshot of a machine.'
180
- def add(name)
181
- uuid = options.uuid.nil? ? config[:use_machine] : options.uuid
182
- output sdc(config(opt(ARGV, options))).machines.snapshots(uuid).create({name: name}), {table: :v}.merge(opt(ARGV, options))
183
- end
184
-
185
- desc 'del [NAME]', 'Deletes the specified snapshot of a machine.'
186
- def del(name)
187
- uuid = options.uuid.nil? ? config[:use_machine] : options.uuid
188
- msg = "Machine #{CLI.ip(uuid)} snapshots #{name} deleted."
189
- output sdc(config(opt(ARGV, options))).machines.snapshots(uuid).destroy(name), {message: msg}.merge(opt(ARGV, options))
190
- end
191
-
192
- desc 'start [NAME]', 'Starts a stopped machine from the referenced snapshot.'
193
- def start(name)
194
- uuid = options.uuid.nil? ? config[:use_machine] : options.uuid
195
- msg = "Machine #{CLI.ip(uuid)} snapshots #{name} started."
196
- output sdc(config(opt(ARGV, options))).machines.snapshots(uuid).start(name), {message: msg}.merge(opt(ARGV, options))
197
- end
198
- end
199
-
200
- class Machine < CLI::Base
201
- desc 'ls', 'Lists all machines on record for an account.'
202
- method_option :type, type: :string, aliases: '-t', desc: 'virtualmachine or smartmachine'
203
- method_option :state, type: :string, aliases: '-s', desc: 'running or stopped'
204
- def ls
205
- include = [:id, :dataset, :primaryIp, :state]
206
- output sdc(config(options)).machines.all(options), {table: :h, include: include}.merge(options)
207
- end
208
-
209
- desc 'get [UUID]', 'Gets the details for an individual machine.'
210
- def get(uuid=nil)
211
- uuid ||= config[:use_machine]
212
- output sdc(config(options)).machines.read(uuid), {table: :v}.merge(options)
213
- end
214
-
215
- desc 'add [NAME]', 'Allows you to provision a machine.'
216
- method_option :dataset, type: :string, aliases: '-e', desc: 'dataset URN; default is indicated in ListDatasets'
217
- method_option :package, type: :string, aliases: '-p', desc: 'Name of the package to use on provisioning; default is indicated in ListPackages'
218
- def add(name)
219
- output sdc(config(options)).machines.create({name: name}.merge(options)), {table: :v}.merge(options)
220
- end
221
-
222
- desc 'del [UUID]', 'Allows you to completely destroy a machine.'
223
- def del(uuid=nil)
224
- uuid ||= config[:use_machine]
225
- output sdc(config(options)).machines.destroy(uuid), {message: "Machine #{CLI.ip(uuid)} deleted."}.merge(options)
226
- end
227
-
228
- desc 'stop [UUID]', 'Allows you to shut down a machine.'
229
- method_option :all, type: :boolean, desc: 'All machine stop.'
230
- def stop(uuid=nil)
231
- if options.all
232
- sdc(config(options)).machines.all({state: 'running'}).content.each do |machine|
233
- output sdc(config(options)).machines.stop(machine['id']), {message: "Machine #{machine['primaryIp']} stoped."}.merge(options)
234
- end
235
- else
236
- uuid ||= config[:use_machine]
237
- output sdc(config(options)).machines.stop(uuid), {message: "Machine #{CLI.ip(uuid)} stoped."}.merge(options)
238
- end
239
- end
240
-
241
- desc 'start [UUID]', 'Allows you to boot up a machine.'
242
- method_option :all, type: :boolean, desc: 'All machine start.'
243
- def start(uuid=nil)
244
- if options.all
245
- sdc(config(options)).machines.all({state: 'stopped'}).content.each do |machine|
246
- output sdc(config(options)).machines.start(machine['id']), {message: "Machine #{machine['primaryIp']} started."}.merge(options)
247
- end
248
- else
249
- uuid ||= config[:use_machine]
250
- output sdc(config(options)).machines.start(uuid), {message: "Machine #{CLI.ip(uuid)} started."}.merge(options)
251
- end
252
- end
253
-
254
- desc 'reboot [UUID]', 'Allows you to reboot a machine.'
255
- def reboot(uuid=nil)
256
- uuid ||= config[:use_machine]
257
- output sdc(config(options)).machines.reboot(uuid), {message: "Machine #{CLI.ip(uuid)} reboot."}.merge(options)
258
- end
259
-
260
- desc 'resize [UUID]', 'Allows you to resize a SmartMachine.'
261
- method_option :package, type: :string, aliases: '-p', desc: 'Use a package name returned from ListPackages'
262
- def resize(uuid=nil)
263
- uuid ||= config[:use_machine]
264
- output sdc(config(options)).machines.resize(uuid, {}.merge(options)), {message: "Machine #{CLI.ip(uuid)} resize."}.merge(options)
265
- end
266
-
267
- desc 'use [UUID]', 'Use machine.'
268
- def use(uuid=nil)
269
- config = Configure.read
270
- if uuid.nil?
271
- puts "use #{config[:use_machine]}"
272
- else
273
- config[:use_machine] = uuid
274
- Configure.write config
275
- end
276
- end
277
-
278
- register(Tag, 'tag', 'tag [COMMAND]', 'Machine tag')
279
- register(Meta, 'meta', 'meta [COMMAND]', 'Machine metadata')
280
- register(Snapshot, 'snapshot', 'snapshot [COMMAND]', 'Machine snapshot')
281
- end
282
-
283
- class Analytic < CLI::Base
284
- desc 'desc', 'Retrieves the schema for instrumentations.'
285
- method_option :all, type: :boolean, desc: 'All describe.'
286
- method_option :output, type: :string, :default => 'metrics', aliases: '-o', desc: 'Only output the modules or fields or types or metrics or transformations.'
287
- def desc
288
- if options['raw']
289
- puts sdc(config(options)).analytics.describe.body
290
- else
291
- content = sdc(config(options)).analytics.describe.content
292
- describe('modules', content, {cols: ['key', 'label']}.merge(options))
293
- describe('fields', content, {cols: ['key', 'label', 'type']}.merge(options))
294
- describe('types', content, {cols: ['key', 'name', 'arity', 'unit', 'abbr', 'base', 'power']}.merge(options))
295
- describe('metrics', content, {cols: :all, exclude: [:fields]}.merge(options))
296
- describe('transformations', content, {cols: ['key', 'label']}.merge(options))
297
- end
298
- end
299
-
300
- desc 'ls', 'Retrieves all currently created instrumentations.'
301
- def ls
302
- include = ['id', 'module', 'stat', 'decomposition']
303
- output sdc(config(options)).analytics.all, {table: :h, include: include}.merge(options)
304
- end
305
-
306
- desc 'get [ID]', 'Retrieves the configuration for an instrumentation.'
307
- method_option :value, type: :boolean, aliases: '-v', desc: 'Analytic value.'
308
- def get(id)
309
- if options[:value]
310
- output sdc(config(options)).analytics.value(id), {table: :v}.merge(options)
311
- else
312
- output sdc(config(options)).analytics.read(id), {table: :v, exclude: ['uris']}.merge(options)
313
- end
314
- end
315
-
316
- desc 'add [NAME]', 'Creates an instrumentation.'
317
- method_option :module, type: :string, aliases: '-m', desc: 'The Cloud analytics module'
318
- method_option :stat, type: :string, aliases: '-s', desc: 'The Cloud analytics stat'
319
- def add
320
- output sdc(config(options)).analytics.create(options), {table: :v, exclude: ['uris']}.merge(options)
321
- end
322
-
323
- desc 'del [ID]', 'Destroys an instrumentation.'
324
- def del(id)
325
- output sdc(config(opt(ARGV, options))).analytics.destroy(id), {message: "Analytic #{id} deleted"}.merge(opt(ARGV, options))
326
- end
327
-
328
- desc 'heatmap [ID]', 'Retrieves a particular instrumentation heatmap.'
329
- method_option :image, type: :boolean, aliases: '-i', desc: 'Heatmap image file.'
330
- method_option :x, type: :numeric, aliases: '-x', desc: 'X-Axis'
331
- method_option :y, type: :numeric, aliases: '-y', desc: 'Y-Axis'
332
- def heatmap(id)
333
- if options[:image]
334
- output sdc(config(options)).analytics.heatmap(id).image, {table: :v, exclude: ['image', 'present']}.merge(options)
335
- else
336
- client = sdc(config(options))
337
- content = client.analytics.heatmap(id).image.content
338
- query = {'ymin' => content['ymin'], 'ymax' => content['ymax']}
339
- output client.analytics.heatmap(id).details(query.merge(options)), {table: :v}.merge(options)
340
- end
341
- end
342
- end
343
-
344
- class Main < Thor
345
- desc 'init', 'Sets up an account on a datacenter for use with this CLI.'
346
- def init
347
- message = ['Successful configuration.', 'Failed Configuration.']
348
- state = 0
349
-
350
- Configure.init
351
- res = sdc(config).keys.all
352
- if res.status == 200
353
- rsa_path = Configure.key(res.content)
354
- config = Configure.read
355
- if rsa_path
356
- raw = {name: config[:use_key], key: File.read(rsa_path)}
357
- res = sdc(config).keys.create(raw)
358
- state = 1 if res.status != 201
359
- config.delete(:password)
360
- else
361
- config.delete(:password)
362
- res = sdc(config).keys.read(config[:use_key])
363
- state = 1 if res.status != 200
364
- end
365
- Configure.write config
366
- else
367
- state = 1
368
- end
369
-
370
- msg = res.content['message'] + '.' if state == 1
371
- puts "#{message[state]} #{msg}"
372
- end
373
-
374
- register(Key, 'key', 'key [COMMAND]', 'SSH key')
375
- register(Datacenter, 'datacenter', 'datacenter [COMMAND]', 'Smart Data Center')
376
- register(Dataset, 'dataset', 'dataset [COMMAND]', 'Machine operating system')
377
- register(Package, 'package', 'package [COMMAND]', 'Machine resources')
378
- register(Machine, 'machine', 'machine [COMMAND]', 'Virtual machine')
379
- register(Analytic, 'analytic', 'analytic [COMMAND]', 'DTrace analytics')
380
- end
381
- end
382
-
383
- CLI::Main.start
7
+ Smartdc::Cli::Main.start