mirror of
https://github.com/containers/podman.git
synced 2025-08-06 11:32:07 +08:00
Move alternate image acquisition to separate function
Moves acquisition of an alternate image provided by the user out of `acquireVMImage` in `pkg/machine/<hypervisor>/machine.go` and into `pkg/machine/pull.go` as its own function. Signed-off-by: Jake Correnti <jakecorrenti+github@proton.me>
This commit is contained in:
@ -100,18 +100,11 @@ func (m *MacMachine) acquireVMImage(opts machine.InitOptions, dataDir string) er
|
||||
// The user has provided an alternate image which can be a file path
|
||||
// or URL.
|
||||
m.ImageStream = "custom"
|
||||
g, err := machine.NewGenericDownloader(vmtype, m.Name, opts.ImagePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
imagePath, err := machine.NewMachineFile(g.Get().LocalUncompressedFile, nil)
|
||||
imagePath, err := machine.AcquireAlternateImage(m.Name, vmtype, opts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
m.ImagePath = *imagePath
|
||||
if err := machine.DownloadImage(g); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -385,3 +385,23 @@ func RemoveImageAfterExpire(dir string, expire time.Duration) error {
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
// AcquireAlternateImage downloads the alternate image the user provided, which
|
||||
// can be a file path or URL
|
||||
func AcquireAlternateImage(name string, vmtype VMType, opts InitOptions) (*VMFile, error) {
|
||||
g, err := NewGenericDownloader(vmtype, name, opts.ImagePath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
imagePath, err := NewMachineFile(g.Get().LocalUncompressedFile, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := DownloadImage(g); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return imagePath, nil
|
||||
}
|
||||
|
@ -225,20 +225,11 @@ func (v *MachineVM) acquireVMImage(opts machine.InitOptions) error {
|
||||
// The user has provided an alternate image which can be a file path
|
||||
// or URL.
|
||||
v.ImageStream = "custom"
|
||||
g, err := machine.NewGenericDownloader(vmtype, v.Name, opts.ImagePath)
|
||||
imagePath, err := machine.AcquireAlternateImage(v.Name, vmtype, opts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
imagePath, err := machine.NewMachineFile(g.Get().LocalUncompressedFile, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
v.ImagePath = *imagePath
|
||||
if err := machine.DownloadImage(g); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user