func Run()

in cli_tools/gce_vm_image_export/exporter/exporter.go [167:256]


func Run(logger logging.Logger, args *ImageExportRequest) error {

	userLabels, err := validateAndParseFlags(args.DestinationURI, args.SourceImage, args.SourceDiskSnapshot, args.Labels)
	if err != nil {
		return err
	}

	ctx := context.Background()
	metadataGCE := &compute.MetadataGCE{}
	storageClient, err := storage.NewStorageClient(
		ctx, logger, option.WithCredentialsFile(args.Oauth))
	if err != nil {
		return err
	}
	defer storageClient.Close()

	scratchBucketCreator := storage.NewScratchBucketCreator(ctx, storageClient)
	computeClient, err := param.CreateComputeClient(&ctx, args.Oauth, args.ComputeEndpoint)
	if err != nil {
		return err
	}
	resourceLocationRetriever := storage.NewResourceLocationRetriever(metadataGCE, computeClient)

	region := new(string)
	paramPopulator := param.NewPopulator(
		param.NewNetworkResolver(computeClient),
		metadataGCE, storageClient,
		resourceLocationRetriever,
		scratchBucketCreator,
		param.NewMachineSeriesDetector(computeClient),
	)
	err = paramPopulator.PopulateMissingParameters(&args.Project, args.ClientID, &args.Zone, region, &args.ScratchBucketGcsPath,
		args.DestinationURI, nil, &args.Network, &args.Subnet, &args.WorkerMachineSeries)
	if err != nil {
		return err
	}

	var imageDiskSizeGb int64
	if args.SourceImage != "" {
		if imageDiskSizeGb, err = validateImageExists(computeClient, args.Project, args.SourceImage); err != nil {
			return err
		}
	} else {
		if imageDiskSizeGb, err = validateSnapshotExists(computeClient, args.Project, args.SourceDiskSnapshot); err != nil {
			return err
		}
	}

	varMap := buildDaisyVars(
		args.DestinationURI, args.SourceImage, args.SourceDiskSnapshot, imageDiskSizeGb,
		args.Format, args.Network, args.Subnet, *region, args.ComputeServiceAccount)

	workflowProvider := func() (*daisy.Workflow, error) {
		return daisy.NewFromFile(getWorkflowPath(args.Format, args.CurrentExecutablePath))
	}

	env := daisyutils.EnvironmentSettings{
		Project:                     args.Project,
		Zone:                        args.Zone,
		GCSPath:                     args.ScratchBucketGcsPath,
		OAuth:                       args.Oauth,
		Timeout:                     args.Timeout,
		EndpointsOverride:           daisyutils.EndpointsOverride{Compute: args.ComputeEndpoint},
		DisableGCSLogs:              args.GcsLogsDisabled,
		DisableCloudLogs:            args.CloudLogsDisabled,
		DisableStdoutLogs:           args.StdoutLogsDisabled,
		Network:                     args.Network,
		Subnet:                      args.Subnet,
		ComputeServiceAccount:       args.ComputeServiceAccount,
		Labels:                      userLabels,
		ExecutionID:                 os.Getenv(os.Getenv(daisyutils.BuildIDOSEnvVarName)),
		WorkerMachineSeries:         args.WorkerMachineSeries,
		NestedVirtualizationEnabled: args.NestedVirtualizationEnabled,
		Tool: daisyutils.Tool{
			HumanReadableName: "gce image export",
			ResourceLabelName: "gce-image-export",
		},
	}

	if env.ExecutionID == "" {
		env.ExecutionID = path.RandString(5)
	}
	values, err := daisyutils.NewDaisyWorker(workflowProvider, env, logger).RunAndReadSerialValues(
		varMap, targetSizeGBKey, sourceSizeGBKey)
	logger.Metric(&pb.OutputInfo{
		SourcesSizeGb: []int64{stringutils.SafeStringToInt(values[sourceSizeGBKey])},
		TargetsSizeGb: []int64{stringutils.SafeStringToInt(values[targetSizeGBKey])},
	})
	return err
}