Code Monkey home page Code Monkey logo

digitalocean's Introduction

Donate

If you found this library useful, donate some CPU cycles to this project by clicking above. Thank you! ๐Ÿ˜‡

Digitalocean Rubygem

The easiest and most complete rubygem for DigitalOcean.

NOTICE: This is a DigitalOcean V1 API client. It supports everything, the V1 API can do with a simple interface written in Ruby. Use DropletKit for consuming the DigitalOcean V2 API.

Build Status Gem Version

Digitalocean.client_id  = "your_client_id"
Digitalocean.api_key    = "your_api_key"
result = Digitalocean::Droplet.all
# =>
# <RecursiveOpenStruct status="OK", droplets=[
#   {"id"=>12345, "name"=>"dev", "image_id"=>2676, "size_id"=>63, "region_id"=>3, "backups_active"=>false, "ip_address"=>"198.555.55.55", "private_ip_address"=>nil, "locked"=>false, "status"=>"active", "created_at"=>"2013-06-12T03:07:14Z"},
#   {"id"=>234674, "name"=>"server2", "image_id"=>441012, "size_id"=>62, "region_id"=>1, "backups_active"=>false, "ip_address"=>"192.555.55.56", "private_ip_address"=>nil, "locked"=>false, "status"=>"active", "created_at"=>"2013-06-17T00:30:12Z"}
# ]>
#

result.status
result.droplets
result.droplets.first.ip_address

Installation

Add this line to your application's Gemfile:

gem 'digitalocean'

And then execute:

bundle

Or install it yourself as:

gem install digitalocean

Then in your application initialize the gem:

Digitalocean.client_id  = "your_client_id"
Digitalocean.api_key    = "your_api_key"

You can find your keys at https://cloud.digitalocean.com/api_access

Usage

List Droplets

Digitalocean::Droplet.all

Find Droplet

Digitalocean::Droplet.find("id_of_droplet")

Create Droplet

Digitalocean::Droplet.create({:name => droplet_name, :size_id => size_id, :image_id => image_id, :region_id => region_id})

Available Commands

Digitalocean::Domain.all
Digitalocean::Domain.find(id)
Digitalocean::Domain.create({name: name, ip_address: ip_address})
Digitalocean::Domain.destroy(id)

Digitalocean::Droplet.all
Digitalocean::Droplet.find(id)
Digitalocean::Droplet.rename(id, {name: name})
Digitalocean::Droplet.reboot(id)
Digitalocean::Droplet.power_cycle(id)
Digitalocean::Droplet.shutdown(id)
Digitalocean::Droplet.power_off(id)
Digitalocean::Droplet.power_on(id)
Digitalocean::Droplet.snapshot(id, {name: name})
Digitalocean::Droplet.create({name: name, size_id: size_id, image_id: image_id, region_id: region_id, ssh_key_ids: ssh_key_ids})
Digitalocean::Droplet.destroy(id)
Digitalocean::Droplet.resize(id, {size_id: size_id})

Digitalocean::Image.all
Digitalocean::Image.all({filter: "my_images"})
Digitalocean::Image.find(id)
Digitalocean::Image.destroy(id)
Digitalocean::Image.transfer(id, {region_id: region_id})

Digitalocean::Record.all(domain_id)
Digitalocean::Record.find(domain_id, record_id)
Digitalocean::Record.create(domain_id, {record_type: record_type, data: data})
Digitalocean::Record.edit(domain_id, record_id, {record_type: record_type, data: data})
Digitalocean::Record.destroy(domain_id, record_id)

Digitalocean::Region.all
Digitalocean::Region.find(region_id)

Digitalocean::Size.all
Digitalocean::Size.find(size_id)

Digitalocean::SshKey.all
Digitalocean::SshKey.find(id)
Digitalocean::SshKey.create({name: name, ssh_pub_key: ssh_pub_key}) # Keep in mind you have to use CGI::escape for your ssh_pub_key

Digitalocean::Event.find(id)

Example

There is a digitalocean-rubygem-example to help jumpstart your development.[tada]

Options

Digitalocean.verify_ssl = false # optionally set this to false. defaults to true.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

When adding methods, add to the list of DEFINITIONS in lib/digitalocean.rb. Additionally, write a spec and add it to the list in the README.

Running Specs

bundle exec rspec spec/*

Publish to RubyGems.org

You first need to request access from scottmotte.

gem build digitalocean.gemspec
gem push digitalocean-1.0.1.gem

digitalocean's People

Contributors

arthurnn avatar doublemalt avatar dsabanin avatar eddiezane avatar eremeevdev avatar gpolek avatar jcmuller avatar jvanbaarsen avatar merqlove avatar molizz avatar motdotla avatar mpchlets avatar petemichaud avatar realanishsharma avatar remediate avatar ryanseys avatar sergiocampama avatar snyff avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

digitalocean's Issues

cgi escape ssh key create

I had to override this one as well... the issue was that your implementation does not CGI.escape the public key, so the + signs are being converted to spaces when they get to DigitalOcean. Here's my override:

Digitalocean::SshKey.singleton_class.send(:define_method, :create, -> (name, pub_key) {
  url = "https://api.digitalocean.com/v1/ssh_keys/new/?name=#{name}&ssh_pub_key=#{CGI.escape(pub_key)}&client_id=#{Digitalocean.client_id}&api_key=#{Digitalocean.api_key}"
  res = Net::HTTP.get(URI(url))
  RecursiveOpenStruct.new(JSON.parse(res))
})

Creation of ssh key

Hi Guys,

When the method SshKey.create is used, the ssh public key does not get encoded before being sent to the server. This should probably get (at least) documented or an extra-encoding could be added since it breaks if the ssh key contains a '+' sign (since it doesn't get encoded as '%2b' and the server thinks it's an encoded space).

Let me know what you think

Faraday dependency problem

TLDR: Because the Gemfile.lock is included in the Gem, there are issues with the dependency on Faraday on a fresh install.

To replicate, you could probably uninstall the faraday_middleware, faraday, and digitalocean Gems and gem install digitalocean.

The issue lies with the fact that there are no restrictions included in the gemspec. The Gemfile.lock file has restrictions on:

    faraday (0.8.9)
    faraday_middleware (0.9.0)
      faraday (>= 0.7.4, < 0.9)

This causes faraday(0.9.0.rc7) to be installed which has the following error when attempting to use the Gem:

/Users/eddiezane/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/faraday-0.9.0.rc7/lib/faraday/options.rb:54:in `fetch': undefined method `preserve_raw=' for #<Faraday::RequestOptions (empty)> (NoMethodError)
        from /Users/eddiezane/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/faraday_middleware-0.9.0/lib/faraday_middleware/response_middleware.rb:75:in `preserve_raw?'
        from /Users/eddiezane/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/faraday_middleware-0.9.0/lib/faraday_middleware/response_middleware.rb:38:in `process_response'
        from /Users/eddiezane/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/faraday_middleware-0.9.0/lib/faraday_middleware/response_middleware.rb:32:in `block in call'
        from /Users/eddiezane/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/faraday-0.9.0.rc7/lib/faraday/response.rb:57:in `on_complete'
        from /Users/eddiezane/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/faraday_middleware-0.9.0/lib/faraday_middleware/response_middleware.rb:30:in `call'
        from /Users/eddiezane/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/faraday-0.9.0.rc7/lib/faraday/request/url_encoded.rb:15:in `call'
        from /Users/eddiezane/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/faraday-0.9.0.rc7/lib/faraday/rack_builder.rb:139:in `build_response'
        from /Users/eddiezane/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/faraday-0.9.0.rc7/lib/faraday/connection.rb:377:in `run_request'
        from /Users/eddiezane/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/faraday-0.9.0.rc7/lib/faraday/connection.rb:140:in `get'
        from /Users/eddiezane/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/digitalocean-1.0.1/lib/digitalocean.rb:123:in `request_and_respond'
        from /Users/eddiezane/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/digitalocean-1.0.1/lib/digitalocean.rb:78:in `block (4 levels) in <module:Digitalocean>'
        from do.rb:6:in `<main>'

A fix would be to remove Gemfile.lock and specify dependency versions in the gemspec locking down faraday(0.8.9). I found a good stackoverflow on why Gemfile.lock's shouldn't be included in a Gem.

Failing to create droplets with ssh key ids

This was working awhile ago (before 1.0.2 or so I think, but not sure), but has been failing recently.

Digitalocean::Droplet.create( {:name => "#{name}.asdf.com", :size_id => 66, :image_id => 333333, :region_id => 4, :ssh_key_ids => [121212, 121213], :private_networking => true})

-> droplet is created with all settings correct except no ssh keys included. I get an email with the root password, which breaks my auto-growing scripts/etc.

I don't see any official API change here https://developers.digitalocean.com/droplets/

Thanks for a great project :)

Support for events?

Hi guys,

Thanks very much for creating this gem. Quick question: are you guys planning on supporting events any time soon? If not, I'd be happy to add support for that.

Cheers.

Getting password and balance

We've been waiting for a new version of API, but have not seen her in two very important functions for us:

  1. Get a password when creating a new droplet or reinstall it
  2. Get money balance

DISCUSSION: Digital Ocean V2 API

Hey guys, particularly maintainers, as you've likely heard DO moved their V2 API out to beta. It's RESTful, more secure, and does pagination well.

Part of the magic of this repo was that it was heavily metaprogrammed. It allowed someone to easily add new endpoints with very little knowledge of the library.

In large part that was thanks to DO's V1 API - which I actually ended up loving despite not following generally accepted RESTful practices.

So, let's discuss moving this to V2. I think we'd all like to take a similar metaprogrammed approach if possible. Is it possible with the new V2 API?

Testing

I forked the repo to add some stuff I needed, but I'm finding that the tests are difficult to add because the API doesn't have a test mode, and some of the methods are destructive. I want to recommend this gem as a solution:

https://github.com/vcr/vcr

that way we can record what an api response looks like directly from DO, and reuse it indefinitely for testing--even for things like destroy or find when we don't know what really exists on the server.

Reviving this library

Hi @averemeev, @jcmuller, @dsabanin, @ryanseys, and @sergiocampama

I'm working on reviving this library. Thanks for all your hard work.

You're all added as direct committers. Let me know if you'd also like to be added to rubygems - so you could push releases.

(
as an aside, I jumped back into this and the test setup I did was definitely not ideal. Hate that I had to use my credentials. I'm thinking of refactoring the tests to simply test against a string.

For example, if the string that gets built looks like this:
https://api.digitalocean.com/droplets/?client_id=[your_client_id]&api_key=[your_api_key]

we can trust that the method is built correctly. That way we won't have to run any tests against our own accounts.

Thoughts?
)

_slug parameters instead of _id

Hello!

How can I get _slug parameters instead of _id parameters?
For example: I need name of image not just it's id.
As I see in DO V1 API documentation it's possible. But how can I do it with this gem?

Thank you in advance.

Getting details of two different images/droplets returns only details of the first one. Problem with api url generation

Example:

images = Digitalocean::Image.all.images
Digitalocean::Image.find(images[0].id).image.id == images[0].id # true
Digitalocean::Image.find(images[1].id).image.id == images[1].id # false
Digitalocean::Image.find(images[1].id).image.id == images[0].id # true

This affects all requests to all resources. The problem is with pre_query variable in closure which gets overwritten after calling any of the resource methods.

DEFINITIONS[resource_name].each do |method_name, url|                                                                                                 
  parts         = url.split("?")                                                                                                                      
  pre_query     = parts[0]                                                                                                                            
  #^^^^^^^^                                                                                                                                           
  post_query    = parts[1]                                                                                                                            

  singleton.send :define_method, "_#{method_name}" do |*args|                                                                                         
    pre_query   = Digitalocean.process_standard_args_from_part(pre_query, args)                                                                       
    #^^^^^^^^                                                  ^^^^^^^^^                                                                              
    post_query  = Digitalocean.process_hash_args_from_part(post_query, args)                                                                          

    [pre_query, post_query].join("?")                                                                                                                 
  end                                                                                                                                                 
  # ...                                                                                                                                                      
end                                                                                                                                                   

Failed to create droplet with ssh_keys error [v2]

Droplet creation fails if ssh_keys parameter is provided. Also I have verified that ssh key is correct.

Equivalent Curl command:

curl -X POST https://api.digitalocean.com/v2/droplets \
 -d "{'ssh_keys': [189024], 'image': 'ubuntu-14-04-x32', \
 'private_networking': False,\
 'region': 'nyc2', 'size': '512mb', 'backups': False,\
 'name': 'test05'}"\
  -H\ 
 "content_type:application/json" -H "authorization:Bearer xxxx" 

Error code: 422
Error message: {
"id":"unprocessable_entity",
"message":"You specified invalid ssh key ids for Droplet creation."
}

New release?

Hello, I think new release needed, because of updated dependencies in gemspec.
I'm really waiting for it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.