Skip to content

Commit

Permalink
Remove the Duplicate Codes
Browse files Browse the repository at this point in the history
  • Loading branch information
innodreamer committed Jul 16, 2024
1 parent 7dc385e commit 6847687
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 215 deletions.
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,129 +8,13 @@
//
// by ETRI, 2020.12.
// by ETRI, 2022.03. updated
// by ETRI, 2024.07.

package main

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

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"

ncloud "github.com/NaverCloudPlatform/ncloud-sdk-go-v2/ncloud"
vserver "github.com/NaverCloudPlatform/ncloud-sdk-go-v2/services/vserver"
vpc "github.com/NaverCloudPlatform/ncloud-sdk-go-v2/services/vpc"
vlb "github.com/NaverCloudPlatform/ncloud-sdk-go-v2/services/vloadbalancer"

// ncpvpccon "github.com/cloud-barista/ncpvpc/ncpvpc/connect" // For local testing
ncpvpccon "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/drivers/ncpvpc/connect"
"C"
ncpvpc "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/drivers/ncpvpc"
)

var cblogger *logrus.Logger

func init() {
// cblog is a global variable.
cblogger = cblog.GetLogger("NCPVPC Handler")
}

type NcpVpcDriver struct {
}

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

func (NcpVpcDriver) 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
drvCapabilityInfo.NLBHandler = true

return drvCapabilityInfo
}

func getVmClient(connectionInfo idrv.ConnectionInfo) (*vserver.APIClient, error) {

// NOTE 주의!!
apiKeys := ncloud.APIKey{
AccessKey: connectionInfo.CredentialInfo.ClientId,
SecretKey: connectionInfo.CredentialInfo.ClientSecret,
}

// NOTE for just test
// cblogger.Info(apiKeys.AccessKey)
// cblogger.Info(apiKeys.SecretKey)

// Create NCPVPC service client
client := vserver.NewAPIClient(vserver.NewConfiguration(&apiKeys))

return client, nil
}

func getVpcClient(connectionInfo idrv.ConnectionInfo) (*vpc.APIClient, error) {
apiKeys := ncloud.APIKey{
AccessKey: connectionInfo.CredentialInfo.ClientId,
SecretKey: connectionInfo.CredentialInfo.ClientSecret,
}

// Create NCP VPC service client
client := vpc.NewAPIClient(vpc.NewConfiguration(&apiKeys))

return client, nil
}

func getVlbClient(connectionInfo idrv.ConnectionInfo) (*vlb.APIClient, error) {
apiKeys := ncloud.APIKey{
AccessKey: connectionInfo.CredentialInfo.ClientId,
SecretKey: connectionInfo.CredentialInfo.ClientSecret,
}

// Create NCP VPC Load Balancer service client
client := vlb.NewAPIClient(vlb.NewConfiguration(&apiKeys))

return client, nil
}

func (driver *NcpVpcDriver) 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
}

vpcClient, err := getVpcClient(connectionInfo)
if err != nil {
return nil, err
}

vlbClient, err := getVlbClient(connectionInfo)
if err != nil {
return nil, err
}

iConn := ncpvpccon.NcpVpcCloudConnection{
CredentialInfo: connectionInfo.CredentialInfo,
RegionInfo: connectionInfo.RegionInfo,
VmClient: vmClient,
VpcClient: vpcClient,
VlbClient: vlbClient,
}

return &iConn, nil
}

var CloudDriver NcpVpcDriver
var CloudDriver ncpvpc.NcpVpcDriver

0 comments on commit 6847687

Please sign in to comment.