@@ -214,8 +214,10 @@ def deploy_instance(self, context, cloudshell_session, cloud_provider_resource,
214214 deployment_model_attributes [deployment_path + '.Machine Type' ],
215215 deployment_model_attributes [deployment_path + '.Disk Type' ],
216216 deployment_model_attributes [deployment_path + '.Disk Size' ],
217- network_data )
217+ network_data ,
218+ image_source_type = deployment_model_attributes [deployment_path + '.Image Source' ])
218219 except Exception as e :
220+ self .logger .exception ("==>" )
219221 return DeployAppResult (actionId = deploy_app_action .actionId , success = False , errorMessage = e .message )
220222
221223 connect_subnet_results = []
@@ -289,9 +291,9 @@ def deploy_instance_from_template(self, context, cloudshell_session, cloud_provi
289291 self .logger .error (ex .message )
290292 raise ex
291293
292-
293294 def _create_instance (self , actionId , cloud_provider_resource , vm_unique_name , image_project , image_id , machine_type ,
294- disk_type , disk_size , network_data , input_user = '' , decrypted_input_password = '' ):
295+ disk_type , disk_size , network_data , input_user = '' , decrypted_input_password = '' ,
296+ image_source_type = 'public' ):
295297
296298 client = self ._get_client ()
297299
@@ -302,6 +304,8 @@ def _create_instance(self, actionId, cloud_provider_resource, vm_unique_name, im
302304
303305 diskType = disk_type .lower ()
304306
307+ source_image_uri = self ._prepare_source_image (image_id , image_project , image_source_type )
308+
305309 instance_body = {
306310 "kind" : "compute#instance" ,
307311 "name" : vm_unique_name ,
@@ -326,7 +330,7 @@ def _create_instance(self, actionId, cloud_provider_resource, vm_unique_name, im
326330 "autoDelete" : True ,
327331 "deviceName" : "instance-1" ,
328332 "initializeParams" : {
329- "sourceImage" : "projects/{}/global/images/{}" . format ( image_project , image_id ) ,
333+ "sourceImage" : source_image_uri ,
330334 "diskType" : "projects/{}/zones/{}/diskTypes/pd-{}" .format (self .project , zone , diskType ),
331335 "diskSizeGb" : disk_size
332336 }
@@ -359,7 +363,7 @@ def _create_instance(self, actionId, cloud_provider_resource, vm_unique_name, im
359363 "deletionProtection" : False
360364 }
361365
362- self .logger .debug ("instance_body: " + str (instance_body ))
366+ self .logger .info ("instance_body: " + str (instance_body ))
363367
364368 request = client .instances ().insert (project = self .project , zone = zone , body = instance_body )
365369 response = request .execute ()
@@ -374,6 +378,17 @@ def _create_instance(self, actionId, cloud_provider_resource, vm_unique_name, im
374378 deployedAppAddress = vm_details_data .vmNetworkData [0 ].privateIpAddress ,
375379 vmDetailsData = vm_details_data )
376380
381+ def _prepare_source_image (self , image_id , image_project , image_source_type ):
382+ source_image_uri = ""
383+ if image_source_type == "public" :
384+ source_image_uri = "projects/{}/global/images/{}" .format (image_project , image_id )
385+ elif image_source_type == "private" :
386+ source_image_uri = "global/images/{}" .format (image_id )
387+ else :
388+ raise ValueError ("Unsupported image source {}" .format (image_source_type ))
389+
390+ return source_image_uri
391+
377392 def _create_instance_from_template (self , actionId , cloud_provider_resource , vm_unique_name , template_name ,
378393 network_data , input_user = '' , decrypted_input_password = '' ):
379394
0 commit comments