github.com/pingcap/tiup@v1.15.1/components/dm/command/scale_out.go (about)

     1  // Copyright 2020 PingCAP, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package command
    15  
    16  import (
    17  	"path/filepath"
    18  
    19  	"github.com/pingcap/tiup/pkg/cluster/manager"
    20  	operator "github.com/pingcap/tiup/pkg/cluster/operation"
    21  	"github.com/pingcap/tiup/pkg/cluster/spec"
    22  	"github.com/pingcap/tiup/pkg/cluster/task"
    23  	"github.com/pingcap/tiup/pkg/utils"
    24  	"github.com/spf13/cobra"
    25  )
    26  
    27  func newScaleOutCmd() *cobra.Command {
    28  	opt := manager.DeployOptions{
    29  		IdentityFile: filepath.Join(utils.UserHome(), ".ssh", "id_rsa"),
    30  	}
    31  	cmd := &cobra.Command{
    32  		Use:          "scale-out <cluster-name> <topology.yaml>",
    33  		Short:        "Scale out a DM cluster",
    34  		SilenceUsage: true,
    35  		RunE: func(cmd *cobra.Command, args []string) error {
    36  			if len(args) != 2 {
    37  				return cmd.Help()
    38  			}
    39  
    40  			clusterName := args[0]
    41  			topoFile := args[1]
    42  
    43  			return cm.ScaleOut(clusterName, topoFile, postScaleOutHook, nil, opt, skipConfirm, gOpt)
    44  		},
    45  		ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
    46  			switch len(args) {
    47  			case 0:
    48  				return shellCompGetClusterName(cm, toComplete)
    49  			case 1:
    50  				return nil, cobra.ShellCompDirectiveDefault
    51  			default:
    52  				return nil, cobra.ShellCompDirectiveNoFileComp
    53  			}
    54  		},
    55  	}
    56  
    57  	cmd.Flags().StringVarP(&opt.User, "user", "u", utils.CurrentUser(), "The user name to login via SSH. The user must has root (or sudo) privilege.")
    58  	cmd.Flags().StringVarP(&opt.IdentityFile, "identity_file", "i", opt.IdentityFile, "The path of the SSH identity file. If specified, public key authentication will be used.")
    59  	cmd.Flags().BoolVarP(&opt.UsePassword, "password", "p", false, "Use password of target hosts. If specified, password authentication will be used.")
    60  
    61  	return cmd
    62  }
    63  
    64  func postScaleOutHook(builder *task.Builder, newPart spec.Topology, gOpt operator.Options) {
    65  	postDeployHook(builder, newPart, gOpt)
    66  }