Skip to content

Commit

Permalink
[+NHN Cloud conn. Driver] Add NHN Driver Codes
Browse files Browse the repository at this point in the history
  • Loading branch information
innodreamer committed Nov 15, 2023
1 parent 9516279 commit 6751b38
Show file tree
Hide file tree
Showing 56 changed files with 12,234 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@ 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/config/config.yaml
cloud-control-manager/cloud-driver/drivers/ncpvpc/main/config/config.yaml
cloud-control-manager/cloud-driver/drivers/nhncloud/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 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 ncp-plugin ncpvpc-plugin nhncloud-plugin )

DRIVER_PATH=$CBSPIDER_ROOT/cloud-control-manager/cloud-driver/drivers
DRIVERLIB_PATH=$CBSPIDER_ROOT/cloud-driver-libs
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
// 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, Innogrid, 2021.12.
// by ETRI Team, 2022.08.

package main

import (
// "github.com/davecgh/go-spew/spew"
nhnsdk "github.com/cloud-barista/nhncloud-sdk-go"
ostack "github.com/cloud-barista/nhncloud-sdk-go/openstack"

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"

// nhncon "github.com/cloud-barista/nhncloud/nhncloud/connect"
nhncon "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/drivers/nhncloud/connect"

// nhnrs "github.com/cloud-barista/nhncloud/nhncloud/resources"
nhnrs "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/drivers/nhncloud/resources"
)

type NhnCloudDriver struct{}

func (NhnCloudDriver) GetDriverVersion() string {
return "NHNCLOUD DRIVER Version 1.0"
}

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

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
drvCapabilityInfo.ClusterHandler = true
drvCapabilityInfo.MyImageHandler = true
drvCapabilityInfo.DiskHandler = true

drvCapabilityInfo.SINGLE_VPC = true

return drvCapabilityInfo
}

func (driver *NhnCloudDriver) 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.

// Initialize Logger
nhnrs.InitLog()

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

ImageClient, err := getImageClient(connectionInfo)
if err != nil {
return nil, err
}

NetworkClient, err := getNetworkClient(connectionInfo)
if err != nil {
return nil, err
}

VolumeClient, err := getVolumeClient(connectionInfo)
if err != nil {
return nil, err
}

ClusterClient, err := getClusterClient(connectionInfo)
if err != nil {
return nil, err
}

iConn := nhncon.NhnCloudConnection{
CredentialInfo: connectionInfo.CredentialInfo, // Note) Need in RegionZoneHandler
RegionInfo: connectionInfo.RegionInfo,
VMClient: VMClient,
ImageClient: ImageClient,
NetworkClient: NetworkClient,
VolumeClient: VolumeClient,
ClusterClient: ClusterClient,
}
return &iConn, nil
}

func getVMClient(connInfo idrv.ConnectionInfo) (*nhnsdk.ServiceClient, error) {
authOpts := nhnsdk.AuthOptions{
IdentityEndpoint: connInfo.CredentialInfo.IdentityEndpoint,
Username: connInfo.CredentialInfo.Username,
Password: connInfo.CredentialInfo.Password,
DomainName: connInfo.CredentialInfo.DomainName,
TenantID: connInfo.CredentialInfo.TenantId, // Caution : TenantID spelling for SDK
}

providerClient, err := ostack.AuthenticatedClient(authOpts)
if err != nil {
return nil, err
}

client, err := ostack.NewComputeV2(providerClient, nhnsdk.EndpointOpts{
Region: connInfo.RegionInfo.Region,
})
if err != nil {
return nil, err
}

return client, err
}

func getImageClient(connInfo idrv.ConnectionInfo) (*nhnsdk.ServiceClient, error) {
authOpts := nhnsdk.AuthOptions{
IdentityEndpoint: connInfo.CredentialInfo.IdentityEndpoint,
Username: connInfo.CredentialInfo.Username,
Password: connInfo.CredentialInfo.Password,
DomainName: connInfo.CredentialInfo.DomainName,
TenantID: connInfo.CredentialInfo.TenantId, // Caution : TenantID spelling for SDK
}

providerClient, err := ostack.AuthenticatedClient(authOpts)
if err != nil {
return nil, err
}

client, err := ostack.NewImageServiceV2(providerClient, nhnsdk.EndpointOpts{
Region: connInfo.RegionInfo.Region,
})
if err != nil {
return nil, err
}

return client, err
}

func getNetworkClient(connInfo idrv.ConnectionInfo) (*nhnsdk.ServiceClient, error) {
authOpts := nhnsdk.AuthOptions{
IdentityEndpoint: connInfo.CredentialInfo.IdentityEndpoint,
Username: connInfo.CredentialInfo.Username,
Password: connInfo.CredentialInfo.Password,
DomainName: connInfo.CredentialInfo.DomainName,
TenantID: connInfo.CredentialInfo.TenantId, // Caution : TenantID spelling for SDK
}

providerClient, err := ostack.AuthenticatedClient(authOpts)
if err != nil {
return nil, err
}

client, err := ostack.NewNetworkV2(providerClient, nhnsdk.EndpointOpts{
Name: "neutron",
Region: connInfo.RegionInfo.Region,
})
if err != nil {
return nil, err
}

return client, err
}

func getVolumeClient(connInfo idrv.ConnectionInfo) (*nhnsdk.ServiceClient, error) {
authOpts := nhnsdk.AuthOptions{
IdentityEndpoint: connInfo.CredentialInfo.IdentityEndpoint,
Username: connInfo.CredentialInfo.Username,
Password: connInfo.CredentialInfo.Password,
DomainName: connInfo.CredentialInfo.DomainName,
TenantID: connInfo.CredentialInfo.TenantId, // Caution : TenantID spelling for SDK
}

providerClient, err := ostack.AuthenticatedClient(authOpts)
if err != nil {
return nil, err
}

client, err := ostack.NewBlockStorageV2(providerClient, nhnsdk.EndpointOpts{
Region: connInfo.RegionInfo.Region,
})
if err != nil {
return nil, err
}
return client, err
}

func getClusterClient(connInfo idrv.ConnectionInfo) (*nhnsdk.ServiceClient, error) {
authOpts := nhnsdk.AuthOptions{
IdentityEndpoint: connInfo.CredentialInfo.IdentityEndpoint,
Username: connInfo.CredentialInfo.Username,
Password: connInfo.CredentialInfo.Password,
DomainName: connInfo.CredentialInfo.DomainName,
TenantID: connInfo.CredentialInfo.TenantId, // Caution : TenantID spelling for SDK
}

providerClient, err := ostack.AuthenticatedClient(authOpts)
if err != nil {
return nil, err
}

client, err := ostack.NewContainerInfraV1(providerClient, nhnsdk.EndpointOpts{
Region: connInfo.RegionInfo.Region,
})
if err != nil {
return nil, err
}
return client, err
}

var CloudDriver NhnCloudDriver
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
source $CBSPIDER_ROOT/setup.env

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

go mod download # cb-spider's go.mod and go.sum will be applied.

function build() {
rm -rf $DRIVERLIB_PATH/${DRIVERFILENAME}.so
env GO111MODULE=on go build -buildmode=plugin -o ${DRIVERFILENAME}.so NHNCloudDriver-lib.go || return 1
chmod +x ${DRIVERFILENAME}.so || return 1
mv ./${DRIVERFILENAME}.so $DRIVERLIB_PATH || return 1
}

build
Loading

0 comments on commit 6751b38

Please sign in to comment.