@@ -2253,39 +2253,49 @@ def GetOperation(self) -> Dict[str, Any]:
22532253 return response
22542254
22552255 def ExportImage (
2256- self , gcs_output_folder : str , output_name : Optional [str ] = None ) -> None :
2257- """Export compute image to Google Cloud storage.
2258-
2256+ self ,
2257+ gcs_output_folder : str ,
2258+ image_format : str ,
2259+ output_name : Optional [str ]) -> str :
2260+ """Export compute image to Google Cloud Storage.
2261+
22592262 Exported image is compressed and stored in .tar.gz format.
22602263
22612264 Args:
22622265 gcs_output_folder (str): Folder path of the exported image.
2266+ image_format (str): The image format to use for the export.
22632267 output_name (str): Optional. Name of the output file. Name will be
22642268 appended with .tar.gz. Default is [image_name].tar.gz.
2265-
2269+ Returns:
2270+ str: The full path of the exported image.
22662271 Raises:
22672272 InvalidNameError: If exported image name is invalid.
22682273 """
2269-
22702274 if output_name :
22712275 if not common .REGEX_DISK_NAME .match (output_name ):
22722276 raise errors .InvalidNameError (
22732277 'Exported image name {0:s} does not comply with {1:s}' .format (
22742278 output_name , common .REGEX_DISK_NAME .pattern ),
22752279 __name__ )
2276- full_path = '{0:s}.tar.gz' .format (
2277- os .path .join (gcs_output_folder , output_name ))
2280+ full_path = '{0:s}' .format (os .path .join (gcs_output_folder , output_name ))
22782281 else :
2279- full_path = '{0:s}.tar.gz' .format (
2280- os .path .join (gcs_output_folder , self .name ))
2282+ full_path = '{0:s}' .format (os .path .join (gcs_output_folder , self .name ))
2283+ if not image_format :
2284+ full_path = '{0:s}.tar.gz' .format (full_path )
2285+ else :
2286+ full_path = '{0:s}.{1:s}' .format (full_path , image_format )
2287+
2288+ build_args = [
2289+ '-source_image={0:s}' .format (self .name ),
2290+ '-destination_uri={0:s}' .format (full_path ),
2291+ '-client_id=api' ,
2292+ ]
2293+ if image_format :
2294+ build_args .append ('-format={0:s}' .format (image_format ))
22812295 build_body = {
22822296 'timeout' : '86400s' ,
2283- 'steps' : [{
2284- 'args' : [
2285- '-source_image={0:s}' .format (self .name ),
2286- '-destination_uri={0:s}' .format (full_path ),
2287- '-client_id=api' ,
2288- ],
2297+ 'steps' : [{
2298+ 'args' : build_args ,
22892299 'name' : 'gcr.io/compute-image-tools/gce_vm_image_export:release' ,
22902300 'env' : []
22912301 }],
@@ -2295,6 +2305,7 @@ def ExportImage(
22952305 response = cloud_build .CreateBuild (build_body )
22962306 cloud_build .BlockOperation (response )
22972307 logger .info ('Image {0:s} exported to {1:s}.' .format (self .name , full_path ))
2308+ return full_path
22982309
22992310 def Delete (self ) -> None :
23002311 """Delete Compute Disk Image from a project."""
0 commit comments