smartdc 0.4.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +0 -1
- data/.travis.yml +5 -0
- data/Gemfile +7 -10
- data/README.md +42 -69
- data/Rakefile +47 -0
- data/VERSION +1 -1
- data/bin/sdc +327 -0
- data/lib/cli_helper.rb +131 -8
- data/lib/configure.rb +73 -0
- data/lib/smartdc.rb +16 -1
- data/lib/smartdc/api/analytics.rb +29 -7
- data/lib/smartdc/api/analytics/heatmap.rb +20 -0
- data/lib/smartdc/api/datacenters.rb +6 -7
- data/lib/smartdc/api/datasets.rb +6 -7
- data/lib/smartdc/api/keys.rb +10 -11
- data/lib/smartdc/api/machine/metadata.rb +9 -15
- data/lib/smartdc/api/machine/snapshots.rb +16 -16
- data/lib/smartdc/api/machine/tags.rb +11 -12
- data/lib/smartdc/api/machines.rb +23 -23
- data/lib/smartdc/api/packages.rb +7 -8
- data/lib/smartdc/client.rb +14 -18
- data/lib/smartdc/request.rb +41 -51
- data/lib/smartdc/response.rb +24 -0
- data/lib/smartdc/response/raise_error.rb +1 -1
- data/smartdc.gemspec +51 -90
- data/spec/fixtures/analytics.json +26 -0
- data/spec/fixtures/datacenter.json +4 -0
- data/spec/fixtures/datacenters.json +3 -0
- data/spec/fixtures/datasets.json +38 -0
- data/spec/fixtures/keys.json +14 -0
- data/spec/fixtures/machines.json +36 -0
- data/spec/fixtures/packages.json +18 -0
- data/spec/fixtures/snapshots.json +8 -0
- data/spec/fixtures/tag.json +3 -0
- data/spec/spec_helper.rb +3 -12
- data/spec/unit/smartdc/api/analytics_spec.rb +53 -0
- data/spec/unit/smartdc/api/datacenters_spec.rb +31 -0
- data/spec/unit/smartdc/api/datasets_spec.rb +31 -0
- data/spec/unit/smartdc/api/keys_spec.rb +53 -0
- data/spec/unit/smartdc/api/machine/metadata_spec.rb +42 -0
- data/spec/unit/smartdc/api/machine/snapshots_spec.rb +132 -0
- data/spec/unit/smartdc/api/machine/tags_spec.rb +53 -0
- data/spec/unit/smartdc/api/machines_spec.rb +53 -0
- data/spec/unit/smartdc/api/packages_spec.rb +31 -0
- data/spec/{smartdc → unit/smartdc}/client_spec.rb +0 -6
- data/spec/{smartdc_spec.rb → unit/smartdc_spec.rb} +1 -1
- metadata +72 -140
- data/LICENSE.md +0 -20
- data/bin/sdc-addmachinemetadata +0 -29
- data/bin/sdc-addmachinetag +0 -29
- data/bin/sdc-createinstrumentation +0 -27
- data/bin/sdc-createkey +0 -32
- data/bin/sdc-createmachine +0 -39
- data/bin/sdc-createmachinesnapshot +0 -27
- data/bin/sdc-deleteinstrumentation +0 -12
- data/bin/sdc-deletekey +0 -12
- data/bin/sdc-deletemachine +0 -12
- data/bin/sdc-deletemachinemetadata +0 -29
- data/bin/sdc-deletemachinesnapshot +0 -29
- data/bin/sdc-deletemachinetag +0 -29
- data/bin/sdc-describeanalytics +0 -10
- data/bin/sdc-getdatacenter +0 -10
- data/bin/sdc-getdataset +0 -10
- data/bin/sdc-getinstrumentation +0 -31
- data/bin/sdc-getkey +0 -10
- data/bin/sdc-getmachine +0 -12
- data/bin/sdc-getmachinemetadata +0 -12
- data/bin/sdc-getmachinesnapshot +0 -27
- data/bin/sdc-getmachinetag +0 -27
- data/bin/sdc-getpackage +0 -10
- data/bin/sdc-listdatacenters +0 -10
- data/bin/sdc-listdatasets +0 -10
- data/bin/sdc-listinstrumentations +0 -10
- data/bin/sdc-listkeys +0 -10
- data/bin/sdc-listmachines +0 -10
- data/bin/sdc-listmachinesnapshots +0 -10
- data/bin/sdc-listmachinetags +0 -10
- data/bin/sdc-listpackages +0 -10
- data/bin/sdc-rebootmachine +0 -12
- data/bin/sdc-resizemachine +0 -34
- data/bin/sdc-setup +0 -67
- data/bin/sdc-startmachine +0 -12
- data/bin/sdc-startmachinefromsnapshot +0 -29
- data/bin/sdc-stopmachine +0 -12
- data/config/fixtures/instrumentation.json +0 -4
- data/config/fixtures/key.json +0 -4
- data/config/fixtures/tag.json +0 -3
- data/lib/smartdc/api/analytics/instrumentations.rb +0 -44
- data/lib/smartdc/response/mashify.rb +0 -29
- data/lib/smartdc/response/parse_json.rb +0 -26
- data/spec/smartdc/api/analytics_spec.rb +0 -32
- data/spec/smartdc/api/datacenters_spec.rb +0 -16
- data/spec/smartdc/api/datasets_spec.rb +0 -16
- data/spec/smartdc/api/keys_spec.rb +0 -32
- data/spec/smartdc/api/machine/metadata_spec.rb +0 -59
- data/spec/smartdc/api/machine/snapshots_spec.rb +0 -70
- data/spec/smartdc/api/machine/tags_spec.rb +0 -65
- data/spec/smartdc/api/machines_spec.rb +0 -92
- data/spec/smartdc/api/packages_spec.rb +0 -16
- data/spec/smartdc/request_spec.rb +0 -12
data/.document
CHANGED
data/.travis.yml
ADDED
data/Gemfile
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
source "http://rubygems.org"
|
|
2
2
|
|
|
3
3
|
group :development do
|
|
4
|
-
gem "
|
|
5
|
-
gem "
|
|
6
|
-
gem "
|
|
7
|
-
gem "rcov", "~> 0.9.11"
|
|
8
|
-
gem "uuid", "~> 2.3.4"
|
|
4
|
+
gem "bundler", "~> 1.1"
|
|
5
|
+
gem "jeweler", "~> 1.8"
|
|
6
|
+
gem "rspec", "~> 2.12"
|
|
9
7
|
end
|
|
10
8
|
|
|
11
9
|
group :runtime do
|
|
12
|
-
gem "faraday", "~> 0.
|
|
13
|
-
gem "
|
|
14
|
-
gem "
|
|
15
|
-
|
|
16
|
-
end
|
|
10
|
+
gem "faraday", "~> 0.8"
|
|
11
|
+
gem "thor", "~> 0.16"
|
|
12
|
+
gem "terminal-table", "~> 1.4"
|
|
13
|
+
end
|
data/README.md
CHANGED
|
@@ -1,87 +1,60 @@
|
|
|
1
|
-
|
|
1
|
+
smartdc
|
|
2
|
+
=======
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
smartdc is Joyent's [SmartDataCenter](http://www.joyent.com/software/smartdatacenter) client and SmartDataCenter Command Line Interface.
|
|
5
|
+
[Joyent CloudAPI Documentation](http://apidocs.joyent.com/sdcapidoc/cloudapi/).
|
|
4
6
|
|
|
7
|
+
## Features
|
|
8
|
+
* Response content is Hash.
|
|
9
|
+
* Debug output Request and Response.
|
|
10
|
+
* Output style is Table or JSON.
|
|
11
|
+
* CLI is sub command style.
|
|
5
12
|
|
|
6
13
|
## Installation
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
14
|
+
```
|
|
15
|
+
gem install smartdc
|
|
16
|
+
```
|
|
10
17
|
|
|
11
18
|
## Usage
|
|
12
19
|
|
|
13
|
-
Get Started with SmartDataCenter [here](http://www.slideshare.net/ogom_/smartdc-by-ruby-10047222).
|
|
14
|
-
|
|
15
|
-
|
|
16
20
|
### CLI
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
"example": "https://example.com"
|
|
27
|
-
}
|
|
28
|
-
|
|
21
|
+
```
|
|
22
|
+
$ sdc init
|
|
23
|
+
$ sdc key add key_name ~/.ssh/id_rsa.pub
|
|
24
|
+
$ sdc dataset ls
|
|
25
|
+
$ sdc package ls
|
|
26
|
+
$ sdc machine add -e DATASET_URN -p PACKAGE_NAME
|
|
27
|
+
$ sdc machine ls
|
|
28
|
+
$ sdc machine ls --raw
|
|
29
|
+
```
|
|
29
30
|
|
|
30
31
|
### Program
|
|
31
32
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
require 'smartdc'
|
|
35
|
-
|
|
36
|
-
config = {
|
|
37
|
-
"url" => "https://example.com/",
|
|
38
|
-
"version" => "~6.5",
|
|
39
|
-
"username" => "auth_user",
|
|
40
|
-
"password" => "auth_pass"
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
client = Smartdc.new(config)
|
|
44
|
-
machines = client.machines.find
|
|
45
|
-
machines.each do |machine|
|
|
46
|
-
puts "machines id: #{machine.id}, state: #{machine.state}"
|
|
47
|
-
machine = client.machines(machine.id)
|
|
48
|
-
|
|
49
|
-
puts 'Stop the machine.'
|
|
50
|
-
machine.stop
|
|
51
|
-
8.times do |i|
|
|
52
|
-
puts "machine(#{i}) id: #{machine.read.id}, state: #{machine.read.state}"
|
|
53
|
-
break if machine.read.state == 'stopped'
|
|
54
|
-
sleep i
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
puts 'Start the machine.'
|
|
58
|
-
machine.start
|
|
59
|
-
8.times do |i|
|
|
60
|
-
puts "machine(#{i}) id: #{machine.read.id}, state: #{machine.read.state}"
|
|
61
|
-
break if machine.read.state == 'running'
|
|
62
|
-
sleep i
|
|
63
|
-
end
|
|
64
|
-
puts
|
|
65
|
-
end
|
|
66
|
-
|
|
33
|
+
```
|
|
34
|
+
require 'smartdc'
|
|
67
35
|
|
|
68
|
-
|
|
36
|
+
client = Smartdc.new({
|
|
37
|
+
hostname: 'example.com',
|
|
38
|
+
username: 'auth_user',
|
|
39
|
+
password: 'auth_pass',
|
|
40
|
+
version: '~6.5'
|
|
41
|
+
})
|
|
69
42
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
# Type of a variable to mash. (Default)
|
|
73
|
-
client.format = 'mash'
|
|
74
|
-
puts client.datacenters.find #=> #<Hashie::Mash example="example.com">
|
|
43
|
+
client.machines.all.content.each do |machine|
|
|
44
|
+
p "#{machine['name']} is state at #{machine['state']}."
|
|
75
45
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
46
|
+
# Stop machine
|
|
47
|
+
p client.machines.stop(machine['id']).status
|
|
48
|
+
end
|
|
49
|
+
```
|
|
79
50
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
51
|
+
## Tests
|
|
52
|
+
```
|
|
53
|
+
$ rake spec
|
|
54
|
+
```
|
|
83
55
|
|
|
56
|
+
[](https://travis-ci.org/ogom/ruby-smartdc)
|
|
84
57
|
|
|
85
|
-
## Copyright
|
|
86
58
|
|
|
87
|
-
|
|
59
|
+
## License
|
|
60
|
+
* MIT
|
data/Rakefile
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'rubygems'
|
|
4
|
+
require 'bundler'
|
|
5
|
+
begin
|
|
6
|
+
Bundler.setup(:default, :development)
|
|
7
|
+
rescue Bundler::BundlerError => e
|
|
8
|
+
$stderr.puts e.message
|
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
|
10
|
+
exit e.status_code
|
|
11
|
+
end
|
|
12
|
+
require 'rake'
|
|
13
|
+
|
|
14
|
+
require 'jeweler'
|
|
15
|
+
Jeweler::Tasks.new do |gem|
|
|
16
|
+
gem.name = "smartdc"
|
|
17
|
+
gem.homepage = "http://github.com/ogom/ruby-smartdc"
|
|
18
|
+
gem.license = "MIT"
|
|
19
|
+
gem.summary = " Joyent SmartDataCenter CloudApi client by ruby."
|
|
20
|
+
gem.description = "SmartDataCenter client and SmartDataCenter Command Line Interface."
|
|
21
|
+
gem.email = "ogom@hotmail.co.jp"
|
|
22
|
+
gem.authors = ["ogom"]
|
|
23
|
+
end
|
|
24
|
+
Jeweler::RubygemsDotOrgTasks.new
|
|
25
|
+
|
|
26
|
+
require 'rspec/core'
|
|
27
|
+
require 'rspec/core/rake_task'
|
|
28
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
|
29
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
|
33
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
|
34
|
+
spec.rcov = true
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
task :default => :spec
|
|
38
|
+
|
|
39
|
+
require 'rdoc/task'
|
|
40
|
+
Rake::RDocTask.new do |rdoc|
|
|
41
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
|
42
|
+
|
|
43
|
+
rdoc.rdoc_dir = 'rdoc'
|
|
44
|
+
rdoc.title = "smartdc #{version}"
|
|
45
|
+
rdoc.rdoc_files.include('README*')
|
|
46
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
47
|
+
end
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.
|
|
1
|
+
1.0.1
|
data/bin/sdc
ADDED
|
@@ -0,0 +1,327 @@
|
|
|
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
|
+
|
|
10
|
+
module CLI
|
|
11
|
+
class Base < Thor
|
|
12
|
+
class_option :debug, type: :boolean, aliases: '-d', desc: 'Debug output'
|
|
13
|
+
class_option :raw, type: :boolean, aliases: '-r', desc: 'Raw response body'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
class Key < CLI::Base
|
|
17
|
+
desc 'ls', 'Lists all public keys we have on record for the specified account.'
|
|
18
|
+
def ls
|
|
19
|
+
output sdc(config(options)).keys.all, {table: :h, exclude: [:key]}.merge(options)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
desc 'get [NAME]', 'Retrieves an individual key record.'
|
|
23
|
+
def get(name)
|
|
24
|
+
output sdc(config(options)).keys.read(name), {only: :key}.merge(options)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
desc 'add [NAME] [FILE]', 'Uploads a new OpenSSH key to SmartDataCenter.'
|
|
28
|
+
def add(name, file)
|
|
29
|
+
raw = {name: name}
|
|
30
|
+
raw[:key] = File.read(file)
|
|
31
|
+
output sdc(config(options)).keys.create(raw), {table: :v, exclude: [:key]}.merge(options)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
desc 'del [NAME]', 'Deletes an SSH key by name.'
|
|
35
|
+
def del(name)
|
|
36
|
+
output sdc(config(options)).keys.destroy(name), {message: "Key #{name} deleted"}.merge(options)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
class Datacenter < CLI::Base
|
|
41
|
+
desc 'ls', 'Provides a list of all datacenters this cloud is aware of.'
|
|
42
|
+
def ls
|
|
43
|
+
output sdc(config(options)).datacenters.all, {table: :v}.merge(options)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
desc 'get [NAME]', 'Gets an individual datacenter by name.'
|
|
47
|
+
def get(name)
|
|
48
|
+
output sdc(config(options)).datacenters.read(name), {table: :v}.merge(options)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
class Dataset < CLI::Base
|
|
53
|
+
desc 'ls', 'Provides a list of datasets available in this datacenter.'
|
|
54
|
+
def ls
|
|
55
|
+
include = [:id, :name, :urn, :version, :os]
|
|
56
|
+
output sdc(config(options)).datasets.all, {table: :h, include: include}.merge(options)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
desc 'get [ID]', 'Gets an individual dataset by id.'
|
|
60
|
+
def get(id)
|
|
61
|
+
output sdc(config(options)).datasets.read(id), {table: :v}.merge(options)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
class Package < CLI::Base
|
|
66
|
+
desc 'ls', 'Provides a list of packages available in this datacenter.'
|
|
67
|
+
def ls
|
|
68
|
+
output sdc(config(options)).packages.all, {table: :h}.merge(options)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
desc 'get [NAME]', 'Gets a package by name.'
|
|
72
|
+
def get(name)
|
|
73
|
+
output sdc(config(options)).packages.read(name), {table: :v}.merge(options)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
class Tag < CLI::Base
|
|
78
|
+
class_option :uuid, type: :string, aliases: '-u', desc: 'Machine uuid'
|
|
79
|
+
|
|
80
|
+
desc 'ls', 'Returns the complete set of tags associated with this machine.'
|
|
81
|
+
def ls
|
|
82
|
+
uuid = options.uuid.nil? ? config[:use_machine] : options.uuid
|
|
83
|
+
output sdc(config(opt(ARGV, options))).machines.tags(uuid).all, {table: :v}.merge(opt(ARGV, options))
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
desc 'get [KEY]', 'Returns the value for a single tag on this machine.'
|
|
87
|
+
def get(key)
|
|
88
|
+
uuid = options.uuid.nil? ? config[:use_machine] : options.uuid
|
|
89
|
+
output sdc(config(opt(ARGV, options))).machines.tags(uuid).read(key), {'raw' => true}.merge(opt(ARGV, options))
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
desc 'add [KEY] [VALUE]', 'Allows you to add additional tags, other than those set at provisioning time.'
|
|
93
|
+
def add(key, value)
|
|
94
|
+
uuid = options.uuid.nil? ? config[:use_machine] : options.uuid
|
|
95
|
+
output sdc(config(opt(ARGV, options))).machines.tags(uuid).create({key => value}), {table: :v}.merge(opt(ARGV, options))
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
desc 'del [KEY]', 'Deletes tag from this machine.'
|
|
99
|
+
method_option :all, type: :boolean, desc: 'All tags delete.'
|
|
100
|
+
def del(key=nil)
|
|
101
|
+
uuid = options.uuid.nil? ? config[:use_machine] : options.uuid
|
|
102
|
+
if key.nil?
|
|
103
|
+
if options.all
|
|
104
|
+
msg = "Machine #{uuid} all tags deleted"
|
|
105
|
+
output sdc(config(opt(ARGV, options))).machines.tags(uuid).destroy, {message: msg}.merge(opt(ARGV, options))
|
|
106
|
+
end
|
|
107
|
+
else
|
|
108
|
+
msg = "Machine #{uuid} tag #{key} deleted"
|
|
109
|
+
output sdc(config(opt(ARGV, options))).machines.tags(uuid).destroy(key), {message: msg}.merge(opt(ARGV, options))
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
class Metadata < CLI::Base
|
|
115
|
+
class_option :uuid, type: :string, aliases: '-u', desc: 'Machine uuid'
|
|
116
|
+
|
|
117
|
+
desc 'ls', 'Returns the complete set of metadata associated with this machine.'
|
|
118
|
+
def ls
|
|
119
|
+
uuid = options.uuid.nil? ? config[:use_machine] : options.uuid
|
|
120
|
+
output sdc(config(opt(ARGV, options))).machines.metadata(uuid).read, {table: :v}.merge(opt(ARGV, options))
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
desc 'add [KEY] [VALUE]', 'Allows you to update the metadata for a given machine.'
|
|
124
|
+
def add(key, value)
|
|
125
|
+
uuid = options.uuid.nil? ? config[:use_machine] : options.uuid
|
|
126
|
+
output sdc(config(opt(ARGV, options))).machines.metadata(uuid).create({key => value}), {table: :v}.merge(opt(ARGV, options))
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
desc 'del [KEY]', 'Deletes metadata key from this machine.'
|
|
130
|
+
method_option :all, type: :boolean, desc: 'All metadata delete.'
|
|
131
|
+
def del(key=nil)
|
|
132
|
+
uuid = options.uuid.nil? ? config[:use_machine] : options.uuid
|
|
133
|
+
if key.nil?
|
|
134
|
+
if options.all
|
|
135
|
+
msg = "Machine #{uuid} all metadata deleted"
|
|
136
|
+
output sdc(config(opt(ARGV, options))).machines.metadata(uuid).destroy, {message: msg}.merge(opt(ARGV, options))
|
|
137
|
+
end
|
|
138
|
+
else
|
|
139
|
+
msg = "Machine #{uuid} metadata #{key} deleted"
|
|
140
|
+
output sdc(config(opt(ARGV, options))).machines.metadata(uuid).destroy(key), {message: msg}.merge(opt(ARGV, options))
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
class Snapshot < CLI::Base
|
|
146
|
+
class_option :uuid, type: :string, aliases: '-u', desc: 'Machine uuid'
|
|
147
|
+
|
|
148
|
+
desc 'ls', 'Lists all snapshots taken for a given machine.'
|
|
149
|
+
def ls
|
|
150
|
+
uuid = options.uuid.nil? ? config[:use_machine] : options.uuid
|
|
151
|
+
output sdc(config(opt(ARGV, options))).machines.snapshots(uuid).all, {table: :h}.merge(opt(ARGV, options))
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
desc 'get [NAME]', 'Gets the state of the named snapshot.'
|
|
155
|
+
def get(name)
|
|
156
|
+
uuid = options.uuid.nil? ? config[:use_machine] : options.uuid
|
|
157
|
+
output sdc(config(opt(ARGV, options))).machines.snapshots(uuid).read(name), {table: :v}.merge(opt(ARGV, options))
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
desc 'add [NAME]', 'Allows you to take a snapshot of a machine.'
|
|
161
|
+
def add(name)
|
|
162
|
+
uuid = options.uuid.nil? ? config[:use_machine] : options.uuid
|
|
163
|
+
output sdc(config(opt(ARGV, options))).machines.snapshots(uuid).create({name: name}), {table: :v}.merge(opt(ARGV, options))
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
desc 'del [NAME]', 'Deletes the specified snapshot of a machine.'
|
|
167
|
+
def del(name)
|
|
168
|
+
uuid = options.uuid.nil? ? config[:use_machine] : options.uuid
|
|
169
|
+
msg = "Machine #{uuid} snapshots #{options[:name]} deleted"
|
|
170
|
+
output sdc(config(opt(ARGV, options))).machines.snapshots(uuid).destroy(name), {message: msg}.merge(opt(ARGV, options))
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
desc 'start [NAME]', 'Starts a stopped machine from the referenced snapshot.'
|
|
174
|
+
def start(name)
|
|
175
|
+
uuid = options.uuid.nil? ? config[:use_machine] : options.uuid
|
|
176
|
+
msg = "Machine #{uuid} snapshots #{options[:key]} started"
|
|
177
|
+
output sdc(config(opt(ARGV, options))).machines.snapshots(uuid).start(name), {message: msg}.merge(opt(ARGV, options))
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
class Machine < CLI::Base
|
|
182
|
+
desc 'ls', 'Lists all machines on record for an account.'
|
|
183
|
+
method_option :type, type: :string, aliases: '-t', desc: 'virtualmachine or smartmachine'
|
|
184
|
+
method_option :state, type: :string, aliases: '-s', desc: 'running or stopped'
|
|
185
|
+
def ls
|
|
186
|
+
include = [:id, :name, :dataset, :state]
|
|
187
|
+
output sdc(config(options)).machines.all(options), {table: :h, include: include}.merge(options)
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
desc 'get [UUID]', 'Gets the details for an individual machine.'
|
|
191
|
+
def get(uuid=nil)
|
|
192
|
+
uuid ||= config[:use_machine]
|
|
193
|
+
output sdc(config(options)).machines.read(uuid), {table: :v}.merge(options)
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
desc 'add [NAME]', 'Allows you to provision a machine.'
|
|
197
|
+
method_option :dataset, type: :string, aliases: '-e', desc: 'dataset URN; default is indicated in ListDatasets'
|
|
198
|
+
method_option :package, type: :string, aliases: '-p', desc: 'Name of the package to use on provisioning; default is indicated in ListPackages'
|
|
199
|
+
def add(name)
|
|
200
|
+
output sdc(config(options)).machines.create({name: name}.merge(options)), {table: :v}.merge(options)
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
desc 'del [UUID]', 'Allows you to completely destroy a machine.'
|
|
204
|
+
def del(uuid=nil)
|
|
205
|
+
uuid ||= config[:use_machine]
|
|
206
|
+
output sdc(config(options)).machines.destroy(uuid), {message: "Machine #{uuid} deleted"}.merge(options)
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
desc 'stop [UUID]', 'Allows you to shut down a machine.'
|
|
210
|
+
def stop(uuid=nil)
|
|
211
|
+
uuid ||= config[:use_machine]
|
|
212
|
+
output sdc(config(options)).machines.stop(uuid), {message: "Machine #{uuid} stoped"}.merge(options)
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
desc 'start [UUID]', 'Allows you to boot up a machine.'
|
|
216
|
+
def start(uuid=nil)
|
|
217
|
+
uuid ||= config[:use_machine]
|
|
218
|
+
output sdc(config(options)).machines.start(uuid), {message: "Machine #{uuid} started"}.merge(options)
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
desc 'reboot [UUID]', 'Allows you to reboot a machine.'
|
|
222
|
+
def reboot(uuid=nil)
|
|
223
|
+
uuid ||= config[:use_machine]
|
|
224
|
+
output sdc(config(options)).machines.reboot(uuid), {message: "Machine #{uuid} reboot"}.merge(options)
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
desc 'resize [UUID]', 'Allows you to resize a SmartMachine.'
|
|
228
|
+
method_option :package, type: :string, aliases: '-p', desc: 'Use a package name returned from ListPackages'
|
|
229
|
+
def resize(uuid=nil)
|
|
230
|
+
uuid ||= config[:use_machine]
|
|
231
|
+
output sdc(config(options)).machines.resize(uuid, {}.merge(options)), {message: "Machine #{uuid} resize"}.merge(options)
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
desc 'use [UUID]', 'Use machine.'
|
|
235
|
+
def use(uuid=nil)
|
|
236
|
+
config = Configure.read
|
|
237
|
+
if uuid.nil?
|
|
238
|
+
puts "use #{config[:use_machine]}"
|
|
239
|
+
else
|
|
240
|
+
config[:use_machine] = uuid
|
|
241
|
+
Configure.write config
|
|
242
|
+
end
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
register(Tag, 'tag', 'tag [COMMAND]', 'Machine tag')
|
|
246
|
+
register(Metadata, 'metadata', 'metadata [COMMAND]', 'Machine metadata')
|
|
247
|
+
register(Snapshot, 'snapshot', 'snapshot [COMMAND]', 'Machine snapshot')
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
class Analytic < CLI::Base
|
|
251
|
+
desc 'desc', 'Retrieves the schema for instrumentations.'
|
|
252
|
+
method_option :all, type: :boolean, desc: 'All describe.'
|
|
253
|
+
method_option :output, type: :string, :default => 'metrics', aliases: '-o', desc: 'Only output the modules or fields or types or metrics or transformations.'
|
|
254
|
+
def desc
|
|
255
|
+
if options['raw']
|
|
256
|
+
puts sdc(config(options)).analytics.describe.body
|
|
257
|
+
else
|
|
258
|
+
content = sdc(config(options)).analytics.describe.content
|
|
259
|
+
describe('modules', content, {cols: ['key', 'label']}.merge(options))
|
|
260
|
+
describe('fields', content, {cols: ['key', 'label', 'type']}.merge(options))
|
|
261
|
+
describe('types', content, {cols: ['key', 'name', 'arity', 'unit', 'abbr', 'base', 'power']}.merge(options))
|
|
262
|
+
describe('metrics', content, {cols: :all, exclude: [:fields]}.merge(options))
|
|
263
|
+
describe('transformations', content, {cols: ['key', 'label']}.merge(options))
|
|
264
|
+
end
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
desc 'ls', 'Retrieves all currently created instrumentations.'
|
|
268
|
+
def ls
|
|
269
|
+
include = ['id', 'module', 'stat', 'decomposition']
|
|
270
|
+
output sdc(config(options)).analytics.all, {table: :h, include: include}.merge(options)
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
desc 'get [ID]', 'Retrieves the configuration for an instrumentation.'
|
|
274
|
+
method_option :value, type: :boolean, aliases: '-v', desc: 'All metadata.'
|
|
275
|
+
def get(id)
|
|
276
|
+
if options[:value]
|
|
277
|
+
output sdc(config(options)).analytics.value(id), {table: :v}.merge(options)
|
|
278
|
+
else
|
|
279
|
+
output sdc(config(options)).analytics.read(id), {table: :v, exclude: ['uris']}.merge(options)
|
|
280
|
+
end
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
desc 'add [NAME]', 'Creates an instrumentation.'
|
|
284
|
+
method_option :module, type: :string, aliases: '-m', desc: 'The Cloud analytics module'
|
|
285
|
+
method_option :stat, type: :string, aliases: '-s', desc: 'The Cloud analytics stat'
|
|
286
|
+
def add
|
|
287
|
+
output sdc(config(options)).analytics.create(options), {table: :v, exclude: ['uris']}.merge(options)
|
|
288
|
+
end
|
|
289
|
+
|
|
290
|
+
desc 'del [ID]', 'Destroys an instrumentation.'
|
|
291
|
+
def del(id)
|
|
292
|
+
output sdc(config(opt(ARGV, options))).analytics.destroy(id), {message: "Analytic #{id} deleted"}.merge(opt(ARGV, options))
|
|
293
|
+
end
|
|
294
|
+
|
|
295
|
+
desc 'heatmap [ID]', 'Retrieves a particular instrumentation heatmap.'
|
|
296
|
+
method_option :image, type: :boolean, aliases: '-i', desc: 'Heatmap image file.'
|
|
297
|
+
method_option :x, type: :numeric, aliases: '-x', desc: 'X-Axis'
|
|
298
|
+
method_option :y, type: :numeric, aliases: '-y', desc: 'Y-Axis'
|
|
299
|
+
def heatmap(id)
|
|
300
|
+
if options[:image]
|
|
301
|
+
output sdc(config(options)).analytics.heatmap(id).image, {table: :v, exclude: ['image', 'present']}.merge(options)
|
|
302
|
+
else
|
|
303
|
+
client = sdc(config(options))
|
|
304
|
+
content = client.analytics.heatmap(id).image.content
|
|
305
|
+
query = {'ymin' => content['ymin'], 'ymax' => content['ymax']}
|
|
306
|
+
output client.analytics.heatmap(id).details(query.merge(options)), {table: :v}.merge(options)
|
|
307
|
+
end
|
|
308
|
+
end
|
|
309
|
+
end
|
|
310
|
+
|
|
311
|
+
class Main < Thor
|
|
312
|
+
desc 'init', 'Sets up an account on a datacenter for use with this CLI.'
|
|
313
|
+
def init
|
|
314
|
+
Configure.make
|
|
315
|
+
puts sdc(config).datacenters.all.status == 200 ? 'Successful configuration.' : 'Failed Configuration.'
|
|
316
|
+
end
|
|
317
|
+
|
|
318
|
+
register(Key, 'key', 'key [COMMAND]', 'SSH key')
|
|
319
|
+
register(Datacenter, 'datacenter', 'datacenter [COMMAND]', 'Smart Data Center')
|
|
320
|
+
register(Dataset, 'dataset', 'dataset [COMMAND]', 'Machine operating system')
|
|
321
|
+
register(Package, 'package', 'package [COMMAND]', 'Machine resources')
|
|
322
|
+
register(Machine, 'machine', 'machine [COMMAND]', 'Virtual machine')
|
|
323
|
+
register(Analytic, 'analytic', 'analytic [COMMAND]', 'DTrace analytics')
|
|
324
|
+
end
|
|
325
|
+
end
|
|
326
|
+
|
|
327
|
+
CLI::Main.start
|