mirror of
https://github.com/containers/podman.git
synced 2025-06-04 13:08:55 +08:00
Allow setting of machine stream and image path from containers.conf
Default is "testing" Signed-off-by: Ashley Cui <acui@redhat.com>
This commit is contained in:
@ -34,6 +34,7 @@ func init() {
|
|||||||
Parent: machineCmd,
|
Parent: machineCmd,
|
||||||
})
|
})
|
||||||
flags := initCmd.Flags()
|
flags := initCmd.Flags()
|
||||||
|
cfg := registry.PodmanConfig()
|
||||||
|
|
||||||
cpusFlagName := "cpus"
|
cpusFlagName := "cpus"
|
||||||
flags.Uint64Var(
|
flags.Uint64Var(
|
||||||
@ -61,7 +62,7 @@ func init() {
|
|||||||
_ = initCmd.RegisterFlagCompletionFunc(memoryFlagName, completion.AutocompleteNone)
|
_ = initCmd.RegisterFlagCompletionFunc(memoryFlagName, completion.AutocompleteNone)
|
||||||
|
|
||||||
ImagePathFlagName := "image-path"
|
ImagePathFlagName := "image-path"
|
||||||
flags.StringVar(&initOpts.ImagePath, ImagePathFlagName, "", "Path to qcow image")
|
flags.StringVar(&initOpts.ImagePath, ImagePathFlagName, cfg.Engine.MachineImage, "Path to qcow image")
|
||||||
_ = initCmd.RegisterFlagCompletionFunc(ImagePathFlagName, completion.AutocompleteDefault)
|
_ = initCmd.RegisterFlagCompletionFunc(ImagePathFlagName, completion.AutocompleteDefault)
|
||||||
|
|
||||||
IgnitionPathFlagName := "ignition-path"
|
IgnitionPathFlagName := "ignition-path"
|
||||||
|
@ -39,7 +39,9 @@ do these things manually or handle otherwise.
|
|||||||
|
|
||||||
#### **--image-path**
|
#### **--image-path**
|
||||||
|
|
||||||
Fully qualified path of the uncompressed image file
|
Fully qualified path or URL to the VM image.
|
||||||
|
Can also be set to `testing` or `stable` to pull down default image.
|
||||||
|
Defaults to `testing`.
|
||||||
|
|
||||||
#### **--memory**, **-m**=*number*
|
#### **--memory**, **-m**=*number*
|
||||||
|
|
||||||
|
@ -24,8 +24,8 @@ type FcosDownload struct {
|
|||||||
Download
|
Download
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFcosDownloader(vmType, vmName string) (DistributionDownload, error) {
|
func NewFcosDownloader(vmType, vmName, imageStream string) (DistributionDownload, error) {
|
||||||
info, err := getFCOSDownload()
|
info, err := getFCOSDownload(imageStream)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -8,16 +8,26 @@ import (
|
|||||||
|
|
||||||
"github.com/coreos/stream-metadata-go/fedoracoreos"
|
"github.com/coreos/stream-metadata-go/fedoracoreos"
|
||||||
"github.com/coreos/stream-metadata-go/stream"
|
"github.com/coreos/stream-metadata-go/stream"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// This should get Exported and stay put as it will apply to all fcos downloads
|
// This should get Exported and stay put as it will apply to all fcos downloads
|
||||||
// getFCOS parses fedoraCoreOS's stream and returns the image download URL and the release version
|
// getFCOS parses fedoraCoreOS's stream and returns the image download URL and the release version
|
||||||
func getFCOSDownload() (*fcosDownloadInfo, error) {
|
func getFCOSDownload(imageStream string) (*fcosDownloadInfo, error) {
|
||||||
var (
|
var (
|
||||||
fcosstable stream.Stream
|
fcosstable stream.Stream
|
||||||
|
streamType string
|
||||||
)
|
)
|
||||||
streamurl := fedoracoreos.GetStreamURL(fedoracoreos.StreamNext)
|
switch imageStream {
|
||||||
|
case "testing", "":
|
||||||
|
streamType = fedoracoreos.StreamNext
|
||||||
|
case "stable":
|
||||||
|
streamType = fedoracoreos.StreamStable
|
||||||
|
default:
|
||||||
|
return nil, errors.Errorf("invalid stream %s: valid streams are `testing` and `stable`", imageStream)
|
||||||
|
}
|
||||||
|
streamurl := fedoracoreos.GetStreamURL(streamType)
|
||||||
resp, err := http.Get(streamurl.String())
|
resp, err := http.Get(streamurl.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -13,7 +13,7 @@ const aarchBaseURL = "https://fedorapeople.org/groups/fcos-images/builds/latest/
|
|||||||
|
|
||||||
// Total hack until automation is possible.
|
// Total hack until automation is possible.
|
||||||
// We need a proper json file at least to automate
|
// We need a proper json file at least to automate
|
||||||
func getFCOSDownload() (*fcosDownloadInfo, error) {
|
func getFCOSDownload(imageStream string) (*fcosDownloadInfo, error) {
|
||||||
meta := Build{}
|
meta := Build{}
|
||||||
resp, err := http.Get(aarchBaseURL + "meta.json")
|
resp, err := http.Get(aarchBaseURL + "meta.json")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -138,9 +138,20 @@ func (v *MachineVM) Init(opts machine.InitOptions) error {
|
|||||||
jsonFile := filepath.Join(vmConfigDir, v.Name) + ".json"
|
jsonFile := filepath.Join(vmConfigDir, v.Name) + ".json"
|
||||||
v.IdentityPath = filepath.Join(sshDir, v.Name)
|
v.IdentityPath = filepath.Join(sshDir, v.Name)
|
||||||
|
|
||||||
// The user has provided an alternate image which can be a file path
|
switch opts.ImagePath {
|
||||||
// or URL.
|
case "testing", "stable", "":
|
||||||
if len(opts.ImagePath) > 0 {
|
// Get image as usual
|
||||||
|
dd, err := machine.NewFcosDownloader(vmtype, v.Name, opts.ImagePath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
v.ImagePath = dd.Get().LocalUncompressedFile
|
||||||
|
if err := dd.DownloadImage(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
// The user has provided an alternate image which can be a file path
|
||||||
|
// or URL.
|
||||||
g, err := machine.NewGenericDownloader(vmtype, v.Name, opts.ImagePath)
|
g, err := machine.NewGenericDownloader(vmtype, v.Name, opts.ImagePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -149,18 +160,7 @@ func (v *MachineVM) Init(opts machine.InitOptions) error {
|
|||||||
if err := g.DownloadImage(); err != nil {
|
if err := g.DownloadImage(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// Get the image as usual
|
|
||||||
dd, err := machine.NewFcosDownloader(vmtype, v.Name)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
v.ImagePath = dd.Get().LocalUncompressedFile
|
|
||||||
if err := dd.DownloadImage(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add arch specific options including image location
|
// Add arch specific options including image location
|
||||||
v.CmdLine = append(v.CmdLine, v.addArchOptions()...)
|
v.CmdLine = append(v.CmdLine, v.addArchOptions()...)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user