joyent 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +26 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +52 -0
- data/VERSION +1 -0
- data/bin/joyent +138 -0
- data/joyent.gemspec +87 -0
- data/lib/joyent/connection.rb +62 -0
- data/lib/joyent/datacenter.rb +10 -0
- data/lib/joyent/datacenters.rb +15 -0
- data/lib/joyent/dataset.rb +16 -0
- data/lib/joyent/datasets.rb +15 -0
- data/lib/joyent/machine.rb +41 -0
- data/lib/joyent/machines.rb +19 -0
- data/lib/joyent/package.rb +13 -0
- data/lib/joyent/packages.rb +15 -0
- data/lib/joyent.rb +11 -0
- data/test/helper.rb +18 -0
- data/test/test_joyent.rb +7 -0
- metadata +219 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gem "json"
|
4
|
+
gem "thor"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "shoulda", ">= 0"
|
10
|
+
gem "yard", "~> 0.6.0"
|
11
|
+
gem "bundler", "~> 1.0.0"
|
12
|
+
gem "jeweler", "~> 1.6.4"
|
13
|
+
gem "rcov", ">= 0"
|
14
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
git (1.2.5)
|
5
|
+
jeweler (1.6.4)
|
6
|
+
bundler (~> 1.0)
|
7
|
+
git (>= 1.2.5)
|
8
|
+
rake
|
9
|
+
json (1.4.6)
|
10
|
+
rake (0.9.2)
|
11
|
+
rcov (0.9.10)
|
12
|
+
shoulda (2.11.3)
|
13
|
+
thor (0.14.6)
|
14
|
+
yard (0.6.8)
|
15
|
+
|
16
|
+
PLATFORMS
|
17
|
+
ruby
|
18
|
+
|
19
|
+
DEPENDENCIES
|
20
|
+
bundler (~> 1.0.0)
|
21
|
+
jeweler (~> 1.6.4)
|
22
|
+
json
|
23
|
+
rcov
|
24
|
+
shoulda
|
25
|
+
thor
|
26
|
+
yard (~> 0.6.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Ben Wyrosdick
|
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.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= joyent
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to joyent
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
+
* Fork the project
|
10
|
+
* Start a feature/bugfix branch
|
11
|
+
* Commit and push until you are happy with your contribution
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2011 Ben Wyrosdick. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
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 is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "joyent"
|
18
|
+
gem.homepage = "http://github.com/mongohq/joyent"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Ruby interface to the joyent cloud API}
|
21
|
+
gem.description = %Q{Ruby interface to the joyent cloud API}
|
22
|
+
gem.email = "ben.wyrosdick@gmail.com"
|
23
|
+
gem.authors = ["Ben Wyrosdick"]
|
24
|
+
# files defined in Gemfile
|
25
|
+
gem.files.include Dir.glob('lib/**/*.rb')
|
26
|
+
# dependencies defined in Gemfile
|
27
|
+
gem.add_dependency 'thor'
|
28
|
+
gem.add_dependency 'json'
|
29
|
+
# executables defined in Gemfile
|
30
|
+
gem.executables = ['joyent']
|
31
|
+
end
|
32
|
+
Jeweler::RubygemsDotOrgTasks.new
|
33
|
+
|
34
|
+
require 'rake/testtask'
|
35
|
+
Rake::TestTask.new(:test) do |test|
|
36
|
+
test.libs << 'lib' << 'test'
|
37
|
+
test.pattern = 'test/**/test_*.rb'
|
38
|
+
test.verbose = true
|
39
|
+
end
|
40
|
+
|
41
|
+
require 'rcov/rcovtask'
|
42
|
+
Rcov::RcovTask.new do |test|
|
43
|
+
test.libs << 'test'
|
44
|
+
test.pattern = 'test/**/test_*.rb'
|
45
|
+
test.verbose = true
|
46
|
+
test.rcov_opts << '--exclude "gems/*"'
|
47
|
+
end
|
48
|
+
|
49
|
+
task :default => :test
|
50
|
+
|
51
|
+
require 'yard'
|
52
|
+
YARD::Rake::YardocTask.new
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/bin/joyent
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'thor'
|
5
|
+
require 'yaml'
|
6
|
+
require File.join(File.dirname(__FILE__), '../lib/joyent')
|
7
|
+
require 'highline/import'
|
8
|
+
|
9
|
+
class JoyentCLI < Thor
|
10
|
+
private
|
11
|
+
|
12
|
+
def get_connection
|
13
|
+
get_config unless load_config
|
14
|
+
|
15
|
+
Joyent::Connection.new(@username, @password)
|
16
|
+
end
|
17
|
+
|
18
|
+
def load_config
|
19
|
+
config_file = File.join(ENV['HOME'], ".joyentcli")
|
20
|
+
if File.exists?(config_file)
|
21
|
+
config = YAML.load(File.open(config_file, 'r').read)
|
22
|
+
@username = config["username"]
|
23
|
+
@password = config["password"]
|
24
|
+
return true
|
25
|
+
else
|
26
|
+
return false
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def get_config
|
31
|
+
@username = ask("Username (login): ")
|
32
|
+
@password = ask("Password: "){|q| q.echo = false}
|
33
|
+
|
34
|
+
config_file = File.join(ENV['HOME'], ".joyentcli")
|
35
|
+
config = {"username" => @username, "password" => @password}
|
36
|
+
File.open(config_file, 'w+') {|f|
|
37
|
+
f.puts config.to_yaml
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
public
|
42
|
+
|
43
|
+
#
|
44
|
+
# Datacenters
|
45
|
+
#
|
46
|
+
desc "list_datacenters", "list all of the available datacenters"
|
47
|
+
def list_datacenters
|
48
|
+
conn = get_connection
|
49
|
+
conn.datacenters.list.each do |dc|
|
50
|
+
puts "#{dc.name}: #{dc.url}"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
#
|
55
|
+
# Datasets
|
56
|
+
#
|
57
|
+
desc "list_datasets", "list all of the datasets available"
|
58
|
+
def list_datasets
|
59
|
+
conn = get_connection
|
60
|
+
conn.datasets.list.each do |d|
|
61
|
+
puts "#{d.name}: #{d.os} (#{d.urn})"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
#
|
66
|
+
# Packages
|
67
|
+
#
|
68
|
+
desc "list_packages", "list all of the packages available"
|
69
|
+
def list_packages
|
70
|
+
conn = get_connection
|
71
|
+
conn.packages.list.each do |p|
|
72
|
+
puts "#{p.name}: RAM-#{p.memory} HD-#{p.disk}"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
#
|
77
|
+
# Machines
|
78
|
+
#
|
79
|
+
desc "list_machines", "list all of the machines on the account"
|
80
|
+
def list_machines
|
81
|
+
conn = get_connection
|
82
|
+
conn.machines.list.each do |m|
|
83
|
+
puts "#{m.name} [#{m.id}]: #{m.dataset} (#{m.state})"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
desc "create_machine", "create a new joyent machine"
|
88
|
+
method_option :name, :type => :string, :aliases => "-n"
|
89
|
+
method_option :package, :type => :string, :aliases => "-p"
|
90
|
+
method_option :dataset, :type => :string, :aliases => "-d"
|
91
|
+
def create_machine
|
92
|
+
conn = get_connection
|
93
|
+
m = conn.machines.create(options)
|
94
|
+
puts "#{m.name}: #{m.dataset} (#{m.state})"
|
95
|
+
end
|
96
|
+
|
97
|
+
desc "stop_machine ID", "stops the machine with the given ID"
|
98
|
+
def stop_machine(id)
|
99
|
+
conn = get_connection
|
100
|
+
m = conn.machines.get(id)
|
101
|
+
m.stop
|
102
|
+
puts "#{m.name} [#{m.id}] STOPPED"
|
103
|
+
end
|
104
|
+
|
105
|
+
desc "start_machine ID", "starts the machine with the given ID"
|
106
|
+
def start_machine(id)
|
107
|
+
conn = get_connection
|
108
|
+
m = conn.machines.get(id)
|
109
|
+
m.start
|
110
|
+
puts "#{m.name} [#{m.id}] STARTED"
|
111
|
+
end
|
112
|
+
|
113
|
+
desc "reboot_machine ID", "reboots the machine with the given ID"
|
114
|
+
def reboot_machine(id)
|
115
|
+
conn = get_connection
|
116
|
+
m = conn.machines.get(id)
|
117
|
+
m.reboot
|
118
|
+
puts "#{m.name} [#{m.id}] REBOOTED"
|
119
|
+
end
|
120
|
+
|
121
|
+
desc "resize_machine ID PACKAGE", "stops the machine with the given ID to the specified PACKAGE"
|
122
|
+
def resize_machine(id, package)
|
123
|
+
conn = get_connection
|
124
|
+
m = conn.machines.get(id)
|
125
|
+
m.resize(package)
|
126
|
+
puts "#{m.name} [#{m.id}] RESIZED to #{package}"
|
127
|
+
end
|
128
|
+
|
129
|
+
desc "delete_machine ID", "deletes the machine with the given ID"
|
130
|
+
def delete_machine(id)
|
131
|
+
conn = get_connection
|
132
|
+
m = conn.machines.get(id)
|
133
|
+
m.delete
|
134
|
+
puts "#{m.name} [#{m.id}] DELETED"
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
JoyentCLI.start
|
data/joyent.gemspec
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{joyent}
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Ben Wyrosdick"]
|
12
|
+
s.date = %q{2011-09-15}
|
13
|
+
s.default_executable = %q{joyent}
|
14
|
+
s.description = %q{Ruby interface to the joyent cloud API}
|
15
|
+
s.email = %q{ben.wyrosdick@gmail.com}
|
16
|
+
s.executables = ["joyent"]
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE.txt",
|
19
|
+
"README.rdoc"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".document",
|
23
|
+
"Gemfile",
|
24
|
+
"Gemfile.lock",
|
25
|
+
"LICENSE.txt",
|
26
|
+
"README.rdoc",
|
27
|
+
"Rakefile",
|
28
|
+
"VERSION",
|
29
|
+
"bin/joyent",
|
30
|
+
"joyent.gemspec",
|
31
|
+
"lib/joyent.rb",
|
32
|
+
"lib/joyent/connection.rb",
|
33
|
+
"lib/joyent/datacenter.rb",
|
34
|
+
"lib/joyent/datacenters.rb",
|
35
|
+
"lib/joyent/dataset.rb",
|
36
|
+
"lib/joyent/datasets.rb",
|
37
|
+
"lib/joyent/machine.rb",
|
38
|
+
"lib/joyent/machines.rb",
|
39
|
+
"lib/joyent/package.rb",
|
40
|
+
"lib/joyent/packages.rb",
|
41
|
+
"test/helper.rb",
|
42
|
+
"test/test_joyent.rb"
|
43
|
+
]
|
44
|
+
s.homepage = %q{http://github.com/mongohq/joyent}
|
45
|
+
s.licenses = ["MIT"]
|
46
|
+
s.require_paths = ["lib"]
|
47
|
+
s.rubygems_version = %q{1.3.7}
|
48
|
+
s.summary = %q{Ruby interface to the joyent cloud API}
|
49
|
+
|
50
|
+
if s.respond_to? :specification_version then
|
51
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
52
|
+
s.specification_version = 3
|
53
|
+
|
54
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
55
|
+
s.add_runtime_dependency(%q<json>, [">= 0"])
|
56
|
+
s.add_runtime_dependency(%q<thor>, [">= 0"])
|
57
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
58
|
+
s.add_development_dependency(%q<yard>, ["~> 0.6.0"])
|
59
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
60
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
61
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
62
|
+
s.add_runtime_dependency(%q<thor>, [">= 0"])
|
63
|
+
s.add_runtime_dependency(%q<json>, [">= 0"])
|
64
|
+
else
|
65
|
+
s.add_dependency(%q<json>, [">= 0"])
|
66
|
+
s.add_dependency(%q<thor>, [">= 0"])
|
67
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
68
|
+
s.add_dependency(%q<yard>, ["~> 0.6.0"])
|
69
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
70
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
71
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
72
|
+
s.add_dependency(%q<thor>, [">= 0"])
|
73
|
+
s.add_dependency(%q<json>, [">= 0"])
|
74
|
+
end
|
75
|
+
else
|
76
|
+
s.add_dependency(%q<json>, [">= 0"])
|
77
|
+
s.add_dependency(%q<thor>, [">= 0"])
|
78
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
79
|
+
s.add_dependency(%q<yard>, ["~> 0.6.0"])
|
80
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
81
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
82
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
83
|
+
s.add_dependency(%q<thor>, [">= 0"])
|
84
|
+
s.add_dependency(%q<json>, [">= 0"])
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module Joyent
|
2
|
+
class Connection
|
3
|
+
def initialize(username, password)
|
4
|
+
@http_connection = Net::HTTP.new(Joyent::API_ENDPOINT, 443)
|
5
|
+
@http_connection.use_ssl = true
|
6
|
+
@http_connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
7
|
+
|
8
|
+
@username = username
|
9
|
+
@password = password
|
10
|
+
end
|
11
|
+
|
12
|
+
def headers
|
13
|
+
{
|
14
|
+
"X-Api-Version" => Joyent::API_VERSION
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
def execute(http_method, url, data = {})
|
19
|
+
case http_method
|
20
|
+
when :get
|
21
|
+
request = Net::HTTP::Get.new("/#{@username}#{url}", self.headers)
|
22
|
+
when :post
|
23
|
+
request = Net::HTTP::Post.new("/#{@username}#{url}", self.headers)
|
24
|
+
request.set_form_data(data)
|
25
|
+
when :delete
|
26
|
+
request = Net::HTTP::Delete.new("/#{@username}#{url}", self.headers)
|
27
|
+
else
|
28
|
+
raise "HTTP method #{http_method} not supported"
|
29
|
+
end
|
30
|
+
|
31
|
+
request.basic_auth(@username, @password)
|
32
|
+
|
33
|
+
response = @http_connection.request(request)
|
34
|
+
|
35
|
+
if response.code =~ /^2/
|
36
|
+
if response.body.nil? or response.body.empty?
|
37
|
+
nil
|
38
|
+
else
|
39
|
+
JSON.parse(response.body)
|
40
|
+
end
|
41
|
+
else
|
42
|
+
raise "#{response.code}: #{response.message} - #{response.body}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def datacenters
|
47
|
+
@datacenters ||= Joyent::Datacenters.new(self)
|
48
|
+
end
|
49
|
+
|
50
|
+
def datasets
|
51
|
+
@datasets ||= Joyent::Datasets.new(self)
|
52
|
+
end
|
53
|
+
|
54
|
+
def packages
|
55
|
+
@packages ||= Joyent::Packages.new(self)
|
56
|
+
end
|
57
|
+
|
58
|
+
def machines
|
59
|
+
@machines ||= Joyent::Machines.new(self)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Joyent
|
2
|
+
class Datacenters
|
3
|
+
def initialize(connection)
|
4
|
+
@connection = connection
|
5
|
+
end
|
6
|
+
|
7
|
+
def list
|
8
|
+
@connection.execute(:get, "/datacenters").map{|name, url| Joyent::Datacenter.new(name, url)}
|
9
|
+
end
|
10
|
+
|
11
|
+
def get(name)
|
12
|
+
Joyent::Datacenter.new(name, @connection.execute(:get, "/datacenters")[name])
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Joyent
|
2
|
+
class Dataset
|
3
|
+
attr_reader :id, :name, :os, :version, :urn, :type, :default, :requirements
|
4
|
+
|
5
|
+
def initialize(attributes)
|
6
|
+
@io = attributes["io"]
|
7
|
+
@name = attributes["name"]
|
8
|
+
@os = attributes["os"]
|
9
|
+
@version = attributes["version"]
|
10
|
+
@urn = attributes["urn"]
|
11
|
+
@type = attributes["type"]
|
12
|
+
@default = attributes["default"]
|
13
|
+
@requirements = attributes["requirements"]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Joyent
|
2
|
+
class Datasets
|
3
|
+
def initialize(connection)
|
4
|
+
@connection = connection
|
5
|
+
end
|
6
|
+
|
7
|
+
def list
|
8
|
+
@connection.execute(:get, "/datasets").map{|attributes| Joyent::Dataset.new(attributes)}
|
9
|
+
end
|
10
|
+
|
11
|
+
def get(name)
|
12
|
+
Joyent::Dataset.new(@connection.execute(:get, "/datasets/#{name}"))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Joyent
|
2
|
+
class Machine
|
3
|
+
attr_reader :id, :name, :type, :state, :dataset, :memory, :disk, :ips, :metadata, :created, :updated
|
4
|
+
|
5
|
+
def initialize(connection, attributes)
|
6
|
+
@connection = connection
|
7
|
+
|
8
|
+
@id = attributes["id"]
|
9
|
+
@name = attributes["name"]
|
10
|
+
@type = attributes["type"]
|
11
|
+
@state = attributes["state"]
|
12
|
+
@dataset = attributes["dataset"]
|
13
|
+
@memory = attributes["memory"]
|
14
|
+
@disk = attributes["disk"]
|
15
|
+
@ips = attributes["ips"]
|
16
|
+
@metadata = attributes["metadata"]
|
17
|
+
@created = attributes["created"]
|
18
|
+
@updated = attributes["updated"]
|
19
|
+
end
|
20
|
+
|
21
|
+
def stop
|
22
|
+
@connection.execute(:post, "/machines/#{self.id}", {"action" => "stop"})
|
23
|
+
end
|
24
|
+
|
25
|
+
def start
|
26
|
+
@connection.execute(:post, "/machines/#{self.id}", {"action" => "start"})
|
27
|
+
end
|
28
|
+
|
29
|
+
def reboot
|
30
|
+
@connection.execute(:post, "/machines/#{self.id}", {"action" => "reboot"})
|
31
|
+
end
|
32
|
+
|
33
|
+
def resize(package)
|
34
|
+
@connection.execute(:post, "/machines/#{self.id}", {"action" => "resize", "package" => package})
|
35
|
+
end
|
36
|
+
|
37
|
+
def delete
|
38
|
+
@connection.execute(:delete, "/machines/#{self.id}")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Joyent
|
2
|
+
class Machines
|
3
|
+
def initialize(connection)
|
4
|
+
@connection = connection
|
5
|
+
end
|
6
|
+
|
7
|
+
def list
|
8
|
+
@connection.execute(:get, "/machines").map{|attributes| Joyent::Machine.new(self, attributes)}
|
9
|
+
end
|
10
|
+
|
11
|
+
def get(id)
|
12
|
+
Joyent::Machine.new(@connection, @connection.execute(:get, "/machines/#{id}"))
|
13
|
+
end
|
14
|
+
|
15
|
+
def create(attributes = {})
|
16
|
+
Joyent::Machine.new(@connection, @connection.execute(:post, "/machines", attributes))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Joyent
|
2
|
+
class Package
|
3
|
+
attr_reader :name, :memory, :disk, :swap, :default
|
4
|
+
|
5
|
+
def initialize(attributes)
|
6
|
+
@name = attributes["name"]
|
7
|
+
@memory = attributes["memory"]
|
8
|
+
@disk = attributes["disk"]
|
9
|
+
@swap = attributes["swap"]
|
10
|
+
@default = attributes["default"]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Joyent
|
2
|
+
class Packages
|
3
|
+
def initialize(connection)
|
4
|
+
@connection = connection
|
5
|
+
end
|
6
|
+
|
7
|
+
def list
|
8
|
+
@connection.execute(:get, "/packages").map{|attributes| Joyent::Package.new(attributes)}
|
9
|
+
end
|
10
|
+
|
11
|
+
def get(name)
|
12
|
+
Joyent::Package.new(@connection.execute(:get, "/packages/#{name}"))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/joyent.rb
ADDED
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'joyent'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
data/test/test_joyent.rb
ADDED
metadata
ADDED
@@ -0,0 +1,219 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: joyent
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Ben Wyrosdick
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-09-15 00:00:00 -07:00
|
19
|
+
default_executable: joyent
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
name: json
|
25
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: 3
|
31
|
+
segments:
|
32
|
+
- 0
|
33
|
+
version: "0"
|
34
|
+
requirement: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
type: :runtime
|
37
|
+
prerelease: false
|
38
|
+
name: thor
|
39
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 3
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
version: "0"
|
48
|
+
requirement: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
type: :development
|
51
|
+
prerelease: false
|
52
|
+
name: shoulda
|
53
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 3
|
59
|
+
segments:
|
60
|
+
- 0
|
61
|
+
version: "0"
|
62
|
+
requirement: *id003
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
type: :development
|
65
|
+
prerelease: false
|
66
|
+
name: yard
|
67
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ~>
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
hash: 7
|
73
|
+
segments:
|
74
|
+
- 0
|
75
|
+
- 6
|
76
|
+
- 0
|
77
|
+
version: 0.6.0
|
78
|
+
requirement: *id004
|
79
|
+
- !ruby/object:Gem::Dependency
|
80
|
+
type: :development
|
81
|
+
prerelease: false
|
82
|
+
name: bundler
|
83
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ~>
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
hash: 23
|
89
|
+
segments:
|
90
|
+
- 1
|
91
|
+
- 0
|
92
|
+
- 0
|
93
|
+
version: 1.0.0
|
94
|
+
requirement: *id005
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
name: jeweler
|
99
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
101
|
+
requirements:
|
102
|
+
- - ~>
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
hash: 7
|
105
|
+
segments:
|
106
|
+
- 1
|
107
|
+
- 6
|
108
|
+
- 4
|
109
|
+
version: 1.6.4
|
110
|
+
requirement: *id006
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
type: :development
|
113
|
+
prerelease: false
|
114
|
+
name: rcov
|
115
|
+
version_requirements: &id007 !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
hash: 3
|
121
|
+
segments:
|
122
|
+
- 0
|
123
|
+
version: "0"
|
124
|
+
requirement: *id007
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
type: :runtime
|
127
|
+
prerelease: false
|
128
|
+
name: thor
|
129
|
+
version_requirements: &id008 !ruby/object:Gem::Requirement
|
130
|
+
none: false
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
hash: 3
|
135
|
+
segments:
|
136
|
+
- 0
|
137
|
+
version: "0"
|
138
|
+
requirement: *id008
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
type: :runtime
|
141
|
+
prerelease: false
|
142
|
+
name: json
|
143
|
+
version_requirements: &id009 !ruby/object:Gem::Requirement
|
144
|
+
none: false
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
hash: 3
|
149
|
+
segments:
|
150
|
+
- 0
|
151
|
+
version: "0"
|
152
|
+
requirement: *id009
|
153
|
+
description: Ruby interface to the joyent cloud API
|
154
|
+
email: ben.wyrosdick@gmail.com
|
155
|
+
executables:
|
156
|
+
- joyent
|
157
|
+
extensions: []
|
158
|
+
|
159
|
+
extra_rdoc_files:
|
160
|
+
- LICENSE.txt
|
161
|
+
- README.rdoc
|
162
|
+
files:
|
163
|
+
- .document
|
164
|
+
- Gemfile
|
165
|
+
- Gemfile.lock
|
166
|
+
- LICENSE.txt
|
167
|
+
- README.rdoc
|
168
|
+
- Rakefile
|
169
|
+
- VERSION
|
170
|
+
- bin/joyent
|
171
|
+
- joyent.gemspec
|
172
|
+
- lib/joyent.rb
|
173
|
+
- lib/joyent/connection.rb
|
174
|
+
- lib/joyent/datacenter.rb
|
175
|
+
- lib/joyent/datacenters.rb
|
176
|
+
- lib/joyent/dataset.rb
|
177
|
+
- lib/joyent/datasets.rb
|
178
|
+
- lib/joyent/machine.rb
|
179
|
+
- lib/joyent/machines.rb
|
180
|
+
- lib/joyent/package.rb
|
181
|
+
- lib/joyent/packages.rb
|
182
|
+
- test/helper.rb
|
183
|
+
- test/test_joyent.rb
|
184
|
+
has_rdoc: true
|
185
|
+
homepage: http://github.com/mongohq/joyent
|
186
|
+
licenses:
|
187
|
+
- MIT
|
188
|
+
post_install_message:
|
189
|
+
rdoc_options: []
|
190
|
+
|
191
|
+
require_paths:
|
192
|
+
- lib
|
193
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
194
|
+
none: false
|
195
|
+
requirements:
|
196
|
+
- - ">="
|
197
|
+
- !ruby/object:Gem::Version
|
198
|
+
hash: 3
|
199
|
+
segments:
|
200
|
+
- 0
|
201
|
+
version: "0"
|
202
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
203
|
+
none: false
|
204
|
+
requirements:
|
205
|
+
- - ">="
|
206
|
+
- !ruby/object:Gem::Version
|
207
|
+
hash: 3
|
208
|
+
segments:
|
209
|
+
- 0
|
210
|
+
version: "0"
|
211
|
+
requirements: []
|
212
|
+
|
213
|
+
rubyforge_project:
|
214
|
+
rubygems_version: 1.3.7
|
215
|
+
signing_key:
|
216
|
+
specification_version: 3
|
217
|
+
summary: Ruby interface to the joyent cloud API
|
218
|
+
test_files: []
|
219
|
+
|