Skip to content

Commit

Permalink
Apply zone info for each infra resource
Browse files Browse the repository at this point in the history
  • Loading branch information
innodreamer committed Aug 26, 2024
1 parent 93cfe2b commit 2682115
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 57 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
Expand Up @@ -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) 드라이버 개발시 참고 사항
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down Expand Up @@ -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{
Expand All @@ -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
Expand Down Expand Up @@ -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},
},
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand Down Expand Up @@ -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."},
Expand All @@ -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++ {
Expand Down

0 comments on commit 2682115

Please sign in to comment.