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

disk: refactor create disk #1083

Merged
merged 5 commits into from
Jul 26, 2024
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
1 change: 1 addition & 0 deletions pkg/cloud/ecsinterface.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cloud
import "github.com/aliyun/alibaba-cloud-sdk-go/services/ecs"

type ECSInterface interface {
CreateDisk(request *ecs.CreateDiskRequest) (response *ecs.CreateDiskResponse, err error)
DescribeAvailableResource(request *ecs.DescribeAvailableResourceRequest) (response *ecs.DescribeAvailableResourceResponse, err error)
DeleteDisk(request *ecs.DeleteDiskRequest) (response *ecs.DeleteDiskResponse, err error)
DescribeRegions(request *ecs.DescribeRegionsRequest) (response *ecs.DescribeRegionsResponse, err error)
Expand Down
15 changes: 15 additions & 0 deletions pkg/cloud/ecsmock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

86 changes: 86 additions & 0 deletions pkg/disk/category.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package disk

type Category string
type PerformanceLevel string

const (
DiskCommon Category = "cloud"
DiskEfficiency Category = "cloud_efficiency"
DiskSSD Category = "cloud_ssd"
DiskESSD Category = "cloud_essd"
DiskESSDAuto Category = "cloud_auto"
DiskESSDEntry Category = "cloud_essd_entry"

DiskPPerf Category = "cloud_pperf"
DiskSPerf Category = "cloud_sperf"
DiskSharedSSD Category = "san_ssd"
DiskSharedEfficiency Category = "san_efficiency"

PERFORMANCE_LEVEL0 PerformanceLevel = "PL0"
PERFORMANCE_LEVEL1 PerformanceLevel = "PL1"
PERFORMANCE_LEVEL2 PerformanceLevel = "PL2"
PERFORMANCE_LEVEL3 PerformanceLevel = "PL3"
)

type SizeRange struct {
Min int64
Max int64
}

type PerformanceLevelDesc struct {
Size SizeRange
}

type CategoryDesc struct {
Size SizeRange
PerformanceLevel map[PerformanceLevel]PerformanceLevelDesc
InstantAccessSnapshot bool
ProvisionedIops bool
Bursting bool
}

var AllCategories = map[Category]CategoryDesc{
DiskCommon: {},
DiskEfficiency: {
Size: SizeRange{Min: 20, Max: 65536},
},
DiskSSD: {
Size: SizeRange{Min: 20, Max: 65536},
},
DiskESSD: {
Size: SizeRange{Min: 20, Max: 65536},
PerformanceLevel: map[PerformanceLevel]PerformanceLevelDesc{
PERFORMANCE_LEVEL0: {Size: SizeRange{Min: 1, Max: 65536}},
PERFORMANCE_LEVEL1: {Size: SizeRange{Min: 20, Max: 65536}},
PERFORMANCE_LEVEL2: {Size: SizeRange{Min: 461, Max: 65536}},
PERFORMANCE_LEVEL3: {Size: SizeRange{Min: 1261, Max: 65536}},
},
InstantAccessSnapshot: true,
},
DiskESSDAuto: {
Size: SizeRange{Min: 1, Max: 65536},
InstantAccessSnapshot: true,
ProvisionedIops: true,
Bursting: true,
},
DiskESSDEntry: {
Size: SizeRange{Min: 10, Max: 65536},
},

// Deprecated shared disk
DiskSharedSSD: {},
DiskSharedEfficiency: {},

// Only available in private cloud
DiskPPerf: {},
DiskSPerf: {},
}

func GetSizeRange(category Category, pl PerformanceLevel) SizeRange {
desc := AllCategories[category]
limit := desc.Size
if plDesc, ok := desc.PerformanceLevel[pl]; ok {
limit = plDesc.Size
}
return limit
}
Loading