Skip to content

Commit ed6a13d

Browse files
tiansuo114caoxianfei1
authored andcommitted
change host to name in hosts moudle
Signed-off-by: noobcoder <[email protected]>
1 parent 67138fb commit ed6a13d

File tree

11 files changed

+37
-21
lines changed

11 files changed

+37
-21
lines changed

cli/cli/cli.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,23 +280,23 @@ func (curveadm *CurveAdm) ClusterPoolData() string { return curveadm.c
280280
func (curveadm *CurveAdm) ClusterType() string { return curveadm.clusterType }
281281
func (curveadm *CurveAdm) Monitor() storage.Monitor { return curveadm.monitor }
282282

283-
func (curveadm *CurveAdm) GetHost(host string) (*hosts.HostConfig, error) {
283+
func (curveadm *CurveAdm) GetHost(name string) (*hosts.HostConfig, error) {
284284
if len(curveadm.Hosts()) == 0 {
285285
return nil, errno.ERR_HOST_NOT_FOUND.
286-
F("host: %s", host)
286+
F("host: %s", name)
287287
}
288288
hcs, err := hosts.ParseHosts(curveadm.Hosts())
289289
if err != nil {
290290
return nil, err
291291
}
292292

293293
for _, hc := range hcs {
294-
if hc.GetHost() == host {
294+
if hc.GetName() == name {
295295
return hc, nil
296296
}
297297
}
298298
return nil, errno.ERR_HOST_NOT_FOUND.
299-
F("host: %s", host)
299+
F("host: %s", name)
300300
}
301301

302302
func (curveadm *CurveAdm) ParseTopologyData(data string) ([]*topology.DeployConfig, error) {
@@ -306,7 +306,7 @@ func (curveadm *CurveAdm) ParseTopologyData(data string) ([]*topology.DeployConf
306306
return nil, err
307307
}
308308
for _, hc := range hcs {
309-
ctx.Add(hc.GetHost(), hc.GetHostname())
309+
ctx.Add(hc.GetName(), hc.GetHostname())
310310
}
311311

312312
dcs, err := topology.ParseTopology(data, ctx)
@@ -466,7 +466,7 @@ func (curveadm *CurveAdm) DiffTopology(data1, data2 string) ([]topology.Topology
466466
return nil, err
467467
}
468468
for _, hc := range hcs {
469-
ctx.Add(hc.GetHost(), hc.GetHostname())
469+
ctx.Add(hc.GetName(), hc.GetHostname())
470470
}
471471

472472
if len(data1) == 0 {

cli/command/hosts/list_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func run(t *testing.T, data string, labels []string, out []string) {
3737
assert.Nil(err)
3838
assert.Equal(len(hcs), len(out))
3939
for i, hc := range hcs {
40-
assert.Equal(hc.GetHost(), out[i])
40+
assert.Equal(hc.GetName(), out[i])
4141
}
4242
}
4343

cli/command/hosts/playbook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func NewPlaybookCommand(curveadm *cli.CurveAdm) *cobra.Command {
9191

9292
func execute(curveadm *cli.CurveAdm, options playbookOptions, idx int, hc *hosts.HostConfig) {
9393
defer func() { wg.Done() }()
94-
name := hc.GetHost()
94+
name := hc.GetName()
9595
target := path.Join("/tmp", utils.RandString(8))
9696
err := tools.Scp(curveadm, name, options.filepath, target)
9797
if err != nil {

internal/configure/hosts/hc_get.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,17 @@ func (hc *HostConfig) getBool(i *comm.Item) bool {
6767
return v.(bool)
6868
}
6969

70+
func (hc *HostConfig) getName() string {
71+
res := hc.GetHost()
72+
if res != "" {
73+
return res
74+
}
75+
76+
return hc.getString(CONFIG_NAME)
77+
}
78+
7079
func (hc *HostConfig) GetHost() string { return hc.getString(CONFIG_HOST) }
80+
func (hc *HostConfig) GetName() string { return hc.getName() }
7181
func (hc *HostConfig) GetHostname() string { return hc.getString(CONFIG_HOSTNAME) }
7282
func (hc *HostConfig) GetSSHHostname() string { return hc.getString(CONFIG_SSH_HOSTNAME) }
7383
func (hc *HostConfig) GetSSHPort() int { return hc.getInt(CONFIG_SSH_PORT) }

internal/configure/hosts/hc_item.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ var (
4545
nil,
4646
)
4747

48+
CONFIG_NAME = itemset.Insert(
49+
"name",
50+
comm.REQUIRE_STRING,
51+
false,
52+
nil,
53+
)
4854
CONFIG_HOSTNAME = itemset.Insert(
4955
"hostname",
5056
comm.REQUIRE_STRING,

internal/configure/hosts/hosts.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ func (hc *HostConfig) Build() error {
141141
}
142142

143143
privateKeyFile := hc.GetPrivateKeyFile()
144-
if len(hc.GetHost()) == 0 {
144+
if len(hc.GetName()) == 0 {
145145
return errno.ERR_HOST_FIELD_MISSING.
146-
F("hosts[%d].host = nil", hc.sequence)
146+
F("hosts[%d].host/name = nil", hc.sequence)
147147
} else if len(hc.GetHostname()) == 0 {
148148
return errno.ERR_HOSTNAME_FIELD_MISSING.
149149
F("hosts[%d].hostname = nil", hc.sequence)
@@ -206,12 +206,12 @@ func ParseHosts(data string) ([]*HostConfig, error) {
206206
return nil, err
207207
}
208208

209-
if _, ok := exist[hc.GetHost()]; ok {
210-
return nil, errno.ERR_DUPLICATE_HOST.
211-
F("duplicate host: %s", hc.GetHost())
209+
if _, ok := exist[hc.GetName()]; ok {
210+
return nil, errno.ERR_DUPLICATE_NAME.
211+
F("duplicate host: %s", hc.GetName())
212212
}
213213
hcs = append(hcs, hc)
214-
exist[hc.GetHost()] = true
214+
exist[hc.GetName()] = true
215215
}
216216
build.DEBUG(build.DEBUG_HOSTS, hosts)
217217
return hcs, nil

internal/configure/monitor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ func ParseMonitorConfig(curveadm *cli.CurveAdm, filename string, data string, hs
265265
return nil, err
266266
}
267267
for _, hc := range hcs {
268-
ctx.Add(hc.GetHost(), hc.GetHostname())
268+
ctx.Add(hc.GetName(), hc.GetHostname())
269269
}
270270

271271
mkind := dcs[0].GetKind()

internal/errno/errno.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ var (
310310
ERR_PRIVATE_KEY_FILE_REQUIRE_ABSOLUTE_PATH = EC(321004, "SSH private key file needs to be an absolute path")
311311
ERR_PRIVATE_KEY_FILE_NOT_EXIST = EC(321005, "SSH private key file not exist")
312312
ERR_PRIVATE_KEY_FILE_REQUIRE_600_PERMISSIONS = EC(321006, "SSH private key file require 600 permissions")
313-
ERR_DUPLICATE_HOST = EC(321007, "host is duplicate")
313+
ERR_DUPLICATE_NAME = EC(321007, "name is duplicate")
314314
ERR_HOSTNAME_REQUIRES_VALID_IP_ADDRESS = EC(321008, "hostname requires valid IP address")
315315

316316
// 322: configure (monitor.yaml: parse failed)

internal/task/task/common/client_status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func NewGetClientStatusTask(curveadm *cli.CurveAdm, v interface{}) (*task.Task,
163163

164164
containerId := client.ContainerId
165165
subname := fmt.Sprintf("host=%s kind=%s containerId=%s",
166-
hc.GetHost(), client.Kind, tui.TrimContainerId(containerId))
166+
hc.GetName(), client.Kind, tui.TrimContainerId(containerId))
167167
t := task.NewTask("Get Client Status", subname, hc.GetSSHConfig())
168168

169169
// add step

internal/task/task/common/collect_client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func NewCollectClientTask(curveadm *cli.CurveAdm, v interface{}) (*task.Task, er
4646
// new task
4747
containerId := client.ContainerId
4848
subname := fmt.Sprintf("host=%s kind=%s containerId=%s",
49-
hc.GetHost(), client.Kind, tui.TrimContainerId(containerId))
49+
hc.GetName(), client.Kind, tui.TrimContainerId(containerId))
5050
t := task.NewTask("Collect Client", subname, hc.GetSSHConfig())
5151

5252
// add step to task

0 commit comments

Comments
 (0)