Skip to content

Commit

Permalink
Add FCD support
Browse files Browse the repository at this point in the history
  • Loading branch information
VoigtS committed Jan 17, 2025
1 parent 4b7b5d3 commit 3e3d74b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 34 deletions.
27 changes: 21 additions & 6 deletions internal/liquids/cinder/capacity.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ func (l *Logic) ScanCapacity(ctx context.Context, req liquid.ServiceCapacityRequ

// sort volume types by VolumeTypeInfo (if multiple volume types have the same VolumeTypeInfo, they need to share the same pools)
volumeTypesByInfo := make(map[VolumeTypeInfo][]VolumeType)
//volumeFCDInfoByType := make(map[VolumeType][]VolumeTypeFCDInfo)

for volumeType, info := range l.VolumeFCDTypes.Get() {
logg.Info("fcdVolType: %s, vcdInfo: %s", volumeType, info)
}

for volumeType, info := range l.VolumeTypes.Get() {
volumeTypesByInfo[info] = append(volumeTypesByInfo[info], volumeType)
Expand All @@ -75,16 +70,37 @@ func (l *Logic) ScanCapacity(ctx context.Context, req liquid.ServiceCapacityRequ
for info := range volumeTypesByInfo {
sortedPools[info] = make(map[liquid.AvailabilityZone][]StoragePool)
}

poolMatches := make(map[StoragePool]VolumeTypeInfo, len(pools))
remainingPools := make(map[StoragePool]struct{}, len(pools))
for _, pool := range pools {
info := VolumeTypeInfo{
VolumeBackendName: pool.Capabilities.VolumeBackendName,
}

_, exists := sortedPools[info]
if !exists {
remainingPools[pool] = struct{}{}
continue
}
poolMatches[pool] = info
}

for pool := range remainingPools {
info := VolumeTypeInfo{
StorageProtocol: pool.Capabilities.StorageProtocol,
QualityType: pool.Capabilities.QualityType,
}
_, exists := sortedPools[info]
if !exists {
logg.Info("ScanCapacity: skipping pool %q: no volume type uses pools with %s", pool.Name, info)
continue
}
poolMatches[pool] = info
delete(remainingPools, pool)
}

for pool, info := range poolMatches {
poolAZ := liquid.AvailabilityZoneUnknown
for az, hosts := range serviceHostsPerAZ {
for _, v := range hosts {
Expand All @@ -99,7 +115,6 @@ func (l *Logic) ScanCapacity(ctx context.Context, req liquid.ServiceCapacityRequ
logg.Info("ScanCapacity: pool %q with %s does not match any service host", pool.Name, info)
}
logg.Debug("ScanCapacity: considering pool %q with %s in AZ %q", pool.Name, info, poolAZ)

sortedPools[info][poolAZ] = append(sortedPools[info][poolAZ], pool)
}

Expand Down
34 changes: 6 additions & 28 deletions internal/liquids/cinder/liquid.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"github.com/gophercloud/gophercloud/v2/openstack/blockstorage/v3/volumetypes"
"github.com/sapcc/go-api-declarations/liquid"
"github.com/sapcc/go-bits/liquidapi"
"github.com/sapcc/go-bits/logg"
)

type Logic struct {
Expand All @@ -40,8 +39,7 @@ type Logic struct {
// connections
CinderV3 *gophercloud.ServiceClient `json:"-"`
// state
VolumeTypes liquidapi.State[map[VolumeType]VolumeTypeInfo] `json:"-"`
VolumeFCDTypes liquidapi.State[map[VolumeType]VolumeTypeFCDInfo] `json:"-"`
VolumeTypes liquidapi.State[map[VolumeType]VolumeTypeInfo] `json:"-"`
}

// VolumeType is a type with convenience functions for deriving resource names.
Expand Down Expand Up @@ -72,20 +70,13 @@ func (vt VolumeType) VolumesQuotaName() string {

type VolumeTypeInfo struct {
VolumeBackendName string
}

// VolumeTypeFCDInfo contains configuration for a volumeType based on FCD.
// We need this for matching pools with their VolumeType.
type VolumeTypeFCDInfo struct {
// During a transition period, legacy volumes are still matched with the volume_backend_nam.
VolumeBackendName string
StorageProtocol string
QualityType string
}

// String returns a string representation of this VolumeTypeInfo for log messages.
func (i VolumeTypeInfo) String() string {
return fmt.Sprintf("volume_backend_name = %q", i.VolumeBackendName)
return fmt.Sprintf("volume_backend_name = %q, storage_protocol = %q, quality_type = %q ", i.VolumeBackendName, i.StorageProtocol, i.QualityType)
}

// Init implements the liquidapi.Logic interface.
Expand All @@ -106,32 +97,19 @@ func (l *Logic) BuildServiceInfo(ctx context.Context) (liquid.ServiceInfo, error
return liquid.ServiceInfo{}, err
}
volumeTypes := make(map[VolumeType]VolumeTypeInfo, len(vtSpecs))
volumeFCDTypes := make(map[VolumeType]VolumeTypeFCDInfo, len(vtSpecs))
for _, vtSpec := range vtSpecs {
if !vtSpec.IsPublic && !vtSpec.PublicAccess {
continue
}

volumeBackendName := vtSpec.ExtraSpecs["volume_backend_name"]
storageProtocol := vtSpec.ExtraSpecs["storage_protocol"]
if storageProtocol == "" {
volumeTypes[VolumeType(vtSpec.Name)] = VolumeTypeInfo{
VolumeBackendName: volumeBackendName,
}
} else {
volumeFCDTypes[VolumeType(vtSpec.Name)] = VolumeTypeFCDInfo{
VolumeBackendName: volumeBackendName,
StorageProtocol: storageProtocol,
QualityType: vtSpec.ExtraSpecs["quality_type"],
}
volumeTypes[VolumeType(vtSpec.Name)] = VolumeTypeInfo{
VolumeBackendName: vtSpec.ExtraSpecs["volume_backend_name"],
StorageProtocol: vtSpec.ExtraSpecs["storage_protocol"],
QualityType: vtSpec.ExtraSpecs["quality_type"],
}
}

l.VolumeTypes.Set(volumeTypes)
l.VolumeFCDTypes.Set(volumeFCDTypes)

logg.Info("volTypes: %s", volumeTypes)
logg.Info("volTypes: %s", volumeFCDTypes)

// build ResourceInfo set
resInfoForCapacity := liquid.ResourceInfo{
Expand Down

0 comments on commit 3e3d74b

Please sign in to comment.