Skip to content

Commit

Permalink
Merge pull request #1358 from ish-hcc/openstack_list_iid
Browse files Browse the repository at this point in the history
[OpenStack] Implement ListIID()
  • Loading branch information
powerkimhub authored Oct 4, 2024
2 parents aa82bc7 + e5e281f commit cf2d6f2
Show file tree
Hide file tree
Showing 8 changed files with 300 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,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) {
Expand Down Expand Up @@ -164,6 +165,14 @@ Loop:
}
cblogger.Info("Finish DeleteKey()")
case 5:
cblogger.Info("Start ListIID() ...")
if result, err := keyPairHandler.ListIID(); err != nil {
cblogger.Error(err)
} else {
spew.Dump(result)
}
cblogger.Info("Finish ListIID()")
case 6:
cblogger.Info("Exit")
break Loop
}
Expand Down Expand Up @@ -252,7 +261,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")
}

func testSecurityHandler(config Config) {
Expand Down Expand Up @@ -378,6 +388,14 @@ Loop:
}
fmt.Println("Finish RemoveRules()")
case 7:
cblogger.Info("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 @@ -393,7 +411,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 @@ -524,6 +543,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 @@ -543,7 +570,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 @@ -694,6 +722,14 @@ Loop:
}
cblogger.Info("Finish TerminateVM()")
case 10:
cblogger.Info("Start ListIID() ...")
if vmStatus, err := vmHandler.ListIID(); err != nil {
cblogger.Error(err)
} else {
spew.Dump(vmStatus)
}
cblogger.Info("Finish ListIID()")
case 11:
cblogger.Info("Exit")
break Loop
}
Expand Down Expand Up @@ -771,7 +807,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 @@ -932,6 +969,14 @@ Loop:
}
cblogger.Info("Finish ChangeHealthCheckerInfo()")
case 11:
cblogger.Info("Start ListIID() ...")
if result, err := nlbHandler.ListIID(); err != nil {
cblogger.Error(err)
} else {
spew.Dump(result)
}
cblogger.Info("Finish ListIID()")
case 12:
cblogger.Info("Exit")
break Loop
}
Expand All @@ -949,7 +994,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 @@ -1047,6 +1093,14 @@ Loop:
}
cblogger.Info("Finish DetachDisk()")
case 8:
cblogger.Info("Start ListIID() ...")
if result, err := diskHandler.ListIID(); err != nil {
cblogger.Error(err)
} else {
spew.Dump(result)
}
cblogger.Info("Finish ListIID()")
case 9:
cblogger.Info("Exit")
break Loop
}
Expand All @@ -1061,7 +1115,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 @@ -1132,6 +1187,14 @@ Loop:
}
cblogger.Info("Finish DeleteMyImage()")
case 5:
cblogger.Info("Start ListIID() ...")
if result, err := myimageHandler.ListIID(); err != nil {
cblogger.Error(err)
} else {
spew.Dump(result)
}
cblogger.Info("Finish ListIID()")
case 6:
cblogger.Info("Exit")
break Loop
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,38 @@ func changeDiskSize(diskIID irs.IID, diskSize string, volumeClient *gophercloud.
return volumeactions.ExtendSize(volumeClient, disk.ID, changeSizeOpts).ExtractErr()
}

func (DiskHandler *OpenstackDiskHandler) ListIID() ([]*irs.IID, error) {
cblogger.Info("Cloud driver: called ListIID()!!")
return nil, errors.New("Does not support ListIID() yet!!")
func (diskHandler *OpenstackDiskHandler) ListIID() ([]*irs.IID, error) {
hiscallInfo := GetCallLogScheme(diskHandler.CredentialInfo.IdentityEndpoint, call.DISK, "DISK", "ListDisk()")

start := call.Start()

var iidList []*irs.IID

err := diskHandler.CheckDiskHandler()
if err != nil {
getErr := errors.New(fmt.Sprintf("Failed to List Disk. err = %s", err.Error()))
cblogger.Error(getErr.Error())
LoggingError(hiscallInfo, getErr)
return make([]*irs.IID, 0), getErr
}

list, err := getRawDiskList(diskHandler.VolumeClient)
if err != nil {
getErr := errors.New(fmt.Sprintf("Failed to List Disk. err = %s", err.Error()))
cblogger.Error(getErr.Error())
LoggingError(hiscallInfo, getErr)
return make([]*irs.IID, 0), getErr
}

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

iidList = append(iidList, &iid)
}

LoggingInfo(hiscallInfo, start)

return iidList, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -228,5 +228,38 @@ func GetRawKey(client *gophercloud.ServiceClient, keyIID irs.IID) (keypairs.KeyP

func (keyPairHandler *OpenStackKeyPairHandler) ListIID() ([]*irs.IID, error) {
cblogger.Info("Cloud driver: called ListIID()!!")
return nil, errors.New("Does not support ListIID() yet!!")
hiscallInfo := GetCallLogScheme(keyPairHandler.Client.IdentityEndpoint, call.VMKEYPAIR, KeyPair, "ListIID()")

start := call.Start()

var iidList []*irs.IID

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

}

allKeypairs, err := keypairs.ExtractKeyPairs(allPages)
if err != nil {
newErr := fmt.Errorf("Failed to Get keypairs List from Openstack!! : [%v] ", err)
cblogger.Error(newErr.Error())
LoggingError(hiscallInfo, 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(hiscallInfo, start)

return iidList, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,30 @@ func (myImageHandler *OpenStackMyImageHandler) CheckWindowsImage(myImageIID irs.
return false, nil
}

func (ImageHandler *OpenStackMyImageHandler) ListIID() ([]*irs.IID, error) {
cblogger.Info("Cloud driver: called ListIID()!!")
return nil, errors.New("Does not support ListIID() yet!!")
func (myImageHandler *OpenStackMyImageHandler) ListIID() ([]*irs.IID, error) {
hiscallInfo := GetCallLogScheme(myImageHandler.CredentialInfo.IdentityEndpoint, "MyImage", "MyImage", "ListIID()")

start := call.Start()

var iidList []*irs.IID

list, err := getRawSnapshotList(myImageHandler.ComputeClient)
if err != nil {
getErr := errors.New(fmt.Sprintf("Failed to List MyImage. err = %s", err))
cblogger.Error(getErr.Error())
LoggingError(hiscallInfo, getErr)
return make([]*irs.IID, 0), getErr
}

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

iidList = append(iidList, &iid)
}

LoggingInfo(hiscallInfo, start)

return iidList, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -1825,7 +1825,38 @@ func checkvmGroupProtocol(protocol string) (pools.Protocol, error) {
return "", errors.New("invalid vmGroup Protocols, openstack vmGroup provides only TCP protocols")
}

func (NLBHandler *OpenStackNLBHandler) ListIID() ([]*irs.IID, error) {
cblogger.Info("Cloud driver: called ListIID()!!")
return nil, errors.New("Does not support ListIID() yet!!")
func (nlbHandler *OpenStackNLBHandler) ListIID() ([]*irs.IID, error) {
hiscallInfo := GetCallLogScheme(nlbHandler.Region.Region, "NETWORKLOADBALANCE", "NLB", "ListIID()")

start := call.Start()

var iidList []*irs.IID

err := nlbHandler.checkNLBClient()
if err != nil {
getErr := errors.New(fmt.Sprintf("Failed to List NLB. err = %s", err.Error()))
cblogger.Error(getErr.Error())
LoggingError(hiscallInfo, getErr)
return make([]*irs.IID, 0), getErr
}

nlbList, err := nlbHandler.getRawNLBList()
if err != nil {
getErr := errors.New(fmt.Sprintf("Failed to List NLB. err = %s", err.Error()))
cblogger.Error(getErr.Error())
LoggingError(hiscallInfo, getErr)
return make([]*irs.IID, 0), getErr
}

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

iidList = append(iidList, &iid)
}

LoggingInfo(hiscallInfo, start)

return iidList, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,37 @@ func checkIPAddressType(cidr string) (rules.RuleEtherType, error) {

func (securityHandler *OpenStackSecurityHandler) ListIID() ([]*irs.IID, error) {
cblogger.Info("Cloud driver: called ListIID()!!")
return nil, errors.New("Does not support ListIID() yet!!")
}
hiscallInfo := GetCallLogScheme(securityHandler.ComputeClient.IdentityEndpoint, call.SECURITYGROUP, SecurityGroup, "ListIID()")

start := call.Start()

var iidList []*irs.IID

allPages, err := secgroups.List(securityHandler.ComputeClient).AllPages()
if err != nil {
newErr := fmt.Errorf("Failed to Get secgroup information from Openstack!! : [%v]", err)
cblogger.Error(newErr.Error())
LoggingError(hiscallInfo, newErr)
return make([]*irs.IID, 0), newErr

}

allSecugroups, err := secgroups.ExtractSecurityGroups(allPages)
if err != nil {
newErr := fmt.Errorf("Failed to Get secgroups List from Openstack!! : [%v] ", err)
cblogger.Error(newErr.Error())
LoggingError(hiscallInfo, newErr)
return make([]*irs.IID, 0), newErr
}

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

iidList = append(iidList, &iid)
}

LoggingInfo(hiscallInfo, start)
return iidList, nil
}
Loading

0 comments on commit cf2d6f2

Please sign in to comment.