mirror of
https://github.com/linka-cloud/d2vm.git
synced 2025-07-04 02:22:27 +00:00
BREAKING CHANGE: remove root default password, configure it only if provided (close #7)
Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
This commit is contained in:
@ -117,7 +117,7 @@ func init() {
|
||||
buildCmd.Flags().StringArrayVar(&buildArgs, "build-arg", nil, "Set build-time variables")
|
||||
|
||||
buildCmd.Flags().StringVarP(&output, "output", "o", output, "The output image, the extension determine the image format, raw will be used if none. Supported formats: "+strings.Join(d2vm.OutputFormats(), " "))
|
||||
buildCmd.Flags().StringVarP(&password, "password", "p", "root", "Root user password")
|
||||
buildCmd.Flags().StringVarP(&password, "password", "p", "", "Optional root user password")
|
||||
buildCmd.Flags().StringVarP(&size, "size", "s", "10G", "The output image size")
|
||||
buildCmd.Flags().BoolVar(&force, "force", false, "Override output image")
|
||||
buildCmd.Flags().StringVar(&cmdLineExtra, "append-to-cmdline", "", "Extra kernel cmdline arguments to append to the generated one")
|
||||
|
@ -111,7 +111,7 @@ func parseSize(s string) (int64, error) {
|
||||
func init() {
|
||||
convertCmd.Flags().BoolVar(&pull, "pull", false, "Always pull docker image")
|
||||
convertCmd.Flags().StringVarP(&output, "output", "o", output, "The output image, the extension determine the image format, raw will be used if none. Supported formats: "+strings.Join(d2vm.OutputFormats(), " "))
|
||||
convertCmd.Flags().StringVarP(&password, "password", "p", "root", "The Root user password")
|
||||
convertCmd.Flags().StringVarP(&password, "password", "p", "", "Optional root user password")
|
||||
convertCmd.Flags().StringVarP(&size, "size", "s", "10G", "The output image size")
|
||||
convertCmd.Flags().BoolVarP(&force, "force", "f", false, "Override output qcow2 image")
|
||||
convertCmd.Flags().StringVar(&cmdLineExtra, "append-to-cmdline", "", "Extra kernel cmdline arguments to append to the generated one")
|
||||
|
@ -34,7 +34,7 @@ import (
|
||||
var (
|
||||
output = "disk0.qcow2"
|
||||
size = "1G"
|
||||
password = "root"
|
||||
password = ""
|
||||
force = false
|
||||
verbose = false
|
||||
timeFormat = ""
|
||||
|
@ -71,7 +71,7 @@ func init() {
|
||||
|
||||
// Paths and settings for disks
|
||||
flags.Var(&disks, "disk", "Disk config, may be repeated. [file=]path[,size=1G][,format=qcow2]")
|
||||
flags.StringVar(&data, "data", "", "String of metadata to pass to VM; error to specify both -data and -data-file")
|
||||
flags.StringVar(&data, "data", "", "String of metadata to pass to VM")
|
||||
|
||||
// VM configuration
|
||||
flags.StringVar(&accel, "accel", defaultAccel, "Choose acceleration mode. Use 'tcg' to disable it.")
|
||||
@ -91,7 +91,7 @@ func init() {
|
||||
// USB devices
|
||||
flags.BoolVar(&usbEnabled, "usb", false, "Enable USB controller")
|
||||
|
||||
flags.Var(&deviceFlags, "device", "Add USB host device(s). Format driver[,prop=value][,...] -- add device, like -device on the qemu command line.")
|
||||
flags.Var(&deviceFlags, "device", "Add USB host device(s). Format driver[,prop=value][,...] -- add device, like --device on the qemu command line.")
|
||||
|
||||
}
|
||||
|
||||
|
@ -93,7 +93,7 @@ func vbox(ctx context.Context, path string) error {
|
||||
}
|
||||
|
||||
// remove machine in case it already exists
|
||||
cleanup(vboxmanage, name)
|
||||
cleanup(vboxmanage, name, false)
|
||||
|
||||
_, out, err := manage(vboxmanage, "createvm", "--name", name, "--register")
|
||||
if err != nil {
|
||||
@ -273,22 +273,26 @@ func vbox(ctx context.Context, path string) error {
|
||||
return <-errs
|
||||
}
|
||||
|
||||
func cleanup(vboxmanage string, name string) {
|
||||
if _, _, err := manage(vboxmanage, "controlvm", name, "poweroff"); err != nil {
|
||||
func cleanup(vboxmanage string, name string, logErrs ...bool) {
|
||||
logErr := true
|
||||
if len(logErrs) > 0 {
|
||||
logErr = logErrs[0]
|
||||
}
|
||||
if _, _, err := manage(vboxmanage, "controlvm", name, "poweroff"); err != nil && logErr {
|
||||
log.Errorf("controlvm poweroff error: %v", err)
|
||||
}
|
||||
_, out, err := manage(vboxmanage, "storageattach", name, "--storagectl", "IDE Controller", "--port", "1", "--device", "0", "--type", "hdd", "--medium", "emptydrive")
|
||||
if err != nil {
|
||||
if err != nil && logErr {
|
||||
log.Errorf("storageattach error: %v\n%s", err, out)
|
||||
}
|
||||
for i := range disks {
|
||||
id := strconv.Itoa(i)
|
||||
_, out, err := manage(vboxmanage, "storageattach", name, "--storagectl", "SATA", "--port", "0", "--device", id, "--type", "hdd", "--medium", "emptydrive")
|
||||
if err != nil {
|
||||
if err != nil && logErr {
|
||||
log.Errorf("storageattach error: %v\n%s", err, out)
|
||||
}
|
||||
}
|
||||
if _, out, err = manage(vboxmanage, "unregistervm", name, "--delete"); err != nil {
|
||||
if _, out, err = manage(vboxmanage, "unregistervm", name, "--delete"); err != nil && logErr {
|
||||
log.Errorf("unregistervm error: %v\n%s", err, out)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user