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

Signed-off-by: noobcoder <[email protected]>

Changed the host keyword in other modules

Changed the host keyword in other modules(with out cluster moudle)
  • Loading branch information
tiansuo114 committed Nov 20, 2023
1 parent 48abdf1 commit a23ba1f
Show file tree
Hide file tree
Showing 79 changed files with 383 additions and 312 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/client/enter.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,5 @@ func runEnter(curveadm *cli.CurveAdm, options enterOptions) error {
if client.Kind == topology.KIND_CURVEFS {
home = "/curvefs/client"
}
return tools.AttachRemoteContainer(curveadm, client.Host, client.ContainerId, home)
return tools.AttachRemoteContainer(curveadm, client.Name, client.ContainerId, home)
}
8 changes: 4 additions & 4 deletions cli/command/client/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ var (

type installOptions struct {
kind string
host string
name string
filename string
}

Expand Down Expand Up @@ -77,7 +77,7 @@ func NewInstallCommand(curveadm *cli.CurveAdm) *cobra.Command {
}

flags := cmd.Flags()
flags.StringVar(&options.host, "host", "local", "Specify install target host")
flags.StringVar(&options.name, "name", "local", "Specify install target name")
flags.StringVarP(&options.filename, "conf", "c", "client.yaml", "Specify client configuration file")

return cmd
Expand All @@ -93,7 +93,7 @@ func genInstallPlaybook(curveadm *cli.CurveAdm,
Type: step,
Configs: ccs,
Options: map[string]interface{}{
comm.KEY_CLIENT_HOST: options.host,
comm.KEY_CLIENT_NAME: options.name,
},
})
}
Expand Down Expand Up @@ -129,6 +129,6 @@ func runInstall(curveadm *cli.CurveAdm, options installOptions) error {
// 4) print success prompt
curveadm.WriteOutln("")
curveadm.WriteOutln(color.GreenString("Install %s to %s success ^_^"),
options.kind, options.host)
options.kind, options.name)
return nil
}
34 changes: 17 additions & 17 deletions cli/command/client/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ import (

const (
MAP_EXAMPLE = `Examples:
$ curveadm map user:/volume --host machine1 --create # Map volume which created by automatic
$ curveadm map user:/volume --host machine1 --size=10GiB --create # Map volume which size is 10GiB and created by automatic
$ curveadm map user:/volume --host machine1 --create --poolset ssd # Map volume created by automatic in poolset 'ssd'
$ curveadm map user:/volume --host machine1 -c /path/to/client.yaml # Map volume with specified configure file`
$ curveadm map user:/volume --name machine1 --create # Map volume which created by automatic
$ curveadm map user:/volume --name machine1 --size=10GiB --create # Map volume which size is 10GiB and created by automatic
$ curveadm map user:/volume --name machine1 --create --poolset ssd # Map volume created by automatic in poolset 'ssd'
$ curveadm map user:/volume --name machine1 -c /path/to/client.yaml # Map volume with specified configure file`
)

var (
Expand All @@ -60,32 +60,32 @@ var (

type mapOptions struct {
image string
host string
name string
size string
create bool
filename string
noExclusive bool
poolset string
}

func ParseImage(image string) (user, name string, err error) {
func ParseImage(image string) (user, volumeName string, err error) {
items := strings.Split(image, ":")
if len(items) != 2 || len(items[0]) == 0 || len(items[1]) == 0 {
err = errno.ERR_INVALID_VOLUME_FORMAT.
F("volume: %s", image)
return
}

user, name = items[0], items[1]
user, volumeName = items[0], items[1]
if user == "root" {
err = errno.ERR_ROOT_VOLUME_USER_NOT_ALLOWED.
F("volume user: %s", user)
} else if !strings.HasPrefix(name, "/") {
} else if !strings.HasPrefix(volumeName, "/") {
err = errno.ERR_VOLUME_NAME_MUST_START_WITH_SLASH_PREFIX.
F("volume name: %s", name)
} else if strings.Contains(name, "_") {
F("volume name: %s", volumeName)
} else if strings.Contains(volumeName, "_") {
err = errno.ERR_VOLUME_NAME_CAN_NOT_CONTAIN_UNDERSCORE.
F("volume name: %s", name)
F("volume name: %s", volumeName)
}
return
}
Expand Down Expand Up @@ -156,7 +156,7 @@ func NewMapCommand(curveadm *cli.CurveAdm) *cobra.Command {
}

flags := cmd.Flags()
flags.StringVar(&options.host, "host", "localhost", "Specify target host")
flags.StringVar(&options.name, "name", "localhost", "Specify target name")
flags.BoolVar(&options.create, "create", false, "Create volume iff not exist")
flags.BoolVar(&options.noExclusive, "no-exclusive", false, "Map volume non exclusive")
flags.StringVar(&options.size, "size", "10GiB", "Specify volume size")
Expand All @@ -168,7 +168,7 @@ func NewMapCommand(curveadm *cli.CurveAdm) *cobra.Command {
func genMapPlaybook(curveadm *cli.CurveAdm,
ccs []*configure.ClientConfig,
options mapOptions) (*playbook.Playbook, error) {
user, name, _ := ParseImage(options.image)
user, volumeName, _ := ParseImage(options.image)
size, _ := ParseSize(options.size)
steps := MAP_PLAYBOOK_STEPS
pb := playbook.NewPlaybook(curveadm)
Expand All @@ -181,15 +181,15 @@ func genMapPlaybook(curveadm *cli.CurveAdm,
Configs: ccs,
Options: map[string]interface{}{
comm.KEY_MAP_OPTIONS: bs.MapOptions{
Host: options.host,
Name: options.name,
User: user,
Volume: name,
Volume: volumeName,
Size: size,
Create: options.create,
NoExclusive: options.noExclusive,
Poolset: options.poolset,
},
comm.KEY_CLIENT_HOST: options.host, // for checker
comm.KEY_CLIENT_NAME: options.name, // for checker
comm.KEY_CHECK_KERNEL_MODULE_NAME: comm.KERNERL_MODULE_NBD,
},
})
Expand Down Expand Up @@ -223,6 +223,6 @@ func runMap(curveadm *cli.CurveAdm, options mapOptions) error {
// 4) print success prompt
curveadm.WriteOutln("")
curveadm.WriteOutln(color.GreenString("Map %s to %s nbd device success ^_^"),
options.image, options.host)
options.image, options.name)
return nil
}
14 changes: 7 additions & 7 deletions cli/command/client/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ import (

const (
MOUNT_EXAMPLE = `Examples:
$ curveadm mount /s3_001 /path/to/mount --host machine -c client.yaml [--fstype s3] # Mount a s3 CurveFS '/s3_001' to '/path/to/mount'
$ curveadm mount /volume_001 /path/to/mount --host machine -c client.yaml --fstype volume # Mount a volume CurveFS '/volume_001' to '/path/to/mount'`
$ curveadm mount /s3_001 /path/to/mount --name machine -c client.yaml [--fstype s3] # Mount a s3 CurveFS '/s3_001' to '/path/to/mount'
$ curveadm mount /volume_001 /path/to/mount --name machine -c client.yaml --fstype volume # Mount a volume CurveFS '/volume_001' to '/path/to/mount'`
)

var (
Expand All @@ -53,7 +53,7 @@ var (
)

type mountOptions struct {
host string
name string
mountFSName string
mountFSType string
mountPoint string
Expand Down Expand Up @@ -91,7 +91,7 @@ func NewMountCommand(curveadm *cli.CurveAdm) *cobra.Command {
}

flags := cmd.Flags()
flags.StringVar(&options.host, "host", "localhost", "Specify target host")
flags.StringVar(&options.name, "name", "localhost", "Specify target name")
flags.StringVarP(&options.filename, "conf", "c", "client.yaml", "Specify client configuration file")
flags.StringVar(&options.mountFSType, "fstype", "s3", "Specify fs data backend")
flags.BoolVarP(&options.insecure, "insecure", "k", false, "Mount without precheck")
Expand All @@ -115,12 +115,12 @@ func genMountPlaybook(curveadm *cli.CurveAdm,
Configs: ccs,
Options: map[string]interface{}{
comm.KEY_MOUNT_OPTIONS: fs.MountOptions{
Host: options.host,
Name: options.name,
MountFSName: options.mountFSName,
MountFSType: options.mountFSType,
MountPoint: utils.TrimSuffixRepeat(options.mountPoint, "/"),
},
comm.KEY_CLIENT_HOST: options.host, // for checker
comm.KEY_CLIENT_NAME: options.name, // for checker
comm.KEY_CHECK_KERNEL_MODULE_NAME: comm.KERNERL_MODULE_FUSE,
},
ExecOptions: playbook.ExecOptions{
Expand Down Expand Up @@ -156,6 +156,6 @@ func runMount(curveadm *cli.CurveAdm, options mountOptions) error {
// 4) print success prompt
curveadm.WriteOutln("")
curveadm.WriteOutln(color.GreenString("Mount %s to %s (%s) success ^_^"),
options.mountFSName, options.mountPoint, options.host)
options.mountFSName, options.mountPoint, options.name)
return nil
}
6 changes: 3 additions & 3 deletions cli/command/client/umount.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var (
)

type umountOptions struct {
host string
name string
mountPoint string
}

Expand Down Expand Up @@ -74,7 +74,7 @@ func NewUmountCommand(curveadm *cli.CurveAdm) *cobra.Command {
}

flags := cmd.Flags()
flags.StringVar(&options.host, "host", "localhost", "Specify target host")
flags.StringVar(&options.name, "name", "localhost", "Specify target name")

return cmd
}
Expand All @@ -90,7 +90,7 @@ func genUnmountPlaybook(curveadm *cli.CurveAdm,
Configs: nil,
Options: map[string]interface{}{
comm.KEY_MOUNT_OPTIONS: fs.MountOptions{
Host: options.host,
Name: options.name,
MountPoint: utils.TrimSuffixRepeat(options.mountPoint, "/"),
},
},
Expand Down
8 changes: 4 additions & 4 deletions cli/command/client/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var (

type uninstallOptions struct {
kind string
host string
name string
}

func checkUninstallOptions(curveadm *cli.CurveAdm, options uninstallOptions) error {
Expand Down Expand Up @@ -72,7 +72,7 @@ func NewUninstallCommand(curveadm *cli.CurveAdm) *cobra.Command {
}

flags := cmd.Flags()
flags.StringVar(&options.host, "host", "local", "Specify uninstall target host")
flags.StringVar(&options.name, "name", "local", "Specify uninstall target name")

return cmd
}
Expand All @@ -86,7 +86,7 @@ func genUninstallPlaybook(curveadm *cli.CurveAdm,
Type: step,
Configs: nil,
Options: map[string]interface{}{
comm.KEY_CLIENT_HOST: options.host,
comm.KEY_CLIENT_NAME: options.name,
comm.KEY_CLIENT_KIND: options.kind,
},
})
Expand All @@ -110,6 +110,6 @@ func runUninstall(curveadm *cli.CurveAdm, options uninstallOptions) error {
// 4) print success prompt
curveadm.WriteOutln("")
curveadm.WriteOutln(color.GreenString("UnInstall %s %s success ^_^"),
options.host, options.kind)
options.name, options.kind)
return nil
}
12 changes: 6 additions & 6 deletions cli/command/client/unmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (

const (
UNMAP_EXAMPLE = `Examples:
$ curveadm unmap user:volume --host machine1 # Unmap volume`
$ curveadm unmap user:volume --name machine1 # Unmap volume`
)

var (
Expand All @@ -44,7 +44,7 @@ var (
)

type unmapOptions struct {
host string
name string
image string
}

Expand Down Expand Up @@ -73,15 +73,15 @@ func NewUnmapCommand(curveadm *cli.CurveAdm) *cobra.Command {
}

flags := cmd.Flags()
flags.StringVar(&options.host, "host", "localhost", "Specify target host")
flags.StringVar(&options.name, "name", "localhost", "Specify target name")

return cmd
}

func genUnmapPlaybook(curveadm *cli.CurveAdm,
ccs []*configure.ClientConfig,
options unmapOptions) (*playbook.Playbook, error) {
user, name, _ := ParseImage(options.image)
user, volumeName, _ := ParseImage(options.image)
steps := UNMAP_PLAYBOOK_STEPS
pb := playbook.NewPlaybook(curveadm)
for _, step := range steps {
Expand All @@ -90,9 +90,9 @@ func genUnmapPlaybook(curveadm *cli.CurveAdm,
Configs: nil,
Options: map[string]interface{}{
comm.KEY_MAP_OPTIONS: bs.MapOptions{
Host: options.host,
Name: options.name,
User: user,
Volume: name,
Volume: volumeName,
},
},
})
Expand Down
Loading

0 comments on commit a23ba1f

Please sign in to comment.