Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RAID Controller (StorageController) support; Marvell CLI (mvcli) #54

Merged
merged 8 commits into from
Oct 20, 2022
Prev Previous commit
Next Next commit
actions/interface.go, actions/storage_controller.go: StorageControlle…
…r Create/Destroy actions

* actions/interface.go: Add VirtualDiskManager interface
* actions/interface.go & actions/storage_controller.go: Add VirtualDiskManager VD listing
  • Loading branch information
splaspood committed Oct 19, 2022
commit 1a9ed67b516c9d1c72799c0016ee8ec626aaf156
17 changes: 17 additions & 0 deletions actions/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

"github.com/bmc-toolbox/common"
"github.com/metal-toolbox/ironlib/utils"
)

// Utility interface couples the configuration, collection and update interfaces
Expand Down Expand Up @@ -96,3 +97,19 @@ type BIOSUpdater interface {
type StorageControllerUpdater interface {
UpdateStorageController() error
}

// VirtualDiskCreator defines an interface to create virtual disks, generally via a StorageController
type VirtualDiskCreator interface {
CreateVirtualDisk(ctx context.Context, raidMode string, physicalDisks []uint, name string, blockSize uint) error
}

// VirtualDiskCreator defines an interface to destroy virtual disks, generally via a StorageController
type VirtualDiskDestroyer interface {
DestroyVirtualDisk(ctx context.Context, virtualDiskID int) error
}

type VirtualDiskManager interface {
VirtualDiskCreator
VirtualDiskDestroyer
VirtualDisks(ctx context.Context) ([]*utils.MvcliDevice, error)
}
67 changes: 67 additions & 0 deletions actions/storage_controller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package actions

import (
"context"
"fmt"
"strings"

"github.com/bmc-toolbox/common"
"github.com/metal-toolbox/ironlib/model"
"github.com/metal-toolbox/ironlib/utils"
"github.com/pkg/errors"
)

var (
ErrVirtualDiskManagerUtilNotIdentified = errors.New("virtual disk management utility not identifed")
)

func CreateVirtualDisk(ctx context.Context, hba *common.StorageController, options *model.CreateVirtualDiskOptions) error {
util, err := GetControllerUtility(hba.Vendor, hba.Model)
if err != nil {
return err
}

return util.CreateVirtualDisk(ctx, options.RaidMode, options.PhysicalDiskIDs, options.Name, options.BlockSize)
}

func DestroyVirtualDisk(ctx context.Context, hba *common.Device, options *model.DestroyVirtualDiskOptions) error {
util, err := GetControllerUtility(hba.Vendor, hba.Model)
if err != nil {
return err
}

return util.DestroyVirtualDisk(ctx, options.VirtualDiskID)
}

func ListVirtualDisks(ctx context.Context, hba *common.StorageController) ([]*common.VirtualDisk, error) {
util, err := GetControllerUtility(hba.Vendor, hba.Model)
if err != nil {
return nil, err
}

virtualDisks, err := util.VirtualDisks(ctx)
if err != nil {
return nil, err
}

cVirtualDisks := []*common.VirtualDisk{}

for _, vd := range virtualDisks {
cVirtualDisks = append(cVirtualDisks, &common.VirtualDisk{
ID: fmt.Sprintf("%d", vd.ID),
Name: vd.Name,
RaidType: vd.Type,
})
}

return cVirtualDisks, nil
}

// GetControllerUtility returns the utility command for the given vendor
func GetControllerUtility(vendorName, modelName string) (VirtualDiskManager, error) {
if strings.EqualFold(vendorName, common.VendorMarvell) {
return utils.NewMvcliCmd(true), nil
}

return nil, errors.Wrap(ErrVirtualDiskManagerUtilNotIdentified, "vendor: "+vendorName+" model: "+modelName)
}