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:
parent
017ea3df50
commit
b8e9bd2b42
@ -468,7 +468,12 @@ Prints the member ID of the new member and the cluster ID.
|
||||
|
||||
```bash
|
||||
./etcdctl member add newMember --peer-urls=https://127.0.0.1:12345
|
||||
# Member 2be1eb8f84b7f63e added to cluster ef37ad9dc622a7c4
|
||||
|
||||
Member ced000fda4d05edf added to cluster 8c4281cc65c7b112
|
||||
|
||||
ETCD_NAME="newMember"
|
||||
ETCD_INITIAL_CLUSTER="newMember=https://127.0.0.1:12345,default=http://10.0.0.30:2380"
|
||||
ETCD_INITIAL_CLUSTER_STATE="existing"
|
||||
```
|
||||
|
||||
### MEMBER UPDATE \<memberID\> [options]
|
||||
|
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user