Skip to content

Commit

Permalink
Changed the host keyword in other modules
Browse files Browse the repository at this point in the history
Changed the host keyword in other modules(with out cluster moudle)
  • Loading branch information
tiansuo114 committed Nov 20, 2023
1 parent 0f66e92 commit 552ff81
Show file tree
Hide file tree
Showing 70 changed files with 332 additions and 280 deletions.
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
18 changes: 9 additions & 9 deletions cli/command/disks/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import (
)

const (
HOST_DEVICE_SEP = ":"
NAME_DEVICE_SEP = ":"
COMMIT_EXAMPLE = `Examples:
$ curveadm disks commit /path/to/disks.yaml # Commit disks`
)
Expand Down Expand Up @@ -103,9 +103,9 @@ func assambleNewDiskRecords(dcs []*disks.DiskConfig,
serviceMountDevice := 0 // 0: false, 1: true
var newDiskRecords, diskRecordDeleteList []storage.Disk
for _, dc := range dcs {
for _, host := range dc.GetHost() {
for _, name := range dc.GetName() {
device := dc.GetDevice()
key := strings.Join([]string{host, device}, HOST_DEVICE_SEP)
key := strings.Join([]string{name, device}, NAME_DEVICE_SEP)
newDiskMap[key] = true
if dc.GetServiceMount() {
serviceMountDevice = 1
Expand All @@ -114,7 +114,7 @@ func assambleNewDiskRecords(dcs []*disks.DiskConfig,
diskUri := comm.DISK_DEFAULT_NULL_URI
diskChunkserverId := comm.DISK_DEFAULT_NULL_CHUNKSERVER_ID
for _, dr := range oldDiskRecords {
if dr.Host == host && device == dr.Device {
if dr.Name == name && device == dr.Device {
diskSize = dr.Size
diskUri = dr.URI
diskChunkserverId = dr.ChunkServerID
Expand All @@ -123,7 +123,7 @@ func assambleNewDiskRecords(dcs []*disks.DiskConfig,
}
newDiskRecords = append(
newDiskRecords, storage.Disk{
Host: host,
Name: name,
Device: device,
Size: diskSize,
URI: diskUri,
Expand All @@ -137,7 +137,7 @@ func assambleNewDiskRecords(dcs []*disks.DiskConfig,
}

for _, dr := range oldDiskRecords {
key := strings.Join([]string{dr.Host, dr.Device}, HOST_DEVICE_SEP)
key := strings.Join([]string{dr.Name, dr.Device}, NAME_DEVICE_SEP)
if _, ok := newDiskMap[key]; !ok {
diskRecordDeleteList = append(diskRecordDeleteList, dr)
}
Expand All @@ -148,7 +148,7 @@ func assambleNewDiskRecords(dcs []*disks.DiskConfig,

func writeDiskRecord(dr storage.Disk, curveadm *cli.CurveAdm) error {
if err := curveadm.Storage().SetDisk(
dr.Host,
dr.Name,
dr.Device,
dr.MountPoint,
dr.ContainerImage,
Expand Down Expand Up @@ -195,10 +195,10 @@ func syncDiskRecords(data string, dcs []*disks.DiskConfig,
if dr.ChunkServerID != comm.DISK_DEFAULT_NULL_CHUNKSERVER_ID {
return errno.ERR_DELETE_SERVICE_BINDING_DISK.
F("The disk[%s:%s] is used by service[%s:%s]",
dr.Host, dr.Device, topology.ROLE_CHUNKSERVER, dr.ChunkServerID)
dr.Name, dr.Device, topology.ROLE_CHUNKSERVER, dr.ChunkServerID)
}

if err := curveadm.Storage().DeleteDisk(dr.Host, dr.Device); err != nil {
if err := curveadm.Storage().DeleteDisk(dr.Name, dr.Device); err != nil {
return errno.ERR_UPDATE_DISK_FAILED.E(err)
}
}
Expand Down
2 changes: 1 addition & 1 deletion cli/command/disks/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func runList(curveadm *cli.CurveAdm, options listOptions) error {
if options.host == "*" {
diskRecords = curveadm.DiskRecords()
} else {
if diskRecords, err = curveadm.Storage().GetDisk(common.DISK_FILTER_HOST,
if diskRecords, err = curveadm.Storage().GetDisk(common.DISK_FILTER_NAME,
options.host); err != nil {
return err
}
Expand Down
Loading

0 comments on commit 552ff81

Please sign in to comment.