Skip to content

Commit

Permalink
[+NCP Conn. Driver] Add NCP Classic Driver Codes
Browse files Browse the repository at this point in the history
  • Loading branch information
innodreamer committed Nov 10, 2023
1 parent de1c1f6 commit c2599a1
Show file tree
Hide file tree
Showing 43 changed files with 9,398 additions and 12 deletions.
16 changes: 9 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ cloud-driver-libs/.ssh-gcp/*
cloud-driver-libs/.ssh-aws/*
cloud-driver-libs/.ssh-aliyun/*
cloud-driver-libs/.ssh-tencent/*
cloud-driver-libs/.ssh-ncp/*
cloud-driver-libs/.ssh-nhn/*
cloud-driver-libs/.ssh-ktcloud/*
cloud-driver-libs/.vpc-ncp/*
cloud-driver-libs/.vpc-nhn/*
cloud-driver-libs/.vpc-kt/*
cloud-driver-libs/.securitygroup-kt/*

vendor/*
cloud-driver-libs/*.so
Expand All @@ -43,18 +50,13 @@ interface/spctl
.history/
.vscode/

cloud-control-manager/cloud-driver/drivers/ncp/*
cloud-control-manager/cloud-driver/drivers/ncp-plugin/*

cloud-control-manager/cloud-driver/drivers/tencent/main/conf/testConfigTencent.yaml

utils/clone-mc-meta-info/vm-image/data/*
utils/clone-mc-meta-info/vm-image/test/*
utils/clone-mc-meta-info/vm-image/az-data/*

cloud-control-manager/cloud-driver/drivers/azure/main/conf/config.yaml

cloud-control-manager/cloud-driver/drivers/cloudit/main/conf/config.yaml
cloud-control-manager/cloud-driver/drivers/ibmcloud-vpc/main/conf/config.yaml
cloud-control-manager/cloud-driver/drivers/openstack/main/conf/config.yaml

cloud-control-manager/cloud-driver/drivers/tencent/main/conf/testConfigTencent.yaml
cloud-control-manager/cloud-driver/drivers/ncp/main/conf/config.yaml
2 changes: 1 addition & 1 deletion build_all_driver_lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
source setup.env

#DRIVERS=( aws-plugin azure-plugin openstack-plugin gcp-plugin alibaba-plugin cloudit-plugin docker-plugin ncp-plugin ncpvpc-plugin)
DRIVERS=( aws-plugin azure-plugin gcp-plugin alibaba-plugin openstack-plugin cloudit-plugin docker-plugin mock-plugin tencent-plugin ibmcloud-vpc-plugin )
DRIVERS=( aws-plugin azure-plugin gcp-plugin alibaba-plugin openstack-plugin cloudit-plugin docker-plugin mock-plugin tencent-plugin ibmcloud-vpc-plugin ncp-plugin )

DRIVER_PATH=$CBSPIDER_ROOT/cloud-control-manager/cloud-driver/drivers
DRIVERLIB_PATH=$CBSPIDER_ROOT/cloud-driver-libs
Expand Down
110 changes: 110 additions & 0 deletions cloud-control-manager/cloud-driver/drivers/ncp-plugin/NcpDriver-lib.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// Proof of Concepts of CB-Spider.
// The CB-Spider is a sub-Framework of the Cloud-Barista Multi-Cloud Project.
// The CB-Spider Mission is to connect all the clouds with a single interface.
//
// * Cloud-Barista: https://github.com/cloud-barista
//
// This is a Cloud Driver Example for PoC Test.
//
// by ETRI, 2020.08.

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
)

/*
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# ncp/ncp-plugin directory
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
source $CBSPIDER_ROOT/setup.env

DRIVERLIB_PATH=$CBSPIDER_ROOT/cloud-driver-libs
DRIVERFILENAME=ncp-driver-v1.0

# To be built in the container
# cp $HOME/ncp/go.* ./
go mod download # cb-spider's go.mod and go.sum will be applied.

rm -rf $DRIVERLIB_PATH/${DRIVERFILENAME}.so
go build -buildmode=plugin -o ${DRIVERFILENAME}.so NcpDriver-lib.go
chmod +x ${DRIVERFILENAME}.so
mv ./${DRIVERFILENAME}.so $DRIVERLIB_PATH
106 changes: 106 additions & 0 deletions cloud-control-manager/cloud-driver/drivers/ncp/NcpDriver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// Proof of Concepts of CB-Spider.
// The CB-Spider is a sub-Framework of the Cloud-Barista Multi-Cloud Project.
// The CB-Spider Mission is to connect all the clouds with a single interface.
//
// * Cloud-Barista: https://github.com/cloud-barista
//
// NCP Cloud Driver PoC
//
// by ETRI, 2020.07.
// updated by ETRI, 2023.08.

package ncp

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"
"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
)

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(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
}
Loading

0 comments on commit c2599a1

Please sign in to comment.