@@ -525,7 +525,9 @@ def CreateDiskFromSnapshot(
525525 snapshot : 'GoogleComputeSnapshot' ,
526526 disk_name : Optional [str ] = None ,
527527 disk_name_prefix : Optional [str ] = None ,
528- disk_type : str = 'pd-standard' ) -> 'GoogleComputeDisk' :
528+ disk_type : str = 'pd-standard' ,
529+ dest_project : Optional [str ] = None ,
530+ dest_zone : Optional [str ] = None ) -> 'GoogleComputeDisk' :
529531 """Create a new disk based on a Snapshot.
530532
531533 Args:
@@ -536,6 +538,10 @@ def CreateDiskFromSnapshot(
536538 which disk type to use to create the disk. Default is pd-standard. Use
537539 pd-ssd to have a SSD disk. You can list all available disk types by
538540 running the following command: gcloud compute disk-types list
541+ dest_project (str): Optional. The destination project where the disk
542+ should be created. Default is self.project_id.
543+ dest_zone (str): Optional. The destination zone where the disk
544+ should be created. Default is self.default_zone.
539545
540546 Returns:
541547 GoogleComputeDisk: Google Compute Disk.
@@ -547,19 +553,23 @@ def CreateDiskFromSnapshot(
547553
548554 if not disk_name :
549555 disk_name = common .GenerateDiskName (snapshot , disk_name_prefix )
556+
557+ project_id = dest_project or self .project_id
558+ zone = dest_zone or self .default_zone
559+
550560 body = {
551561 'name' :
552562 disk_name ,
553563 'sourceSnapshot' :
554564 snapshot .GetSourceString (),
555565 'type' :
556566 'projects/{0:s}/zones/{1:s}/diskTypes/{2:s}' .format (
557- self . project_id , self . default_zone , disk_type )
567+ project_id , zone , disk_type )
558568 }
559569 try :
560570 gce_disks_client = self .GceApi ().disks () # pylint: disable=no-member
561571 request = gce_disks_client .insert (
562- project = self . project_id , zone = self . default_zone , body = body )
572+ project = project_id , zone = zone , body = body )
563573 response = request .execute ()
564574 except HttpError as exception :
565575 if exception .resp .status == 409 :
@@ -570,9 +580,9 @@ def CreateDiskFromSnapshot(
570580 'Unknown error occurred when creating disk from Snapshot:'
571581 ' {0!s}' .format (exception ),
572582 __name__ ) from exception
573- self .BlockOperation (response , zone = self . default_zone )
583+ self .BlockOperation (response , zone = zone )
574584 return GoogleComputeDisk (
575- project_id = self . project_id , zone = self . default_zone , name = disk_name )
585+ project_id = project_id , zone = zone , name = disk_name )
576586
577587 def GetMachineTypes (self , machine_type : str ,
578588 zone : Optional [str ] = None ) -> Dict [str , Any ]:
0 commit comments