engine: resources: Pull out a distro function for guest

This commit is contained in:
James Shubin
2024-12-06 15:58:51 -05:00
parent ecee84aa28
commit 50265d2303

View File

@@ -163,6 +163,17 @@ func (obj *VirtBuilderRes) getOutput() string {
return obj.Name() return obj.Name()
} }
// getDistro returns the distro of the guest that we want to use. If not
// specified, or if we don't have a mapping for it, we return the empty string.
func (obj *VirtBuilderRes) getDistro() string {
ix := strings.Index(obj.OSVersion, "-") // fedora- or debian-
if ix == -1 {
return "" // os version is not supported
}
return obj.OSVersion[0:ix] // everything before the dash, eg: fedora
}
// getArch returns the architecture that we want to use. If not specified, or if // getArch returns the architecture that we want to use. If not specified, or if
// we don't have a mapping for it, we return the empty string. // we don't have a mapping for it, we return the empty string.
func (obj *VirtBuilderRes) getArch() string { func (obj *VirtBuilderRes) getArch() string {
@@ -219,12 +230,10 @@ func (obj *VirtBuilderRes) getGuestfs() ([]string, error) {
// that we can easily run mgmt. // that we can easily run mgmt.
func (obj *VirtBuilderRes) getDeps() ([]string, error) { func (obj *VirtBuilderRes) getDeps() ([]string, error) {
// TODO: Improve this function as things evolve. // TODO: Improve this function as things evolve.
ix := strings.Index(obj.OSVersion, "-") // fedora- or debian- distro := obj.getDistro()
if ix == -1 { if distro == "" {
return nil, fmt.Errorf("os version is not supported") return nil, fmt.Errorf("os version is not supported")
} }
distro := obj.OSVersion[0:ix] // everything before the dash, eg: fedora
packages, exists := distroUtil.ToBootstrapPackages(distro) packages, exists := distroUtil.ToBootstrapPackages(distro)
if !exists { if !exists {
// TODO: patches welcome! // TODO: patches welcome!