Skip to content

Commit

Permalink
Merge pull request #1287 from innodreamer/master
Browse files Browse the repository at this point in the history
[KT Cloud Classic] Update Tagging features - Appy TagList after Creation process of VM, MyImage and Disk volume
  • Loading branch information
powerkimhub authored Aug 20, 2024
2 parents 1b016bb + ce29512 commit 345ad57
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 21 deletions.
4 changes: 4 additions & 0 deletions cloud-control-manager/cloud-driver/drivers/ktcloud/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ $GOPATH/src/github.com/cloud-barista/ktcloud/ktcloud/main/
- https://cloud.kt.com/docs/open-api-guide/g/computing/disk-volume
<p><br>

O VM을 대상으로 MyImage 생성시 주의할 점
- KT Cloud Classic 클라우드 서비스에서는 VM이 중지된(Suspended) 상태에서만 MyImage 생성이 가능함.
<p><br>

#### # KT Cloud Classic (G1/G2) 드라이버 개발시 참고 사항
​ O 생성되는 VM의 root disk(volume) type 정보
- KT Cloud Volume 정보에서 root disk의 type 정보는 제공하지 않음.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,19 @@ func (diskHandler *KtCloudDiskHandler) CreateDisk(diskReqInfo irs.DiskInfo) (irs
return irs.DiskInfo{}, waitErr
}

// 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
}
time.Sleep(time.Second * 1)

newVolumeIID := irs.IID{SystemId: createVolumeResponse.Createvolumeresponse.ID}
newDiskInfo, err := diskHandler.GetDisk(newVolumeIID)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,19 @@ func (myImageHandler *KtCloudMyImageHandler) SnapshotVM(snapshotReqInfo irs.MyIm
return irs.MyImageInfo{}, waitErr
}

// 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
}
time.Sleep(time.Second * 1)

newImgIID := irs.IID{SystemId: imgResp.Createtemplateresponse.ID}
myImageInfo, err := myImageHandler.GetMyImage(newImgIID)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@ func (tagHandler *KtCloudTagHandler) AddTag(resType irs.RSType, resIID irs.IID,
return irs.KeyValue{}, newErr
}

if (resType != irs.VM) && (resType != irs.MYIMAGE) && (resType != irs.DISK) {
newErr := fmt.Errorf("Only 'VM', 'MyImage' and 'Disk' type are supported as a resource type to Add a Tag Info on KT Classic!!")
cblogger.Error(newErr.Error())
return irs.KeyValue{}, newErr
}

if strings.EqualFold(resIID.SystemId, "") {
newErr := fmt.Errorf("Invalid Resource SystemId!!")
cblogger.Error(newErr.Error())
Expand Down Expand Up @@ -273,11 +267,11 @@ func (tagHandler *KtCloudTagHandler) createTagList(resType irs.RSType, resID *st

var rsType string
switch resType {
case irs.VM:
case irs.VM, "VM":
rsType = VM
case irs.MYIMAGE:
case irs.MYIMAGE, "MYIMAGE":
rsType = MyImage
case irs.DISK:
case irs.DISK, "DISK":
rsType = DISK
default:
newErr := fmt.Errorf("Invalid Resource Type. [%v] type is Not Supported on KT Cloud for Tagging!!", resType)
Expand Down Expand Up @@ -327,11 +321,11 @@ func (tagHandler *KtCloudTagHandler) getTagList(resType irs.RSType) ([]ktsdk.Tag

var rsType string
switch resType {
case irs.VM:
case irs.VM, "VM":
rsType = VM
case irs.MYIMAGE:
case irs.MYIMAGE, "MYIMAGE":
rsType = MyImage
case irs.DISK:
case irs.DISK, "DISK":
rsType = DISK
default:
newErr := fmt.Errorf("Invalid Resource Type. [%v] type is Not Supported on KT Cloud for Tagging!!", resType)
Expand Down Expand Up @@ -361,11 +355,11 @@ func (tagHandler *KtCloudTagHandler) getTagListWithResId(resType irs.RSType, res

var rsType string
switch resType {
case irs.VM:
case irs.VM, "VM":
rsType = VM
case irs.MYIMAGE:
case irs.MYIMAGE, "MYIMAGE":
rsType = MyImage
case irs.DISK:
case irs.DISK, "DISK":
rsType = DISK
default:
newErr := fmt.Errorf("Invalid Resource Type. [%v] type is Not Supported on KT Cloud for Tagging!!", resType)
Expand Down Expand Up @@ -396,11 +390,11 @@ func (tagHandler *KtCloudTagHandler) getTagValue(resType irs.RSType, resourceID

var rsType string
switch resType {
case irs.VM:
case irs.VM, "VM":
rsType = VM
case irs.MYIMAGE:
case irs.MYIMAGE, "MYIMAGE":
rsType = MyImage
case irs.DISK:
case irs.DISK, "DISK":
rsType = DISK
default:
newErr := fmt.Errorf("Invalid Resource Type. [%v] type is Not Supported on KT Cloud for Tagging!!", resType)
Expand Down Expand Up @@ -432,11 +426,11 @@ func (tagHandler *KtCloudTagHandler) deleteTag(resType irs.RSType, resID *string

var rsType string
switch resType {
case irs.VM:
case irs.VM, "VM":
rsType = VM
case irs.MYIMAGE:
case irs.MYIMAGE, "MYIMAGE":
rsType = MyImage
case irs.DISK:
case irs.DISK, "DISK":
rsType = DISK
default:
newErr := fmt.Errorf("Invalid Resource Type. [%v] type is Not Supported on KT Cloud for Tagging!!", resType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,19 @@ func (vmHandler *KtCloudVMHandler) StartVM(vmReqInfo irs.VMReqInfo) (irs.VMInfo,
cblogger.Info("\n\n### Waiting for Setting New PublicIP and Firewall Rules on KT Cloud!!")
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
}
time.Sleep(time.Second * 1)

newVMInfo, error := vmHandler.GetVM(newVMIID)
if error != nil {
cblogger.Errorf("Failed to Get Created VM Info : [%v]", err)
Expand Down

0 comments on commit 345ad57

Please sign in to comment.