func()

in cli_tools/common/image/importer/process_planner.go [66:126]


func (p *defaultPlanner) plan(pd persistentDisk) (*processingPlan, error) {
	// Don't run inspection if the user specified a custom workflow.
	if p.request.CustomWorkflow != "" {
		return &processingPlan{translationWorkflowPath: p.request.CustomWorkflow}, nil
	}

	inspectionResults, inspectionError := p.inspectDisk(pd.uri)
	var detectedOs distro.Release
	osID := p.request.OS
	requiresUEFI := p.request.UefiCompatible
	if inspectionError == nil && inspectionResults != nil {
		if inspectionResults.GetOsCount() == 1 && inspectionResults.GetOsRelease() != nil {
			detectedOs, _ = distro.FromGcloudOSArgument(inspectionResults.GetOsRelease().CliFormatted)
		}
		if osID == "" && inspectionResults.GetOsCount() == 1 && inspectionResults.GetOsRelease() != nil {
			osID = inspectionResults.GetOsRelease().CliFormatted
			if p.request.BYOL {
				osID += "-byol"
			}
		}

		if requiresUEFI {
			if !inspectionResults.GetUefiBootable() {
				p.logger.User("UEFI booting was specified, but we could not detect a UEFI bootloader. " +
					"Specifying an incorrect boot type can increase load times, or lead to boot failures.")
			}
		} else {
			hybridGPTBootable := inspectionResults.GetUefiBootable() && inspectionResults.GetBiosBootable()
			if hybridGPTBootable {
				p.logger.User("The boot disk can boot with either BIOS or a UEFI bootloader. The default setting for booting is BIOS. " +
					"If you want to boot using UEFI, please see https://cloud.google.com/compute/docs/import/importing-virtual-disks#importing_a_virtual_disk_with_uefi_bootloader'.")
			}
			requiresUEFI = inspectionResults.GetUefiBootable() && !hybridGPTBootable
		}
	}

	if osID == "" {
		return nil, errors.New("could not detect operating system. Please re-import with the operating system specified. " +
			"For more information, see https://cloud.google.com/compute/docs/import/importing-virtual-disks#bootable")
	}

	settings, err := daisyutils.GetTranslationSettings(osID)
	if err != nil {
		return nil, err
	}

	var requiredGuestOSFeatures []*compute.GuestOsFeature
	if strings.Contains(osID, "windows") {
		requiredGuestOSFeatures = append(requiredGuestOSFeatures, &compute.GuestOsFeature{Type: "WINDOWS"})
	}
	if requiresUEFI {
		requiredGuestOSFeatures = append(requiredGuestOSFeatures, &compute.GuestOsFeature{Type: "UEFI_COMPATIBLE"})
	}

	return &processingPlan{
		requiredLicenses:        []string{settings.LicenseURI},
		requiredFeatures:        requiredGuestOSFeatures,
		translationWorkflowPath: path.Join(p.request.WorkflowDir, "image_import", settings.WorkflowPath),
		detectedOs:              detectedOs,
	}, nil
}