Skip to content

Commit

Permalink
Add KT Cloud Classic NLBHandler features
Browse files Browse the repository at this point in the history
  • Loading branch information
innodreamer committed Jan 19, 2024
1 parent 7074546 commit 3556fb8
Show file tree
Hide file tree
Showing 6 changed files with 1,158 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ package ktcloud

import (
"os"
"strings"

"github.com/sirupsen/logrus"

// "github.com/davecgh/go-spew/spew"

cblog "github.com/cloud-barista/cb-log"
Expand Down Expand Up @@ -55,32 +58,35 @@ func (KtCloudDriver) GetDriverCapability() idrv.DriverCapabilityInfo {
return drvCapabilityInfo
}

const (
KOR_Seoul_M2_ZoneID string = "d7d0177e-6cda-404a-a46f-a5b356d2874e"
)

func getVMClient(connectionInfo idrv.ConnectionInfo) (*ktsdk.KtCloudClient, error) {
// cblogger.Info("### connectionInfo.RegionInfo.Zone : " + connectionInfo.RegionInfo.Zone)

// $$$ Caution!!
var apiurl string // When Zone is "KOR-Seoul M2"
if connectionInfo.RegionInfo.Zone == "d7d0177e-6cda-404a-a46f-a5b356d2874e" {
var apiurl string
if strings.EqualFold(connectionInfo.RegionInfo.Zone, KOR_Seoul_M2_ZoneID) { // When Zone is "KOR-Seoul M2"
apiurl = "https://api.ucloudbiz.olleh.com/server/v2/client/api"
} else {
apiurl = "https://api.ucloudbiz.olleh.com/server/v1/client/api"
}

if len(apiurl) == 0 {
cblogger.Error("KT Cloud API URL not found!!")
cblogger.Error("KT Cloud API URL Not Found!!")
os.Exit(1)
}

apikey := connectionInfo.CredentialInfo.ClientId
if len(apikey) == 0 {
cblogger.Error("KT Cloud API KEY not found!!")
cblogger.Error("KT Cloud API Key Not Found!!")
os.Exit(1)
}

secretkey := connectionInfo.CredentialInfo.ClientSecret
if len(secretkey) == 0 {
cblogger.Error("KT Cloud SECRET KEY not found!!")
cblogger.Error("KT Cloud Secret Key Not Found!!")
os.Exit(1)
}

Expand All @@ -89,7 +95,45 @@ func getVMClient(connectionInfo idrv.ConnectionInfo) (*ktsdk.KtCloudClient, erro
// cblogger.Info(apikey)
// cblogger.Info(secretkey)

// Create KT Cloud service client
// Always validate any SSL certificates in the chain
insecureskipverify := false
client := ktsdk.KtCloudClient{}.New(apiurl, apikey, secretkey, insecureskipverify)

return client, nil
}

func getNLBClient(connectionInfo idrv.ConnectionInfo) (*ktsdk.KtCloudClient, error) {
// cblogger.Info("### connectionInfo.RegionInfo.Zone : " + connectionInfo.RegionInfo.Zone)

// $$$ Caution!!
var apiurl string
if strings.EqualFold(connectionInfo.RegionInfo.Zone, KOR_Seoul_M2_ZoneID) { // When Zone is "KOR-Seoul M2"
apiurl = "https://api.ucloudbiz.olleh.com/loadbalancer/v2/client/api"
} else {
apiurl = "https://api.ucloudbiz.olleh.com/loadbalancer/v1/client/api"
}

if len(apiurl) == 0 {
cblogger.Error("KT Cloud API URL Not Found!!")
os.Exit(1)
}

apikey := connectionInfo.CredentialInfo.ClientId
if len(apikey) == 0 {
cblogger.Error("KT Cloud API Key Not Found!!")
os.Exit(1)
}

secretkey := connectionInfo.CredentialInfo.ClientSecret
if len(secretkey) == 0 {
cblogger.Error("KT Cloud Secret Key Not Found!!")
os.Exit(1)
}

// NOTE for just test
// cblogger.Info(apiurl)
// cblogger.Info(apikey)
// cblogger.Info(secretkey)

// Always validate any SSL certificates in the chain
insecureskipverify := false
Expand All @@ -114,10 +158,16 @@ func (driver *KtCloudDriver) ConnectCloud(connectionInfo idrv.ConnectionInfo) (i
}
// spew.Dump(vmClient)

nlbClient, err := getNLBClient(connectionInfo)
if err != nil {
return nil, err
}

iConn := ktcloudcon.KtCloudConnection{
CredentialInfo: connectionInfo.CredentialInfo,
RegionInfo: connectionInfo.RegionInfo,
Client: vmClient,
NLBClient: nlbClient,
}
return &iConn, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type KtCloudConnection struct {
CredentialInfo idrv.CredentialInfo
RegionInfo idrv.RegionInfo
Client *ktsdk.KtCloudClient
NLBClient *ktsdk.KtCloudClient
}

var cblogger *logrus.Logger
Expand Down Expand Up @@ -88,7 +89,8 @@ func (cloudConn *KtCloudConnection) CreateVPCHandler() (irs.VPCHandler, error) {

func (cloudConn *KtCloudConnection) CreateNLBHandler() (irs.NLBHandler, error) {
cblogger.Info("KT Cloud Driver: called CreateNLBHandler()!")
return nil, fmt.Errorf("KT Cloud Driver does not support CreateNLBHandler yet.")
nlbHandler := ktrs.KtCloudNLBHandler{RegionInfo: cloudConn.RegionInfo, Client: cloudConn.Client, NLBClient: cloudConn.NLBClient}
return &nlbHandler, nil
}

func (cloudConn *KtCloudConnection) CreateDiskHandler() (irs.DiskHandler, error) {
Expand Down
Loading

0 comments on commit 3556fb8

Please sign in to comment.