func GetOSId()

in cli_tools/gce_ovf_import/ovf_utils/ovf_utils.go [438:482]


func GetOSId(ovfDescriptor *ovf.Envelope) (string, error) {

	if ovfDescriptor.VirtualSystem == nil {
		return "", daisy.Errf("OVF descriptor error: VirtualSystem must be defined to retrieve OS info. Use --os flag to specify OS")
	}
	if ovfDescriptor.VirtualSystem.OperatingSystem == nil ||
		len(ovfDescriptor.VirtualSystem.OperatingSystem) == 0 {
		return "", daisy.Errf("OVF descriptor error: OperatingSystemSection must be defined to retrieve OS info. Use --os flag to specify OS")
	}
	if ovfDescriptor.VirtualSystem.OperatingSystem[0].OSType == nil && ovfDescriptor.VirtualSystem.OperatingSystem[0].ID == 0 {
		return "", daisy.Errf("OVF descriptor error: OperatingSystemSection.OSType or OperatingSystemSection.ID must be defined to retrieve OS info. Use --os flag to specify OS")
	}

	var osInfoFromOSType, osInfoFromOSID *OsInfo
	if ovfDescriptor.VirtualSystem.OperatingSystem[0].OSType != nil && *ovfDescriptor.VirtualSystem.OperatingSystem[0].OSType != "" {
		if osInfoFromOSTypeValue, ok := ovfOSTypeToOSID[*ovfDescriptor.VirtualSystem.OperatingSystem[0].OSType]; ok {
			osInfoFromOSType = &osInfoFromOSTypeValue
		}
	}

	if ovfDescriptor.VirtualSystem.OperatingSystem[0].ID != 0 {
		if osInfoFromOSIDValue, ok := ovfOSIDToImporterOSID[ovfDescriptor.VirtualSystem.OperatingSystem[0].ID]; ok {
			osInfoFromOSID = &osInfoFromOSIDValue
		}
	}

	if osInfoFromOSType == nil && osInfoFromOSID == nil {
		return "", daisy.Errf("cannot determine OS from OVF descriptor. Use --os flag to specify OS")
	}

	osInfo := getMoreSpecificOSInfo(osInfoFromOSType, osInfoFromOSID)

	if !osInfo.hasImporterOSIDs() {
		return "", daisy.Errf("operating system `%v` detected but is not supported by Google Compute Engine. Use --os flag to specify OS", osInfo.description)
	}
	if osInfo.isDeterministic() {
		return osInfo.importerOSIDs[0], nil
	}

	return "",
		daisy.Errf(
			"cannot determine OS from OVF descriptor. Use --os flag to specify OS. Potential valid values for given osType attribute are: %v",
			strings.Join(osInfo.importerOSIDs, ", "),
		)
}