Skip to content

Commit df0b8af

Browse files
committed
Updated the object mask for the new filterMask root property type. Fixed a bug which prevented objects from updating properly
1 parent 5d2cfc7 commit df0b8af

6 files changed

Lines changed: 32 additions & 13 deletions

File tree

lib/softlayer/ModelBase.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def to_ary
6161
# and return the new hash.
6262
#
6363
def refresh_details(object_mask = nil)
64-
softlayer_hash = self.softlayer_properties(object_mask)
64+
@softlayer_hash = self.softlayer_properties(object_mask)
6565
end
6666

6767
##

lib/softlayer/ObjectMaskParser.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,17 @@ def parse(mask_string)
5353
elsif token.type == :property_set_start
5454
property_set = parse_property_set(@tokenizer)
5555
else
56-
raise ObjectMaskParserError, "A valid Object mask is a 'mask' root property, or a property set containing root properties" + ObjectMaskToken.error_for_unexpected_token(token)
56+
raise ObjectMaskParserError, "A valid Object mask is a 'mask' or 'filterMask' root property, or a property set containing root properties" + ObjectMaskToken.error_for_unexpected_token(token)
5757
end
5858

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

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

65-
if property_set && property_set.find { |subproperty| subproperty.name != 'mask'}
66-
raise ObjectMaskParserError, "A root property set must contain only root properties"
65+
if property_set && property_set.find { |subproperty| subproperty.name != 'mask' && subproperty.name != 'filterMask' }
66+
raise ObjectMaskParserError, "A root property set must contain only 'mask' or 'filterMask' root properties"
6767
end
6868

6969
property || property_set

lib/softlayer/Server.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,16 @@ def notes=(new_notes)
119119
}
120120

121121
service.object_with_id(self.id).editObject(edit_template)
122+
self.refresh_details()
122123
end
123124

124125
##
125126
# Change the user metadata for the server.
126127
#
127128
def user_metadata=(new_metadata)
128129
raise ArgumentError.new("Cannot set user metadata to nil") unless new_metadata
129-
130130
service.object_with_id(self.id).setUserMetadata([new_metadata])
131+
self.refresh_details()
131132
end
132133

133134
##
@@ -143,6 +144,7 @@ def set_hostname!(new_hostname)
143144
}
144145

145146
service.object_with_id(self.id).editObject(edit_template)
147+
self.refresh_details()
146148
end
147149

148150
##
@@ -160,6 +162,7 @@ def set_domain!(new_domain)
160162
}
161163

162164
service.object_with_id(self.id).editObject(edit_template)
165+
self.refresh_details()
163166
end
164167

165168
##
@@ -179,6 +182,7 @@ def change_port_speed(new_speed, public = true)
179182
service.object_with_id(self.id).setPrivateNetworkInterfaceSpeed(new_speed)
180183
end
181184

185+
self.refresh_details()
182186
self
183187
end
184188

lib/softlayer/VirtualServer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ class VirtualServer < Server
5454
# transaction can be active at a time.
5555
sl_attr :activeTransaction
5656

57-
5857
##
5958
# :attr_reader:
6059
# Storage devices attached to the server. Storage may be local
@@ -187,6 +186,7 @@ def wait_until_ready(max_trials, wait_for_transactions = false, seconds_between_
187186
# a server is ready when it is provisioned, not reloading the OS
188187
# (and if wait_for_transactions is true, when there are no active transactions).
189188
ready = provisioned && !reloading_os && (!wait_for_transactions || !has_active_transaction)
189+
190190
num_trials = num_trials + 1
191191

192192
yield ready if block_given?

lib/softlayer/object_mask_helpers.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Hash
2828
# Given a hash, generate an Object Mask string from the structure
2929
# found within the hash. This allows object masks to be constructed
3030
# as hashes, then converted to strings when they must be passed
31-
# to the API. The routine does some very rudimentary validation to
31+
# to the API. The routine does some very rudimentary validation to
3232
# ensure that the hash represents a valid object mask, but care must
3333
# still be taken when constructing the hash.
3434
def to_sl_object_mask()
@@ -40,7 +40,7 @@ def to_sl_object_mask()
4040
end
4141

4242
# Returns a string representing the hash as a property within a larger
43-
# object mask. This routine is an implementation detail used in the conversion
43+
# object mask. This routine is an implementation detail used in the conversion
4444
# of hashes to object mask strings. You should not have to call this method directly.
4545
def _to_sl_object_mask_property()
4646
key_strings = __sl_object_mask_properties_for_keys();
@@ -112,9 +112,9 @@ def _to_sl_object_mask_property()
112112
# Softlayer Extensions to the Symbol class to support using symbols to create
113113
# object masks
114114
class Symbol
115-
# Converts the Symbol to a string, then converts the string to an
116-
# object mask property. This routine is an implementation detail used in
117-
# the conversion of hashes to object mask strings. You should not have to
115+
# Converts the Symbol to a string, then converts the string to an
116+
# object mask property. This routine is an implementation detail used in
117+
# the conversion of hashes to object mask strings. You should not have to
118118
# call this method directly.
119119
def _to_sl_object_mask_property()
120120
self.to_s._to_sl_object_mask_property()

spec/ModelBase_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,19 @@
6464
expect(test_model.to_ary).to be_nil
6565
end
6666

67+
it "realizes when low-level hash keys are added" do
68+
test_model = SoftLayer::ModelBase.new(nil, { "id" => "12345" })
69+
allow(test_model).to receive(:softlayer_properties) { { "id" => "12345", "newInfo" => "fun" } }
70+
expect(test_model.has_sl_property? :newInfo).to be_false
71+
test_model.refresh_details()
72+
expect(test_model.has_sl_property? :newInfo).to be_true
73+
end
74+
75+
it "realizes when low-level hash keys are removed" do
76+
test_model = SoftLayer::ModelBase.new(nil, { "id" => "12345", "newInfo" => "fun" })
77+
allow(test_model).to receive(:softlayer_properties) { { "id" => "12345" } }
78+
expect(test_model.has_sl_property? :newInfo).to be_true
79+
test_model.refresh_details()
80+
expect(test_model.has_sl_property? :newInfo).to be_false
81+
end
6782
end

0 commit comments

Comments
 (0)