mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
ctlv3: print cluster info after adding new member
This commit is contained in:
@@ -99,6 +99,7 @@ func memberAddCommandFunc(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 1 {
|
||||
ExitWithError(ExitBadArgs, fmt.Errorf("member name not provided."))
|
||||
}
|
||||
newMemberName := args[0]
|
||||
|
||||
if len(memberPeerURLs) == 0 {
|
||||
ExitWithError(ExitBadArgs, fmt.Errorf("member peer urls not provided."))
|
||||
@@ -111,8 +112,35 @@ func memberAddCommandFunc(cmd *cobra.Command, args []string) {
|
||||
if err != nil {
|
||||
ExitWithError(ExitError, err)
|
||||
}
|
||||
newID := resp.Member.ID
|
||||
|
||||
display.MemberAdd(*resp)
|
||||
|
||||
if _, ok := (display).(*simplePrinter); ok {
|
||||
ctx, cancel = commandCtx(cmd)
|
||||
listResp, err := mustClientFromCmd(cmd).MemberList(ctx)
|
||||
cancel()
|
||||
|
||||
if err != nil {
|
||||
ExitWithError(ExitError, err)
|
||||
}
|
||||
|
||||
conf := []string{}
|
||||
for _, memb := range listResp.Members {
|
||||
for _, u := range memb.PeerURLs {
|
||||
n := memb.Name
|
||||
if memb.ID == newID {
|
||||
n = newMemberName
|
||||
}
|
||||
conf = append(conf, fmt.Sprintf("%s=%s", n, u))
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Print("\n")
|
||||
fmt.Printf("ETCD_NAME=%q\n", newMemberName)
|
||||
fmt.Printf("ETCD_INITIAL_CLUSTER=%q\n", strings.Join(conf, ","))
|
||||
fmt.Printf("ETCD_INITIAL_CLUSTER_STATE=\"existing\"\n")
|
||||
}
|
||||
}
|
||||
|
||||
// memberRemoveCommandFunc executes the "member remove" command.
|
||||
|
||||
Reference in New Issue
Block a user