Skip to content

Commit

Permalink
Merge pull request #1303 from innodreamer/master
Browse files Browse the repository at this point in the history
[KT Cloud Classic] Apply zone info to each infra resource info
  • Loading branch information
powerkimhub authored Aug 27, 2024
2 parents 7419878 + 2682115 commit c02c472
Showing 7 changed files with 98 additions and 63 deletions.
7 changes: 5 additions & 2 deletions cloud-control-manager/cloud-driver/drivers/ktcloud/README.md
Original file line number Diff line number Diff line change
@@ -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로부터 오류 발생
<p><br>

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)는 삭제할 수 없음.
<p><br>

#### # KT Cloud Classic (G1/G2) 드라이버 개발시 참고 사항
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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 {
Original file line number Diff line number Diff line change
@@ -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++ {
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -70,7 +70,7 @@ require (
github.com/alibabacloud-go/ecs-20140526/v4 v4.24.17
github.com/alibabacloud-go/tea v1.2.2
github.com/alibabacloud-go/vpc-20160428/v6 v6.4.0
github.com/cloud-barista/ktcloud-sdk-go v0.2.1-0.20240819125322-850a4e70f35b
github.com/cloud-barista/ktcloud-sdk-go v0.2.1-0.20240826073400-9dd317d24d0a
github.com/cloud-barista/ktcloudvpc-sdk-go v0.0.0-20240812121947-01daa5e57030
github.com/cloud-barista/nhncloud-sdk-go v0.0.0-20240709053216-536bc37fa6c9
github.com/go-openapi/strfmt v0.21.3
@@ -193,7 +193,7 @@ require (
go.opencensus.io v0.24.0 // indirect
go.uber.org/atomic v1.11.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/term v0.22.0 // indirect
golang.org/x/text v0.17.0 // indirect
golang.org/x/time v0.5.0 // indirect
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -187,8 +187,8 @@ github.com/clbanning/mxj/v2 v2.7.0/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cloud-barista/cb-log v0.8.2 h1:hPCbLj6TW6m9UWlq002sDuGgxKFVp68w4V3k493+MxY=
github.com/cloud-barista/cb-log v0.8.2/go.mod h1:nGgfTFMPwl1MpCO3FBjexUkNdOYA0BNJoyM9Pd0lMms=
github.com/cloud-barista/ktcloud-sdk-go v0.2.1-0.20240819125322-850a4e70f35b h1:7FS2TiSnFz8XMbi0saOpQ03e0+kPm5jIJGvv1dKUaiE=
github.com/cloud-barista/ktcloud-sdk-go v0.2.1-0.20240819125322-850a4e70f35b/go.mod h1:ZIrUxItUvMIGZyX6Re7tUdcS3cwBIzBPcL+Pk/6lt/8=
github.com/cloud-barista/ktcloud-sdk-go v0.2.1-0.20240826073400-9dd317d24d0a h1:7sm+NSqmjuktaERMdTayiqsKmfgmFLMBzHrpG85Z5do=
github.com/cloud-barista/ktcloud-sdk-go v0.2.1-0.20240826073400-9dd317d24d0a/go.mod h1:ZIrUxItUvMIGZyX6Re7tUdcS3cwBIzBPcL+Pk/6lt/8=
github.com/cloud-barista/ktcloudvpc-sdk-go v0.0.0-20240812121947-01daa5e57030 h1:KZSxMftDrIKpk0+qW0rt3UX/e2QsHolvesazvl2av4s=
github.com/cloud-barista/ktcloudvpc-sdk-go v0.0.0-20240812121947-01daa5e57030/go.mod h1:SDTNI+0ZyoEWhQKHASGwhS1a9kad+mxsXCKSfnpWnSA=
github.com/cloud-barista/nhncloud-sdk-go v0.0.0-20240709053216-536bc37fa6c9 h1:br7+CBDJEXofGPWUj79sldxuvrj4GNktmF6T8zVrVOk=
@@ -1045,8 +1045,8 @@ golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=

0 comments on commit c02c472

Please sign in to comment.