smartdc 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +16 -0
- data/LICENSE.md +20 -0
- data/README.md +87 -0
- data/VERSION +1 -0
- data/bin/sdc-addmachinemetadata +29 -0
- data/bin/sdc-addmachinetag +29 -0
- data/bin/sdc-createinstrumentation +28 -0
- data/bin/sdc-createkey +33 -0
- data/bin/sdc-createmachine +39 -0
- data/bin/sdc-createmachinesnapshot +28 -0
- data/bin/sdc-deleteinstrumentation +10 -0
- data/bin/sdc-deletekey +10 -0
- data/bin/sdc-deletemachine +10 -0
- data/bin/sdc-deletemachinemetadata +27 -0
- data/bin/sdc-deletemachinesnapshot +28 -0
- data/bin/sdc-deletemachinetag +27 -0
- data/bin/sdc-describeanalytics +11 -0
- data/bin/sdc-getdatacenter +11 -0
- data/bin/sdc-getdataset +11 -0
- data/bin/sdc-getinstrumentation +32 -0
- data/bin/sdc-getkey +11 -0
- data/bin/sdc-getmachine +11 -0
- data/bin/sdc-getmachinemetadata +11 -0
- data/bin/sdc-getmachinesnapshot +28 -0
- data/bin/sdc-getmachinetag +28 -0
- data/bin/sdc-getpackage +11 -0
- data/bin/sdc-listdatacenters +11 -0
- data/bin/sdc-listdatasets +11 -0
- data/bin/sdc-listinstrumentations +11 -0
- data/bin/sdc-listkeys +11 -0
- data/bin/sdc-listmachines +11 -0
- data/bin/sdc-listmachinesnapshots +11 -0
- data/bin/sdc-listmachinetags +11 -0
- data/bin/sdc-listpackages +11 -0
- data/bin/sdc-rebootmachine +10 -0
- data/bin/sdc-resizemachine +32 -0
- data/bin/sdc-setup +63 -0
- data/bin/sdc-startmachine +10 -0
- data/bin/sdc-startmachinefromsnapshot +28 -0
- data/bin/sdc-stopmachine +10 -0
- data/config/fixtures/instrumentation.json +4 -0
- data/config/fixtures/key.json +4 -0
- data/config/fixtures/tag.json +3 -0
- data/lib/cli_helper.rb +12 -0
- data/lib/faraday/response/mashify.rb +26 -0
- data/lib/faraday/response/parse_json.rb +22 -0
- data/lib/smartdc.rb +8 -0
- data/lib/smartdc/api/analytics.rb +22 -0
- data/lib/smartdc/api/analytics/instrumentations.rb +45 -0
- data/lib/smartdc/api/datacenters.rb +21 -0
- data/lib/smartdc/api/datasets.rb +21 -0
- data/lib/smartdc/api/keys.rb +31 -0
- data/lib/smartdc/api/machine/metadata.rb +31 -0
- data/lib/smartdc/api/machine/snapshots.rb +37 -0
- data/lib/smartdc/api/machine/tags.rb +31 -0
- data/lib/smartdc/api/machines.rb +75 -0
- data/lib/smartdc/api/packages.rb +21 -0
- data/lib/smartdc/client.rb +40 -0
- data/lib/smartdc/request.rb +85 -0
- data/smartdc.gemspec +138 -0
- data/spec/smartdc/api/analytics_spec.rb +32 -0
- data/spec/smartdc/api/datacenters_spec.rb +16 -0
- data/spec/smartdc/api/datasets_spec.rb +16 -0
- data/spec/smartdc/api/keys_spec.rb +32 -0
- data/spec/smartdc/api/machine/metadata_spec.rb +42 -0
- data/spec/smartdc/api/machine/snapshots_spec.rb +58 -0
- data/spec/smartdc/api/machine/tags_spec.rb +48 -0
- data/spec/smartdc/api/machines_spec.rb +96 -0
- data/spec/smartdc/api/packages_spec.rb +16 -0
- data/spec/smartdc/client_spec.rb +45 -0
- data/spec/smartdc/request_spec.rb +11 -0
- data/spec/smartdc_spec.rb +9 -0
- data/spec/spec_helper.rb +12 -0
- metadata +259 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
group :development do
|
4
|
+
gem "rspec", "~> 2.7.0"
|
5
|
+
gem "bundler", "~> 1.0.0"
|
6
|
+
gem "jeweler", "~> 1.6.4"
|
7
|
+
gem "rcov", ">= 0"
|
8
|
+
gem "uuid", "~> 2.3.4"
|
9
|
+
end
|
10
|
+
|
11
|
+
group :runtime do
|
12
|
+
gem "faraday", "~> 0.7.5"
|
13
|
+
gem "hashie", "~> 1.2.0"
|
14
|
+
gem "multi_json", "~> 1.0.3"
|
15
|
+
gem "multipart-post", "~> 1.1.3"
|
16
|
+
end
|
data/LICENSE.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 ogom
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
# smartdc
|
2
|
+
|
3
|
+
ruby-smartdc is a ruby client library for interacting with the Joyent SmartDataCenter CloudApi.
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
gem install smartdc
|
9
|
+
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
Get Started with SmartDataCenter [here](http://www.slideshare.net/ogom_/smartdc-by-ruby-10047222).
|
14
|
+
|
15
|
+
|
16
|
+
### CLI
|
17
|
+
|
18
|
+
$ sdc-setup https://example.com
|
19
|
+
version:[~6.5]
|
20
|
+
Username (login): auth_user
|
21
|
+
Password: auth_pass
|
22
|
+
Successful configuration.
|
23
|
+
|
24
|
+
$ sdc-listdatacenters
|
25
|
+
{
|
26
|
+
"example": "https://example.com"
|
27
|
+
}
|
28
|
+
|
29
|
+
|
30
|
+
### Program
|
31
|
+
|
32
|
+
Connect and Machine find.
|
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
|
+
|
67
|
+
|
68
|
+
Return type of the variable.
|
69
|
+
|
70
|
+
client = Smartdc.new(config)
|
71
|
+
|
72
|
+
# Type of a variable to mash. (Default)
|
73
|
+
client.request.return_variable = 'mash'
|
74
|
+
puts client.datacenters.find #=> #<Hashie::Mash example="example.com">
|
75
|
+
|
76
|
+
# Type of a variable to hash.
|
77
|
+
client.request.return_variable = 'hash'
|
78
|
+
puts client.datacenters.find #=> {"example"=>"https://example.com"}
|
79
|
+
|
80
|
+
# Type of a variable to json.
|
81
|
+
client.request.return_variable = 'json'
|
82
|
+
puts client.datacenters.find #=> {"example": "https://example.com"}
|
83
|
+
|
84
|
+
|
85
|
+
## Copyright
|
86
|
+
|
87
|
+
Copyright (c) 2011 ogom. See LICENSE.md for further details.
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.3.0
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
4
|
+
require 'cli_helper'
|
5
|
+
|
6
|
+
options = {}
|
7
|
+
OptionParser.new do |opts|
|
8
|
+
opts.banner = "Usage: #{File.basename($0)} machine.id [options]"
|
9
|
+
opts.on('-k', '--key [NAME]', 'Key Tag.') {|v| options[:key] = v }
|
10
|
+
opts.on('-v', '--value [NAME]', 'Value Tag.') {|v| options[:value] = v }
|
11
|
+
opts.on_tail('-h','--help') do
|
12
|
+
puts opts
|
13
|
+
exit
|
14
|
+
end
|
15
|
+
|
16
|
+
begin
|
17
|
+
opts.parse!(ARGV)
|
18
|
+
rescue => e
|
19
|
+
puts e.to_s << "\n" << opts.to_s
|
20
|
+
exit
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
begin
|
25
|
+
metadata = {options[:key] => options[:value]}
|
26
|
+
pp client.machines(ARGV[0]).metadata.create metadata
|
27
|
+
rescue => e
|
28
|
+
puts e
|
29
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
4
|
+
require 'cli_helper'
|
5
|
+
|
6
|
+
options = {}
|
7
|
+
OptionParser.new do |opts|
|
8
|
+
opts.banner = "Usage: #{File.basename($0)} machine.id [options]"
|
9
|
+
opts.on('-k', '--key [NAME]', 'Key Tag.') {|v| options[:key] = v }
|
10
|
+
opts.on('-v', '--value [NAME]', 'Value Tag.') {|v| options[:value] = v }
|
11
|
+
opts.on_tail('-h','--help') do
|
12
|
+
puts opts
|
13
|
+
exit
|
14
|
+
end
|
15
|
+
|
16
|
+
begin
|
17
|
+
opts.parse!(ARGV)
|
18
|
+
rescue => e
|
19
|
+
puts e.to_s << "\n" << opts.to_s
|
20
|
+
exit
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
begin
|
25
|
+
tag = {options[:key] => options[:value]}
|
26
|
+
pp client.machines(ARGV[0]).tags.create tag
|
27
|
+
rescue => e
|
28
|
+
puts e
|
29
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
4
|
+
require 'cli_helper'
|
5
|
+
|
6
|
+
options = {}
|
7
|
+
OptionParser.new do |opts|
|
8
|
+
opts.on('-m', '--module NAME', 'The CA module.') {|v| options[:module] = v }
|
9
|
+
opts.on('-s', '--stat NAME', 'The CA stat.') {|v| options[:stat] = v }
|
10
|
+
opts.on('-h','--help') do
|
11
|
+
puts opts
|
12
|
+
exit
|
13
|
+
end
|
14
|
+
|
15
|
+
begin
|
16
|
+
opts.parse!(ARGV)
|
17
|
+
rescue => e
|
18
|
+
puts e.to_s << "\n" << opts.to_s
|
19
|
+
exit
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
begin
|
24
|
+
client.request.return_variable = 'json'
|
25
|
+
puts client.analytics.instrumentations.create options
|
26
|
+
rescue => e
|
27
|
+
puts e
|
28
|
+
end
|
data/bin/sdc-createkey
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
4
|
+
require 'cli_helper'
|
5
|
+
|
6
|
+
key = {}
|
7
|
+
name = ARGV[0]
|
8
|
+
if name
|
9
|
+
key[:name] = name
|
10
|
+
else
|
11
|
+
puts 'name is empty.'
|
12
|
+
exit 1
|
13
|
+
end
|
14
|
+
|
15
|
+
key_file = ARGV[1]
|
16
|
+
if key_file
|
17
|
+
begin
|
18
|
+
key[:key] = File.read(key_file)
|
19
|
+
rescue => e
|
20
|
+
puts e
|
21
|
+
exit 1
|
22
|
+
end
|
23
|
+
else
|
24
|
+
puts 'key file is empty.'
|
25
|
+
exit 1
|
26
|
+
end
|
27
|
+
|
28
|
+
begin
|
29
|
+
client.request.return_variable = 'json'
|
30
|
+
puts client.keys.create key
|
31
|
+
rescue => e
|
32
|
+
puts e
|
33
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
4
|
+
require 'cli_helper'
|
5
|
+
|
6
|
+
options = {}
|
7
|
+
OptionParser.new do |opts|
|
8
|
+
opts.on('-n', '--name NAME', 'friendly name for this machine.') {|v| options[:name] = v }
|
9
|
+
opts.on('-e', '--dataset URN', 'dataset URN.') {|v| options[:dataset] = v }
|
10
|
+
opts.on('-p', '--package NAME', 'Name of the package to use on provisioning.') {|v| options[:package] = v }
|
11
|
+
opts.on('-h','--help') do
|
12
|
+
puts opts
|
13
|
+
print 'Datasets(urn):'
|
14
|
+
fixture('datasets').each do |dataset|
|
15
|
+
print ' ' + dataset['urn']
|
16
|
+
end
|
17
|
+
puts
|
18
|
+
print 'Packages(name):'
|
19
|
+
fixture('packages').each do |packages|
|
20
|
+
print ' ' + packages['name']
|
21
|
+
end
|
22
|
+
puts
|
23
|
+
exit
|
24
|
+
end
|
25
|
+
|
26
|
+
begin
|
27
|
+
opts.parse!(ARGV)
|
28
|
+
rescue => e
|
29
|
+
puts e.to_s << "\n" << opts.to_s
|
30
|
+
exit
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
begin
|
35
|
+
client.request.return_variable = 'json'
|
36
|
+
puts client.machines.create options
|
37
|
+
rescue => e
|
38
|
+
puts e
|
39
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
4
|
+
require 'cli_helper'
|
5
|
+
|
6
|
+
options = {}
|
7
|
+
OptionParser.new do |opts|
|
8
|
+
opts.banner = "Usage: #{File.basename($0)} machine.id [options]"
|
9
|
+
opts.on('-n', '--name NAME', 'The name to assign to the new snapshot.') {|v| options[:name] = v }
|
10
|
+
opts.on_tail('-h','--help') do
|
11
|
+
puts opts
|
12
|
+
exit
|
13
|
+
end
|
14
|
+
|
15
|
+
begin
|
16
|
+
opts.parse!(ARGV)
|
17
|
+
rescue => e
|
18
|
+
puts e.to_s << "\n" << opts.to_s
|
19
|
+
exit
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
begin
|
24
|
+
client.request.return_variable = 'json'
|
25
|
+
puts client.machines(ARGV[0]).snapshots.create options
|
26
|
+
rescue => e
|
27
|
+
puts e
|
28
|
+
end
|
data/bin/sdc-deletekey
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
4
|
+
require 'cli_helper'
|
5
|
+
|
6
|
+
options = {}
|
7
|
+
OptionParser.new do |opts|
|
8
|
+
opts.banner = "Usage: #{File.basename($0)} machine.id [options]"
|
9
|
+
opts.on('-k', '--key [NAME]', 'Key Tag.') {|v| options[:key] = v }
|
10
|
+
opts.on_tail('-h','--help') do
|
11
|
+
puts opts
|
12
|
+
exit
|
13
|
+
end
|
14
|
+
|
15
|
+
begin
|
16
|
+
opts.parse!(ARGV)
|
17
|
+
rescue => e
|
18
|
+
puts e.to_s << "\n" << opts.to_s
|
19
|
+
exit
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
begin
|
24
|
+
pp client.machines(ARGV[0]).metadata(options[:key]).delete
|
25
|
+
rescue => e
|
26
|
+
puts e
|
27
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
4
|
+
require 'cli_helper'
|
5
|
+
|
6
|
+
options = {}
|
7
|
+
OptionParser.new do |opts|
|
8
|
+
opts.banner = "Usage: #{File.basename($0)} machine.id [options]"
|
9
|
+
opts.on('-n', '--name NAME', 'snapshot name.') {|v| options[:name] = v }
|
10
|
+
opts.on_tail('-h','--help') do
|
11
|
+
puts opts
|
12
|
+
exit
|
13
|
+
end
|
14
|
+
|
15
|
+
begin
|
16
|
+
opts.parse!(ARGV)
|
17
|
+
rescue => e
|
18
|
+
puts e.to_s << "\n" << opts.to_s
|
19
|
+
exit
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
begin
|
24
|
+
client.request.return_variable = 'json'
|
25
|
+
puts client.machines(ARGV[0]).snapshots(options[:name]).delete
|
26
|
+
rescue => e
|
27
|
+
puts e
|
28
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
4
|
+
require 'cli_helper'
|
5
|
+
|
6
|
+
options = {}
|
7
|
+
OptionParser.new do |opts|
|
8
|
+
opts.banner = "Usage: #{File.basename($0)} machine.id [options]"
|
9
|
+
opts.on('-k', '--key [NAME]', 'Key Tag.') {|v| options[:key] = v }
|
10
|
+
opts.on_tail('-h','--help') do
|
11
|
+
puts opts
|
12
|
+
exit
|
13
|
+
end
|
14
|
+
|
15
|
+
begin
|
16
|
+
opts.parse!(ARGV)
|
17
|
+
rescue => e
|
18
|
+
puts e.to_s << "\n" << opts.to_s
|
19
|
+
exit
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
begin
|
24
|
+
pp client.machines(ARGV[0]).tags(options[:key]).delete
|
25
|
+
rescue => e
|
26
|
+
puts e
|
27
|
+
end
|