mirror of
https://github.com/containers/podman.git
synced 2025-08-06 19:44:14 +08:00
Merge pull request #15411 from arixmkii/override_default_username
Allow to override default username via command line
This commit is contained in:
@ -42,7 +42,6 @@ func init() {
|
|||||||
})
|
})
|
||||||
flags := initCmd.Flags()
|
flags := initCmd.Flags()
|
||||||
cfg := registry.PodmanConfig()
|
cfg := registry.PodmanConfig()
|
||||||
initOpts.Username = cfg.Config.Machine.User
|
|
||||||
|
|
||||||
cpusFlagName := "cpus"
|
cpusFlagName := "cpus"
|
||||||
flags.Uint64Var(
|
flags.Uint64Var(
|
||||||
@ -89,6 +88,10 @@ func init() {
|
|||||||
)
|
)
|
||||||
_ = flags.MarkHidden("reexec")
|
_ = flags.MarkHidden("reexec")
|
||||||
|
|
||||||
|
UsernameFlagName := "username"
|
||||||
|
flags.StringVar(&initOpts.Username, UsernameFlagName, cfg.Machine.User, "Username used in qcow image")
|
||||||
|
_ = initCmd.RegisterFlagCompletionFunc(UsernameFlagName, completion.AutocompleteDefault)
|
||||||
|
|
||||||
ImagePathFlagName := "image-path"
|
ImagePathFlagName := "image-path"
|
||||||
flags.StringVar(&initOpts.ImagePath, ImagePathFlagName, cfg.Machine.Image, "Path to qcow image")
|
flags.StringVar(&initOpts.ImagePath, ImagePathFlagName, cfg.Machine.Image, "Path to qcow image")
|
||||||
_ = initCmd.RegisterFlagCompletionFunc(ImagePathFlagName, completion.AutocompleteDefault)
|
_ = initCmd.RegisterFlagCompletionFunc(ImagePathFlagName, completion.AutocompleteDefault)
|
||||||
|
@ -76,6 +76,12 @@ Set the timezone for the machine and containers. Valid values are `local` or
|
|||||||
a `timezone` such as `America/Chicago`. A value of `local`, which is the default,
|
a `timezone` such as `America/Chicago`. A value of `local`, which is the default,
|
||||||
means to use the timezone of the machine host.
|
means to use the timezone of the machine host.
|
||||||
|
|
||||||
|
#### **--username**
|
||||||
|
|
||||||
|
Username to use for executing commands in remote VM. Default value is `core`
|
||||||
|
for FCOS and `user` for Fedora (default on Windows hosts). Should match the one
|
||||||
|
used inside the resulting VM image.
|
||||||
|
|
||||||
#### **--volume**, **-v**=*source:target[:options]*
|
#### **--volume**, **-v**=*source:target[:options]*
|
||||||
|
|
||||||
Mounts a volume from source to target.
|
Mounts a volume from source to target.
|
||||||
|
@ -9,6 +9,7 @@ type initMachine struct {
|
|||||||
--cpus uint Number of CPUs (default 1)
|
--cpus uint Number of CPUs (default 1)
|
||||||
--disk-size uint Disk size in GB (default 100)
|
--disk-size uint Disk size in GB (default 100)
|
||||||
--ignition-path string Path to ignition file
|
--ignition-path string Path to ignition file
|
||||||
|
--username string Username of the remote user (default "core" for FCOS, "user" for Fedora)
|
||||||
--image-path string Path to qcow image (default "testing")
|
--image-path string Path to qcow image (default "testing")
|
||||||
-m, --memory uint Memory in MB (default 2048)
|
-m, --memory uint Memory in MB (default 2048)
|
||||||
--now Start machine now
|
--now Start machine now
|
||||||
@ -21,6 +22,7 @@ type initMachine struct {
|
|||||||
cpus *uint
|
cpus *uint
|
||||||
diskSize *uint
|
diskSize *uint
|
||||||
ignitionPath string
|
ignitionPath string
|
||||||
|
username string
|
||||||
imagePath string
|
imagePath string
|
||||||
memory *uint
|
memory *uint
|
||||||
now bool
|
now bool
|
||||||
@ -42,6 +44,9 @@ func (i *initMachine) buildCmd(m *machineTestBuilder) []string {
|
|||||||
if l := len(i.ignitionPath); l > 0 {
|
if l := len(i.ignitionPath); l > 0 {
|
||||||
cmd = append(cmd, "--ignition-path", i.ignitionPath)
|
cmd = append(cmd, "--ignition-path", i.ignitionPath)
|
||||||
}
|
}
|
||||||
|
if l := len(i.username); l > 0 {
|
||||||
|
cmd = append(cmd, "--username", i.username)
|
||||||
|
}
|
||||||
if l := len(i.imagePath); l > 0 {
|
if l := len(i.imagePath); l > 0 {
|
||||||
cmd = append(cmd, "--image-path", i.imagePath)
|
cmd = append(cmd, "--image-path", i.imagePath)
|
||||||
}
|
}
|
||||||
@ -76,6 +81,11 @@ func (i *initMachine) withIgnitionPath(path string) *initMachine { //nolint:unus
|
|||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (i *initMachine) withUsername(username string) *initMachine {
|
||||||
|
i.username = username
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
|
||||||
func (i *initMachine) withImagePath(path string) *initMachine {
|
func (i *initMachine) withImagePath(path string) *initMachine {
|
||||||
i.imagePath = path
|
i.imagePath = path
|
||||||
return i
|
return i
|
||||||
|
@ -77,6 +77,26 @@ var _ = Describe("podman machine init", func() {
|
|||||||
Expect(inspectAfter[0].State).To(Equal(machine.Running))
|
Expect(inspectAfter[0].State).To(Equal(machine.Running))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("simple init with username", func() {
|
||||||
|
i := new(initMachine)
|
||||||
|
remoteUsername := "remoteuser"
|
||||||
|
session, err := mb.setCmd(i.withImagePath(mb.imagePath).withUsername(remoteUsername)).run()
|
||||||
|
Expect(err).To(BeNil())
|
||||||
|
Expect(session).To(Exit(0))
|
||||||
|
|
||||||
|
inspectBefore, ec, err := mb.toQemuInspectInfo()
|
||||||
|
Expect(err).To(BeNil())
|
||||||
|
Expect(ec).To(BeZero())
|
||||||
|
|
||||||
|
Expect(len(inspectBefore)).To(BeNumerically(">", 0))
|
||||||
|
testMachine := inspectBefore[0]
|
||||||
|
Expect(testMachine.Name).To(Equal(mb.names[0]))
|
||||||
|
Expect(testMachine.Resources.CPUs).To(Equal(uint64(1)))
|
||||||
|
Expect(testMachine.Resources.Memory).To(Equal(uint64(2048)))
|
||||||
|
Expect(testMachine.SSHConfig.RemoteUsername).To((Equal(remoteUsername)))
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
It("machine init with cpus, disk size, memory, timezone", func() {
|
It("machine init with cpus, disk size, memory, timezone", func() {
|
||||||
name := randomString()
|
name := randomString()
|
||||||
i := new(initMachine)
|
i := new(initMachine)
|
||||||
|
Reference in New Issue
Block a user