mirror of https://github.com/containers/podman.git
Merge pull request #20707 from baude/vmtypesarereserved
vmtypes names cannot be used as machine names
This commit is contained in:
commit
f17d8df555
|
@ -140,6 +140,12 @@ func initMachine(cmd *cobra.Command, args []string) error {
|
|||
}
|
||||
initOpts.Name = args[0]
|
||||
}
|
||||
|
||||
// The vmtype names need to be reserved and cannot be used for podman machine names
|
||||
if _, err := machine.ParseVMType(initOpts.Name, machine.UnknownVirt); err == nil {
|
||||
return fmt.Errorf("cannot use %q for a machine name", initOpts.Name)
|
||||
}
|
||||
|
||||
if _, err := provider.LoadVMByName(initOpts.Name); err == nil {
|
||||
return fmt.Errorf("%s: %w", initOpts.Name, machine.ErrVMAlreadyExists)
|
||||
}
|
||||
|
|
|
@ -346,6 +346,7 @@ const (
|
|||
WSLVirt
|
||||
AppleHvVirt
|
||||
HyperVVirt
|
||||
UnknownVirt
|
||||
)
|
||||
|
||||
func (v VMType) String() string {
|
||||
|
@ -383,7 +384,7 @@ func ParseVMType(input string, emptyFallback VMType) (VMType, error) {
|
|||
case "":
|
||||
return emptyFallback, nil
|
||||
default:
|
||||
return QemuVirt, fmt.Errorf("unknown VMType `%s`", input)
|
||||
return UnknownVirt, fmt.Errorf("unknown VMType `%s`", input)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -41,6 +41,12 @@ var _ = Describe("podman machine init", func() {
|
|||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(session).To(Exit(125))
|
||||
|
||||
reservedName := initMachine{}
|
||||
reservedNameSession, err := mb.setName(testProvider.VMType().String()).setCmd(&reservedName).run()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(reservedNameSession).To(Exit(125))
|
||||
Expect(reservedNameSession.errorToString()).To(ContainSubstring(fmt.Sprintf("cannot use %q", testProvider.VMType().String())))
|
||||
|
||||
badName := "foobar"
|
||||
bm := basicMachine{}
|
||||
sysConn, err := mb.setCmd(bm.withPodmanCommand([]string{"system", "connection", "add", badName, "tcp://localhost:8000"})).run()
|
||||
|
|
Loading…
Reference in New Issue