Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
powerkimhub committed Sep 29, 2022
2 parents 3278174 + bb2d5bd commit c34717c
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ create 시 특정 instance에 바로 attach 가능하나 CB-SPIDER에서는 사
func (diskHandler *AlibabaDiskHandler) CreateDisk(diskReqInfo irs.DiskInfo) (irs.DiskInfo, error) {
cblogger.Info("Start CreateDisk : ", diskReqInfo)

err := validateCreateDisk(diskReqInfo)
err := validateCreateDisk(&diskReqInfo)
if err != nil {
return irs.DiskInfo{}, err
}
Expand Down Expand Up @@ -475,7 +475,7 @@ Disk 생성시 validation check
- DiskType
- DiskType 별 min/max capacity check
*/
func validateCreateDisk(diskReqInfo irs.DiskInfo) error {
func validateCreateDisk(diskReqInfo *irs.DiskInfo) error {
// Check Disk Exists

cloudOSMetaInfo, err := cim.GetCloudOSMetaInfo("ALIBABA")
Expand All @@ -484,18 +484,32 @@ func validateCreateDisk(diskReqInfo irs.DiskInfo) error {

arrDiskType := cloudOSMetaInfo.DiskType
arrDiskSizeOfType := cloudOSMetaInfo.DiskSize
arrRootDiskSizeOfType := cloudOSMetaInfo.RootDiskSize
// Check Disk available
// Size :
// DiskCategory : cloud / cloud_efficiency / cloud_ssd / cloud_essd
// valid size : cloud 5 ~ 2000, cloud_efficiency 20 ~ 32768, cloud_ssd 20 ~ 32768, cloud_essd

reqDiskCategory := diskReqInfo.DiskType
diskSize := diskReqInfo.DiskSize

if reqDiskCategory == "" || reqDiskCategory == "default" {
diskSizeArr := strings.Split(arrRootDiskSizeOfType[0], "|")
reqDiskCategory = diskSizeArr[0] // ESSD
diskReqInfo.DiskType = diskSizeArr[0] // set default value
}
// 정의된 type인지
if !ContainString(arrDiskType, diskReqInfo.DiskType) {
return errors.New("Disktype : " + diskReqInfo.DiskType + "' is not valid")
if !ContainString(arrDiskType, reqDiskCategory) {
return errors.New("Disktype : " + reqDiskCategory + "' is not valid")
}

reqDiskCategory := diskReqInfo.DiskType
reqDiskSize, err := strconv.ParseInt(diskReqInfo.DiskSize, 10, 64)
if diskSize == "" || diskSize == "default" {
diskSizeArr := strings.Split(arrRootDiskSizeOfType[0], "|")
diskSize = diskSizeArr[1]
diskReqInfo.DiskSize = diskSizeArr[1] // set default value
}

reqDiskSize, err := strconv.ParseInt(diskSize, 10, 64)
if err != nil {
return err
}
Expand All @@ -509,7 +523,8 @@ func validateCreateDisk(diskReqInfo irs.DiskInfo) error {
case "cloud_essd":
// cloud_essd 는 performanceLevel(PL0, PL1, PL2, PL3) 에 따라 또 다시 min/max가 생김.
// cb-spider는 performanceLevel을 관리하지 않으므로 기본값인 PL2 를 사용한다.
reqDiskType += "_PL2"
// console 상 attach disk의 default는 PL1
reqDiskType += "_PL1"
}

if strings.EqualFold(reqDiskType, diskSizeArr[0]) {
Expand All @@ -531,7 +546,7 @@ func validateCreateDisk(diskReqInfo irs.DiskInfo) error {
}

if !isExists {
return errors.New("Invalid Root Disk Type : " + diskReqInfo.DiskType)
return errors.New("Invalid Disk Type : " + diskReqInfo.DiskType)
}

if reqDiskSize < diskSizeValue.diskMinSize {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (DiskHandler *AwsDiskHandler) CreateDisk(diskReqInfo irs.DiskInfo) (irs.Dis

zone := DiskHandler.Region.Zone
spew.Dump(DiskHandler.Region)
err := validateCreateDisk(diskReqInfo)
err := validateCreateDisk(&diskReqInfo)
if err != nil {
return irs.DiskInfo{}, err
}
Expand Down Expand Up @@ -460,21 +460,40 @@ Throughput
This parameter is valid only for gp3 volumes.
Valid Range: Minimum value of 125. Maximum value of 1000.
*/
func validateCreateDisk(diskReqInfo irs.DiskInfo) error {
func validateCreateDisk(diskReqInfo *irs.DiskInfo) error {
// VolumeType
cloudOSMetaInfo, err := cim.GetCloudOSMetaInfo("AWS")
arrDiskType := cloudOSMetaInfo.DiskType
arrRootDiskType := cloudOSMetaInfo.RootDiskType
arrDiskSizeOfType := cloudOSMetaInfo.DiskSize

cblogger.Info(arrDiskType)
reqDiskType := diskReqInfo.DiskType
reqDiskSize := diskReqInfo.DiskSize
if reqDiskType == "" || reqDiskType == "default" {
reqDiskType = arrRootDiskType[0]
diskReqInfo.DiskType = arrRootDiskType[0]
}

// 정의된 type인지
if !ContainString(arrDiskType, diskReqInfo.DiskType) {
return errors.New("Disktype : " + diskReqInfo.DiskType + "' is not valid")
if !ContainString(arrDiskType, reqDiskType) {
return errors.New("Disktype : " + reqDiskType + " is not valid")
}

if reqDiskSize == "" || reqDiskSize == "default" {
for _, diskSizeInfo := range arrDiskSizeOfType {
diskSizeArr := strings.Split(diskSizeInfo, "|")
if strings.EqualFold(reqDiskType, diskSizeArr[0]) {
reqDiskSize = diskSizeArr[1]
diskReqInfo.DiskSize = diskSizeArr[1] // set default value
break
}
}

}

// volume Size
volumeSize, err := strconv.ParseInt(diskReqInfo.DiskSize, 10, 64)
volumeSize, err := strconv.ParseInt(reqDiskSize, 10, 64)
if err != nil {
return err
}
Expand Down Expand Up @@ -513,12 +532,12 @@ func validateCreateDisk(diskReqInfo irs.DiskInfo) error {

if volumeSize < diskSizeValue.diskMinSize {
fmt.Println("Disk Size Error!!: ", volumeSize, diskSizeValue.diskMinSize, diskSizeValue.diskMaxSize)
return errors.New("Root Disk Size must be at least the default size (" + strconv.FormatInt(diskSizeValue.diskMinSize, 10) + " GB).")
return errors.New("Disk Size must be at least the default size (" + strconv.FormatInt(diskSizeValue.diskMinSize, 10) + " GB).")
}

if volumeSize > diskSizeValue.diskMaxSize {
fmt.Println("Disk Size Error!!: ", volumeSize, diskSizeValue.diskMinSize, diskSizeValue.diskMaxSize)
return errors.New("Root Disk Size must be smaller than the maximum size (" + strconv.FormatInt(diskSizeValue.diskMaxSize, 10) + " GB).")
return errors.New("Disk Size must be smaller than the maximum size (" + strconv.FormatInt(diskSizeValue.diskMaxSize, 10) + " GB).")
}

//switch diskReqInfo.DiskType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const CBDefaultSubnetName string = "CB-VNet-Subnet" // CB Default Subnet Name
const CBDefaultCidrBlock string = "192.168.0.0/16" // CB Default CidrBlock

// 2021-10-27 이슈#480에 의해 Local Key 로직 제거
//const CBKeyPairPath string = "/meta_db/.ssh-tencent/"
// const CBKeyPairPath string = "/meta_db/.ssh-tencent/"
const CBCloudInitFilePath string = "/cloud-driver-libs/.cloud-init-tencent/cloud-init"
const CBDefaultVmUserName string = "cb-user" // default VM User Name

Expand All @@ -45,12 +45,12 @@ type TencentCBNetworkInfo struct {
const CUSTOM_ERR_CODE_TOOMANY string = "600" //"n개 이상의 xxxx 정보가 존재합니다."
const CUSTOM_ERR_CODE_NOTFOUND string = "404" //"XXX 정보가 존재하지 않습니다."

//VPC
// VPC
func GetCBDefaultVNetName() string {
return CBDefaultVNetName
}

//Subnet
// Subnet
func GetCBDefaultSubnetName() string {
return CBDefaultSubnetName
}
Expand All @@ -67,7 +67,7 @@ func JSONMarshal(t interface{}) ([]byte, error) {
return buffer.Bytes(), err
}

//Cloud Object를 JSON String 타입으로 변환
// Cloud Object를 JSON String 타입으로 변환
func ConvertJsonStringNoEscape(v interface{}) (string, error) {
//jsonBytes, errJson := json.Marshal(v)

Expand All @@ -92,7 +92,7 @@ func ConvertJsonStringNoEscape(v interface{}) (string, error) {
return jsonString, nil
}

//Cloud Object를 JSON String 타입으로 변환
// Cloud Object를 JSON String 타입으로 변환
func ConvertJsonString(v interface{}) (string, error) {
jsonBytes, errJson := json.Marshal(v)

Expand All @@ -107,7 +107,7 @@ func ConvertJsonString(v interface{}) (string, error) {
return jsonString, nil
}

//CB-KeyValue 등을 위해 String 타입으로 변환
// CB-KeyValue 등을 위해 String 타입으로 변환
func ConvertToString(value interface{}) (string, error) {
if value == nil {
cblogger.Debugf("Nil Value")
Expand All @@ -133,7 +133,7 @@ func ConvertToString(value interface{}) (string, error) {
return result, nil
}

//Cloud Object를 CB-KeyValue 형식으로 변환이 필요할 경우 이용
// Cloud Object를 CB-KeyValue 형식으로 변환이 필요할 경우 이용
func ConvertKeyValueList(v interface{}) ([]irs.KeyValue, error) {
//spew.Dump(v)
var keyValueList []irs.KeyValue
Expand Down Expand Up @@ -181,3 +181,15 @@ func ConvertKeyValueList(v interface{}) ([]irs.KeyValue, error) {

return keyValueList, nil
}

// array에 주어진 string이 있는지 체크
func ContainString(s []string, str string) bool {
for _, v := range s {
cblogger.Info(v + " : " + str)
cblogger.Info(v == str)
if v == str {
return true
}
}
return false
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ const (
)

/*
CreateDisk 이후에 DescribeDisks 호출하여 상태가 UNATTACHED 또는 ATTACHED면 정상적으로 생성된 것임
비동기로 처리되기는 하나 생성 직후 호출해도 정상적으로 상태값을 받아옴
따라서 Operation이 완료되길 기다리는 function(WaitForXXX)은 만들지 않음
CreateDisk 이후에 DescribeDisks 호출하여 상태가 UNATTACHED 또는 ATTACHED면 정상적으로 생성된 것임
비동기로 처리되기는 하나 생성 직후 호출해도 정상적으로 상태값을 받아옴
따라서 Operation이 완료되길 기다리는 function(WaitForXXX)은 만들지 않음
*/
func (DiskHandler *TencentDiskHandler) CreateDisk(diskReqInfo irs.DiskInfo) (irs.DiskInfo, error) {

Expand All @@ -43,13 +43,11 @@ func (DiskHandler *TencentDiskHandler) CreateDisk(diskReqInfo irs.DiskInfo) (irs
request := cbs.NewCreateDisksRequest()
request.Placement = &cbs.Placement{Zone: common.StringPtr(DiskHandler.Region.Zone)}
request.DiskChargeType = common.StringPtr("POSTPAID_BY_HOUR")
request.DiskType = common.StringPtr(diskReqInfo.DiskType)
request.DiskName = common.StringPtr(diskReqInfo.IId.NameId)

diskSizeErr := validateDiskSize(diskReqInfo)
if diskSizeErr != nil {
cblogger.Error(diskSizeErr)
return irs.DiskInfo{}, diskSizeErr
diskErr := validateDisk(&diskReqInfo)
if diskErr != nil {
cblogger.Error(diskErr)
return irs.DiskInfo{}, diskErr
}

diskSize, sizeErr := strconv.ParseUint(diskReqInfo.DiskSize, 10, 64)
Expand All @@ -58,6 +56,8 @@ func (DiskHandler *TencentDiskHandler) CreateDisk(diskReqInfo irs.DiskInfo) (irs
}

request.DiskSize = common.Uint64Ptr(diskSize)
request.DiskType = common.StringPtr(diskReqInfo.DiskType)
request.DiskName = common.StringPtr(diskReqInfo.IId.NameId)

response, err := DiskHandler.Client.CreateDisks(request)
if err != nil {
Expand Down Expand Up @@ -227,11 +227,32 @@ func convertTenStatusToDiskStatus(diskInfo *cbs.Disk) irs.DiskStatus {
return returnStatus
}

func validateDiskSize(diskInfo irs.DiskInfo) error {
func validateDisk(diskReqInfo *irs.DiskInfo) error {
cloudOSMetaInfo, err := cim.GetCloudOSMetaInfo("TENCENT")
arrDiskType := cloudOSMetaInfo.DiskType
arrDiskSizeOfType := cloudOSMetaInfo.DiskSize
arrRootDiskSizeOfType := cloudOSMetaInfo.RootDiskSize

diskSize, err := strconv.ParseInt(diskInfo.DiskSize, 10, 64)
reqDiskType := diskReqInfo.DiskType
reqDiskSize := diskReqInfo.DiskSize

if reqDiskType == "" || reqDiskType == "default" {
diskSizeArr := strings.Split(arrRootDiskSizeOfType[0], "|")
reqDiskType = diskSizeArr[0] //
diskReqInfo.DiskType = diskSizeArr[0] // set default value
}
// 정의된 type인지
if !ContainString(arrDiskType, reqDiskType) {
return errors.New("Disktype : " + reqDiskType + "' is not valid")
}

if reqDiskSize == "" || reqDiskSize == "default" {
diskSizeArr := strings.Split(arrRootDiskSizeOfType[0], "|")
reqDiskSize = diskSizeArr[1]
diskReqInfo.DiskSize = diskSizeArr[1] // set default value
}

diskSize, err := strconv.ParseInt(reqDiskSize, 10, 64)
if err != nil {
cblogger.Error(err)
return err
Expand All @@ -249,7 +270,7 @@ func validateDiskSize(diskInfo irs.DiskInfo) error {

for _, diskSizeInfo := range arrDiskSizeOfType {
diskSizeArr := strings.Split(diskSizeInfo, "|")
if strings.EqualFold(diskInfo.DiskType, diskSizeArr[0]) {
if strings.EqualFold(reqDiskType, diskSizeArr[0]) {
diskSizeValue.diskType = diskSizeArr[0]
diskSizeValue.unit = diskSizeArr[3]
diskSizeValue.diskMinSize, err = strconv.ParseInt(diskSizeArr[1], 10, 64)
Expand All @@ -268,7 +289,7 @@ func validateDiskSize(diskInfo irs.DiskInfo) error {
}

if !isExists {
return errors.New("Invalid Disk Type : " + diskInfo.DiskType)
return errors.New("Invalid Disk Type : " + reqDiskType)
}

if diskSize < diskSizeValue.diskMinSize {
Expand Down Expand Up @@ -341,8 +362,8 @@ func validateChangeDiskSize(diskInfo irs.DiskInfo, newSize string) error {
}

/*
disk가 존재하는지 check
동일이름이 없으면 false, 있으면 true
disk가 존재하는지 check
동일이름이 없으면 false, 있으면 true
*/
func (DiskHandler *TencentDiskHandler) diskExist(chkName string) (bool, error) {
cblogger.Debugf("chkName : %s", chkName)
Expand Down

0 comments on commit c34717c

Please sign in to comment.