From 26821156682452580cf8a8dc101c9e48e610ff52 Mon Sep 17 00:00:00 2001 From: innodreamer Date: Mon, 26 Aug 2024 20:03:47 +0900 Subject: [PATCH] Apply zone info for each infra resource --- .../cloud-driver/drivers/ktcloud/README.md | 7 +- .../drivers/ktcloud/resources/DiskHandler.go | 53 +++++++++++---- .../ktcloud/resources/MyImageHandler.go | 22 ++++--- .../drivers/ktcloud/resources/VMHandler.go | 64 ++++++++++--------- .../drivers/ktcloud/resources/VPCHandler.go | 3 + 5 files changed, 92 insertions(+), 57 deletions(-) diff --git a/cloud-control-manager/cloud-driver/drivers/ktcloud/README.md b/cloud-control-manager/cloud-driver/drivers/ktcloud/README.md index 0adb29f24..d5e9c39df 100644 --- a/cloud-control-manager/cloud-driver/drivers/ktcloud/README.md +++ b/cloud-control-manager/cloud-driver/drivers/ktcloud/README.md @@ -112,10 +112,13 @@ $GOPATH/src/github.com/cloud-barista/ktcloud/ktcloud/main/ - SSD-Provisioned : 100 ~ 800G(100G 단위 지정) - 아래의 link에서 'Volume : 생성' 부분 > 'diskofferingid' 표 참고 - https://cloud.kt.com/docs/open-api-guide/g/computing/disk-volume + - Disk 생성시 다른 해당 connection 외의 다른 zone을 지정하여 disk를 생성할 수 없음. + - 다른 zone을 지정하여 생성할 경우 CSP(KT Cloud) API로부터 오류 발생


- O VM을 대상으로 MyImage 생성시 주의할 점 - - KT Cloud Classic 클라우드 서비스에서는 VM이 중지된(Suspended) 상태에서만 MyImage 생성이 가능함. + O VM을 대상으로 MyImage 생성 및 삭제시 주의할 점 + - KT Cloud Classic 클라우드 서비스에서는 VM이 중지된(Suspended) 상태에서만 MyImage(KT Cloud Template) 생성이 가능함. + - 생성된지 1시간 이내의 MyImage(KT Cloud Template)는 삭제할 수 없음.


#### # KT Cloud Classic (G1/G2) 드라이버 개발시 참고 사항 diff --git a/cloud-control-manager/cloud-driver/drivers/ktcloud/resources/DiskHandler.go b/cloud-control-manager/cloud-driver/drivers/ktcloud/resources/DiskHandler.go index df8631e4f..382814a10 100644 --- a/cloud-control-manager/cloud-driver/drivers/ktcloud/resources/DiskHandler.go +++ b/cloud-control-manager/cloud-driver/drivers/ktcloud/resources/DiskHandler.go @@ -123,7 +123,7 @@ func (diskHandler *KtCloudDiskHandler) CreateDisk(diskReqInfo irs.DiskInfo) (irs volumeReq := ktsdk.CreateVolumeReqInfo{ Name: diskReqInfo.IId.NameId, // Required DiskOfferingId: "", // Required - ZoneId: diskHandler.RegionInfo.Zone, // Required + ZoneId: diskReqInfo.Zone, // Required UsagePlanType: DefaultDiskUsagePlanType, ProductCode: volumeProductCode, IOPS: reqIOPS, // When entering IOPS value, it is created with 'SSD-Provisioned' type of volume. (Not general SSD type) @@ -146,17 +146,19 @@ func (diskHandler *KtCloudDiskHandler) CreateDisk(diskReqInfo irs.DiskInfo) (irs } // Add the Tag List according to the ReqInfo - tagHandler := KtCloudTagHandler { - RegionInfo: diskHandler.RegionInfo, - Client: diskHandler.Client, - } - _, createErr := tagHandler.createTagList(irs.RSType(irs.DISK), &createVolumeResponse.Createvolumeresponse.ID, diskReqInfo.TagList) - if err != nil { - newErr := fmt.Errorf("Failed to Add the Tag List on the Disk : [%v]", createErr) - cblogger.Error(newErr.Error()) - return irs.DiskInfo{}, newErr + if len(diskReqInfo.TagList) > 0 { + tagHandler := KtCloudTagHandler { + RegionInfo: diskHandler.RegionInfo, + Client: diskHandler.Client, + } + _, createErr := tagHandler.createTagList(irs.RSType(irs.DISK), &createVolumeResponse.Createvolumeresponse.ID, diskReqInfo.TagList) + if err != nil { + newErr := fmt.Errorf("Failed to Add the Tag List on the Disk : [%v]", createErr) + cblogger.Error(newErr.Error()) + return irs.DiskInfo{}, newErr + } + time.Sleep(time.Second * 1) } - time.Sleep(time.Second * 1) newVolumeIID := irs.IID{SystemId: createVolumeResponse.Createvolumeresponse.ID} newDiskInfo, err := diskHandler.GetDisk(newVolumeIID) @@ -642,6 +644,10 @@ func (diskHandler *KtCloudDiskHandler) mappingDiskInfo(volume *ktsdk.Volume) (ir } } + if !strings.EqualFold(volume.ZoneId, "") { + diskInfo.Zone = volume.ZoneId + } + // Get the Tag List of the Disk var kvList []irs.KeyValue tagHandler := KtCloudTagHandler { @@ -670,11 +676,30 @@ func (diskHandler *KtCloudDiskHandler) mappingDiskInfo(volume *ktsdk.Volume) (ir iops = strconv.FormatInt(volume.MaxIOPS, 10) } + // Set Display Name of the Zone + var zoneDisplaName string + if volume.ZoneName != "" { + if strings.EqualFold(volume.ZoneName, "kr-0") { // ??? + zoneDisplaName= "KOR-Seoul M" + } else if strings.EqualFold(volume.ZoneName, "kr-md2-1") { + zoneDisplaName= "KOR-Seoul M2" + } else if strings.EqualFold(volume.ZoneName, "kr-1") { + zoneDisplaName= "KOR-Central A" + } else if strings.EqualFold(volume.ZoneName, "kr-2") { + zoneDisplaName= "KOR-Central B" + } else if strings.EqualFold(volume.ZoneName, "kr-3") { + zoneDisplaName= "KOR-HA" + } else { + zoneDisplaName= volume.ZoneName + } + } + keyValueList := []irs.KeyValue{ {Key: "Type", Value: volume.Type}, {Key: "MaxIOPS", Value: iops}, {Key: "UsagePlanType", Value: volume.UsagePlanType}, {Key: "AttachedTime", Value: volume.AttachedTime}, + {Key: "ZoneDisplaName", Value: zoneDisplaName}, {Key: "VMState", Value: volume.VMState}, } diskInfo.KeyValueList = keyValueList @@ -731,14 +756,14 @@ func (diskHandler *KtCloudDiskHandler) getVolumeIdsWithVMId(vmId string) ([]stri start := call.Start() result, err := diskHandler.Client.ListVolumes(volumeReq) if err != nil { - cblogger.Error("Failed to Get KT Cloud Volume list : [%v]", err) + cblogger.Error("Failed to Get Volume list from KT Cloud : [%v]", err) return nil, err } LoggingInfo(callLogInfo, start) // spew.Dump(result) if len(result.Listvolumesresponse.Volume) < 1 { - newErr := fmt.Errorf("Failed to Get Volume List on the Zone!!") + newErr := fmt.Errorf("Failed to Find Any Volume Info on the Zone!!") cblogger.Error(newErr.Error()) return nil, newErr } @@ -751,7 +776,7 @@ func (diskHandler *KtCloudDiskHandler) getVolumeIdsWithVMId(vmId string) ([]stri } if len(volumeIds) < 1 { newErr := fmt.Errorf("Failed to Get Volume ID with the VM ID!!") - cblogger.Error(newErr.Error()) + cblogger.Debug(newErr.Error()) return nil, newErr } return volumeIds, nil diff --git a/cloud-control-manager/cloud-driver/drivers/ktcloud/resources/MyImageHandler.go b/cloud-control-manager/cloud-driver/drivers/ktcloud/resources/MyImageHandler.go index c7ecaa5c6..5329e1728 100644 --- a/cloud-control-manager/cloud-driver/drivers/ktcloud/resources/MyImageHandler.go +++ b/cloud-control-manager/cloud-driver/drivers/ktcloud/resources/MyImageHandler.go @@ -91,17 +91,19 @@ func (myImageHandler *KtCloudMyImageHandler) SnapshotVM(snapshotReqInfo irs.MyIm } // Add the Tag List according to the ReqInfo - tagHandler := KtCloudTagHandler { - RegionInfo: myImageHandler.RegionInfo, - Client: myImageHandler.Client, - } - _, createErr := tagHandler.createTagList(irs.RSType(irs.MYIMAGE), &imgResp.Createtemplateresponse.ID, snapshotReqInfo.TagList) - if err != nil { - newErr := fmt.Errorf("Failed to Add the Tag List on the Image : [%v]", createErr) - cblogger.Error(newErr.Error()) - return irs.MyImageInfo{}, newErr + if len(snapshotReqInfo.TagList) > 0 { + tagHandler := KtCloudTagHandler { + RegionInfo: myImageHandler.RegionInfo, + Client: myImageHandler.Client, + } + _, createErr := tagHandler.createTagList(irs.RSType(irs.MYIMAGE), &imgResp.Createtemplateresponse.ID, snapshotReqInfo.TagList) + if err != nil { + newErr := fmt.Errorf("Failed to Add the Tag List on the Image : [%v]", createErr) + cblogger.Error(newErr.Error()) + return irs.MyImageInfo{}, newErr + } + time.Sleep(time.Second * 1) } - time.Sleep(time.Second * 1) newImgIID := irs.IID{SystemId: imgResp.Createtemplateresponse.ID} myImageInfo, err := myImageHandler.GetMyImage(newImgIID) diff --git a/cloud-control-manager/cloud-driver/drivers/ktcloud/resources/VMHandler.go b/cloud-control-manager/cloud-driver/drivers/ktcloud/resources/VMHandler.go index ef358e3fc..1836d7abf 100644 --- a/cloud-control-manager/cloud-driver/drivers/ktcloud/resources/VMHandler.go +++ b/cloud-control-manager/cloud-driver/drivers/ktcloud/resources/VMHandler.go @@ -452,17 +452,19 @@ func (vmHandler *KtCloudVMHandler) StartVM(vmReqInfo irs.VMReqInfo) (irs.VMInfo, time.Sleep(time.Second * 10) // Add the Tag List according to the ReqInfo - tagHandler := KtCloudTagHandler { - RegionInfo: vmHandler.RegionInfo, - Client: vmHandler.Client, - } - _, createErr := tagHandler.createTagList(irs.RSType(irs.VM), &newVM.Deployvirtualmachineresponse.ID, vmReqInfo.TagList) - if err != nil { - newErr := fmt.Errorf("Failed to Add the Tag List on the VM : [%v]", createErr) - cblogger.Error(newErr.Error()) - return irs.VMInfo{}, newErr + if len(vmReqInfo.TagList) > 0 { + tagHandler := KtCloudTagHandler { + RegionInfo: vmHandler.RegionInfo, + Client: vmHandler.Client, + } + _, createErr := tagHandler.createTagList(irs.RSType(irs.VM), &newVM.Deployvirtualmachineresponse.ID, vmReqInfo.TagList) + if err != nil { + newErr := fmt.Errorf("Failed to Add the Tag List on the VM : [%v]", createErr) + cblogger.Error(newErr.Error()) + return irs.VMInfo{}, newErr + } + time.Sleep(time.Second * 1) } - time.Sleep(time.Second * 1) newVMInfo, error := vmHandler.GetVM(newVMIID) if error != nil { @@ -472,7 +474,6 @@ func (vmHandler *KtCloudVMHandler) StartVM(vmReqInfo irs.VMReqInfo) (irs.VMInfo, cblogger.Info("### VM Creation Processes have been Finished !!") return newVMInfo, nil } - return irs.VMInfo{}, err } func (vmHandler *KtCloudVMHandler) mappingVMInfo(KtCloudInstance *ktsdk.Virtualmachine) (irs.VMInfo, error) { @@ -562,6 +563,24 @@ func (vmHandler *KtCloudVMHandler) mappingVMInfo(KtCloudInstance *ktsdk.Virtualm rootDiskType = "HDD" } + // Set Display Name of the Zone + var zoneDisplaName string + if KtCloudInstance.ZoneName != "" { + if strings.EqualFold(KtCloudInstance.ZoneName, "kr-0") { // ??? + zoneDisplaName = "KOR-Seoul M" + } else if strings.EqualFold(KtCloudInstance.ZoneName, "kr-md2-1") { + zoneDisplaName = "KOR-Seoul M2" + } else if strings.EqualFold(KtCloudInstance.ZoneName, "kr-1") { + zoneDisplaName = "KOR-Central A" + } else if strings.EqualFold(KtCloudInstance.ZoneName, "kr-2") { + zoneDisplaName = "KOR-Central B" + } else if strings.EqualFold(KtCloudInstance.ZoneName, "kr-3") { + zoneDisplaName = "KOR-HA" + } else { + zoneDisplaName = KtCloudInstance.ZoneName + } + } + // To Set the VM resources Info. // PublicIpID : To use it when delete the PublicIP vmInfo := irs.VMInfo{ @@ -574,7 +593,7 @@ func (vmHandler *KtCloudVMHandler) mappingVMInfo(KtCloudInstance *ktsdk.Virtualm Region: irs.RegionInfo{ Region: vmHandler.RegionInfo.Region, - // Zone info is bellow. + Zone: KtCloudInstance.ZoneId, }, VMSpecName: vmSpecId, //Server Spec code @@ -607,10 +626,10 @@ func (vmHandler *KtCloudVMHandler) mappingVMInfo(KtCloudInstance *ktsdk.Virtualm {Key: "CpuSpeed", Value: strconv.FormatFloat(float64(KtCloudInstance.CpuSpeed), 'f', 0, 64)}, {Key: "MemorySize(GB)", Value: strconv.FormatFloat(float64(KtCloudInstance.Memory)/(1024), 'f', 0, 64)}, {Key: "KTCloudVMSpecInfo", Value: KtCloudInstance.ServiceOfferingName}, - {Key: "ZoneId", Value: KtCloudInstance.ZoneId}, {Key: "VMStatus", Value: vmStatus}, {Key: "VMNetworkID", Value: KtCloudInstance.Nic[0].NetworkId}, - {Key: "Hypervisor", Value: KtCloudInstance.Hypervisor}, + {Key: "Hypervisor", Value: KtCloudInstance.Hypervisor}, + {Key: "ZoneDisplaName", Value: zoneDisplaName}, // {Key: "VM Secondary IP", Value: KtCloudInstance.Nic[0].SecondaryIp}, // {Key: "PublicIpID", Value: publicIpId}, }, @@ -682,23 +701,6 @@ func (vmHandler *KtCloudVMHandler) mappingVMInfo(KtCloudInstance *ktsdk.Virtualm } vmInfo.DataDiskIIDs = diskIIDs - // Set VM Zone Info - if KtCloudInstance.ZoneName != "" { - if strings.EqualFold(KtCloudInstance.ZoneName, "kr-0") { // ??? - vmInfo.Region.Zone = "KOR-Seoul M" - } else if strings.EqualFold(KtCloudInstance.ZoneName, "kr-md2-1") { - vmInfo.Region.Zone = "KOR-Seoul M2" - } else if strings.EqualFold(KtCloudInstance.ZoneName, "kr-1") { - vmInfo.Region.Zone = "KOR-Central A" - } else if strings.EqualFold(KtCloudInstance.ZoneName, "kr-2") { - vmInfo.Region.Zone = "KOR-Central B" - } else if strings.EqualFold(KtCloudInstance.ZoneName, "kr-3") { - vmInfo.Region.Zone = "KOR-HA" - } else { - vmInfo.Region.Zone = KtCloudInstance.ZoneName - } - } - // Get the Tag List of the VM var kvList []irs.KeyValue tagHandler := KtCloudTagHandler { diff --git a/cloud-control-manager/cloud-driver/drivers/ktcloud/resources/VPCHandler.go b/cloud-control-manager/cloud-driver/drivers/ktcloud/resources/VPCHandler.go index e83d97f4c..9e3be3cbe 100644 --- a/cloud-control-manager/cloud-driver/drivers/ktcloud/resources/VPCHandler.go +++ b/cloud-control-manager/cloud-driver/drivers/ktcloud/resources/VPCHandler.go @@ -52,6 +52,7 @@ type VPCFileInfo struct { type Subnet struct { IID IId `json:"IId"` + Zone string `json:"Zone"` Cidr string `json:"IPv4_CIDR"` KeyValue_List []KeyValue `json:"KeyValueList"` } @@ -323,6 +324,7 @@ func (VPCHandler *KtCloudVPCHandler) CreateSubnet(subnetReqInfo irs.SubnetInfo) // Caution!! : subnetReqInfo.IId.NameId -> SystemId SystemId: subnetReqInfo.IId.NameId, }, + Zone: subnetReqInfo.Zone, IPv4_CIDR: "N/A", KeyValueList: []irs.KeyValue{ {Key: "KTCloud-Subnet-info.", Value: "This Subne info. is temporary."}, @@ -344,6 +346,7 @@ func (VPCHandler *KtCloudVPCHandler) mappingVPCInfo(vpcFileInfo VPCFileInfo) (ir for i := 0; i < len(vpcFileInfo.Subnet_List); i++ { subnetInfo.IId.NameId = vpcFileInfo.Subnet_List[i].IID.NameID subnetInfo.IId.SystemId = vpcFileInfo.Subnet_List[i].IID.SystemID + subnetInfo.Zone = vpcFileInfo.Subnet_List[i].Zone subnetInfo.IPv4_CIDR = vpcFileInfo.Subnet_List[i].Cidr for j := 0; j < len(vpcFileInfo.Subnet_List[i].KeyValue_List); j++ {