ctlv3: print cluster info after adding new member

This commit is contained in:
Armstrong Li
2016-12-22 13:43:49 +08:00
committed by Gyu-Ho Lee
parent 017ea3df50
commit b8e9bd2b42
2 changed files with 34 additions and 1 deletions

View File

@@ -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.