Skip to content

Commit

Permalink
Merge pull request #1360 from ish-hcc/nhn_list_iid
Browse files Browse the repository at this point in the history
[NHN] Implement ListIID()
  • Loading branch information
powerkimhub authored Oct 4, 2024
2 parents 7a6946b + 7905eed commit aa82bc7
Show file tree
Hide file tree
Showing 9 changed files with 367 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,8 @@ func testSecurityHandlerListPrint() {
cblogger.Info("4. DeleteSecurity()")
cblogger.Info("5. AddRules()")
cblogger.Info("6. RemoveRules()")
cblogger.Info("7. Exit")
cblogger.Info("7. ListIID()")
cblogger.Info("8. Exit")
}

// SecurityGroup
Expand Down Expand Up @@ -428,6 +429,14 @@ Loop:
}
fmt.Println("Finish RemoveRules()")
case 7:
fmt.Println("Start ListIID() ...")
if result, err := securityHandler.ListIID(); err != nil {
cblogger.Error(err)
} else {
spew.Dump(result)
}
cblogger.Info("Finish ListIID()")
case 8:
fmt.Println("Exit")
break Loop
}
Expand All @@ -444,7 +453,8 @@ func testVPCHandlerListPrint() {
cblogger.Info("4. DeleteVPC()")
cblogger.Info("5. AddSubnet()")
cblogger.Info("6. RemoveSubnet()")
cblogger.Info("7. Exit")
cblogger.Info("7. ListIID()")
cblogger.Info("8. Exit")
}

func testVPCHandler(config Config) {
Expand Down Expand Up @@ -546,6 +556,14 @@ Loop:
}
cblogger.Info("Finish RemoveSubnet()")
case 7:
cblogger.Info("Start ListIID() ...")
if result, err := vpcHandler.ListIID(); err != nil {
cblogger.Error(err)
} else {
spew.Dump(result)
}
cblogger.Info("Finish ListIID()")
case 8:
cblogger.Info("Exit")
break Loop
}
Expand All @@ -560,7 +578,8 @@ func testKeyPairHandlerListPrint() {
cblogger.Info("2. GetKey()")
cblogger.Info("3. CreateKey()")
cblogger.Info("4. DeleteKey()")
cblogger.Info("5. Exit")
cblogger.Info("5. ListIID()")
cblogger.Info("6. Exit")
}
func testKeyPairHandler(config Config) {
resourceHandler, err := getResourceHandler("keypair", config)
Expand Down Expand Up @@ -624,6 +643,14 @@ Loop:
}
cblogger.Info("Finish DeleteKey()")
case 5:
cblogger.Info("Start ListIID() ...")
if info, err := keyPairHandler.ListIID(); err != nil {
cblogger.Error(err)
} else {
spew.Dump(info)
}
cblogger.Info("Finish ListIID()")
case 6:
cblogger.Info("Exit")
break Loop
}
Expand Down Expand Up @@ -716,7 +743,8 @@ func testVMHandlerListPrint() {
cblogger.Info("7. SuspendVM()")
cblogger.Info("8. ResumeVM()")
cblogger.Info("9. TerminateVM()")
cblogger.Info("10. Exit")
cblogger.Info("10. ListIID()")
cblogger.Info("11. Exit")
}

func testVMHandler(config Config) {
Expand Down Expand Up @@ -852,6 +880,14 @@ Loop:
}
cblogger.Info("Finish TerminateVM()")
case 10:
cblogger.Info("Start ListIID() ...")
if info, err := vmHandler.ListIID(); err != nil {
cblogger.Error(err)
} else {
spew.Dump(info)
}
cblogger.Info("Finish ListIID()")
case 11:
cblogger.Info("Exit")
break Loop
}
Expand All @@ -872,7 +908,8 @@ func testNLBHandlerListPrint() {
cblogger.Info("8. RemoveVMs()")
cblogger.Info("9. GetVMGroupHealthInfo()")
cblogger.Info("10. ChangeHealthCheckerInfo()")
cblogger.Info("11. Exit")
cblogger.Info("11. ListIID()")
cblogger.Info("12. Exit")
}

func testNLBHandler(config Config) {
Expand Down Expand Up @@ -1038,8 +1075,16 @@ Loop:
} else {
spew.Dump(info)
}
cblogger.Info("Finish ChangeHealthCheckerInfo()")

case 11:
cblogger.Info("Start ListIID() ...")
if info, err := nlbHandler.ListIID(); err != nil {
cblogger.Error(err)
} else {
spew.Dump(info)
}
cblogger.Info("Finish ChangeHealthCheckerInfo()")
case 12:
cblogger.Info("Exit")
break Loop
}
Expand All @@ -1056,7 +1101,8 @@ func testDiskHandlerListPrint() {
cblogger.Info("5. ChangeDiskSize()")
cblogger.Info("6. AttachDisk()")
cblogger.Info("7. DetachDisk()")
cblogger.Info("8. Exit")
cblogger.Info("8. ListIID()")
cblogger.Info("9. Exit")
}

func testDiskHandler(config Config) {
Expand Down Expand Up @@ -1158,6 +1204,14 @@ Loop:
}
cblogger.Info("Finish DetachDisk()")
case 8:
cblogger.Info("Start ListIID() ...")
if info, err := diskHandler.ListIID(); err != nil {
cblogger.Error(err)
} else {
spew.Dump(info)
}
cblogger.Info("Finish ListIID()")
case 9:
cblogger.Info("Exit")
break Loop
}
Expand All @@ -1172,7 +1226,8 @@ func testMyImageHandlerListPrint() {
cblogger.Info("2. GetMyImage()")
cblogger.Info("3. SnapshotVM()")
cblogger.Info("4. DeleteMyImage()")
cblogger.Info("5. Exit")
cblogger.Info("5. ListIID()")
cblogger.Info("6. Exit")
}

func testMyImageHandler(config Config) {
Expand Down Expand Up @@ -1235,6 +1290,13 @@ Loop:
}
cblogger.Info("Finish DeleteMyImage()")
case 5:
fmt.Println("Start ListIID() ...")
if result, err := myimageHandler.ListIID(); err != nil {
cblogger.Error(err)
} else {
spew.Dump(result)
}
case 6:
cblogger.Info("Exit")
break Loop
}
Expand Down Expand Up @@ -1434,7 +1496,8 @@ func testClusterHandlerListPrint() {
cblogger.Info("8. ChangeNodeGroupScaling()")
cblogger.Info("9. UpgradeCluster()")
cblogger.Info("10. Create->GET->List->AddNodeGroup->RemoveNodeGroup->SetNodeGroupAutoScaling(Change)->SetNodeGroupAutoScaling(restore)->ChangeNodeGroupScaling->Upgrade->Delete")
cblogger.Info("11. Exit")
cblogger.Info("11. ListIID()")
cblogger.Info("12. Exit")
}

func testClusterHandler(config Config) {
Expand Down Expand Up @@ -1933,6 +1996,13 @@ Loop:
}
cblogger.Info(fmt.Sprintf("Finish %s =====", falowStr))
case 11:
fmt.Println("Start ListIID() ...")
if result, err := clusterHandler.ListIID(); err != nil {
cblogger.Error(err)
} else {
spew.Dump(result)
}
case 12:
cblogger.Info("Exit")
break Loop
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2329,6 +2329,43 @@ func validateAtChangeNodeGroupScaling(minNodeSize int, maxNodeSize int) error {
}

func (nch *NhnCloudClusterHandler) ListIID() ([]*irs.IID, error) {
cblogger.Info("Cloud driver: called ListIID()!!")
return nil, errors.New("Does not support ListIID() yet!!")
defer func() {
if r := recover(); r != nil {
err := fmt.Errorf("PANIC!!\n%v\n%v", r, string(debug.Stack()))
cblogger.Error(err)
}
}()

cblogger.Debug("NHN Cloud Driver: called ListCluster()")
hiscallInfo := getCallLogScheme(nch.RegionInfo.Region, call.CLUSTER, "ListCluster()", "ListIID()") // HisCall logging

start := call.Start()

var iidList []*irs.IID

var listErr error
defer func() {
if listErr != nil {
cblogger.Error(listErr)
LoggingError(hiscallInfo, listErr)
}
}()

clusterList, err := nhnGetClusterList(nch.ClusterClient)
if err != nil {
listErr = fmt.Errorf("Failed to List Cluster: %v", err)
return nil, listErr
}

for _, cluster := range clusterList {
var iid irs.IID
iid.SystemId = cluster.UUID
iid.NameId = cluster.Name

iidList = append(iidList, &iid)
}

LoggingInfo(hiscallInfo, start)

return iidList, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,41 @@ func (diskHandler *NhnCloudDiskHandler) getNhnVolumeList() ([]volumes.Volume, er
return nhnVolumeList, nil
}

func (DiskHandler *NhnCloudDiskHandler) ListIID() ([]*irs.IID, error) {
func (diskHandler *NhnCloudDiskHandler) ListIID() ([]*irs.IID, error) {
cblogger.Info("Cloud driver: called ListIID()!!")
return nil, errors.New("Does not support ListIID() yet!!")
callLogInfo := getCallLogScheme(diskHandler.RegionInfo.Zone, call.DISK, "diskId", "ListIID()")

start := call.Start()

var iidList []*irs.IID

listOpts := volumes.ListOpts{}

allPages, err := volumes.List(diskHandler.VolumeClient, listOpts).AllPages()
if err != nil {
newErr := fmt.Errorf("Failed to Get disk information from NhnCloud!! : [%v]", err)
cblogger.Error(newErr.Error())
LoggingError(callLogInfo, newErr)
return make([]*irs.IID, 0), newErr
}

allDisks, err := volumes.ExtractVolumes(allPages)
if err != nil {
newErr := fmt.Errorf("Failed to Get disk List from NhnCloud!! : [%v] ", err)
cblogger.Error(newErr.Error())
LoggingError(callLogInfo, newErr)
return make([]*irs.IID, 0), newErr
}

for _, disk := range allDisks {
var iid irs.IID
iid.SystemId = disk.ID
iid.NameId = disk.Name

iidList = append(iidList, &iid)
}

LoggingInfo(callLogInfo, start)

return iidList, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
package resources

import (
"errors"
"fmt"

nhnsdk "github.com/cloud-barista/nhncloud-sdk-go"
Expand All @@ -32,6 +31,8 @@ func (keyPairHandler *NhnCloudKeyPairHandler) CreateKey(keyPairReqInfo irs.KeyPa
cblogger.Info("NHN Cloud Driver: called CreateKey()")
callLogInfo := getCallLogScheme(keyPairHandler.RegionInfo.Region, call.VMKEYPAIR, keyPairReqInfo.IId.NameId, "CreateKey()")

fmt.Println(keyPairReqInfo)

if keyPairReqInfo.IId.NameId == "" {
newErr := fmt.Errorf("Invalid KeyPair NameId.")
cblogger.Error(newErr.Error())
Expand Down Expand Up @@ -234,5 +235,39 @@ func mappingKeypairInfo(keypair keypairs.KeyPair) *irs.KeyPairInfo {

func (keyPairHandler *NhnCloudKeyPairHandler) ListIID() ([]*irs.IID, error) {
cblogger.Info("Cloud driver: called ListIID()!!")
return nil, errors.New("Does not support ListIID() yet!!")
callLogInfo := getCallLogScheme(keyPairHandler.RegionInfo.Zone, call.VMKEYPAIR, "keyId", "ListIID()")

start := call.Start()

var iidList []*irs.IID

listOpts := keypairs.ListOpts{}

allPages, err := keypairs.List(keyPairHandler.VMClient, listOpts).AllPages()
if err != nil {
newErr := fmt.Errorf("Failed to Get kypairs information from NhnCloud!! : [%v]", err)
cblogger.Error(newErr.Error())
LoggingError(callLogInfo, newErr)
return make([]*irs.IID, 0), newErr
}

allKeypairs, err := keypairs.ExtractKeyPairs(allPages)
if err != nil {
newErr := fmt.Errorf("Failed to Get kypairs List from NhnCloud!! : [%v] ", err)
cblogger.Error(newErr.Error())
LoggingError(callLogInfo, newErr)
return make([]*irs.IID, 0), newErr
}

for _, keypair := range allKeypairs {
var iid irs.IID
iid.NameId = keypair.Name
iid.SystemId = keypair.Name

iidList = append(iidList, &iid)
}

LoggingInfo(callLogInfo, start)

return iidList, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,41 @@ func (myImageHandler *NhnCloudMyImageHandler) isPublicImage(myImageIID irs.IID)
return isPublicImage, nil
}

func (ImageHandler *NhnCloudMyImageHandler) ListIID() ([]*irs.IID, error) {
cblogger.Info("Cloud driver: called ListIID()!!")
return nil, errors.New("Does not support ListIID() yet!!")
func (myImageHandler *NhnCloudMyImageHandler) ListIID() ([]*irs.IID, error) {
cblogger.Info("NHN Cloud Driver: called ListIID()")
callLogInfo := getCallLogScheme(myImageHandler.RegionInfo.Region, call.MYIMAGE, "ListMyImage()", "ListMyImage()")

start := call.Start()

var iidList []*irs.IID

listOpts := images.ListOpts{
Visibility: images.ImageVisibilityPrivate, // Note : Private image only
}
allPages, err := images.List(myImageHandler.ImageClient, listOpts).AllPages()
if err != nil {
newErr := fmt.Errorf("Failed to Get NHN Cloud Image pages. [%v]", err.Error())
cblogger.Error(newErr.Error())
LoggingError(callLogInfo, newErr)
return make([]*irs.IID, 0), newErr
}
nhnImageList, err := images.ExtractImages(allPages)
if err != nil {
newErr := fmt.Errorf("Failed to Get NHN Cloud Image List. [%v]", err.Error())
cblogger.Error(newErr.Error())
LoggingError(callLogInfo, newErr)
return make([]*irs.IID, 0), newErr
}

for _, nhnImage := range nhnImageList {
var iid irs.IID
iid.SystemId = nhnImage.ID
iid.NameId = nhnImage.Name

iidList = append(iidList, &iid)
}

LoggingInfo(callLogInfo, start)

return iidList, nil
}
Loading

0 comments on commit aa82bc7

Please sign in to comment.