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

[ALIBABA, TENCENT] update resources iid list #1375

Merged
merged 6 commits into from
Oct 23, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ package resources

import (
"encoding/json"
"errors"
"fmt"
"runtime/debug"
"strconv"
Expand Down Expand Up @@ -1040,6 +1039,7 @@ func aliDescribeClustersV1(csClient *cs2015.Client, regionId string) ([]*cs2015.
describeClustersV1Request := &cs2015.DescribeClustersV1Request{
ClusterType: tea.String("ManagedKubernetes"),
RegionId: tea.String(regionId),
//RegionId: tea.String("ap-northeast-1"),
}
cblogger.Debug(describeClustersV1Request)
describeClustersV1Response, err := csClient.DescribeClustersV1(describeClustersV1Request)
Expand Down Expand Up @@ -2321,7 +2321,29 @@ func waitUntilClusterSecurityGroupIdIsExist(csClient *cs2015.Client, clusterId s
}
*/

func (ClusterHandler *AlibabaClusterHandler) ListIID() ([]*irs.IID, error) {
cblogger.Info("Cloud driver: called ListIID()!!")
return nil, errors.New("Does not support ListIID() yet!!")
func (alibabaClusterHandler *AlibabaClusterHandler) ListIID() ([]*irs.IID, error) {
var iidList []*irs.IID

cblogger.Debug("Alibaba Cloud Driver: called ListCluster()")
hiscallInfo := GetCallLogScheme(alibabaClusterHandler.RegionInfo, call.CLUSTER, "ListCluster()", "ListCluster()")
start := call.Start()

cblogger.Infof("Get Cluster List")
regionId := alibabaClusterHandler.RegionInfo.Region
clusters, err := aliDescribeClustersV1(alibabaClusterHandler.CsClient, regionId)
if err != nil {
err := fmt.Errorf("Failed to List Cluster: %v", err)
cblogger.Error(err)
LoggingError(hiscallInfo, err)
return iidList, err
}

for _, cluster := range clusters {
iid := irs.IID{SystemId: tea.StringValue(cluster.ClusterId)}
iidList = append(iidList, &iid)

}
LoggingInfo(hiscallInfo, start)
return iidList, nil

}
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,49 @@ func DescribeDiskByDiskId(client *ecs.Client, regionInfo idrv.RegionInfo, diskII
return diskList[0], nil
}

/*
*
디스크 목록 조회
*/
func DescribeDisksIdOnly(client *ecs.Client, regionInfo idrv.RegionInfo) ([]*irs.IID, error) {
regionID := regionInfo.Region

request := ecs.CreateDescribeDisksRequest()
request.Scheme = "https"
request.RegionId = regionID
request.PageNumber = requests.NewInteger(CBPageNumber)
request.PageSize = requests.NewInteger(CBPageSize)

var totalCount = 0
curPage := CBPageNumber
var iidList []*irs.IID
for {
result, err := client.DescribeDisks(request)
//cblogger.Debug(result) //출력 정보가 너무 많아서 생략
if err != nil {
cblogger.Errorf("Unable to get Disks, %v", err)
return iidList, err
}

for _, curDisk := range result.Disks.Disk {
iid := irs.IID{SystemId: curDisk.DiskId}
iidList = append(iidList, &iid)
}

totalCount = len(iidList)
cblogger.Debugf("Total number of disks across CSP: [%d] - Current page: [%d] - Accumulated result count: [%d]", result.TotalCount, curPage, totalCount)
if totalCount >= result.TotalCount {
break
}
curPage++
request.PageNumber = requests.NewInteger(curPage)
}

cblogger.Debug(iidList)

return iidList, nil
}

/*
*
InstanceID로 1개 Disk의 정보 조회
Expand Down Expand Up @@ -345,6 +388,44 @@ func DescribeInstanceById(client *ecs.Client, regionInfo idrv.RegionInfo, vmIID
return response[0], nil
}

/*
*
Instance ID 목록 조회
*/
func DescribeInstancesIdOnly(client *ecs.Client, regionInfo idrv.RegionInfo) ([]*irs.IID, error) {
var iidList []*irs.IID

request := ecs.CreateDescribeInstancesRequest()
request.Scheme = "https"
request.PageNumber = requests.NewInteger(1)
request.PageSize = requests.NewInteger(100)

var totalCount = 0
curPage := 1
for {
response, err := client.DescribeInstances(request)
if err != nil {
cblogger.Errorf("Unable to get key pairs, %v", err)
return iidList, err
}

for _, curInstance := range response.Instances.Instance {
iid := irs.IID{SystemId: curInstance.InstanceId}
iidList = append(iidList, &iid)
}

totalCount = len(iidList)
cblogger.Infof("Total number of instance across CSP: [%d] - Current page: [%d] - Accumulated result count: [%d]", response.TotalCount, curPage, totalCount)
if totalCount >= response.TotalCount {
break
}
curPage++
request.PageNumber = requests.NewInteger(curPage)
}

return iidList, nil
}

/*
*
Image 목록 조회
Expand Down Expand Up @@ -384,6 +465,48 @@ func DescribeImages(client *ecs.Client, regionInfo idrv.RegionInfo, imageIIDs []
return result.Images.Image, nil
}

func DescribeImagesIdOnly(client *ecs.Client, regionInfo idrv.RegionInfo, isMyImage bool) ([]*irs.IID, error) {
var iidList []*irs.IID

request := ecs.CreateDescribeImagesRequest()
request.Scheme = "https"
request.PageNumber = requests.NewInteger(1)
request.PageSize = requests.NewInteger(100)
request.RegionId = regionInfo.Region // 필수 Req Name

// MyImage 여부
if isMyImage {
request.ImageOwnerAlias = "self"
}

var totalCount = 0
curPage := 1
for {

result, err := client.DescribeImages(request)
if err != nil {
cblogger.Error(err)
return iidList, err
}
cblogger.Debug(result)

for _, curImage := range result.Images.Image {
iid := irs.IID{SystemId: curImage.ImageId}
iidList = append(iidList, &iid)
}

totalCount = len(iidList)
cblogger.Debugf("Total number of image across CSP: [%d] - Current page: [%d] - Accumulated result count: [%d]", result.TotalCount, curPage, totalCount)
if totalCount >= result.TotalCount {
break
}
curPage++
request.PageNumber = requests.NewInteger(curPage)
}
//cblogger.Debug(result)
return iidList, nil
}

/*
*
ImageID로 1개 Image의 정보 조회
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,31 @@ func convertAlibabaDiskStatusToDiskStatus(aliDiskStaus string) (irs.DiskStatus,
return returnStatus, nil
}

func (DiskHandler *AlibabaDiskHandler) ListIID() ([]*irs.IID, error) {
cblogger.Info("Cloud driver: called ListIID()!!")
return nil, errors.New("Does not support ListIID() yet!!")
/*
DISK IID 목록 조회
*/
func (diskHandler *AlibabaDiskHandler) ListIID() ([]*irs.IID, error) {
// logger for HisCall
callogger := call.GetLogger("HISCALL")
callLogInfo := call.CLOUDLOGSCHEMA{
CloudOS: call.ALIBABA,
RegionZone: diskHandler.Region.Zone,
ResourceType: call.VM,
ResourceName: "ListIID()",
CloudOSAPI: "DescribeDisksIdOnly()",
ElapsedTime: "",
ErrorMSG: "",
}

callLogStart := call.Start()

iidList, err := DescribeDisksIdOnly(diskHandler.Client, diskHandler.Region)
callLogInfo.ElapsedTime = call.Elapsed(callLogStart)

if err != nil {
callogger.Error(call.String(callLogInfo))
return iidList, err
}
return iidList, err

}
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,60 @@ func (keyPairHandler *AlibabaKeyPairHandler) CheckKeyPairFolder(keyPairPath stri
}

func (keyPairHandler *AlibabaKeyPairHandler) ListIID() ([]*irs.IID, error) {
cblogger.Info("Cloud driver: called ListIID()!!")
return nil, errors.New("Does not support ListIID() yet!!")
var iidList []*irs.IID
//cblogger.Debug(keyPairHandler)
cblogger.Debug(keyPairHandler)

request := ecs.CreateDescribeKeyPairsRequest()
request.Scheme = "https"
request.PageNumber = requests.NewInteger(1)
request.PageSize = requests.NewInteger(50) // 키 페어는 최대 50개까지 지정 가능

// logger for HisCall
callogger := call.GetLogger("HISCALL")
callLogInfo := call.CLOUDLOGSCHEMA{
CloudOS: call.ALIBABA,
RegionZone: keyPairHandler.Region.Zone,
ResourceType: call.VMKEYPAIR,
ResourceName: "ListKey()",
CloudOSAPI: "DescribeKeyPairs()",
ElapsedTime: "",
ErrorMSG: "",
}

callLogStart := call.Start()

var totalCount = 0
curPage := 1
for {
// Returns a list of key pairs
result, err := keyPairHandler.Client.DescribeKeyPairs(request)
callLogInfo.ElapsedTime = call.Elapsed(callLogStart)

if err != nil {
callLogInfo.ErrorMSG = err.Error()
callogger.Error(call.String(callLogInfo))

cblogger.Errorf("Unable to get key pairs, %v", err)
return iidList, err
}
callogger.Info(call.String(callLogInfo))
cblogger.Debug(result)

//cblogger.Debugf("Key Pairs:")
for _, pair := range result.KeyPairs.KeyPair {
iid := irs.IID{SystemId: pair.KeyPairName}
iidList = append(iidList, &iid)
}

totalCount = len(iidList)
cblogger.Infof("Total number of key pairs across CSP: [%d] - Current page: [%d] - Accumulated result count: [%d]", result.TotalCount, curPage, totalCount)
if totalCount >= result.TotalCount {
break
}
curPage++
request.PageNumber = requests.NewInteger(curPage)
}

return iidList, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,26 @@ func (myImageHandler *AlibabaMyImageHandler) DeleteSnapshotBySnapshotID(snapshot
return true, err
}

func (ImageHandler *AlibabaMyImageHandler) ListIID() ([]*irs.IID, error) {
cblogger.Info("Cloud driver: called ListIID()!!")
return nil, errors.New("Does not support ListIID() yet!!")
func (myImageHandler *AlibabaMyImageHandler) ListIID() ([]*irs.IID, error) {
// logger for HisCall
callogger := call.GetLogger("HISCALL")
callLogInfo := call.CLOUDLOGSCHEMA{
CloudOS: call.ALIBABA,
RegionZone: myImageHandler.Region.Zone,
ResourceType: call.VM,
ResourceName: "ListIID()",
CloudOSAPI: "DescribeImages()",
ElapsedTime: "",
ErrorMSG: "",
}
callLogStart := call.Start()

iidList, err := DescribeImagesIdOnly(myImageHandler.Client, myImageHandler.Region, true)
callLogInfo.ElapsedTime = call.Elapsed(callLogStart)
if err != nil {
callogger.Error(call.String(callLogInfo))
return iidList, err
}

return iidList, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -1427,6 +1427,55 @@ func (NLBHandler *AlibabaNLBHandler) validateCreateNLB(nlbReqInfo irs.NLBInfo) e
}

func (NLBHandler *AlibabaNLBHandler) ListIID() ([]*irs.IID, error) {
cblogger.Info("Cloud driver: called ListIID()!!")
return nil, errors.New("Does not support ListIID() yet!!")
var iidList []*irs.IID

request := slb.CreateDescribeLoadBalancersRequest()
request.PageNumber = requests.NewInteger(1)
request.PageSize = requests.NewInteger(50)
request.RegionId = NLBHandler.Region.Region

// logger for HisCall
callogger := call.GetLogger("HISCALL")
callLogInfo := call.CLOUDLOGSCHEMA{
CloudOS: call.ALIBABA,
RegionZone: NLBHandler.Region.Zone,
ResourceType: call.NLB,
ResourceName: "ListIID()",
CloudOSAPI: "DescribeLoadBalancers()",
ElapsedTime: "",
ErrorMSG: "",
}
callLogStart := call.Start()

var totalCount = 0
curPage := 1
for {
result, err := NLBHandler.Client.DescribeLoadBalancers(request)
callLogInfo.ElapsedTime = call.Elapsed(callLogStart)
//cblogger.Debug(result)
if err != nil {
callLogInfo.ErrorMSG = err.Error()
callogger.Info(call.String(callLogInfo))
return iidList, err
}

callogger.Info("result count ", result.TotalCount)
callogger.Info(result)

for _, curLB := range result.LoadBalancers.LoadBalancer {
cblogger.Debugf("[%s] NLB information retrieval", curLB.LoadBalancerId)
iid := irs.IID{SystemId: curLB.LoadBalancerId}
iidList = append(iidList, &iid)
}

totalCount = len(iidList)
cblogger.Debugf("Total number of nlb across CSP: [%d] - Current page: [%d] - Accumulated result count: [%d]", result.TotalCount, curPage, totalCount)
if totalCount >= result.TotalCount {
break
}
curPage++
request.PageNumber = requests.NewInteger(curPage)
}
cblogger.Debug(iidList)
return iidList, nil
}
Loading