softlayer / softlayer-ruby

http://softlayer.github.io/softlayer-ruby/
MIT License
54 stars 35 forks source link

Request help to handle Net::ReadTimeout error #81

Closed YochanaSH closed 9 years ago

YochanaSH commented 9 years ago

Hi There,

I'm new to ruby scripts.

I'm using ruby scripts with softlayer API : $me = SoftLayer::Client.new( :username => "USER", :api_key => "api", :base_url => "url", :time_out => "120") def createObj(obj) begin svc = me.service_named("SoftLayer_Virtual_Guest") return in = svc.createObject(obj) rescue Exception => exception raise "Exception : #{exception}." end end

This fails frequently with error :

"Exception `Net::ReadTimeout' at /usr/local/ruby-2.2.0/lib/ruby/2.2.0/net/http.rb:1447 Net::ReadTimeout"

Is there a way to handle this ?

Many Thanks !

SLsthompson commented 9 years ago

The first thing that strikes me about your script is that you are providing the base_url. You do not need to provide a base url unless you are trying to use the API through the SoftLayer private network.

You create your client as a global variable ($me) but then inside of createObj, you are referring to a separate variable named "me". Those are two different things.

If your goal is to order a virtual server, you might try starting with the example code in the source:

https://github.com/softlayer/softlayer-ruby/blob/master/examples/order_virtual_server.rb

YochanaSH commented 9 years ago

I have made the changes you suggested, but still I see the same error. I provision 3 VMs simultaneously. So it works for 1 or 2 and fails everytime for one or the other

pbuckley commented 8 years ago

I think regardless of any syntax issues with the posted code, I found http://stackoverflow.com/questions/19798091/ruby-error-netreadtimeout was helpful when I faced the same error. It might also be helpful for others who find this issue after hitting the Net::ReadTimeout exception. In my case it was some sort of timeout or ratelimit, and once I added a pagination limit it was fine.

(slightly modified https://softlayer.github.io/ruby/server_locate/)

servers = SoftLayer::BareMetalServer.find_servers(object_mask: 'mask[location.pathString]', result_limit: {:limit => 100, :offset => 0})