From efdcb707b20978b311463162f0d2e77c92af1011 Mon Sep 17 00:00:00 2001 From: SungWoongz Date: Fri, 27 Dec 2024 15:01:35 +0900 Subject: [PATCH] modify vm image metadata for alibaba --- .../alibaba/resources/CommonHandler.go | 32 ++++++++++++++++ .../drivers/alibaba/resources/ImageHandler.go | 37 ++++++++++++++++--- 2 files changed, 63 insertions(+), 6 deletions(-) diff --git a/cloud-control-manager/cloud-driver/drivers/alibaba/resources/CommonHandler.go b/cloud-control-manager/cloud-driver/drivers/alibaba/resources/CommonHandler.go index c8aad5f8e..9107bb924 100644 --- a/cloud-control-manager/cloud-driver/drivers/alibaba/resources/CommonHandler.go +++ b/cloud-control-manager/cloud-driver/drivers/alibaba/resources/CommonHandler.go @@ -534,6 +534,38 @@ func DescribeImageByImageId(client *ecs.Client, regionInfo idrv.RegionInfo, imag return imageList[0], nil } +/* +* +ImageName으로 1개 Image의 정보 조회 +*/ +func DescribeImageByImageName(client *ecs.Client, regionInfo idrv.RegionInfo, imageName string, isMyImage bool) (ecs.Image, error) { + + var imageNameList []string + imageNameList = append(imageNameList, imageName) + + var imageIIDList []irs.IID + for _, name := range imageNameList { + imageIIDList = append(imageIIDList, irs.IID{NameId: name, SystemId: name}) + } + + imageList, err := DescribeImages(client, regionInfo, imageIIDList, isMyImage) + if err != nil { + return ecs.Image{}, err + } + + //if len(imageList) != 1 { + // return ecs.Image{}, errors.New("search failed") + //} + + if len(imageList) == 0 { + // return ecs.Image{}, errors.New("no result with request image Name: " + imageName) + } else if len(imageList) > 1 { + return ecs.Image{}, errors.New("search failed. too many results") + } + + return imageList[0], nil +} + /* * 이미지의 상태 조회 diff --git a/cloud-control-manager/cloud-driver/drivers/alibaba/resources/ImageHandler.go b/cloud-control-manager/cloud-driver/drivers/alibaba/resources/ImageHandler.go index e80f32bf9..4a815685d 100644 --- a/cloud-control-manager/cloud-driver/drivers/alibaba/resources/ImageHandler.go +++ b/cloud-control-manager/cloud-driver/drivers/alibaba/resources/ImageHandler.go @@ -199,10 +199,17 @@ func ExtractImageDescribeInfo(image *ecs.Image) irs.ImageInfo { cblogger.Debug(image) imageInfo := irs.ImageInfo{ - IId: irs.IID{NameId: image.ImageId, SystemId: image.ImageId}, - //Name: image.ImageName, - Status: image.Status, - GuestOS: image.OSNameEn, + // IId: irs.IID{NameId: image.ImageId, SystemId: image.ImageId}, + // //Name: image.ImageName, + // Status: image.Status, + // GuestOS: image.OSNameEn, + Name: image.ImageFamily, + OSArchitecture: irs.OSArchitecture(image.Architecture), + OSPlatform: irs.OSPlatform(image.Platform), + OSDistribution: image.Description, + OSDiskType: "NA", + OSDiskSizeInGB: "-1", + ImageStatus: irs.ImageStatus(image.Status), } keyValueList := []irs.KeyValue{ @@ -224,8 +231,12 @@ func ExtractImageDescribeInfo(image *ecs.Image) irs.ImageInfo { {Key: "Platform", Value: image.Platform}, {Key: "Size", Value: strconv.Itoa(image.Size)}, } - - keyValueList = append(keyValueList, irs.KeyValue{Key: "Description", Value: image.Description}) + // keyValueList = append(keyValueList, irs.KeyValue{Key: "Description", Value: image.Description}) + // imageInfo.KeyValueList = keyValueList + keyValueList, err := ConvertKeyValueList(image) + if err != nil { + cblogger.Error("Failed to convert image to KeyValueList:", err) + } imageInfo.KeyValueList = keyValueList return imageInfo @@ -285,6 +296,20 @@ func (imageHandler *AlibabaImageHandler) GetImage(imageIID irs.IID) (irs.ImageIn return imageInfo, nil } +func (imageHandler *AlibabaImageHandler) GetImageN(Name string) (irs.ImageInfo, error) { + cblogger.Infof("imageId : ", Name) + + result, err := DescribeImageByImageName(imageHandler.Client, imageHandler.Region, Name, false) + + if err != nil { + return irs.ImageInfo{}, err + } + + imageInfo := ExtractImageDescribeInfo(&result) + + return imageInfo, nil +} + func (imageHandler *AlibabaImageHandler) DeleteImage(imageIID irs.IID) (bool, error) { cblogger.Infof("DeleteImage : [%s]", imageIID.SystemId) // Delete the Image by Id