Skip to content

Commit 569f0d9

Browse files
mbhavyarenier
authored andcommitted
Add search for virtual disk image (#114)
* Add search for virtual disk image
1 parent 99ff196 commit 569f0d9

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

lib/softlayer/VirtualDiskImage.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,35 @@ def service
188188
softlayer_client[:Virtual_Disk_Image].object_with_id(self.id)
189189
end
190190

191+
##
192+
# Retrieve the virtual disk image with the given image ID from the API
193+
#
194+
# The options parameter should contain:
195+
#
196+
# <b>+:client+</b> - The client used to connect to the API
197+
#
198+
# If no client is given, then the routine will try to use Client.default_client
199+
# If no client can be found the routine will raise an error.
200+
#
201+
# The options may include the following keys
202+
# * <b>+:object_mask+</b> (string) - A object mask of properties, in addition to the default properties, that you wish to retrieve for the image
203+
#
204+
def self.image_with_id(image_id, options = {})
205+
softlayer_client = options[:client] || Client.default_client
206+
raise "#{__method__} requires a client but none was given and Client::default_client is not set" if !softlayer_client
207+
208+
vdi_service = softlayer_client[:Virtual_Disk_Image]
209+
vdi_service = vdi_service.object_mask(default_object_mask.to_sl_object_mask)
210+
211+
if options.has_key?(:object_mask)
212+
vdi_service = vdi_service.object_mask(options[:object_mask])
213+
end
214+
215+
image_data = vdi_service.object_with_id(image_id).getObject()
216+
217+
return VirtualDiskImage.new(softlayer_client, image_data)
218+
end
219+
191220
protected
192221

193222
def self.default_object_mask

0 commit comments

Comments
 (0)