Skip to content

Commit

Permalink
Apply NCP's Updated Parameter Return Values about VMImage/MyImage
Browse files Browse the repository at this point in the history
  • Loading branch information
innodreamer committed Jul 18, 2024
1 parent b220e20 commit 6d531ef
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"fmt"
"strconv"
"strings"
// "github.com/davecgh/go-spew/spew"

ncloud "github.com/NaverCloudPlatform/ncloud-sdk-go-v2/ncloud"
server "github.com/NaverCloudPlatform/ncloud-sdk-go-v2/services/server"
Expand Down Expand Up @@ -117,7 +118,7 @@ func MappingImageInfo(serverImage server.Product) irs.ImageInfo {
NameId: *serverImage.ProductCode,
SystemId: *serverImage.ProductCode,
},
GuestOS: *serverImage.ProductDescription,
GuestOS: *serverImage.OsInformation,
Status: "available",
}

Expand All @@ -126,9 +127,9 @@ func MappingImageInfo(serverImage server.Product) irs.ImageInfo {
{Key: "PlatformType", Value: *serverImage.PlatformType.CodeName},
{Key: "InfraResourceType", Value: *serverImage.InfraResourceType.CodeName},
{Key: "BaseBlockStorageSize(GB)", Value: strconv.FormatFloat(float64(*serverImage.BaseBlockStorageSize)/(1024*1024*1024), 'f', 0, 64)},
//{Key: "OsInformation", Value: *serverImage.OsInformation},
//{Key: "DB Type", Value: *serverImage.DbKindCode},
//{Key: "NCP GenerationCode", Value: *serverImage.GenerationCode},
// {Key: "OsInformation", Value: *serverImage.OsInformation},
// {Key: "DB Type", Value: *serverImage.DbKindCode},
// {Key: "NCP GenerationCode", Value: *serverImage.GenerationCode},
}
keyValueList = append(keyValueList, irs.KeyValue{Key: "Description", Value: *serverImage.ProductDescription})
imageInfo.KeyValueList = keyValueList
Expand Down Expand Up @@ -192,11 +193,30 @@ func (imageHandler *NcpImageHandler) GetNcpImageInfo(imageIID irs.IID) (*server.
return nil, createErr
}

imageReq := server.GetServerImageProductListRequest{ProductCode: ncloud.String(imageIID.SystemId)}
// cblogger.Info("\n\n### imageIID : ")
// spew.Dump(imageIID)
// cblogger.Info("\n")

vmHandler := NcpVMHandler{
RegionInfo: imageHandler.RegionInfo,
VMClient: imageHandler.VMClient,
}
regionNo, err := vmHandler.GetRegionNo(imageHandler.RegionInfo.Region)
if err != nil {
newErr := fmt.Errorf("Failed to Get NCP Region No of the Region Code : [%v]", err)
cblogger.Error(newErr.Error())
LoggingError(callLogInfo, newErr)
return nil, newErr
}

imageReq := server.GetServerImageProductListRequest{
ProductCode: ncloud.String(imageIID.SystemId),
RegionNo: regionNo,
}
callLogStart := call.Start()
result, err := imageHandler.VMClient.V2Api.GetServerImageProductList(&imageReq)
if err != nil {
newErr := fmt.Errorf("Failed to Find Image list from NCP : [%v]", err)
newErr := fmt.Errorf("Failed to Get Image list from NCP : [%v]", err)
cblogger.Error(newErr.Error())
LoggingError(callLogInfo, newErr)
return nil, newErr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ func (myImageHandler *NcpMyImageHandler) MappingMyImageInfo(myImage *server.Memb
{Key: "Region", Value: myImageHandler.RegionInfo.Region},
{Key: "OriginalImageProductCode", Value: *myImage.OriginalServerImageProductCode},
{Key: "MyImagePlatformType", Value: *myImage.MemberServerImagePlatformType.CodeName},
{Key: "OriginalOsInformation", Value: *myImage.OriginalOsInformation},
{Key: "CreateDate", Value: *myImage.CreateDate},
}
myImageInfo.KeyValueList = keyValueList
Expand Down Expand Up @@ -383,8 +384,8 @@ func (myImageHandler *NcpMyImageHandler) GetNcpMemberServerImageInfo(myImageIID
LoggingInfo(callLogInfo, callLogStart)

if len(result.MemberServerImageList) < 1 {
newErr := fmt.Errorf("Failed to Get the Member Server Image List from NCP. Member Server Image does Not Exist!!")
cblogger.Error(newErr.Error())
newErr := fmt.Errorf("The Member Server Image does Not Exist!!")
cblogger.Debug(newErr.Error())
LoggingError(callLogInfo, newErr)
return server.MemberServerImage{}, newErr
} else {
Expand Down Expand Up @@ -424,7 +425,9 @@ func (myImageHandler *NcpMyImageHandler) GetOriginImageOSPlatform(imageIID irs.I
LoggingError(callLogInfo, newErr)
return "", newErr
} else {
imagePlatformType := strings.ToUpper(*ncpImageInfo.PlatformType.CodeName)
// cblogger.Infof("### ImageOsInformation : [%s]", *ncpImageInfo.OsInformation)
imagePlatformType := strings.ToUpper(*ncpImageInfo.OsInformation)

var originImagePlatform string
if strings.Contains(imagePlatformType, "UBUNTU") {
originImagePlatform = "UBUNTU"
Expand All @@ -444,13 +447,13 @@ func (myImageHandler *NcpMyImageHandler) GetOriginImageOSPlatform(imageIID irs.I
memberServerImageInfo, err := myImageHandler.GetNcpMemberServerImageInfo(imageIID)
if err != nil {
newErr := fmt.Errorf("Failed to Get NCP Member Server Image Info. [%v]", err.Error())
cblogger.Error(newErr.Error())
cblogger.Debug(newErr.Error())
LoggingError(callLogInfo, newErr)
return "", newErr
}
cblogger.Infof("### MyImagePlatformType : [%s]", *memberServerImageInfo.MemberServerImagePlatformType.CodeName)

imagePlatformType := strings.ToUpper(*memberServerImageInfo.MemberServerImagePlatformType.CodeName)
// cblogger.Infof("### MyImageOriginalOsInformation : [%s]", *memberServerImageInfo.OriginalOsInformation)
imagePlatformType := strings.ToUpper(*memberServerImageInfo.OriginalOsInformation)

var originImagePlatform string
if strings.Contains(imagePlatformType, "UBUNTU") {
originImagePlatform = "UBUNTU"
Expand Down

0 comments on commit 6d531ef

Please sign in to comment.