Skip to content

Commit 0b740ea

Browse files
committed
Merge pull request #46 from softlayer/Version_2.2.0
Version 2.2.0 - This build includes the ability to set a network timeout and contains a bug fix for the existing Object Mask parser.
2 parents aa7f834 + 3423274 commit 0b740ea

11 files changed

Lines changed: 67 additions & 10 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
log/
66
internal_examples/
77
doc/
8+
coverage/
89
Gemfile.lock

CHANGELOG.textile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
*2.2*
2-
* Added a method to reboot servers.
2+
* Added the ability to set a timout for network requests. The timeout is given when a client is created by passing the :timeout hash parameter when creating a client. The value of the parameter is an integer number of seconds.
3+
* Fixed a bug in VirtualServer#capture_image
34

45
*2.1.1*
56
* Virtual server upgrades no longer raise exceptions

lib/softlayer/Client.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ class Client
4545

4646
# A string passsed as the value for the User-Agent header when requests are sent to SoftLayer API.
4747
attr_accessor :user_agent
48+
49+
# An integer value (in seconds). The number of seconds to wait for HTTP requests to the network API
50+
# until they timeout. This value can be nil in which case the timeout will be the default value for
51+
# the library handling network communication (often 30 seconds)
52+
attr_reader :network_timeout
4853

4954
##
5055
# The client class maintains an (optional) default client. The default client
@@ -66,6 +71,7 @@ def self.default_client=(new_default)
6671
# * <b>+:api_key+</b> - The API key used to authenticate the user with the API
6772
# * <b>+:enpoint_url+</b> - The API endpoint the client should connect to. This defaults to API_PUBLIC_ENDPOINT
6873
# * <b>+:user_agent+</b> - A string that is passed along as the user agent when the client sends requests to the server
74+
# * <b>+:timeout+</b> - An integer number of seconds to wait until network requests time out. Corresponds to the network_timeout property of the client
6975
#
7076
# If these arguments are not provided then the client will try to locate them using other
7177
# sources including global variables, and the SoftLayer config file (if one exists)
@@ -85,6 +91,8 @@ def initialize(options = {})
8591
@endpoint_url = settings[:endpoint_url] || API_PUBLIC_ENDPOINT
8692

8793
@user_agent = settings[:user_agent] || "softlayer_api gem/#{SoftLayer::VERSION} (Ruby #{RUBY_PLATFORM}/#{RUBY_VERSION})"
94+
95+
@network_timeout = settings[:timeout] if settings.has_key?(:timeout)
8896

8997
raise "A SoftLayer Client requires a username" if !@username || @username.empty?
9098
raise "A SoftLayer Client requires an api_key" if !@api_key || @api_key.empty?

lib/softlayer/Config.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ module SoftLayer
5454
# [softlayer]
5555
# username = joeusername
5656
# api_key = DEADBEEFBADF00D
57+
# timeout = 60
5758
#
5859
# = Environment Variables
5960
#
@@ -110,6 +111,7 @@ def Config.file_settings(*additional_files)
110111
result[:username] = softlayer_section['username'] if softlayer_section['username']
111112
result[:endpoint_url] = softlayer_section['endpoint_url'] if softlayer_section['endpoint_url']
112113
result[:api_key] = softlayer_section['api_key'] if softlayer_section['api_key']
114+
result[:timeout] = softlayer_section['timeout'] if softlayer_section['timeout']
113115
end
114116
end
115117
end

lib/softlayer/ObjectMaskParser.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def parse(mask_string)
5858

5959
recognize_token(@tokenizer, :eos, "Extraneous text after object mask: ")
6060

61-
if property && (property.name != "mask" && propertyName != "filterMask")
61+
if property && (property.name != "mask" && property.name != "filterMask")
6262
raise ObjectMaskParserError, "Object Mask must begin with a 'mask' or 'filterMask' root property"
6363
end
6464

lib/softlayer/Service.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,9 @@ def to_ary
296296

297297
def xmlrpc_client()
298298
if !@xmlrpc_client
299-
@xmlrpc_client = XMLRPC::Client.new2(URI.join(@client.endpoint_url,@service_name).to_s)
299+
@xmlrpc_client = XMLRPC::Client.new2(URI.join(@client.endpoint_url,@service_name).to_s, nil, @client.network_timeout)
300300

301-
# this is a workaround for a bug in later versions of the XML-RPC client in Ruby Core.
301+
# This is a workaround for a bug in later versions of the XML-RPC client in Ruby Core.
302302
# see https://bugs.ruby-lang.org/issues/8182
303303
@xmlrpc_client.http_header_extra = {
304304
"Accept-Encoding" => "identity",

lib/softlayer/VirtualServer.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,15 @@ def upgrade_max_port_speed!(network_speed_in_Mbps)
143143
#
144144
# The image_notes should be a string and will be added to the image as notes.
145145
#
146-
def capture_image(image_name, include_attached_storage = false, image_notes = nil)
146+
def capture_image(image_name, include_attached_storage = false, image_notes = '')
147+
image_notes = '' if !image_notes
148+
147149
disk_filter = lambda { |disk| disk['device'] == '0' }
148-
disk_filter = lambda { |disk| disk['device'] == '1' } if include_attached_storage
150+
disk_filter = lambda { |disk| disk['device'] != '1' } if include_attached_storage
149151

150152
disks = self.blockDevices.select(&disk_filter)
151153

152-
self.service.createArchiveTransaction(image_name, disks, notes) if disks && !disks.empty?
154+
self.service.createArchiveTransaction(image_name, disks, image_notes) if disks && !disks.empty?
153155
end
154156

155157
##

lib/softlayer/base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
# - +$SL_API_BASE_URL+- The default URL used to access the SoftLayer API. This defaults to the value of +SoftLayer::API_PUBLIC_ENDPOINT+
3232
#
3333
module SoftLayer
34-
VERSION = "2.1.1" # version history in the CHANGELOG.textile file at the root of the source
34+
VERSION = "2.2.0" # version history in the CHANGELOG.textile file at the root of the source
3535

3636
# The base URL of the SoftLayer API available to the public internet.
3737
API_PUBLIC_ENDPOINT = 'https://api.softlayer.com/xmlrpc/v3/'

spec/Client_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,16 @@
9595
end.to raise_error
9696
end
9797

98+
it 'initializes by default with nil as the timeout' do
99+
client = SoftLayer::Client.new(:username => 'fake_user', :api_key => 'fake_key', :endpoint_url => 'http://fakeurl.org/')
100+
expect(client.network_timeout).to be_nil
101+
end
102+
103+
it 'Accepts a timeout given as a config parameter' do
104+
client = SoftLayer::Client.new(:username => 'fake_user', :api_key => 'fake_key', :endpoint_url => 'http://fakeurl.org/', :timeout => 60)
105+
expect(client.network_timeout).to eq 60
106+
end
107+
98108
it 'gets the default endpoint even if none is provided' do
99109
$SL_API_BASE_URL = nil
100110
client = SoftLayer::Client.new(:username => 'fake_user', :api_key => 'fake_key')

spec/ObjectMaskParser_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,27 @@
5454
expect { result = subject.parse("mask[two,children], bob") }.to raise_error
5555
end
5656

57+
it "should parse a mask with fiterMask" do
58+
result = nil
59+
expect { result = subject.parse("filterMask.simple1") }.to_not raise_error
60+
61+
expect(result.name).to eq 'filterMask'
62+
expect(result.children[0].name).to eq 'simple1'
63+
end
64+
65+
it "should parse a mask set with fiterMask" do
66+
result = nil
67+
expect { result = subject.parse("[filterMask.simple1, filterMask.simple2]") }.to_not raise_error
68+
69+
expect(result.count).to eq 2
70+
expect(result[0].name).to eq 'filterMask'
71+
expect(result[0].children.count).to eq 1
72+
expect(result[0].children[0].name).to eq "simple1"
73+
74+
expect(result[1].name).to eq 'filterMask'
75+
expect(result[1].children.count).to eq 1
76+
expect(result[1].children[0].name).to eq "simple2"
77+
end
5778
end
5879

5980
describe SoftLayer::ObjectMaskParser, "#parse_property_set" do

0 commit comments

Comments
 (0)