Skip to content

Commit

Permalink
Added a flag to query host OSDs only
Browse files Browse the repository at this point in the history
Signed-off-by: Utkarsh Bhatt <utkarsh.bhatt@canonical.com>
  • Loading branch information
UtkarshBhatthere committed Jul 2, 2024
1 parent 6d79454 commit 2dff4b2
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions microceph/cmd/microceph/disk_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ import (
)

type cmdDiskList struct {
common *CmdControl
disk *cmdDisk
json bool
common *CmdControl
disk *cmdDisk
json bool
hostOnly bool
}

func (c *cmdDiskList) Command() *cobra.Command {
Expand All @@ -35,6 +36,7 @@ func (c *cmdDiskList) Command() *cobra.Command {
}

cmd.PersistentFlags().BoolVar(&c.json, "json", false, "Provide output as Json encoded string.")
cmd.PersistentFlags().BoolVar(&c.hostOnly, "host-only", false, "Output only the disks configured on current host.")
return cmd
}

Expand Down Expand Up @@ -74,6 +76,25 @@ func (c *cmdDiskList) Run(cmd *cobra.Command, args []string) error {
return fmt.Errorf("internal error: unable to fetch unpartitoned disks: %w", err)
}

if c.hostOnly {
fcg := types.Disks{}

// Get system hostname.
hostname, err := os.Hostname()
if err != nil {
return fmt.Errorf("failed to retrieve system hostname: %w", err)
}

for _, disk := range configuredDisks {
if disk.Location == hostname {
fcg = append(fcg, disk)
}
}

// Overwrite configured disks with the filtered disks.
configuredDisks = fcg
}

if c.json {
return outputJson(configuredDisks, availableDisks)
}
Expand Down

0 comments on commit 2dff4b2

Please sign in to comment.