forked from cloud-barista/cb-spider
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[+NCP Conn. Driver] Add NCP Classic Driver Codes
- Loading branch information
1 parent
de1c1f6
commit c2599a1
Showing
43 changed files
with
9,398 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
cloud-control-manager/cloud-driver/drivers/ncp-plugin/NcpDriver-lib.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
1 change: 1 addition & 0 deletions
1
cloud-control-manager/cloud-driver/drivers/ncp-plugin/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# ncp/ncp-plugin directory |
14 changes: 14 additions & 0 deletions
14
cloud-control-manager/cloud-driver/drivers/ncp-plugin/build_driver_lib.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
106
cloud-control-manager/cloud-driver/drivers/ncp/NcpDriver.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.