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

[VMImage:GCP,Alibaba] Develop #1414

Merged
merged 4 commits into from
Jan 2, 2025
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
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
Loading