digital_ocean 0.0.1alpha1
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/.gitignore +18 -0
- data/.rspec +2 -0
- data/.travis.yml +9 -0
- data/Gemfile +4 -0
- data/Guardfile +11 -0
- data/LICENSE.txt +22 -0
- data/README.md +32 -0
- data/Rakefile +17 -0
- data/digital_ocean.gemspec +38 -0
- data/lib/digital_ocean/api.rb +46 -0
- data/lib/digital_ocean/authentication_middleware.rb +29 -0
- data/lib/digital_ocean/resource/base.rb +22 -0
- data/lib/digital_ocean/resource/droplet.rb +84 -0
- data/lib/digital_ocean/resource/image.rb +17 -0
- data/lib/digital_ocean/resource/region.rb +9 -0
- data/lib/digital_ocean/resource/size.rb +9 -0
- data/lib/digital_ocean/resource/ssh_key.rb +27 -0
- data/lib/digital_ocean/resource.rb +12 -0
- data/lib/digital_ocean/version.rb +3 -0
- data/lib/digital_ocean.rb +10 -0
- data/spec/api_spec.rb +421 -0
- data/spec/digital_ocean_spec.rb +7 -0
- data/spec/spec_helper.rb +21 -0
- data/spec/support/vcr.rb +21 -0
- data/spec/vcr/cassettes/DigitalOcean_API/_droplets/_create/should_be_successful.yml +48 -0
- data/spec/vcr/cassettes/DigitalOcean_API/_droplets/_delete/should_be_successful.yml +48 -0
- data/spec/vcr/cassettes/DigitalOcean_API/_droplets/_disable_backups/should_be_successful.yml +48 -0
- data/spec/vcr/cassettes/DigitalOcean_API/_droplets/_enable_backups/should_be_successful.yml +48 -0
- data/spec/vcr/cassettes/DigitalOcean_API/_droplets/_list/should_be_successful.yml +48 -0
- data/spec/vcr/cassettes/DigitalOcean_API/_droplets/_list/should_return_a_list_of_all_droplets.yml +48 -0
- data/spec/vcr/cassettes/DigitalOcean_API/_droplets/_power_cycle/should_be_successful.yml +48 -0
- data/spec/vcr/cassettes/DigitalOcean_API/_droplets/_power_off/should_be_successful.yml +48 -0
- data/spec/vcr/cassettes/DigitalOcean_API/_droplets/_power_on/should_be_successful.yml +48 -0
- data/spec/vcr/cassettes/DigitalOcean_API/_droplets/_reboot/should_be_successful.yml +48 -0
- data/spec/vcr/cassettes/DigitalOcean_API/_droplets/_rebuild/should_be_successful.yml +48 -0
- data/spec/vcr/cassettes/DigitalOcean_API/_droplets/_reset_root_password/should_be_successful.yml +49 -0
- data/spec/vcr/cassettes/DigitalOcean_API/_droplets/_resize/should_be_successful.yml +48 -0
- data/spec/vcr/cassettes/DigitalOcean_API/_droplets/_restore/should_be_successful.yml +48 -0
- data/spec/vcr/cassettes/DigitalOcean_API/_droplets/_show/should_be_successful.yml +48 -0
- data/spec/vcr/cassettes/DigitalOcean_API/_droplets/_shutdown/should_be_successful.yml +48 -0
- data/spec/vcr/cassettes/DigitalOcean_API/_droplets/_snapshot/should_be_successful.yml +48 -0
- data/spec/vcr/cassettes/DigitalOcean_API/_images/_delete/invalid/should_not_be_successful.yml +48 -0
- data/spec/vcr/cassettes/DigitalOcean_API/_images/_delete/valid/should_be_successful.yml +49 -0
- data/spec/vcr/cassettes/DigitalOcean_API/_images/_list/with_filter_global/should_be_successful.yml +69 -0
- data/spec/vcr/cassettes/DigitalOcean_API/_images/_list/with_filter_global/should_return_global_images.yml +69 -0
- data/spec/vcr/cassettes/DigitalOcean_API/_images/_list/with_filter_my_images/should_be_successful.yml +48 -0
- data/spec/vcr/cassettes/DigitalOcean_API/_images/_list/with_filter_my_images/should_return_my_images.yml +48 -0
- data/spec/vcr/cassettes/DigitalOcean_API/_images/_list/without_filter/should_be_successful.yml +70 -0
- data/spec/vcr/cassettes/DigitalOcean_API/_images/_list/without_filter/should_return_a_list_of_all_images.yml +70 -0
- data/spec/vcr/cassettes/DigitalOcean_API/_images/_show/invalid/should_not_be_successful.yml +48 -0
- data/spec/vcr/cassettes/DigitalOcean_API/_images/_show/valid/should_be_successful.yml +48 -0
- data/spec/vcr/cassettes/DigitalOcean_API/_images/_show/valid/should_return_the_image.yml +48 -0
- data/spec/vcr/cassettes/DigitalOcean_API/_regions/_list/should_be_successful.yml +49 -0
- data/spec/vcr/cassettes/DigitalOcean_API/_regions/_list/should_return_a_list_of_all_available_regions.yml +49 -0
- data/spec/vcr/cassettes/DigitalOcean_API/_regions/_list/should_return_a_list_of_all_regions.yml +49 -0
- data/spec/vcr/cassettes/DigitalOcean_API/_sizes/_list/should_be_successful.yml +48 -0
- data/spec/vcr/cassettes/DigitalOcean_API/_sizes/_list/should_return_a_list_of_all_droplet_sizes.yml +48 -0
- data/spec/vcr/cassettes/DigitalOcean_API/_sizes/_list/should_return_the_correct_ID_for_the_96GB_size.yml +48 -0
- data/spec/vcr/cassettes/DigitalOcean_API/_ssh_keys/_add/should_be_successful.yml +48 -0
- data/spec/vcr/cassettes/DigitalOcean_API/_ssh_keys/_delete/should_be_successful.yml +48 -0
- data/spec/vcr/cassettes/DigitalOcean_API/_ssh_keys/_list/should_be_successful.yml +48 -0
- data/spec/vcr/cassettes/DigitalOcean_API/_ssh_keys/_list/should_return_a_list_of_all_SSH_keys.yml +48 -0
- data/spec/vcr/cassettes/DigitalOcean_API/_ssh_keys/_show/invalid/should_not_be_successful.yml +48 -0
- data/spec/vcr/cassettes/DigitalOcean_API/_ssh_keys/_show/valid/should_be_successful.yml +50 -0
- data/spec/vcr/cassettes/DigitalOcean_API/_ssh_keys/_show/valid/should_return_a_list_of_all_SSH_keys.yml +50 -0
- data/spec/vcr/cassettes/DigitalOcean_API/_ssh_keys/_show/valid/should_return_the_public_keykey.yml +50 -0
- metadata +353 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard 'rspec' do
|
5
|
+
watch(%r{^spec/.+_spec\.rb$})
|
6
|
+
watch(%r{^lib/(.+)/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}/#{m[2]}_spec.rb" }
|
7
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
8
|
+
|
9
|
+
watch('spec/spec_helper.rb') { "spec" }
|
10
|
+
end
|
11
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Roland Moriz
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# DigitalOcean
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
[](https://travis-ci.org/rmoriz/digital_ocean)
|
6
|
+
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'digital_ocean'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install digital_ocean
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
TODO: Write usage instructions here
|
25
|
+
|
26
|
+
## Contributing
|
27
|
+
|
28
|
+
1. Fork it
|
29
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
30
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
31
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
32
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
require 'rubygems'
|
3
|
+
require 'bundler'
|
4
|
+
Bundler.setup
|
5
|
+
Bundler::GemHelper.install_tasks
|
6
|
+
|
7
|
+
require 'rspec/core/rake_task'
|
8
|
+
desc 'Run RSpec'
|
9
|
+
RSpec::Core::RakeTask.new do |spec|
|
10
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
11
|
+
spec.rspec_opts = ['--color', '--format nested']
|
12
|
+
end
|
13
|
+
|
14
|
+
desc 'Run rspec tests'
|
15
|
+
task :test => [:spec]
|
16
|
+
|
17
|
+
task :default => :test
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'digital_ocean/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = 'digital_ocean'
|
8
|
+
gem.version = DigitalOcean::VERSION
|
9
|
+
gem.authors = ['Roland Moriz']
|
10
|
+
gem.email = ['roland@moriz.de']
|
11
|
+
gem.description = %q{A Ruby gem to interact with DigitalOcean, a cloud hosting provider}
|
12
|
+
gem.summary = %q{This gem wraps the DigitalOcean API documented at https://api.digitalocean.com/}
|
13
|
+
gem.homepage = 'https://github.com/rmoriz/digital_ocean'
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ['lib']
|
19
|
+
|
20
|
+
if RUBY_PLATFORM == 'java'
|
21
|
+
gem.add_runtime_dependency 'jruby-openssl'
|
22
|
+
end
|
23
|
+
|
24
|
+
gem.add_dependency 'faraday', '~> 0.8.4'
|
25
|
+
gem.add_dependency 'faraday_middleware'
|
26
|
+
gem.add_dependency 'json'
|
27
|
+
gem.add_dependency 'rash'
|
28
|
+
|
29
|
+
gem.add_development_dependency 'rspec', '~> 2.0'
|
30
|
+
gem.add_development_dependency 'guard'
|
31
|
+
gem.add_development_dependency 'guard-rspec'
|
32
|
+
gem.add_development_dependency 'rb-fsevent'
|
33
|
+
|
34
|
+
gem.add_development_dependency 'vcr', '~> 2.4'
|
35
|
+
gem.add_development_dependency 'fakeweb', '~> 1.3.0'
|
36
|
+
gem.add_development_dependency 'rake'
|
37
|
+
gem.add_development_dependency 'yard'
|
38
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module DigitalOcean
|
2
|
+
class API
|
3
|
+
def initialize(params)
|
4
|
+
@client_id = params[:client_id]
|
5
|
+
@api_key = params[:api_key]
|
6
|
+
@debug = params[:debug]
|
7
|
+
@base_url = params[:base_url] || 'https://api.digitalocean.com/'
|
8
|
+
@faraday_adapter = params[:faraday_adapter] || Faraday.default_adapter
|
9
|
+
@faraday = params[:faraday] || default_faraday
|
10
|
+
|
11
|
+
raise ArgumentError, ':client_id missing' unless @client_id
|
12
|
+
raise ArgumentError, ':api_key missing' unless @api_key
|
13
|
+
end
|
14
|
+
|
15
|
+
def droplets
|
16
|
+
DigitalOcean::Resource::Droplet.new(@faraday)
|
17
|
+
end
|
18
|
+
|
19
|
+
def sizes
|
20
|
+
DigitalOcean::Resource::Size.new(@faraday)
|
21
|
+
end
|
22
|
+
|
23
|
+
def regions
|
24
|
+
DigitalOcean::Resource::Region.new(@faraday)
|
25
|
+
end
|
26
|
+
|
27
|
+
def ssh_keys
|
28
|
+
DigitalOcean::Resource::SSHKey.new(@faraday)
|
29
|
+
end
|
30
|
+
|
31
|
+
def images
|
32
|
+
DigitalOcean::Resource::Image.new(@faraday)
|
33
|
+
end
|
34
|
+
|
35
|
+
def default_faraday
|
36
|
+
Faraday.new(:url => @base_url) do |faraday|
|
37
|
+
faraday.use AuthenticationMiddleware, @client_id, @api_key
|
38
|
+
faraday.request :url_encoded
|
39
|
+
faraday.response :rashify
|
40
|
+
faraday.response :json
|
41
|
+
faraday.response(:logger) if @debug
|
42
|
+
faraday.adapter @faraday_adapter
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module DigitalOcean
|
2
|
+
class AuthenticationMiddleware < Faraday::Middleware
|
3
|
+
extend Forwardable
|
4
|
+
def_delegators :'Faraday::Utils', :parse_query, :build_query
|
5
|
+
|
6
|
+
def initialize(app, client_id, api_key)
|
7
|
+
@client_id = client_id
|
8
|
+
@api_key = api_key
|
9
|
+
|
10
|
+
super(app)
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(env)
|
14
|
+
params = { 'client_id' => @client_id, 'api_key' => @api_key }.update query_params(env[:url])
|
15
|
+
|
16
|
+
env[:url].query = build_query params
|
17
|
+
|
18
|
+
@app.call(env)
|
19
|
+
end
|
20
|
+
|
21
|
+
def query_params(url)
|
22
|
+
if url.query.nil? or url.query.empty?
|
23
|
+
{}
|
24
|
+
else
|
25
|
+
parse_query url.query
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module DigitalOcean
|
2
|
+
module Resource
|
3
|
+
class Base
|
4
|
+
def initialize(connection, options = {})
|
5
|
+
@connection = connection
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def apply_params(query, opts)
|
11
|
+
apply_default_params(query)
|
12
|
+
|
13
|
+
opts.each_pair do |key, value|
|
14
|
+
query.params[key] = value
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def apply_default_params(query)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module DigitalOcean
|
2
|
+
module Resource
|
3
|
+
class Droplet < Base
|
4
|
+
|
5
|
+
def list(opts = {})
|
6
|
+
@connection.get '/droplets' do |query|
|
7
|
+
apply_params(query, opts)
|
8
|
+
end.body
|
9
|
+
end
|
10
|
+
|
11
|
+
def show(id, opts = {})
|
12
|
+
@connection.get "/droplets/#{id}" do |query|
|
13
|
+
apply_params(query, opts)
|
14
|
+
end.body
|
15
|
+
end
|
16
|
+
|
17
|
+
def create(params)
|
18
|
+
@connection.get '/droplets/new' do |query|
|
19
|
+
apply_params(query, params)
|
20
|
+
end.body
|
21
|
+
end
|
22
|
+
|
23
|
+
def reboot(id)
|
24
|
+
@connection.put("/droplets/#{id}/reboot").body
|
25
|
+
end
|
26
|
+
|
27
|
+
def power_cycle(id)
|
28
|
+
@connection.put("/droplets/#{id}/power_cycle").body
|
29
|
+
end
|
30
|
+
|
31
|
+
def shutdown(id)
|
32
|
+
@connection.put("/droplets/#{id}/shutdown").body
|
33
|
+
end
|
34
|
+
|
35
|
+
def power_on(id)
|
36
|
+
@connection.put("/droplets/#{id}/power_on").body
|
37
|
+
end
|
38
|
+
|
39
|
+
def power_off(id)
|
40
|
+
@connection.put("/droplets/#{id}/power_off").body
|
41
|
+
end
|
42
|
+
|
43
|
+
def reset_root_password(id)
|
44
|
+
@connection.post("/droplets/#{id}/reset_root_password").body
|
45
|
+
end
|
46
|
+
|
47
|
+
def resize(id, params)
|
48
|
+
@connection.get "/droplets/#{id}/resize" do |query|
|
49
|
+
apply_params(query, params)
|
50
|
+
end.body
|
51
|
+
end
|
52
|
+
|
53
|
+
def snapshot(id, params)
|
54
|
+
@connection.get "/droplets/#{id}/snapshot" do |query|
|
55
|
+
apply_params(query, params)
|
56
|
+
end.body
|
57
|
+
end
|
58
|
+
|
59
|
+
def restore(id, params)
|
60
|
+
@connection.post "/droplets/#{id}/restore" do |query|
|
61
|
+
apply_params(query, params)
|
62
|
+
end.body
|
63
|
+
end
|
64
|
+
|
65
|
+
def rebuild(id, params)
|
66
|
+
@connection.post "/droplets/#{id}/rebuild" do |query|
|
67
|
+
apply_params(query, params)
|
68
|
+
end.body
|
69
|
+
end
|
70
|
+
|
71
|
+
def enable_backups(id)
|
72
|
+
@connection.post("/droplets/#{id}/enable_backups").body
|
73
|
+
end
|
74
|
+
|
75
|
+
def disable_backups(id)
|
76
|
+
@connection.post("/droplets/#{id}/disable_backups").body
|
77
|
+
end
|
78
|
+
|
79
|
+
def delete(id)
|
80
|
+
@connection.delete("/droplets/#{id}/destroy").body
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module DigitalOcean
|
2
|
+
module Resource
|
3
|
+
class Image < Base
|
4
|
+
def list(opts = {})
|
5
|
+
@connection.get('/images', opts).body
|
6
|
+
end
|
7
|
+
|
8
|
+
def show(id)
|
9
|
+
@connection.get("/images/#{id}").body
|
10
|
+
end
|
11
|
+
|
12
|
+
def delete(id)
|
13
|
+
@connection.get("/images/#{id}/destroy").body
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module DigitalOcean
|
2
|
+
module Resource
|
3
|
+
class SSHKey < Base
|
4
|
+
def list
|
5
|
+
@connection.get('/ssh_keys').body
|
6
|
+
end
|
7
|
+
|
8
|
+
def show(id)
|
9
|
+
@connection.get("/ssh_keys/#{id}").body
|
10
|
+
end
|
11
|
+
|
12
|
+
def delete(id)
|
13
|
+
@connection.delete("/ssh_keys/#{id}").body
|
14
|
+
end
|
15
|
+
|
16
|
+
#def add(args)
|
17
|
+
# @connection.get('/ssh_keys.json') do |query|
|
18
|
+
# apply_params(query, args)
|
19
|
+
# end.body
|
20
|
+
#end
|
21
|
+
#
|
22
|
+
#def edit
|
23
|
+
#end
|
24
|
+
#
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'digital_ocean/resource/base'
|
2
|
+
require 'digital_ocean/resource/droplet'
|
3
|
+
require 'digital_ocean/resource/size'
|
4
|
+
require 'digital_ocean/resource/region'
|
5
|
+
require 'digital_ocean/resource/ssh_key'
|
6
|
+
require 'digital_ocean/resource/image'
|
7
|
+
|
8
|
+
module DigitalOcean
|
9
|
+
module Resource
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|