mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
过滤掉不支持的huawei skus & image
This commit is contained in:
@@ -130,6 +130,17 @@ func inWhiteList(provider string) bool {
|
||||
}
|
||||
}
|
||||
|
||||
func excludeSkus(q *sqlchemy.SQuery) *sqlchemy.SQuery {
|
||||
// 排除掉华为云对镜像有特殊要求的sku
|
||||
return q.Filter(
|
||||
sqlchemy.OR(
|
||||
sqlchemy.NotEquals(q.Field("provider"), CLOUD_PROVIDER_HUAWEI),
|
||||
sqlchemy.AND(
|
||||
sqlchemy.Equals(q.Field("provider"), CLOUD_PROVIDER_HUAWEI),
|
||||
sqlchemy.NotIn(q.Field("instance_type_family"), []string{"e1", "e2", "e3", "d1", "d2", "i3", "h2", "g1", "g3", "p2v", "p1", "pi1", "fp1", "fp1c"}),
|
||||
)))
|
||||
}
|
||||
|
||||
func genInstanceType(family string, cpu, mem_mb int64) (string, error) {
|
||||
if cpu <= 0 {
|
||||
return "", fmt.Errorf("cpu_core_count should great than zero")
|
||||
@@ -315,6 +326,8 @@ func (self *SServerSkuManager) GetPropertyInstanceSpecs(ctx context.Context, use
|
||||
q = q.Equals("provider", provider)
|
||||
}
|
||||
|
||||
q = excludeSkus(q)
|
||||
|
||||
// 如果是查询私有云需要忽略zone参数
|
||||
zone := jsonutils.GetAnyString(query, []string{"zone", "zone_id"})
|
||||
if !inWhiteList(provider) {
|
||||
@@ -538,6 +551,8 @@ func (manager *SServerSkuManager) ListItemFilter(ctx context.Context, q *sqlchem
|
||||
return nil, err
|
||||
}
|
||||
|
||||
q = excludeSkus(q)
|
||||
|
||||
regionStr := jsonutils.GetAnyString(query, []string{"region", "cloudregion", "region_id", "cloudregion_id"})
|
||||
if len(regionStr) > 0 {
|
||||
regionObj, err := CloudregionManager.FetchByIdOrName(nil, regionStr)
|
||||
|
||||
+73
-29
@@ -36,34 +36,39 @@ const (
|
||||
type SImage struct {
|
||||
storageCache *SStoragecache
|
||||
|
||||
Schema string `json:"schema"`
|
||||
MinDiskGB int64 `json:"min_disk"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
ImageSourceType string `json:"__image_source_type"`
|
||||
ContainerFormat string `json:"container_format"`
|
||||
File string `json:"file"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
Protected bool `json:"protected"`
|
||||
Checksum string `json:"checksum"`
|
||||
SupportKVMFPGAType string `json:"__support_kvm_fpga_type"`
|
||||
ID string `json:"id"`
|
||||
Isregistered string `json:"__isregistered"`
|
||||
MinRamMB int `json:"min_ram"`
|
||||
Lazyloading string `json:"__lazyloading"`
|
||||
Owner string `json:"owner"`
|
||||
OSType string `json:"__os_type"`
|
||||
Imagetype string `json:"__imagetype"`
|
||||
Visibility string `json:"visibility"`
|
||||
VirtualEnvType string `json:"virtual_env_type"`
|
||||
Platform string `json:"__platform"`
|
||||
SizeGB int `json:"size"`
|
||||
ImageSize int64 `json:"__image_size"`
|
||||
OSBit string `json:"__os_bit"`
|
||||
OSVersion string `json:"__os_version"`
|
||||
Name string `json:"name"`
|
||||
Self string `json:"self"`
|
||||
DiskFormat string `json:"disk_format"`
|
||||
Status string `json:"status"`
|
||||
Schema string `json:"schema"`
|
||||
MinDiskGB int64 `json:"min_disk"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
ImageSourceType string `json:"__image_source_type"`
|
||||
ContainerFormat string `json:"container_format"`
|
||||
File string `json:"file"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
Protected bool `json:"protected"`
|
||||
Checksum string `json:"checksum"`
|
||||
ID string `json:"id"`
|
||||
Isregistered string `json:"__isregistered"`
|
||||
MinRamMB int `json:"min_ram"`
|
||||
Lazyloading string `json:"__lazyloading"`
|
||||
Owner string `json:"owner"`
|
||||
OSType string `json:"__os_type"`
|
||||
Imagetype string `json:"__imagetype"`
|
||||
Visibility string `json:"visibility"`
|
||||
VirtualEnvType string `json:"virtual_env_type"`
|
||||
Platform string `json:"__platform"`
|
||||
SizeGB int `json:"size"`
|
||||
ImageSize int64 `json:"__image_size"`
|
||||
OSBit string `json:"__os_bit"`
|
||||
OSVersion string `json:"__os_version"`
|
||||
Name string `json:"name"`
|
||||
Self string `json:"self"`
|
||||
DiskFormat string `json:"disk_format"`
|
||||
Status string `json:"status"`
|
||||
SupportKVMFPGAType string `json:"__support_kvm_fpga_type"`
|
||||
SupportKVMNVMEHIGHIO string `json:"__support_nvme_highio"`
|
||||
SupportLargeMemory string `json:"__support_largememory"`
|
||||
SupportDiskIntensive string `json:"__support_diskintensive"`
|
||||
SupportXENGPUType string `json:"__support_xen_gpu_type"`
|
||||
SupportKVMGPUType string `json:"__support_kvm_gpu_type"`
|
||||
}
|
||||
|
||||
func (self *SImage) GetMinRamSizeMb() int {
|
||||
@@ -200,6 +205,34 @@ func (self *SRegion) GetImage(imageId string) (SImage, error) {
|
||||
return image, err
|
||||
}
|
||||
|
||||
func excludeImage(image SImage) bool {
|
||||
if len(image.SupportDiskIntensive) > 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
if len(image.SupportKVMFPGAType) > 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
if len(image.SupportKVMGPUType) > 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
if len(image.SupportKVMNVMEHIGHIO) > 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
if len(image.SupportLargeMemory) > 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
if len(image.SupportXENGPUType) > 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// https://support.huaweicloud.com/api-ims/zh-cn_topic_0060804959.html
|
||||
func (self *SRegion) GetImages(status string, imagetype TImageOwnerType, name string, envType string) ([]SImage, error) {
|
||||
queries := map[string]string{}
|
||||
@@ -223,7 +256,18 @@ func (self *SRegion) GetImages(status string, imagetype TImageOwnerType, name st
|
||||
|
||||
images := make([]SImage, 0)
|
||||
err := doListAllWithMarker(self.ecsClient.Images.List, queries, &images)
|
||||
return images, err
|
||||
|
||||
// 排除掉需要特定镜像才能创建的实例类型
|
||||
// https://support.huaweicloud.com/eu-west-0-api-ims/zh-cn_topic_0031617666.html#ZH-CN_TOPIC_0031617666__table48545918250
|
||||
// https://support.huaweicloud.com/productdesc-ecs/zh-cn_topic_0088142947.html
|
||||
filtedImages := make([]SImage, 0)
|
||||
for i := range images {
|
||||
if !excludeImage(images[i]) {
|
||||
filtedImages = append(filtedImages, images[i])
|
||||
}
|
||||
}
|
||||
|
||||
return filtedImages, err
|
||||
}
|
||||
|
||||
func (self *SRegion) DeleteImage(imageId string) error {
|
||||
|
||||
Reference in New Issue
Block a user