@@ -83,30 +83,59 @@ def datacenters
8383
8484 ##
8585 # Accepts an array of datacenters (instances of SoftLayer::Datacenter) where this
86- # image should be made available. The call will kick off transactions to make
87- # the image available in the given datacenters. These transactions can take
86+ # image should be made available. The call will kick off one or more transactions
87+ # to make the image available in the given datacenters. These transactions can take
8888 # some time to complete.
8989 #
9090 # Note that the template will be REMOVED from any datacenter that does not
91- # appear in this array! The list given must be comprehensive.
91+ # appear in this array! The list given must be comprehensive.
92+ #
93+ # The available_datacenters call returns a list of the values that are valid
94+ # whithin this array.
9295 def datacenters = ( datacenters_array )
93- datacenter_data = datacenters_array . collect do |datacenter |
94- raise "Image templates cannot be copied to the data center #{ datacenter . name } " unless datacenter . available_for_image_templates?
96+ datacenter_data = datacenters_array . collect do |datacenter |
9597 { "id" => datacenter . id }
9698 end
9799
98100 self . service . setAvailableLocations ( datacenter_data . compact )
99101 end
100102
101103 ##
102- # Works with an array of account IDs (or should use master user names i.e. "SL232279" )
103- # that the image template is shared with
104+ # Returns an array of the datacenters that this image can be stored in.
105+ # This is the set of datacenters that you may choose from, when putting
106+ # together a list you will send to the datacenters= setter.
107+ #
108+ def available_datacenters
109+ datacenters_data = self . service . getStorageLocations ( )
110+ datacenters_data . collect { |datacenter_data | SoftLayer ::Datacenter . datacenter_named ( datacenter_data [ "name" ] ) }
111+ end
112+
113+ ##
114+ # Share this image template with another account
104115 #
105- # Should this be datacenters an "share_with_accounts, stop_sharing_with_accounts"
106- def shared_with_accounts
116+ # The id of another account can usually be determined
117+ # by the user name of the master user which is typically
118+ # "SL<account_id>" or something similar.
119+ #
120+ # Note that this routine raises an exception if you call
121+ # it with an account that is already in the list of
122+ # shared accounts.
123+ def start_sharing ( with_account_id )
124+ self . service . permitSharingAccess ( with_account_id )
107125 end
108126
109- def shared_with_accounts =
127+ ##
128+ # Stop sharing this image with the account_id given
129+ def stop_sharing ( with_account_id )
130+ raise "You cannot stop sharing an image template with the account that owns it" if with_account_id == self [ "accountId" ]
131+ self . service . denySharingAccess ( with_account_id )
132+ end
133+
134+ ##
135+ # Return an array with the id's of accounts that this image is shared with
136+ def shared_with
137+ accounts_data = self . service . getAccountReferences
138+ accounts_data . collect { |account_data | account_data [ "accountId" ] }
110139 end
111140
112141 ##
@@ -122,16 +151,15 @@ def delete!
122151 end
123152
124153 ##
125- # Wait until transactions related to the image template are finished
154+ # Repeatedly poll the netwokr API until transactions related to this image
155+ # template are finished
126156 #
127- # A template is not ready until all the transactions on the template
157+ # A template is not ' ready' until all the transactions on the template
128158 # itself, and all its children are complete.
129159 #
130160 # At each trial, the routine will yield to a block if one is given
131161 # The block is passed one parameter, a boolean flag indicating
132- # whether or not the image template is 'ready'. Interim invocations
133- # of the block should receive +false+, the final invocation should
134- # receieve +true+
162+ # whether or not the image template is 'ready'.
135163 #
136164 def wait_until_ready ( max_trials , seconds_between_tries = 2 )
137165 # pessimistically assume the server is not ready
@@ -324,7 +352,7 @@ def self.template_with_id(id, options_hash = {})
324352 protected
325353
326354 def self . default_object_mask
327- return "mask[id,name,note,globalIdentifier,datacenters,blockDevices,tagReferences,publicFlag,flexImageFlag,transactionId,children.transactionId]"
355+ return "mask[id,accountId, name,note,globalIdentifier,datacenters,blockDevices,tagReferences,publicFlag,flexImageFlag,transactionId,children.transactionId]"
328356 end
329357 end
330358end
0 commit comments