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

[NCP Classic/VPC] Update for VM Status check when running GetVM() and ListVM(), Apply Updated Parameter Return Values on VMImage/MyImage #1244

Merged
merged 12 commits into from
Jul 27, 2024
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
4 changes: 2 additions & 2 deletions api-runtime/rest-runtime/admin-web/AdminWeb-VM.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,8 +590,8 @@ func VM(c echo.Context) error {
imageName = "16681742-f408-444d-a430-dd21a4bef42c"
specName = "ETRI-small-2"
case "NCP":
imageName = "SPSW0LINUX000052"
specName = "SPSVRHICPUSSD002"
imageName = "SPSW0LINUX000139"
specName = "SPSVRSTAND000005"
case "NCPVPC":
imageName = "SW.VSVR.OS.LNX64.UBNTU.SVR2004.B050"
specName = "SVR.VSVR.HICPU.C004.M008.NET.SSD.B050.G002"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,104 +7,13 @@
// This is a Cloud Driver Example for PoC Test.
//
// by ETRI, 2020.08.
// by ETRI, 2024.07.

package main

import (
//cblog "github.com/cloud-barista/cb-log"

idrv "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces"
icon "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces/connect"

// "github.com/davecgh/go-spew/spew"
// unused import "github.com/sirupsen/logrus"

ncloud "github.com/NaverCloudPlatform/ncloud-sdk-go-v2/ncloud"
server "github.com/NaverCloudPlatform/ncloud-sdk-go-v2/services/server"
lb "github.com/NaverCloudPlatform/ncloud-sdk-go-v2/services/loadbalancer"

// ncpcon "github.com/cloud-barista/ncp/ncp/connect"
ncpcon "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/drivers/ncp/connect" //To be built in the container
"C"
ncp "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/drivers/ncp"
)

/*
var cblogger *logrus.Logger

func init() {
// cblog is a global variable.
cblogger = cblog.GetLogger("NCP VMHandler")
}
*/

type NcpDriver struct {
}

func (NcpDriver) GetDriverVersion() string {
return "TEST NCP DRIVER Version 1.0"
}

func (NcpDriver) GetDriverCapability() idrv.DriverCapabilityInfo {
var drvCapabilityInfo idrv.DriverCapabilityInfo

// NOTE Temporary Setting
drvCapabilityInfo.ImageHandler = true
drvCapabilityInfo.VPCHandler = true
drvCapabilityInfo.SecurityHandler = true
drvCapabilityInfo.KeyPairHandler = true
drvCapabilityInfo.VNicHandler = false
drvCapabilityInfo.PublicIPHandler = false
drvCapabilityInfo.VMHandler = true
drvCapabilityInfo.VMSpecHandler = true

return drvCapabilityInfo
}

// func getVMClient(credential idrv.CredentialInfo) (*server.APIClient, error) {
func getVMClient(connectionInfo idrv.ConnectionInfo) (*server.APIClient, error) {
// NOTE 주의!!
apiKeys := ncloud.APIKey{
AccessKey: connectionInfo.CredentialInfo.ClientId,
SecretKey: connectionInfo.CredentialInfo.ClientSecret,
}
// Create NCP service client
client := server.NewAPIClient(server.NewConfiguration(&apiKeys))
return client, nil
}

func getLbClient(connectionInfo idrv.ConnectionInfo) (*lb.APIClient, error) {
apiKeys := ncloud.APIKey{
AccessKey: connectionInfo.CredentialInfo.ClientId,
SecretKey: connectionInfo.CredentialInfo.ClientSecret,
}
// Create NCP Classic Load Balancer service client
client := lb.NewAPIClient(lb.NewConfiguration(&apiKeys))
return client, nil
}

func (driver *NcpDriver) ConnectCloud(connectionInfo idrv.ConnectionInfo) (icon.CloudConnection, error) {
// 1. get info of credential and region for Test A Cloud from connectionInfo.
// 2. create a client object(or service object) of Test A Cloud with credential info.
// 3. create CloudConnection Instance of "connect/TDA_CloudConnection".
// 4. return CloudConnection Interface of TDA_CloudConnection.

vmClient, err := getVMClient(connectionInfo)
if err != nil {
return nil, err
}

lbClient, err := getLbClient(connectionInfo)
if err != nil {
return nil, err
}

iConn := ncpcon.NcpCloudConnection{
CredentialInfo: connectionInfo.CredentialInfo,
RegionInfo: connectionInfo.RegionInfo,
VmClient: vmClient,
LbClient: lbClient,
}

return &iConn, nil
}

var CloudDriver NcpDriver
var CloudDriver ncp.NcpDriver
14 changes: 10 additions & 4 deletions cloud-control-manager/cloud-driver/drivers/ncp/NcpDriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,20 @@ func (NcpDriver) GetDriverCapability() idrv.DriverCapabilityInfo {
var drvCapabilityInfo idrv.DriverCapabilityInfo

// NOTE Temporary Setting
drvCapabilityInfo.ImageHandler = true
drvCapabilityInfo.VPCHandler = true
drvCapabilityInfo.SecurityHandler = true
drvCapabilityInfo.KeyPairHandler = true
drvCapabilityInfo.VNicHandler = false
drvCapabilityInfo.ImageHandler = true
drvCapabilityInfo.VMSpecHandler = true
drvCapabilityInfo.SecurityHandler = true
drvCapabilityInfo.KeyPairHandler = true
drvCapabilityInfo.PublicIPHandler = false
drvCapabilityInfo.VMHandler = true
drvCapabilityInfo.VMSpecHandler = true
drvCapabilityInfo.DiskHandler = true
drvCapabilityInfo.MyImageHandler = true
drvCapabilityInfo.NLBHandler = true
drvCapabilityInfo.PriceInfoHandler = true
drvCapabilityInfo.RegionZoneHandler = true
drvCapabilityInfo.TagHandler = true

return drvCapabilityInfo
}
Expand Down
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
Loading