Open riddlefixer opened 8 years ago
Hi Ed,
The full API documentation can be found at our developer's portal. It documents each endpoint provided by the API. If you look to the bottom right hand corner of that page, you'll see that you can toggle the examples. Selecting Ruby will give you examples using droplet_kit for each API call:
https://developers.digitalocean.com/documentation/v2/
If you're more comfortable working in other programing languages, the developer's portal also has a list of client libraries provided by our community:
https://developers.digitalocean.com/libraries/
Here's a minimal example for creating output like knife digital_ocean
require 'droplet_kit'
token = ENV['DO_TOKEN']
client = DropletKit::Client.new(access_token: token)
droplets = client.droplets.all
droplets.each do |droplet|
print droplet.id.to_s + "\t"
print droplet.name.to_s + "\t"
print droplet.status.to_s + "\t"
print droplet.region.name.to_s + "\n"
end
Hope that points you in the right direction. Let us know if we can do any more to help.
That little ruby toggle button helps a lot!!! And thank you for the example! This will get me going in the right direction quite nicely!
Cheers, Ed
Hi Guys!
Thanks to @andrewsomething I am cruising right along with my scripts. I am managing with the ruby stuff well enough to get a job done, though I could use a tutor. ;-)
But, my new issue is the user_data. I cannot seem to get it to work based on Step Three: Customization with User-Data. Can you please check my code? I am calling this from bash with
createdrop.rb example.com 1234567
Everything works but iptables does not shut down. Alternatively, I'd like to run a script that is already in the image, for example /home/user/bin/initialize_instance.sh
require 'droplet_kit'
token = ENV['DO_TOKEN']
client = DropletKit::Client.new(access_token: token)
userdata = "
#cloud-config
runcmd:
- /etc/init.d/iptables stop
"
droplet = DropletKit::Droplet.new(name: ARGV[0], region: 'sfo1', size: '8gb', image: ARGV[1], ipv6: false, user_data: userdata)
client.droplets.create(droplet)
What am I doing wrong? Please help.
Cheers, Ed
Hey! I don't see anything wrong with the Ruby code. When debugging a cloud-config script, check the log files at /var/log/cloud-init.log
and /var/log/cloud-init-output.log
The file /etc/init.d/iptables
doesn't exist on many Linux distros. I suspect that is the issue. If you're looking to remove all iptables rules, you can use the command iptables -F
This is getting a bit out of scope for an issue against droplet_kit
but you're always welcome to ask questions over on our community site:
Hello,
I am new to ruby and droplet_kit but I'm trying to learn. I have been using irb commands and not getting expected results. For example, after
I get the following result ()
=> #<DropletKit::PaginatedResource:0xb95191f4 @current_page=0, @total=nil, @action=#<ResourceKit::Action:0xb97308fc @name=:all, @verb=:get, @path="/v2/droplets", @query_keys=[:per_page, :page], @handlers={:any=>#<Proc:0xb9730a64@/opt/rubies/ruby-2.3.0/lib/ruby/gems/2.3.0/gems/droplet_kit-1.3.3/lib/droplet_kit/error_handling_resourcable.rb:4>, 200=>#<Proc:0xb9730794@/opt/rubies/ruby-2.3.0/lib/ruby/gems/2.3.0/gems/droplet_kit-1.3.3/lib/droplet_kit/resources/droplet_resource.rb:8>}>, @resource=#<DropletKit::DropletResource:0xb989dc6c @connection=#<Faraday::Connection:0xb95b859c @parallel_manager=nil, @headers={"Content-Type"=>"application/json", "Authorization"=>"Bearer SECRET", "User-Agent"=>"Faraday v0.9.2"}, @params={}, @options=#<Faraday::RequestOptions (empty)>, @ssl=#<Faraday::SSLOptions (empty)>, @default_parallel_manager=nil, @builder=#<Faraday::RackBuilder:0xb95abfa4 @handlers=[Faraday::Adapter::NetHttp]>, @url_prefix=#<URI::HTTPS https://api.digitalocean.com/>, @proxy=nil>, @scope=nil>, @collection=[], @args=[], @options={}>
Just by guessing and trial and error, I was able to get a better result with
client.droplets.all.each
and I saw another example usingclient.droplets.all.first
but other than that, I have no idea what I am doing. :-)My question is, where can I find a list of all available and valid options to
client.droplets.all()
andclient.images.all()
etc.?My goal is to try to automate some things like taking snapshots (saw the snapshots.rb example but I need something more robust) and transferring the resulting images to different data centers and creating droplets based off those snapshot images. I'd like to be able to create some of the results I have seen with
knife digital_ocean
such as:Anything you can do to help would be greatly appreciated!
Cheers, Ed