util: distro, engine: resources: Update virt-builder res
A little easier to maintain if we support more distros eventually.
This commit is contained in:
@@ -199,19 +199,20 @@ func (obj *VirtBuilderRes) getBinaryPath() (string, error) {
|
|||||||
|
|
||||||
// getGuestfs returns the package to install for our os so that we can run
|
// getGuestfs returns the package to install for our os so that we can run
|
||||||
// virt-builder.
|
// virt-builder.
|
||||||
func (obj *VirtBuilderRes) getGuestfs() (string, error) {
|
func (obj *VirtBuilderRes) getGuestfs() ([]string, error) {
|
||||||
// TODO: Improve this function as things evolve.
|
// TODO: Improve this function as things evolve.
|
||||||
|
distro, err := distroUtil.Distro(context.TODO()) // what is this resource running in?
|
||||||
if _, err := os.Stat("/etc/redhat-release"); err == nil { // fedora
|
if err != nil {
|
||||||
return "guestfs-tools", nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := os.Stat("/etc/debian_version"); err == nil { // debian
|
packages, exists := distroUtil.DistroToGuestfsPackages(distro)
|
||||||
return "guestfs-tools", nil
|
if !exists {
|
||||||
|
// TODO: patches welcome!
|
||||||
|
return nil, fmt.Errorf("os/version is not supported")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: patches welcome!
|
return packages, nil
|
||||||
return "", fmt.Errorf("os/version is not supported")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// getDeps returns a list of packages to install for the specific os-version so
|
// getDeps returns a list of packages to install for the specific os-version so
|
||||||
@@ -307,7 +308,7 @@ func (obj *VirtBuilderRes) Init(init *engine.Init) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to get the package of the binary...
|
// Try to get the packages for the binary...
|
||||||
p, err := obj.getGuestfs()
|
p, err := obj.getGuestfs()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -317,9 +318,11 @@ func (obj *VirtBuilderRes) Init(init *engine.Init) error {
|
|||||||
defer virtBuilderMutex.Unlock()
|
defer virtBuilderMutex.Unlock()
|
||||||
|
|
||||||
// Try to install the binary...
|
// Try to install the binary...
|
||||||
obj.init.Logf("installing: %s", p)
|
for _, x := range p {
|
||||||
if err := InstallOnePackage(context.TODO(), p); err != nil {
|
obj.init.Logf("installing: %s", x)
|
||||||
return err
|
if err := InstallOnePackage(context.TODO(), x); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -71,6 +71,18 @@ var (
|
|||||||
"PackageKit",
|
"PackageKit",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MapDistroToGuestfsPackages is a map of distro to packages needed to
|
||||||
|
// run the virt-builder software and guestfs suite.
|
||||||
|
MapDistroToGuestfsPackages = map[string][]string{
|
||||||
|
// TODO: add more values
|
||||||
|
DistroDebian: {
|
||||||
|
"guestfs-tools",
|
||||||
|
},
|
||||||
|
DistroFedora: {
|
||||||
|
"guestfs-tools",
|
||||||
|
},
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// DistroToBootstrapPackages returns the list of packages corresponding to the
|
// DistroToBootstrapPackages returns the list of packages corresponding to the
|
||||||
@@ -80,6 +92,14 @@ func DistroToBootstrapPackages(distro string) ([]string, bool) {
|
|||||||
return l, exists
|
return l, exists
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DistroToGuestfsPackages returns the list of packages corresponding to the
|
||||||
|
// distro for running the virt-builder software and guestfs suite. This returns
|
||||||
|
// false if the value doesn't exist.
|
||||||
|
func DistroToGuestfsPackages(distro string) ([]string, bool) {
|
||||||
|
l, exists := MapDistroToGuestfsPackages[distro]
|
||||||
|
return l, exists
|
||||||
|
}
|
||||||
|
|
||||||
// Family returns the distro family.
|
// Family returns the distro family.
|
||||||
func Family(ctx context.Context) (string, error) {
|
func Family(ctx context.Context) (string, error) {
|
||||||
if b, err := IsFamilyRedHat(ctx); err != nil {
|
if b, err := IsFamilyRedHat(ctx); err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user