diff --git a/app/model.go b/app/model.go index c4d172d..ce86541 100644 --- a/app/model.go +++ b/app/model.go @@ -190,6 +190,9 @@ func (instance *Instance) RebuildVolume(host *Node, volid string) error { return err } + voltype := AnyPrefixes(volid, VolumeTypes) + volume.Type = voltype + instance.Volumes[VolumeID(volid)] = volume return nil diff --git a/app/types.go b/app/types.go index 5e6c62d..c4e9bfd 100644 --- a/app/types.go +++ b/app/types.go @@ -48,8 +48,18 @@ type Instance struct { configHostPCIs map[string]string } +var VolumeTypes = []string{ + "sata", + "scsi", + "ide", + "rootfs", + "mp", + "unused", +} + type VolumeID string type Volume struct { + Type string `json:"type"` Storage string `json:"storage"` Format string `json:"format"` Size uint64 `json:"size"` diff --git a/app/utils.go b/app/utils.go index 3ca4afd..85eeff9 100644 --- a/app/utils.go +++ b/app/utils.go @@ -36,7 +36,7 @@ func GetConfig(configPath string) Config { return config } -// returns if a device pcie bus id is a super device or subsystem device +// checks if a device pcie bus id is a super device or subsystem device // // subsystem devices always has the format xxxx:yy.z, whereas super devices have the format xxxx:yy // @@ -44,3 +44,16 @@ func GetConfig(configPath string) Config { func DeviceBusIDIsSuperDevice(BusID DeviceID) bool { return !strings.ContainsRune(string(BusID), '.') } + +// checks if string s has one of any prefixes, and returns the prefix or "" if there was no match +// +// matches the first prefix match in array order +func AnyPrefixes(s string, prefixes []string) string { + for _, prefix := range prefixes { + if strings.HasPrefix(s, prefix) { + return prefix + } + } + + return "" +}