Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#910 [+Region/Zone] GCP Cloud Driver Implementation #921

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions cloud-control-manager/cloud-driver/drivers/gcp/GCPDriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func (GCPDriver) GetDriverCapability() idrv.DriverCapabilityInfo {
drvCapabilityInfo.VPCHandler = true
drvCapabilityInfo.DiskHandler = false
drvCapabilityInfo.MyImageHandler = false
drvCapabilityInfo.RegionZoneHandler = false
drvCapabilityInfo.ClusterHandler = true

return drvCapabilityInfo
Expand Down Expand Up @@ -89,10 +90,11 @@ func (driver *GCPDriver) ConnectCloud(connectionInfo idrv.ConnectionInfo) (icon.
SecurityGroupClient: VMClient,
// VNetClient: VMClient,
// VNicClient: VMClient,
SubnetClient: VMClient,
VMSpecHandler: VMClient,
VPCHandler: VMClient,
ContainerClient: containerClient,
SubnetClient: VMClient,
VMSpecClient: VMClient,
VPCClient: VMClient,
RegionZoneClient: VMClient,
ContainerClient: containerClient,
}

//fmt.Println("################## resource ConnectionInfo ##################")
Expand Down Expand Up @@ -173,4 +175,3 @@ func getContainerClient(credential idrv.CredentialInfo) (context.Context, *conta

return ctx, containerClient, nil
}

Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ type GCPCloudConnection struct {
VNetClient *compute.Service
VNicClient *compute.Service
SubnetClient *compute.Service
VMSpecHandler *compute.Service
VPCHandler *compute.Service
VMSpecClient *compute.Service
VPCClient *compute.Service
RegionZoneClient *compute.Service
ContainerClient *container.Service
}

Expand Down Expand Up @@ -135,3 +136,9 @@ func (cloudConn *GCPCloudConnection) CreateClusterHandler() (irs.ClusterHandler,
func (cloudConn *GCPCloudConnection) CreateAnyCallHandler() (irs.AnyCallHandler, error) {
return nil, errors.New("GCP Driver: not implemented")
}

func (cloudConn *GCPCloudConnection) CreateRegionZoneHandler() (irs.RegionZoneHandler, error) {
cblogger.Info("GCP Cloud Driver: called CreateRegionZoneHandler()!")
regionZoneHandler := gcprs.GCPRegionZoneHandler{cloudConn.Region, cloudConn.Ctx, cloudConn.RegionZoneClient, cloudConn.Credential}
return &regionZoneHandler, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -1793,7 +1793,71 @@ func handleMyImage() {
}
}

//import "path/filepath"
func handleRegionZone() {
cblogger.Debug("Start RegionZoneHandler Resource Test")

ResourceHandler, err := testconf.GetResourceHandler("RegionZone")
if err != nil {
panic(err)
}
handler := ResourceHandler.(irs.RegionZoneHandler)

for {
fmt.Println("RegionZoneHandler Management")
fmt.Println("0. Quit")
fmt.Println("1. RegionZone List")
fmt.Println("2. OrgRegion List")
fmt.Println("3. OrgZone List")

var commandNum int
inputCnt, err := fmt.Scan(&commandNum)
if err != nil {
panic(err)
}

if inputCnt == 1 {
switch commandNum {
case 0:
return

case 1:
result, err := handler.ListRegionZone()
if err != nil {
cblogger.Infof(" RegionZone 목록 조회 실패 : ", err)
} else {
cblogger.Info("RegionZone 목록 조회 결과")
cblogger.Info(result)
cblogger.Info("출력 결과 수 : ", len(result))
spew.Dump(result)
//spew.Dump(result)

//조회및 삭제 테스트를 위해 리스트의 첫번째 정보의 ID를 요청ID로 자동 갱신함.
// if result != nil {
// diskReqInfo.IId = result[0].IId // 조회 및 삭제를 위해 생성된 ID로 변경
// }
}

case 2:
result, err := handler.ListOrgRegion()
if err != nil {
cblogger.Infof("[%s] ListOrgZone 조회 실패 : ", err)
} else {
cblogger.Infof("[%s] ListOrgZone 조회 성공 : ", result)
spew.Dump(result)
}

case 3:
result, err := handler.ListOrgZone()
if err != nil {
cblogger.Infof("[%s] ListOrgZone 조회 실패 : ", err)
} else {
cblogger.Infof("[%s] ListOrgZone 조회 성공 : ", result)
spew.Dump(result)
}
}
}
}
}

func main() {
cblogger.Info("GCP Resource Test")
Expand All @@ -1802,10 +1866,11 @@ func main() {
//handleImage() //AMI
//handleKeyPair()
//handleSecurity()
handleVM()
//handleVM()
//handleLoadBalancer()
//handleDisk()
//handleMyImage()
handleRegionZone()
//cblogger.Info(filepath.Join("a/b", "\\cloud-driver-libs\\.ssh-gcp\\"))
//cblogger.Info(filepath.Join("\\cloud-driver-libs\\.ssh-gcp\\", "/b/c/d"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ type Config struct {
}

// 환경변수 : GOOGLE_APPLICATION_CREDENTIALS - 인증용 .json 파일의 위치
//handlerType : resources폴더의 xxxHandler.go에서 Handler이전까지의 문자열
//(예) ImageHandler.go -> "Image"
// handlerType : resources폴더의 xxxHandler.go에서 Handler이전까지의 문자열
// (예) ImageHandler.go -> "Image"
func GetResourceHandler(handlerType string) (interface{}, error) {
var cloudDriver idrv.CloudDriver
cloudDriver = new(gcpdrv.GCPDriver)
Expand Down Expand Up @@ -100,6 +100,8 @@ func GetResourceHandler(handlerType string) (interface{}, error) {
resourceHandler, err = cloudConnection.CreateVMSpecHandler()
case "VPCHandler":
resourceHandler, err = cloudConnection.CreateVPCHandler()
case "RegionZone":
resourceHandler, err = cloudConnection.CreateRegionZoneHandler()
}

if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import (
"sync"
"time"

"github.com/davecgh/go-spew/spew"
cblog "github.com/cloud-barista/cb-log"
call "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/call-log"
idrv "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces"
irs "github.com/cloud-barista/cb-spider/cloud-control-manager/cloud-driver/interfaces/resources"
"github.com/davecgh/go-spew/spew"
"github.com/sirupsen/logrus"
compute "google.golang.org/api/compute/v1"
container "google.golang.org/api/container/v1"
Expand Down Expand Up @@ -512,6 +512,46 @@ func WaitContainerOperationDone(client *container.Service, project string, regio
return nil
}

// region에 해당하는 zone 목록 조회
func GetZoneListByRegion(client *compute.Service, regionUrl string) (*compute.ZoneList, error) {
projectId := ""
regionName := ""

arrLink := strings.Split(regionUrl, "/")
if len(arrLink) > 0 {
regionName = arrLink[len(arrLink)-1]
for pos, item := range arrLink {
if strings.EqualFold(item, "projects") {
projectId = arrLink[pos+1]
break
}
}
}
cblogger.Infof("projectId : [%s] / imageName : [%s]", projectId, regionName)
if projectId == "" {
return nil, errors.New("ProjectId information not found in URL.")
}

resp, err := client.Zones.List(projectId).Do()

if err != nil {
cblogger.Error(err)
return nil, err
}
return resp, nil

}

// Available or Unavailable 로 return
// Status of the zone, either UP or DOWN.
func GetZoneStatus(status string) irs.ZoneStatus {
if status == "UP" {
return irs.ZoneAvailable
} else {
return irs.ZoneUnavailable
}
}

/*
### container operation ###
(*container.Operation)(0xc0003d6a00)({
Expand Down
Loading
Loading