Skip to content

Commit

Permalink
Merge pull request #1271 from innodreamer/ncp-tagging
Browse files Browse the repository at this point in the history
[Ncp Classic] Update TagHandler and Apply it to VMHandler
  • Loading branch information
powerkimhub authored Aug 8, 2024
2 parents d09d567 + 239c166 commit 0cc8b29
Show file tree
Hide file tree
Showing 6 changed files with 359 additions and 198 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (cloudConn *NcpCloudConnection) CreatePriceInfoHandler() (irs.PriceInfoHand
func (cloudConn *NcpCloudConnection) CreateTagHandler() (irs.TagHandler, error) {
cblogger.Info("NCP Cloud Driver: called CreateTagHandler()!")

tagHandler := ncprs.NcpTagHandler{cloudConn.CredentialInfo, cloudConn.RegionInfo, cloudConn.VmClient}
tagHandler := ncprs.NcpTagHandler{cloudConn.RegionInfo, cloudConn.VmClient}
return &tagHandler, nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ func handleTag() {

rsIId := irs.IID{
NameId: "MyVM-1",
SystemId: "25453063",
// SystemId: "25504672",
SystemId: "25927580",
}

tagKV := irs.KeyValue{
Expand All @@ -75,7 +76,7 @@ func handleTag() {

tagKey := "VPCNameTest"

keyword := "VPC"
keyword := "vpc"

inputCnt, err := fmt.Scan(&commandNum)
if err != nil {
Expand Down
163 changes: 88 additions & 75 deletions cloud-control-manager/cloud-driver/drivers/ncp/main/Test_VMHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func handleVM() {
fmt.Println("============================================================================================")

//config := readConfigFile()
VmID := irs.IID{SystemId: "19313606"}
VmID := irs.IID{SystemId: "25504672"}

var commandNum int
inputCnt, err := fmt.Scan(&commandNum)
Expand All @@ -77,97 +77,111 @@ func handleVM() {
panic(err)
}

if inputCnt == 1 {
switch commandNum {
case 0:
return
vmReqInfo := irs.VMReqInfo{
// ImageType: irs.MyImage,
ImageType: irs.PublicImage,

case 1:
vmReqInfo := irs.VMReqInfo{
// ImageType: irs.MyImage,
ImageType: irs.PublicImage,
// # NCP에서는 VM instance 이름에 대문자 허용 안되므로 VMHandler 내부에서 소문자로 변환되어 반영됨.
// Caution!! : Under bar 문자 허용 안됨.
IId: irs.IID{NameId: "ncp-test-vm-10"},

// # NCP에서는 VM instance 이름에 대문자 허용 안되므로 VMHandler 내부에서 소문자로 변환되어 반영됨.
// Caution!! : Under bar 문자 허용 안됨.
IId: irs.IID{NameId: "ncp-test-vm-007"},
// Caution!!) /home/sean/go/src/github.com/cloud-barista/ncp/ncp/main/config/config.yaml 에서 해당 region을 설정해야 그 region에 VM이 생성됨.

// Caution!!) /home/sean/go/src/github.com/cloud-barista/ncp/ncp/main/config/config.yaml 에서 해당 region을 설정해야 그 region에 VM이 생성됨.
//(참고) When Region is 'DEN'.
//VMSpec := "SPSVRSTAND000063" vCPU 8EA, Memory 64GB, [SSD]Disk 50GB",
//Image ID : SPSW0LINUX000031

//(참고) When Region is 'DEN'.
//VMSpec := "SPSVRSTAND000063" vCPU 8EA, Memory 64GB, [SSD]Disk 50GB",
//Image ID : SPSW0LINUX000031
// KR
// ImageIID: irs.IID{NameId: "Ubuntu Server 18.04 (64-bit)", SystemId: "SPSW0LINUX000130"}, // $$$ PublicImage $$$
// VMSpecName: "SPSVRSTAND000006",

// KR
ImageIID: irs.IID{NameId: "Ubuntu Server 18.04 (64-bit)", SystemId: "SPSW0LINUX000130"}, // $$$ PublicImage $$$
VMSpecName: "SPSVRSTAND000073",
// KR
ImageIID: irs.IID{NameId: "CentOS 7.8 (64-bit)", SystemId: "SPSW0LINUX000139"}, // $$$ PublicImage $$$
VMSpecName: "SPSVRSTAND000005",

// KR
// ImageIID: irs.IID{NameId: "Windows Server 2012 (64bit) R2 English Edition", SystemId: "SPSW0WINNTEN0015A"},
// VMSpecName: "SPSVRSTAND000005A",
// KR
// ImageIID: irs.IID{NameId: "Windows Server 2016 (64-bit) English Edition", SystemId: "SPSW0WINNTEN0016A"}, // $$$ PublicImage $$$
// SPSW0WINNTEN0016A - 'Windows' Server 2016 (64-bit) English Edition
// # VMSpecName: "SPSVRSSD00000005A" // 상기 win server와 호환

// KR
// ImageIID: irs.IID{NameId: "Windows Server (64bit)", SystemId: "96215"}, // $$$ MyImage $$$
// VMSpecName: "SPSVRSTAND000005A",
// KR
// ImageIID: irs.IID{NameId: "Windows Server 2012 (64bit) R2 English Edition", SystemId: "SPSW0WINNTEN0015A"},
// VMSpecName: "SPSVRSTAND000005A",

// USWN
//ImageIID: irs.IID{NameId: "Ubuntu Server 18.04 (64-bit)", SystemId: "SPSW0LINUX000130"},
//VMSpecName: "SPSVRSTAND000025",
// KR
// ImageIID: irs.IID{NameId: "Windows Server (64bit)", SystemId: "96215"}, // $$$ MyImage $$$
// VMSpecName: "SPSVRSTAND000005A",

// USWN
//ImageIID: irs.IID{NameId: "WordPress-Ubuntu-16.04-64", SystemId: "SPSW0LINUX000088"},
//VMSpecName: "SPSVRSTAND000050",
// USWN
//ImageIID: irs.IID{NameId: "Ubuntu Server 18.04 (64-bit)", SystemId: "SPSW0LINUX000130"},
//VMSpecName: "SPSVRSTAND000025",

// DEN :
//ImageIID: irs.IID{NameId: "Ubuntu Server 18.04 (64-bit)", SystemId: "SPSW0LINUX000130"},
//VMSpecName: "SPSVRSTAND000025",
// USWN
//ImageIID: irs.IID{NameId: "WordPress-Ubuntu-16.04-64", SystemId: "SPSW0LINUX000088"},
//VMSpecName: "SPSVRSTAND000050",

// DEN :
//ImageIID: irs.IID{NameId: "centOS-6.3-64", SystemId: "SPSW0LINUX000031"},
//VMSpecName: "SPSVRSSD00000006",
// DEN :
//ImageIID: irs.IID{NameId: "Ubuntu Server 18.04 (64-bit)", SystemId: "SPSW0LINUX000130"},
//VMSpecName: "SPSVRSTAND000025",

// JPN
//ImageIID: irs.IID{NameId: "Ubuntu Server 18.04 (64-bit)", SystemId: "SPSW0LINUX000130"},
//VMSpecName: "SPSVRSTAND000025",
// DEN :
//ImageIID: irs.IID{NameId: "centOS-6.3-64", SystemId: "SPSW0LINUX000031"},
//VMSpecName: "SPSVRSSD00000006",

// SGN
//ImageIID: irs.IID{NameId: "Ubuntu Server 18.04 (64-bit)", SystemId: "SPSW0LINUX000130"},
//VMSpecName: "SPSVRSTAND000025",
// JPN
//ImageIID: irs.IID{NameId: "Ubuntu Server 18.04 (64-bit)", SystemId: "SPSW0LINUX000130"},
//VMSpecName: "SPSVRSTAND000025",

// HK
//ImageIID: irs.IID{NameId: "ubuntu-16.04", SystemId: "SPSW0LINUX000095"},
//VMSpecName: "SPSVRSTAND000052",
// SGN
//ImageIID: irs.IID{NameId: "Ubuntu Server 18.04 (64-bit)", SystemId: "SPSW0LINUX000130"},
//VMSpecName: "SPSVRSTAND000025",

KeyPairIID: irs.IID{SystemId: "NCP-keypair-06"},
// KeyPairIID: irs.IID{SystemId: "ncp-key-0-cjheqe9jcupqtmoaa6bg"},
// HK
//ImageIID: irs.IID{NameId: "ubuntu-16.04", SystemId: "SPSW0LINUX000095"},
//VMSpecName: "SPSVRSTAND000052",

// # NCP Classic 2세대 service에서 subnet, VPC 지정은 미지원
VpcIID: irs.IID{SystemId: "vpc-01-cdn00lhjcupqjjlde1rg"},
SubnetIID: irs.IID{SystemId: "subnet-01-cdn00lhjcupqjjlde1s0"},
KeyPairIID: irs.IID{SystemId: "oh-keypai-cqccsj4vtts7hk9ghtmg"},
// KeyPairIID: irs.IID{SystemId: "ncp-key-0-cjheqe9jcupqtmoaa6bg"},

// SecurityGroupIIDs 미지정시, NCP default 값으로서 "ncloud-default-acg"인 "293807이 적용됨.
// SecurityGroupIIDs: []irs.IID{{SystemId: "293807"},{SystemId: "332703"}},
SecurityGroupIIDs: []irs.IID{{SystemId: "1333707"}},
// # NCP Classic 2세대 service에서 subnet, VPC 지정은 미지원
VpcIID: irs.IID{SystemId: "oh-vpc-01-cqab15kvtts35l1k5c6g"},
SubnetIID: irs.IID{SystemId: "oh-subnet-cqab15kvtts35l1k5c70"},

VMUserPasswd: "abcd000abcd",
}
// SecurityGroupIIDs 미지정시, NCP default 값으로서 "ncloud-default-acg"인 "293807이 적용됨.
// SecurityGroupIIDs: []irs.IID{{SystemId: "293807"},{SystemId: "332703"}},
SecurityGroupIIDs: []irs.IID{{SystemId: "1333707"}},

VMUserPasswd: "abcd000abcd",

TagList: []irs.KeyValue{
{ Key: "aaa", Value: "aaaAAAAA"},
{ Key: "ccc", Value: "cccCCCCC"},
},
}

if inputCnt == 1 {
switch commandNum {
case 0:
return

case 1:
vmInfo, err := vmHandler.StartVM(vmReqInfo)
if err != nil {
//panic(err)
cblogger.Error(err)
} else {
cblogger.Info("VM 생성 완료!!", vmInfo)
cblogger.Info("Succeeded in VM Creation!!", vmInfo)
spew.Dump(vmInfo)
}
cblogger.Info("\nCreateVM Test Finished")

case 2:
vmInfo, err := vmHandler.GetVM(VmID)
if err != nil {
cblogger.Errorf("[%s] VM info. 조회 실패", VmID)
cblogger.Errorf("[%s] Failed to Get VM info!!", VmID)
cblogger.Error(err)
} else {
cblogger.Infof("[%s] VM info. 조회 결과", VmID)
cblogger.Infof("[%s] Result : ", VmID)
spew.Dump(vmInfo)
}
cblogger.Info("\nGetVM Test Finished")
Expand All @@ -176,65 +190,65 @@ func handleVM() {
cblogger.Info("Start Suspend VM ...")
result, err := vmHandler.SuspendVM(VmID)
if err != nil {
cblogger.Errorf("[%s] VM Suspend 실패 - [%s]", VmID, result)
cblogger.Errorf("[%s] Failed to Suspend VM : [%s]", VmID, result)
cblogger.Error(err)
} else {
cblogger.Infof("[%s] VM Suspend 실행 성공 - [%s]", VmID, result)
cblogger.Infof("[%s] Succeeded in VM Suspend : [%s]", VmID, result)
}
cblogger.Info("\nSuspendVM Test Finished")

case 4:
cblogger.Info("Start Resume VM ...")
result, err := vmHandler.ResumeVM(VmID)
if err != nil {
cblogger.Errorf("[%s] VM Resume 실패 - [%s]", VmID, result)
cblogger.Errorf("[%s] Failed to Resume VM : [%s]", VmID, result)
cblogger.Error(err)
} else {
cblogger.Infof("[%s] VM Resume 실행 성공 - [%s]", VmID, result)
cblogger.Infof("[%s] Succeeded in VM Resumme : [%s]", VmID, result)
}
cblogger.Info("\nResumeVM Test Finished")

case 5:
cblogger.Info("Start Reboot VM ...")
result, err := vmHandler.RebootVM(VmID)
if err != nil {
cblogger.Errorf("[%s] VM Reboot 실패 - [%s]", VmID, result)
cblogger.Errorf("[%s] Failed to Reboot VM : [%s]", VmID, result)
cblogger.Error(err)
} else {
cblogger.Infof("[%s] VM Reboot 실행 성공 - [%s]", VmID, result)
cblogger.Infof("[%s] Succeeded in VM Reboot : [%s]", VmID, result)
}
cblogger.Info("\nRebootVM Test Finished")

case 6:
cblogger.Info("Start Terminate VM ...")
result, err := vmHandler.TerminateVM(VmID)
if err != nil {
cblogger.Errorf("[%s] VM Terminate 실패 - [%s]", VmID, result)
cblogger.Errorf("[%s] Failed to Terminate VM : [%s]", VmID, result)
cblogger.Error(err)
} else {
cblogger.Infof("[%s] VM Terminate 실행 성공 - [%s]", VmID, result)
cblogger.Infof("[%s] Succeeded in VM Terminate : [%s]", VmID, result)
}
cblogger.Info("\nTerminateVM Test Finished")

case 7:
cblogger.Info("Start Get VM Status...")
vmStatus, err := vmHandler.GetVMStatus(VmID)
if err != nil {
cblogger.Errorf("[%s] Get VM Status 실패", VmID)
cblogger.Errorf("[%s] Failed to Get VM Status : ", VmID)
cblogger.Error(err)
} else {
cblogger.Infof("[%s] Get VM Status 실행 성공 : [%s]", VmID, vmStatus)
cblogger.Infof("[%s] Succeeded in Getting VM Status : [%s]", VmID, vmStatus)
}
cblogger.Info("\nGet VMStatus Test Finished")

case 8:
cblogger.Info("Start ListVMStatus ...")
vmStatusInfos, err := vmHandler.ListVMStatus()
if err != nil {
cblogger.Error("ListVMStatus 실패")
cblogger.Error("Failed to List VMStatus")
cblogger.Error(err)
} else {
cblogger.Info("ListVMStatus 실행 성공")
cblogger.Info("Succeeded in Listing VMStatus")
spew.Dump(vmStatusInfos)
}
cblogger.Info("\nListVM Status Test Finished")
Expand All @@ -243,13 +257,12 @@ func handleVM() {
cblogger.Info("Start ListVM ...")
vmList, err := vmHandler.ListVM()
if err != nil {
cblogger.Error("ListVM 실패")
cblogger.Error("Failed to List VM")
cblogger.Error(err)
} else {
cblogger.Info("ListVM 실행 성공")
cblogger.Info("=========== VM 목록 ================")
cblogger.Info("Succeeded in Listing VM")
spew.Dump(vmList)
cblogger.Infof("=========== VM 목록 수 : [%d] ================", len(vmList))
cblogger.Infof("=========== Count VM : [%d] ================", len(vmList))
if len(vmList) > 0 {
VmID = vmList[0].IId
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source ../../../../../setup.env

go run Test_TagHandler.go
Loading

0 comments on commit 0cc8b29

Please sign in to comment.