Skip to content

Commit

Permalink
Merge pull request #1414 from MZC-CSC/develop
Browse files Browse the repository at this point in the history
[VMImage:GCP,Alibaba] Develop
  • Loading branch information
powerkimhub authored Jan 2, 2025
2 parents 901da83 + bcb5bad commit c52300b
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/*
*
이미지의 상태 조회
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c52300b

Please sign in to comment.