Skip to content

Commit

Permalink
change host to name
Browse files Browse the repository at this point in the history
change the hosts config keyword host to name
  • Loading branch information
tiansuo114 committed Nov 4, 2023
1 parent 48abdf1 commit 540f3c2
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 32 deletions.
16 changes: 8 additions & 8 deletions cli/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,23 +312,23 @@ func (curveadm *CurveAdm) ClusterPoolData() string { return curveadm.c
func (curveadm *CurveAdm) Monitor() storage.Monitor { return curveadm.monitor }
func (curveadm *CurveAdm) SetDebugLevel() { glg.Get().SetLevel(glg.DEBG) }

func (curveadm *CurveAdm) GetHost(host string) (*hosts.HostConfig, error) {
func (curveadm *CurveAdm) GetHost(name string) (*hosts.HostConfig, error) {
if len(curveadm.Hosts()) == 0 {
return nil, errno.ERR_HOST_NOT_FOUND.
F("host: %s", host)
return nil, errno.ERR_NAME_NOT_FOUND.
F("name: %s", name)
}
hcs, err := hosts.ParseHosts(curveadm.Hosts())
if err != nil {
return nil, err
}

for _, hc := range hcs {
if hc.GetHost() == host {
if hc.GetName() == name {
return hc, nil
}
}
return nil, errno.ERR_HOST_NOT_FOUND.
F("host: %s", host)
return nil, errno.ERR_NAME_NOT_FOUND.
F("name: %s", name)
}

func (curveadm *CurveAdm) ParseTopologyData(data string) ([]*topology.DeployConfig, error) {
Expand All @@ -338,7 +338,7 @@ func (curveadm *CurveAdm) ParseTopologyData(data string) ([]*topology.DeployConf
return nil, err
}
for _, hc := range hcs {
ctx.Add(hc.GetHost(), hc.GetHostname())
ctx.Add(hc.GetName(), hc.GetHostname())
}

dcs, err := topology.ParseTopology(data, ctx)
Expand Down Expand Up @@ -503,7 +503,7 @@ func (curveadm *CurveAdm) DiffTopology(data1, data2 string) ([]topology.Topology
return nil, err
}
for _, hc := range hcs {
ctx.Add(hc.GetHost(), hc.GetHostname())
ctx.Add(hc.GetName(), hc.GetHostname())
}

if len(data1) == 0 {
Expand Down
2 changes: 1 addition & 1 deletion cli/command/hosts/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func run(t *testing.T, data string, labels []string, out []string) {
assert.Nil(err)
assert.Equal(len(hcs), len(out))
for i, hc := range hcs {
assert.Equal(hc.GetHost(), out[i])
assert.Equal(hc.GetName(), out[i])
}
}

Expand Down
2 changes: 1 addition & 1 deletion cli/command/hosts/playbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func NewPlaybookCommand(curveadm *cli.CurveAdm) *cobra.Command {

func execute(curveadm *cli.CurveAdm, options playbookOptions, idx int, hc *hosts.HostConfig) {
defer func() { wg.Done() }()
name := hc.GetHost()
name := hc.GetName()
target := path.Join("/tmp", utils.RandString(8))
err := tools.Scp(curveadm, name, options.filepath, target)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions internal/configure/disks/disks.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func mergeFinalHost(dc *DiskConfig) error {
// check if the host to be excluded is the member of global host list
for _, h := range hostExclude {
if _, ok := hostMap[h]; !ok {
return errno.ERR_HOST_NOT_FOUND.
return errno.ERR_NAME_NOT_FOUND.
F("no such host: %s", h)
}
}
Expand All @@ -95,7 +95,7 @@ func checkDupHost(dc *DiskConfig) error {
existHost := map[string]bool{}
for _, h := range dc.GetHost() {
if _, ok := existHost[h]; ok {
return errno.ERR_DUPLICATE_HOST.
return errno.ERR_DUPLICATE_NAME.
F("duplicated host: %s", h)
}
existHost[h] = true
Expand Down Expand Up @@ -161,7 +161,7 @@ func (dc *DiskConfig) Build() error {
}

if len(dc.GetHost()) == 0 {
return errno.ERR_HOST_FIELD_MISSING.
return errno.ERR_NAME_FIELD_MISSING.
F("disks[%d].host = []", dc.sequence)
} else if dc.GetDevice() == "" {
return errno.ERR_DEVICE_FIELD_MISSING.
Expand Down
10 changes: 10 additions & 0 deletions internal/configure/hosts/hc_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,17 @@ func (hc *HostConfig) getBool(i *comm.Item) bool {
return v.(bool)
}

func (hc *HostConfig) getName() string {
res := hc.GetHost()
if res != "" {
return res
}

return hc.getString(CONFIG_NAME)
}

func (hc *HostConfig) GetHost() string { return hc.getString(CONFIG_HOST) }
func (hc *HostConfig) GetName() string { return hc.getName() }
func (hc *HostConfig) GetHostname() string { return hc.getString(CONFIG_HOSTNAME) }
func (hc *HostConfig) GetSSHHostname() string { return hc.getString(CONFIG_SSH_HOSTNAME) }
func (hc *HostConfig) GetUser() string { return hc.getString(CONFIG_USER) }
Expand Down
7 changes: 7 additions & 0 deletions internal/configure/hosts/hc_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ var (
nil,
)

CONFIG_NAME = itemset.Insert(
"name",
comm.REQUIRE_STRING,
false,
nil,
)

CONFIG_HOSTNAME = itemset.Insert(
"hostname",
comm.REQUIRE_STRING,
Expand Down
12 changes: 6 additions & 6 deletions internal/configure/hosts/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ func (hc *HostConfig) Build() error {
}

privateKeyFile := hc.GetPrivateKeyFile()
if len(hc.GetHost()) == 0 {
return errno.ERR_HOST_FIELD_MISSING.
if len(hc.GetName()) == 0 {
return errno.ERR_NAME_NOT_FOUND.
F("hosts[%d].host = nil", hc.sequence)
} else if len(hc.GetHostname()) == 0 {
return errno.ERR_HOSTNAME_FIELD_MISSING.
Expand Down Expand Up @@ -206,12 +206,12 @@ func ParseHosts(data string) ([]*HostConfig, error) {
return nil, err
}

if _, ok := exist[hc.GetHost()]; ok {
return nil, errno.ERR_DUPLICATE_HOST.
F("duplicate host: %s", hc.GetHost())
if _, ok := exist[hc.GetName()]; ok {
return nil, errno.ERR_DUPLICATE_NAME.
F("duplicate name: %s", hc.GetName())
}
hcs = append(hcs, hc)
exist[hc.GetHost()] = true
exist[hc.GetName()] = true
}
build.DEBUG(build.DEBUG_HOSTS, hosts)
return hcs, nil
Expand Down
4 changes: 2 additions & 2 deletions internal/configure/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,14 @@ func ParseMonitorConfig(curveadm *cli.CurveAdm, filename string, data string, hs
return nil, errno.ERR_PARSE_MONITOR_CONFIGURE_FAILED.E(err)
}

// get host -> hostname(ip)
// get name -> hostname(ip)
ctx := topology.NewContext()
hcs, err := hosts.ParseHosts(curveadm.Hosts())
if err != nil {
return nil, err
}
for _, hc := range hcs {
ctx.Add(hc.GetHost(), hc.GetHostname())
ctx.Add(hc.GetName(), hc.GetHostname())
}

mkind := dcs[0].GetKind()
Expand Down
2 changes: 1 addition & 1 deletion internal/configure/topology/dc.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ func (dc *DeployConfig) ResolveHost() error {
}
dc.hostname = dc.ctx.Lookup(dc.GetHost())
if len(dc.hostname) == 0 {
return errno.ERR_HOST_NOT_FOUND.
return errno.ERR_NAME_NOT_FOUND.
F("host: %s", dc.GetHost())
}
return nil
Expand Down
8 changes: 5 additions & 3 deletions internal/errno/errno.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,14 +310,16 @@ var (
ERR_PARSE_HOSTS_FAILED = EC(320003, "parse hosts failed")
// 321: configure (hosts.yaml: invalid configure value)
ERR_UNSUPPORT_HOSTS_CONFIGURE_ITEM = EC(321000, "unsupport hosts configure item")
ERR_HOST_FIELD_MISSING = EC(321001, "host field missing")
ERR_NAME_FIELD_MISSING = EC(321001, "name field missing")
ERR_HOSTNAME_FIELD_MISSING = EC(321002, "hostname field missing")
ERR_HOSTS_SSH_PORT_EXCEED_MAX_PORT_NUMBER = EC(321003, "ssh_port exceed max port number")
ERR_PRIVATE_KEY_FILE_REQUIRE_ABSOLUTE_PATH = EC(321004, "SSH private key file needs to be an absolute path")
ERR_PRIVATE_KEY_FILE_NOT_EXIST = EC(321005, "SSH private key file not exist")
ERR_PRIVATE_KEY_FILE_REQUIRE_600_PERMISSIONS = EC(321006, "SSH private key file require 600 permissions")
ERR_DUPLICATE_HOST = EC(321007, "host is duplicate")
ERR_DUPLICATE_NAME = EC(321007, "name is duplicate")
ERR_HOSTNAME_REQUIRES_VALID_IP_ADDRESS = EC(321008, "hostname requires valid IP address")
//ERR_HOST_FIELD_MISSING = EC(321001, "host field missing")
//ERR_DUPLICATE_HOST = EC(321007, "host is duplicate")

// 322: configure (disks.yaml: parse failed)
ERR_DISKS_FILE_NOT_FOUND = EC(322000, "disks file not found")
Expand Down Expand Up @@ -401,7 +403,7 @@ var (
ERR_DATABASE_EMPTY_DISK_UUID = EC(360001, "empty disk uuid")

// 400: common (hosts)
ERR_HOST_NOT_FOUND = EC(400000, "host not found")
ERR_NAME_NOT_FOUND = EC(400000, "name not found")

// 410: common (services command)
ERR_NO_CLUSTER_SPECIFIED = EC(410001, "no cluster specified")
Expand Down
4 changes: 2 additions & 2 deletions internal/task/task/common/client_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ func NewGetClientStatusTask(curveadm *cli.CurveAdm, v interface{}) (*task.Task,
}

containerId := client.ContainerId
subname := fmt.Sprintf("host=%s kind=%s containerId=%s",
hc.GetHost(), client.Kind, tui.TrimContainerId(containerId))
subname := fmt.Sprintf("name=%s kind=%s containerId=%s",
hc.GetName(), client.Kind, tui.TrimContainerId(containerId))
t := task.NewTask("Get Client Status", subname, hc.GetSSHConfig())

// add step
Expand Down
4 changes: 2 additions & 2 deletions internal/task/task/common/collect_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ func NewCollectClientTask(curveadm *cli.CurveAdm, v interface{}) (*task.Task, er

// new task
containerId := client.ContainerId
subname := fmt.Sprintf("host=%s kind=%s containerId=%s",
hc.GetHost(), client.Kind, tui.TrimContainerId(containerId))
subname := fmt.Sprintf("name=%s kind=%s containerId=%s",
hc.GetName(), client.Kind, tui.TrimContainerId(containerId))
t := task.NewTask("Collect Client", subname, hc.GetSSHConfig())

// add step to task
Expand Down
6 changes: 3 additions & 3 deletions internal/tui/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const (
func FormatHosts(hcs []*configure.HostConfig, verbose bool) string {
lines := [][]interface{}{}
title := []string{
"Host",
"Name",
"Hostname",
"User",
"Port",
Expand All @@ -58,7 +58,7 @@ func FormatHosts(hcs []*configure.HostConfig, verbose bool) string {
for i := 0; i < len(hcs); i++ {
hc := hcs[i]

host := hc.GetHost()
name := hc.GetName()
hostname := hc.GetHostname()
user := hc.GetUser()
port := strconv.Itoa(hc.GetSSHPort())
Expand All @@ -74,7 +74,7 @@ func FormatHosts(hcs []*configure.HostConfig, verbose bool) string {
}

lines = append(lines, []interface{}{
host,
name,
hostname,
user,
port,
Expand Down

0 comments on commit 540f3c2

Please sign in to comment.