Merge branch '20457-careful-near-quota'
[arvados.git] / lib / cloud / cloudtest / cmd.go
index 4816f20ee714df422b185e1801dc08349bbe7a84..0c1049b76c25ee3bfd3278e8e15c954f9065b632 100644 (file)
@@ -13,11 +13,11 @@ import (
        "os"
 
        "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"
-       "golang.org/x/crypto/ssh"
 )
 
 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,23 @@ 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,
+               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")