Linode Ruby API INSTALLATION: Make sure gemcutter.org is in your gem sources list, then: % sudo gem install linode To run tests you will need both rspec and mocha installed. RUNNING: Consult the Linode API guide here: http://www.linode.com/api/autodoc.cfm You will need to get an API key (check your account profile). Here is an annoyingly exhaustive IRB session where I play around with the API: irb> require 'rubygems' irb> require 'linode' irb> api_key = 'TOPSECRETAPIKEY' irb> l = Linode.new(:api_key => api_key) => # irb> result = l.test.echo(:foo => 'bar', :baz => 'xyzzy') => # irb> result.foo => "bar" irb> result.baz => "xyzzy" irb> result = l.avail.datacenters => [#, #, #, #] irb> s = _ => [#, #, #, #] irb> result.first => # irb> result.first.location => "Dallas, TX, USA" irb> l.avail.datacenters.collect {|i| i.location } => ["Dallas, TX, USA", "Fremont, CA, USA", "Atlanta, GA, USA", "Newark, NJ, USA"] irb> l.avail.datacenters.collect {|i| i.datacenterid } => [2, 3, 4, 6] irb> l.user.getapikey(:username => 'me', :password => 'SECKRIT') => # irb> l.user.getapikey(:username => 'me', :password => 'SECKRIT').api_key => "TOPSECRETAPIKEY" irb> l.user.getapikey(:username => 'me', :password => 'SECKRIT').username => "me" irb> l.avail.kernels => [#, #, #, #, #, #, #, #, #, #, #, #, #, #, #, #, #, #, #, #, #] irb> l.avail.kernels.size => 21 irb> l.avail.kernels.first => # irb> l.avail.kernels.first.label => "2.6.16.38-x86_64-linode2" irb> l.avail.linodeplans => [#26, "2"=>57, "3"=>20, "4"=>39}, price=19.95, planid=1, xfer=200, disk=16>, #11, "2"=>38, "3"=>14, "4"=>28}, price=29.95, planid=2, xfer=300, disk=24>, #13, "2"=>27, "3"=>18, "4"=>30}, price=39.95, planid=3, xfer=400, disk=32>, #18, "2"=>7, "3"=>9, "4"=>4}, price=59.95, planid=4, xfer=600, disk=48>, #14, "2"=>5, "3"=>7, "4"=>3}, price=79.95, planid=5, xfer=800, disk=64>, #3, "2"=>3, "3"=>3, "4"=>3}, price=159.95, planid=6, xfer=1600, disk=128>, #5, "2"=>6, "3"=>5, "4"=>5}, price=319.95, planid=7, xfer=2000, disk=256>, #5, "2"=>6, "3"=>5, "4"=>5}, price=479.95, planid=8, xfer=2000, disk=384>, #5, "2"=>6, "3"=>5, "4"=>5}, price=639.95, planid=9, xfer=2000, disk=512>, #5, "2"=>6, "3"=>5, "4"=>5}, price=799.95, planid=10, xfer=2000, disk=640>] irb> l.avail.linodeplans.size => 10 irb> l.avail.linodeplans.first => #26, "2"=>57, "3"=>20, "4"=>39}, price=19.95, planid=1, xfer=200, disk=16> irb> l.avail.linodeplans.first.avail => {"6"=>26, "2"=>57, "3"=>20, "4"=>39} irb> l.avail.distributions => [#, #, #, #, #, #, #, #, #, #, #, #, #, #, #, #, #, #, #, #, #, #] irb> l.avail.distributions.size => 22 irb> l.avail.distributions.first => # irb> l.avail.distributions.first.label => "Arch Linux 2007.08" irb> l.domain.resource.list RuntimeError: Error completing request [domain.resource.list] @ [https://api.linode.com/] with data [{}]: ERRORCODE6ERRORMESSAGEDOMAINID is required but was not passed in from ./lib/linode.rb:31:in `send_request' from ./lib/linode.rb:13:in `list' from (irb):3 irb> l.domain.resource.list(:DomainId => '1') RuntimeError: Error completing request [domain.resource.list] @ [https://api.linode.com/] with data [{:DomainId=>"1"}]: ERRORCODE5ERRORMESSAGEObject not found from ./lib/linode.rb:31:in `send_request' from ./lib/linode.rb:13:in `list' from (irb):5 irb> l.domain.resource.list(:DomainId => '1', :ResourceId => '2') RuntimeError: Error completing request [domain.resource.list] @ [https://api.linode.com/] with data [{:DomainId=>"1", :ResourceId=>"2"}]: ERRORCODE5ERRORMESSAGEObject not found from ./lib/linode.rb:31:in `send_request' from ./lib/linode.rb:13:in `list' from (irb):7 irb> l.linode => # irb> l.linode.list => [#, #, #, #] irb> l.linode.list.size => 4 irb> l.linode.list.first => # irb> l.linode.list.first.datacenterid => 6 irb> l.linode.list.first.label => "byggvir" irb(main):003:0* l.linode.config.list RuntimeError: Error completing request [linode.config.list] @ [https://api.linode.com/] with data [{}]: ERRORCODE6ERRORMESSAGELINODEID is required but was not passed in from ./lib/linode.rb:45:in `send_request' from ./lib/linode.rb:13:in `list' from (irb):3 irb> l.linode.list => [#, #, #, #] irb> l.linode.list.first => # irb> l.linode.list.first.linodeid => 12446 irb> l.linode.config.list(:LinodeId => 12446) => [#] irb> l.linode.config.list(:LinodeId => 12446).first.disklist => "79850,79851,79854,,,,,," irb> l.linode.job.list RuntimeError: Error completing request [linode.job.list] @ [https://api.linode.com/] with data [{}]: ERRORCODE6ERRORMESSAGELINODEID is required but was not passed in from ./lib/linode.rb:45:in `send_request' from ./lib/linode.rb:13:in `list' from (irb):7 irb> l.linode.job.list(:LinodeId => 12446) => [#, #, #, #, #, #, #, #] irb> l.linode.job.list(:LinodeId => 12446).size => 8 irb> l.linode.ip.list RuntimeError: Error completing request [linode.ip.list] @ [https://api.linode.com/] with data [{}]: ERRORCODE6ERRORMESSAGELINODEID is required but was not passed in from ./lib/linode.rb:45:in `send_request' from ./lib/linode.rb:13:in `list' from (irb):10 irb> l.linode.ip.list(:LinodeId => 12446) => [#, #] irb> ^D@ Wed Aug 05 01:50:52 rick@Yer-Moms-Computer CREDITS: - Thanks to Aditya Sanghi (github: asanghi) for a patch to properly namespace stackscripts functionality. - Thanks to Dan Hodos (github: danhodos) for diagnosing and fixing an issue with sending GET requests instead of POST request. - Thanks to Aaron Hamid for updates for RSpec 2 and work on user.getapikey + username/password initialization.