Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions core/commoncmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ func FlagKey(flags *pflag.FlagSet, p *string) {
flags.StringVar(p, "key", "", "a data key name")
}

func FlagKeys(flags *pflag.FlagSet, p *[]string) {
flags.StringSliceVar(p, "key", nil, "a data key name")
}

func FlagKeyTo(flags *pflag.FlagSet, p *string) {
flags.StringVar(p, "to", "", "the new data key name")
}
Expand Down Expand Up @@ -382,6 +386,10 @@ func FlagKeyName(flags *pflag.FlagSet, p *string) {
flags.StringVar(p, "name", "", "the key name")
}

func FlagKeyNames(flags *pflag.FlagSet, p *[]string) {
flags.StringSliceVar(p, "name", nil, "a data key name")
}

func FlagKeyValue(flags *pflag.FlagSet, p *string) {
flags.StringVar(p, "value", "", "the key value")
}
Expand Down
4 changes: 2 additions & 2 deletions core/om/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ func newCmdObjectKeyRemove(kind string) *cobra.Command {
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
commoncmd.FlagKeyName(flags, &options.Name)
commoncmd.FlagKeyNames(flags, &options.Names)
return cmd
}

Expand Down Expand Up @@ -3536,7 +3536,7 @@ func newCmdDataStoreRemove(kind string) *cobra.Command {
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
commoncmd.FlagKey(flags, &options.Name)
commoncmd.FlagKeys(flags, &options.Names)
return cmd
}

Expand Down
9 changes: 7 additions & 2 deletions core/omcmd/object_key_remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
type (
CmdObjectKeyRemove struct {
OptsGlobal
Name string
Names []string
}
)

Expand All @@ -27,7 +27,12 @@ func (t *CmdObjectKeyRemove) Run(kind string) error {
if err != nil {
return nil, err
}
return nil, store.RemoveKey(t.Name)
for _, name := range t.Names {
if err := store.TransactionRemoveKey(name); err != nil {
return nil, err
}
}
return nil, store.Config().CommitInvalid()
}),
).Do()
}
4 changes: 2 additions & 2 deletions core/ox/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ func newCmdObjectKeyRemove(kind string) *cobra.Command {
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
commoncmd.FlagKeyName(flags, &options.Name)
commoncmd.FlagKeyNames(flags, &options.Names)
return cmd
}

Expand Down Expand Up @@ -3289,7 +3289,7 @@ func newCmdDataStoreRemove(kind string) *cobra.Command {
}
flags := cmd.Flags()
addFlagsGlobal(flags, &options.OptsGlobal)
commoncmd.FlagKey(flags, &options.Name)
commoncmd.FlagKeys(flags, &options.Names)
return cmd
}

Expand Down
18 changes: 14 additions & 4 deletions core/oxcmd/object_key_remove.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package oxcmd

import (
"bytes"
"context"
"encoding/json"
"fmt"
"net/http"
"slices"
Expand All @@ -16,7 +18,7 @@ import (
type (
CmdObjectKeyRemove struct {
OptsGlobal
Name string
Names []string
}
)

Expand Down Expand Up @@ -46,10 +48,18 @@ func (t *CmdObjectKeyRemove) Run(kind string) error {
}

func (t *CmdObjectKeyRemove) RunForPath(ctx context.Context, c *client.T, path naming.Path) error {
params := api.DeleteObjectDataKeyParams{
Name: t.Name,
data := make(api.PatchDataKeys, len(t.Names))
for i, name := range t.Names {
data[i] = api.PatchDataKey{
Action: "remove",
Name: name,
}
}
r := bytes.NewBuffer(nil)
if err := json.NewEncoder(r).Encode(data); err != nil {
return err
}
response, err := c.DeleteObjectDataKeyWithResponse(ctx, path.Namespace, path.Kind, path.Name, &params)
response, err := c.PatchObjectDataWithBodyWithResponse(ctx, path.Namespace, path.Kind, path.Name, "application/json", r)
if err != nil {
return err
}
Expand Down
58 changes: 40 additions & 18 deletions core/pool/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ type (
Pools() []Pooler
}
Lookup struct {
Name string
Type string
Access volaccess.T
Size int64
Format bool
Shared bool
Usage bool
Nodes []string
Name string
Type string
Access volaccess.T
Size int64
Format bool
Shared bool
Usage bool
Volatile bool
Nodes []string

manager manager
}
Expand All @@ -36,6 +37,19 @@ type (
}
)

const (
CapBlk Capability = "blk"
CapFile Capability = "file"
CapMove Capability = "move"
CapROO Capability = "roo"
CapROX Capability = "rox"
CapRWO Capability = "rwo"
CapRWX Capability = "rwx"
CapShared Capability = "shared"
CapSnap Capability = "snap"
CapVolatile Capability = "volatile"
)

func (by By) Sort(l StatusList) {
s := &statusSorter{
data: l,
Expand Down Expand Up @@ -72,10 +86,6 @@ func (t Lookup) Do(ctx context.Context) (Pooler, error) {
cause = append(cause, fmt.Sprintf("[%s] not matching name %s", p.Name(), t.Name))
continue
}
if t.Type == "" && "shm" == p.Type() {
cause = append(cause, fmt.Sprintf("[%s] volatile, type not requested, assume persistence is expected.", p.Name()))
continue
}
if t.Type != "" && t.Type != p.Type() {
cause = append(cause, fmt.Sprintf("[%s] type %s not matching %s", p.Name(), p.Type(), t.Type))
continue
Expand All @@ -84,14 +94,26 @@ func (t Lookup) Do(ctx context.Context) (Pooler, error) {
cause = append(cause, fmt.Sprintf("[%s] not %s capable %s", p.Name(), t.Access, p.Capabilities()))
continue
}
if t.Format == false && !HasCapability(p, "blk") {
if t.Format == false && !HasCapability(p, CapBlk) {
cause = append(cause, fmt.Sprintf("[%s] not blk capable", p.Name()))
continue
}
if t.Shared == true && !HasCapability(p, "shared") {
if t.Format == true && !HasCapability(p, CapFile) {
cause = append(cause, fmt.Sprintf("[%s] not file capable", p.Name()))
continue
}
if t.Shared == true && !HasCapability(p, CapShared) {
cause = append(cause, fmt.Sprintf("[%s] not shared capable", p.Name()))
continue
}
if t.Volatile == true && !HasCapability(p, CapVolatile) {
cause = append(cause, fmt.Sprintf("[%s] not volatile capable", p.Name()))
continue
}
if t.Volatile == false && HasCapability(p, CapVolatile) {
cause = append(cause, fmt.Sprintf("[%s] not persistent capable", p.Name()))
continue
}
if t.Usage == true {
usage, err := p.Usage(ctx)
if err != nil {
Expand All @@ -112,19 +134,19 @@ func (t Lookup) Do(ctx context.Context) (Pooler, error) {
}
weight := func(p1, p2 *StatusItem) bool {
if !t.Shared {
p1shared := p1.HasCapability("shared")
p2shared := p2.HasCapability("shared")
p1shared := p1.HasCapability(CapShared)
p2shared := p2.HasCapability(CapShared)
switch {
case p1shared && p2shared:
// not decisive
case !p1shared && !p2shared:
// not decisive
case p1shared && !p2shared:
// prefer p2, not shared-capable
return true
return false
case !p1shared && p2shared:
// prefer p1, not shared-capable
return false
return true
}
}
if p1.Usage.Free < p2.Usage.Free {
Expand Down
39 changes: 26 additions & 13 deletions core/pool/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,21 @@ type (

Status struct {
Usage
Capabilities []string `json:"capabilities"`
Errors []string `json:"errors"`
Head string `json:"head"`
Type string `json:"type"`
UpdatedAt time.Time `json:"updated_at"`
VolumeCount int `json:"volume_count"`
Capabilities Capabilities `json:"capabilities"`
Errors []string `json:"errors"`
Head string `json:"head"`
Type string `json:"type"`
UpdatedAt time.Time `json:"updated_at"`
VolumeCount int `json:"volume_count"`
}
StatusItem struct {
Status
Name string `json:"name"`
}

StatusList []StatusItem
Capabilities []string
Capabilities []Capability
Capability string

VolumeStatus struct {
Pool string `json:"pool"`
Expand Down Expand Up @@ -85,7 +86,7 @@ type (
Type() string
Head() string
Mappings() map[string]string
Capabilities() []string
Capabilities() Capabilities
Usage(context.Context) (Usage, error)
SetConfig(Config)
Config() Config
Expand Down Expand Up @@ -120,6 +121,18 @@ type (
}
)

func (t Capabilities) StringSlice() []string {
l := make([]string, len(t))
for i, c := range t {
l[i] = string(c)
}
return l
}

func (t Capabilities) String() string {
return strings.Join(t.StringSlice(), ",")
}

func MappingsFromPaths(paths san.Paths) (array.Mappings, error) {
m := make(array.Mappings)
for _, path := range paths.MappingList() {
Expand Down Expand Up @@ -458,10 +471,10 @@ func (t VolumeStatusList) Swap(i, j int) {
}

func HasAccess(p Pooler, acs volaccess.T) bool {
return HasCapability(p, acs.String())
return HasCapability(p, Capability(acs.String()))
}

func HasCapability(p Pooler, s string) bool {
func HasCapability(p Pooler, s Capability) bool {
for _, capa := range p.Capabilities() {
if capa == s {
return true
Expand All @@ -472,10 +485,10 @@ func HasCapability(p Pooler, s string) bool {
}

func (t *Status) HasAccess(acs volaccess.T) bool {
return t.HasCapability(acs.String())
return t.HasCapability(Capability(acs.String()))
}

func (t *Status) HasCapability(s string) bool {
func (t *Status) HasCapability(s Capability) bool {
for _, capa := range t.Capabilities {
if capa == s {
return true
Expand All @@ -490,7 +503,7 @@ func (t *Status) DeepCopy() *Status {
Type: t.Type,
Head: t.Head,
VolumeCount: t.VolumeCount,
Capabilities: append([]string{}, t.Capabilities...),
Capabilities: append(Capabilities{}, t.Capabilities...),
UpdatedAt: t.UpdatedAt,
Usage: Usage{
Free: t.Usage.Free,
Expand Down
2 changes: 1 addition & 1 deletion core/tui/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (t *App) updatePoolList(forceUpdate bool) {
return []string{
poolName,
poolData.Type,
strings.Join(poolData.Capabilities, ","),
poolData.Capabilities.String(),
poolData.Head,
strconv.FormatInt(int64(poolData.VolumeCount), 10),
sizeconv.BSizeCompact(float64(poolData.Size)),
Expand Down
12 changes: 10 additions & 2 deletions daemon/daemonapi/get_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,12 @@ func (a *DaemonAPI) getNodePools(ctx echo.Context, name *string, nodeMap nodesel
continue
}
stat := *e.Value
capabilities := make([]string, len(stat.Capabilities))
for i, c := range stat.Capabilities {
capabilities[i] = string(c)
}
item := api.Pool{
Capabilities: append([]string{}, stat.Capabilities...),
Capabilities: capabilities,
Free: stat.Free,
Head: stat.Head,
Name: e.Name,
Expand Down Expand Up @@ -89,9 +93,13 @@ func (a *DaemonAPI) getClusterPools(ctx echo.Context, name *string) api.PoolItem
}
item, ok := m[e.Name]
stat := *e.Value
capabilities := make([]string, len(stat.Capabilities))
for i, c := range stat.Capabilities {
capabilities[i] = string(c)
}
if !ok {
item = api.Pool{
Capabilities: append([]string{}, stat.Capabilities...),
Capabilities: capabilities,
Free: stat.Free,
Head: stat.Head,
Name: e.Name,
Expand Down
11 changes: 9 additions & 2 deletions drivers/pooldirectory/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,15 @@ func (t T) Head() string {
return t.path()
}

func (t T) Capabilities() []string {
return []string{"rox", "rwx", "roo", "rwo", "blk"}
func (t T) Capabilities() pool.Capabilities {
return pool.Capabilities{
pool.CapBlk,
pool.CapFile,
pool.CapROO,
pool.CapROX,
pool.CapRWO,
pool.CapRWX,
}
}

func (t T) Usage(ctx context.Context) (pool.Usage, error) {
Expand Down
14 changes: 12 additions & 2 deletions drivers/pooldrbd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,18 @@ func New() *T {
return &t
}

func (t T) Capabilities() []string {
return []string{"rox", "rwx", "roo", "rwo", "snap", "blk", "shared"}
func (t T) Capabilities() pool.Capabilities {
return pool.Capabilities{
pool.CapBlk,
pool.CapFile,
pool.CapMove,
pool.CapROO,
pool.CapROX,
pool.CapRWO,
pool.CapRWX,
pool.CapShared,
pool.CapSnap,
}
}

func (t T) vg() string {
Expand Down
Loading