Skip to content

Commit

Permalink
Add the WAL and DB devices for the disk-add command
Browse files Browse the repository at this point in the history
Signed-off-by: Luciano Lo Giudice <luciano.logiudice@canonical.com>
  • Loading branch information
lmlg committed Sep 21, 2023
1 parent 01d40b7 commit d00323d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
2 changes: 1 addition & 1 deletion microceph/api/disks.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func cmdDisksPost(s *state.State, r *http.Request) response.Response {

mu.Lock()
defer mu.Unlock()
err = ceph.AddOSD(s, req.Path, req.Wipe, req.Encrypt)
err = ceph.AddOSD(s, req.Path, req.Wipe, req.Encrypt, req.WALDev, req.DBDev)
if err != nil {
return response.SmartError(err)
}
Expand Down
8 changes: 5 additions & 3 deletions microceph/api/types/disks.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package types

// DisksPost hold a path and a flag for enabling device wiping
type DisksPost struct {
Path string `json:"path" yaml:"path"`
Wipe bool `json:"wipe" yaml:"wipe"`
Encrypt bool `json:"encrypt" yaml:"encrypt"`
Path string `json:"path" yaml:"path"`
Wipe bool `json:"wipe" yaml:"wipe"`
Encrypt bool `json:"encrypt" yaml:"encrypt"`
WALDev *string `json:"waldev" yaml:"waldev"`
DBDev *string `json:"dbdev" yaml:"dbdev"`
}

// DisksDelete holds an OSD number and a flag for forcing the removal
Expand Down
12 changes: 10 additions & 2 deletions microceph/ceph/osd.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func updateFailureDomain(s *state.State) error {
}

// AddOSD adds an OSD to the cluster, given a device path and a flag for wiping
func AddOSD(s *state.State, path string, wipe bool, encrypt bool) error {
func AddOSD(s *state.State, path string, wipe bool, encrypt bool, waldev *string, dbdev *string) error {
logger.Debugf("Adding OSD %s", path)

revert := revert.New()
Expand Down Expand Up @@ -416,7 +416,15 @@ func AddOSD(s *state.State, path string, wipe bool, encrypt bool) error {
}

// Bootstrap OSD.
_, err = processExec.RunCommand("ceph-osd", "--mkfs", "--no-mon-config", "-i", fmt.Sprintf("%d", nr))
args := []string{"--mkfs", "--no-mon-config", "-i", fmt.Sprintf("%d", nr)}
if waldev != nil {
args = append(args, *waldev)
}
if dbdev != nil {
args = append(args, *dbdev)
}

_, err = processExec.RunCommand("ceph-osd", args...)
if err != nil {
return fmt.Errorf("Failed to bootstrap OSD: %w", err)
}
Expand Down
12 changes: 12 additions & 0 deletions microceph/cmd/microceph/disk_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ type cmdDiskAdd struct {

flagWipe bool
flagEncrypt bool
walDevice string
dbDevice string
}

func (c *cmdDiskAdd) Command() *cobra.Command {
Expand All @@ -27,6 +29,8 @@ func (c *cmdDiskAdd) Command() *cobra.Command {

cmd.PersistentFlags().BoolVar(&c.flagWipe, "wipe", false, "Wipe the disk prior to use")
cmd.PersistentFlags().BoolVar(&c.flagEncrypt, "encrypt", false, "Encrypt the disk prior to use")
cmd.PersistentFlags().StringVar(&c.walDevice, "wal-device", "", "The device used for WAL")
cmd.PersistentFlags().StringVar(&c.dbDevice, "db-device", "", "The device used for the DB")

return cmd
}
Expand All @@ -52,6 +56,14 @@ func (c *cmdDiskAdd) Run(cmd *cobra.Command, args []string) error {
Encrypt: c.flagEncrypt,
}

if c.walDevice != "" {
req.WALDev = &c.walDevice
}

if c.dbDevice != "" {
req.DBDev = &c.dbDevice
}

err = client.AddDisk(context.Background(), cli, req)
if err != nil {
return err
Expand Down

0 comments on commit d00323d

Please sign in to comment.