Merge commit 'main' into 21160-user-activation
[arvados.git] / lib / cloud / cloudtest / cmd.go
index 9c3fc46c0c754d467c3997c2895f5bd8ea7ba1cc..2dc13e5a51a2f3c423db922a837186400e3d812d 100644 (file)
@@ -12,12 +12,12 @@ import (
        "io"
        "os"
 
-       "git.curoverse.com/arvados.git/lib/cloud"
-       "git.curoverse.com/arvados.git/lib/config"
-       "git.curoverse.com/arvados.git/lib/dispatchcloud"
-       "git.curoverse.com/arvados.git/sdk/go/arvados"
-       "git.curoverse.com/arvados.git/sdk/go/ctxlog"
-       "golang.org/x/crypto/ssh"
+       "git.arvados.org/arvados.git/lib/cloud"
+       "git.arvados.org/arvados.git/lib/cmd"
+       "git.arvados.org/arvados.git/lib/config"
+       "git.arvados.org/arvados.git/lib/dispatchcloud"
+       "git.arvados.org/arvados.git/sdk/go/arvados"
+       "git.arvados.org/arvados.git/sdk/go/ctxlog"
 )
 
 var Command command
@@ -41,17 +41,8 @@ func (command) RunCommand(prog string, args []string, stdin io.Reader, stdout, s
        destroyExisting := flags.Bool("destroy-existing", false, "Destroy any existing instances tagged with our InstanceSetID, instead of erroring out")
        shellCommand := flags.String("command", "", "Run an interactive shell command on the test instance when it boots")
        pauseBeforeDestroy := flags.Bool("pause-before-destroy", false, "Prompt and wait before destroying the test instance")
-       err = flags.Parse(args)
-       if err == flag.ErrHelp {
-               err = nil
-               return 0
-       } else if err != nil {
-               return 2
-       }
-
-       if len(flags.Args()) != 0 {
-               flags.Usage()
-               return 2
+       if ok, code := cmd.ParseFlags(flags, prog, args, "", stderr); !ok {
+               return code
        }
        logger := ctxlog.New(stderr, "text", "info")
        defer func() {
@@ -73,9 +64,9 @@ func (command) RunCommand(prog string, args []string, stdin io.Reader, stdout, s
        if err != nil {
                return 1
        }
-       key, err := ssh.ParsePrivateKey([]byte(cluster.Containers.DispatchPrivateKey))
+       key, err := config.LoadSSHKey(cluster.Containers.DispatchPrivateKey)
        if err != nil {
-               err = fmt.Errorf("error parsing configured Containers.DispatchPrivateKey: %s", err)
+               err = fmt.Errorf("error loading Containers.DispatchPrivateKey: %s", err)
                return 1
        }
        driver, ok := dispatchcloud.Drivers[cluster.Containers.CloudVMs.Driver]
@@ -94,22 +85,24 @@ func (command) RunCommand(prog string, args []string, stdin io.Reader, stdout, s
        tagKeyPrefix := cluster.Containers.CloudVMs.TagKeyPrefix
        tags[tagKeyPrefix+"CloudTestPID"] = fmt.Sprintf("%d", os.Getpid())
        if !(&tester{
-               Logger:           logger,
-               Tags:             tags,
-               TagKeyPrefix:     tagKeyPrefix,
-               SetID:            cloud.InstanceSetID(*instanceSetID),
-               DestroyExisting:  *destroyExisting,
-               ProbeInterval:    cluster.Containers.CloudVMs.ProbeInterval.Duration(),
-               SyncInterval:     cluster.Containers.CloudVMs.SyncInterval.Duration(),
-               TimeoutBooting:   cluster.Containers.CloudVMs.TimeoutBooting.Duration(),
-               Driver:           driver,
-               DriverParameters: cluster.Containers.CloudVMs.DriverParameters,
-               ImageID:          cloud.ImageID(*imageID),
-               InstanceType:     it,
-               SSHKey:           key,
-               SSHPort:          cluster.Containers.CloudVMs.SSHPort,
-               BootProbeCommand: cluster.Containers.CloudVMs.BootProbeCommand,
-               ShellCommand:     *shellCommand,
+               Logger:              logger,
+               Tags:                tags,
+               TagKeyPrefix:        tagKeyPrefix,
+               SetID:               cloud.InstanceSetID(*instanceSetID),
+               DestroyExisting:     *destroyExisting,
+               ProbeInterval:       cluster.Containers.CloudVMs.ProbeInterval.Duration(),
+               SyncInterval:        cluster.Containers.CloudVMs.SyncInterval.Duration(),
+               TimeoutBooting:      cluster.Containers.CloudVMs.TimeoutBooting.Duration(),
+               Driver:              driver,
+               DriverParameters:    cluster.Containers.CloudVMs.DriverParameters,
+               ImageID:             cloud.ImageID(*imageID),
+               InstanceType:        it,
+               SSHKey:              key,
+               SSHPort:             cluster.Containers.CloudVMs.SSHPort,
+               DeployPublicKey:     cluster.Containers.CloudVMs.DeployPublicKey,
+               BootProbeCommand:    cluster.Containers.CloudVMs.BootProbeCommand,
+               InstanceInitCommand: cloud.InitCommand(cluster.Containers.CloudVMs.InstanceInitCommand),
+               ShellCommand:        *shellCommand,
                PauseBeforeDestroy: func() {
                        if *pauseBeforeDestroy {
                                logger.Info("waiting for operator to press Enter")