Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update NHN Cloud VMHandler/DiskHandler and cloud-init scripts #1036

Merged
merged 4 commits into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ func handleDisk() {
return
}
diskHandler := resourceHandler.(irs.DiskHandler)
//config := readConfigFile()

for {
fmt.Println("\n============================================================================================")
Expand All @@ -59,19 +58,20 @@ func handleDisk() {
fmt.Println("============================================================================================")

var commandNum int
config := readConfigFile()

diskIId := irs.IID{
NameId: "...",
SystemId: "5fb57e6c-a8ed-4e66-8549-f9d804e72f95",
SystemId: config.KtCloud.DiskID,
}

createReqInfo := irs.DiskInfo{
IId: irs.IID{
NameId: "kt-disk-1",
},
// DiskType: "default",
// DiskType: "HDD",
DiskType: "SSD",
DiskType: "HDD",
// DiskType: "SSD",
// DiskSize: "default",
DiskSize: "100",
}
Expand Down Expand Up @@ -234,8 +234,8 @@ type Config struct {

SubnetID string `yaml:"subnet_id"`
SecurityGroupID string `yaml:"security_group_id"`

PublicIP string `yaml:"public_ip"`
PublicIP string `yaml:"public_ip"`
DiskID string `yaml:"disk_id"`
} `yaml:"ktcloud"`
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,12 @@ func handleImage() {
}

imageReqInfo := irs.ImageReqInfo{
IId: irs.IID{NameId: "Ubuntu 20.04 64bit", SystemId: "23bc4025-8a16-4ebf-aa49-3160ee2ac24b"},
// # KT Cloud : Ubuntu 20.04 64bit
// Zone : KOR-Central A
IId: irs.IID{NameId: "WIN 2019 STD [Korean] MSSQL 2019 ENT", SystemId: "297b2872-7ba9-4e6f-a8b7-e7f81fffc5f3"},

// Zone : KOR-Seoul M2
// IId: irs.IID{NameId: "Ubuntu 20.04 64bit", SystemId: "23bc4025-8a16-4ebf-aa49-3160ee2ac24b"},
// # KT Cloud : Ubuntu 20.04 64bit

// IId: irs.IID{NameId: "Test OS Image", SystemId: "528fdf79-c57f-4f9a-b8ea-c887b9fed003"},
// # KT Cloud : ubuntu-18.04, Ubuntu Server 64-bit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,3 +292,14 @@ func ConvertJsonString(v interface{}) (string, error) {
jsonString := string(jsonBytes)
return jsonString, nil
}

// Convert time to KTC
func ConvertTimeToKTC(givenTime time.Time) (time.Time, error) {
loc, err := time.LoadLocation("Asia/Seoul")
if err != nil {
newErr := fmt.Errorf("Failed to Convert the Time to KTC. [%v]", err)
cblogger.Error(newErr.Error())
return givenTime, newErr
}
return givenTime.In(loc), nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -603,16 +603,17 @@ func (diskHandler *NhnCloudDiskHandler) MappingDiskInfo(volume volumes.Volume) (
}

if volume.Attachments != nil && len(volume.Attachments) > 0 {
vmId := volume.Attachments[0].ServerID
nhnVm, err := servers.Get(diskHandler.VMClient, vmId).Extract()
if err != nil {
newErr := fmt.Errorf("Failed to Get Volume Info list!! : [%v] ", err)
cblogger.Error(newErr.Error())
return irs.DiskInfo{}, newErr
} else {
diskInfo.OwnerVM = irs.IID{
NameId: nhnVm.Name,
SystemId: nhnVm.ID,
for _, attachment := range volume.Attachments {
nhnVm, err := servers.Get(diskHandler.VMClient, attachment.ServerID).Extract()
if err != nil {
newErr := fmt.Errorf("Failed to Get Volume Info list!! : [%v] ", err)
cblogger.Error(newErr.Error())
return irs.DiskInfo{}, newErr
} else {
diskInfo.OwnerVM = irs.IID{
NameId: nhnVm.Name,
SystemId: nhnVm.ID,
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ import (
const (
DefaultVMUserName string = "cb-user"
DefaultWindowsUserName string = "Administrator"
CloudInitFilePath string = "/cloud-driver-libs/.cloud-init-nhncloud/cloud-init"
UbuntuCloudInitFilePath string = "/cloud-driver-libs/.cloud-init-nhncloud/cloud-init-ubuntu"
WinCloudInitFilePath string = "/cloud-driver-libs/.cloud-init-nhncloud/cloud-init-windows"
DefaultDiskSize string = "20"
DefaultWindowsDiskSize string = "50"
)
Expand Down Expand Up @@ -114,15 +115,19 @@ func (vmHandler *NhnCloudVMHandler) StartVM(vmReqInfo irs.VMReqInfo) (irs.VMInfo

// Set cloud-init script
rootPath := os.Getenv("CBSPIDER_ROOT")
fileData, err := os.ReadFile(rootPath + CloudInitFilePath)
fileData, err := os.ReadFile(rootPath + UbuntuCloudInitFilePath)
if err != nil {
cblogger.Error(err.Error())
LoggingError(callLogInfo, err)
return irs.VMInfo{}, err
}
fileStr := string(fileData)
fileStr = strings.ReplaceAll(fileStr, "{{username}}", DefaultVMUserName)
fileStr = strings.ReplaceAll(fileStr, "{{public_key}}", keyPair.PublicKey)
fileStr = strings.ReplaceAll(fileStr, "{{public_key}}", keyPair.PublicKey)
fileStr = strings.ReplaceAll(fileStr, "{{PASSWORD}}", vmReqInfo.VMUserPasswd) // For Windows VM

// cblogger.Info("\n# fileStr : ")
// spew.Dump(fileStr)

// Preparing VM Creation Options
serverCreateOpts := servers.CreateOpts{
Expand Down Expand Up @@ -271,7 +276,8 @@ func (vmHandler *NhnCloudVMHandler) StartVM(vmReqInfo irs.VMReqInfo) (irs.VMInfo
blockDeviceSet := []bootfromvolume.BlockDevice{
{
UUID: vmReqInfo.ImageIID.SystemId,
SourceType: bootfromvolume.SourceImage,
SourceType: bootfromvolume.SourceImage,
// Note) In case of 'MyImage', SourceType is 'SourceImage', too. Not 'bootfromvolume.SourceSnapshot'
VolumeType: reqDiskType,
VolumeSize: reqDiskSizeInt,
DestinationType: bootfromvolume.DestinationVolume, // Destination_type must be 'Volume'. Not 'bootfromvolume.DestinationLocal'
Expand Down Expand Up @@ -825,11 +831,16 @@ func getVmStatus(vmStatus string) irs.VMStatus {

func (vmHandler *NhnCloudVMHandler) MappingVMInfo(server servers.Server) (irs.VMInfo, error) {
cblogger.Info("NHN Cloud Driver: called MappingVMInfo()")

// cblogger.Infof("\n\n### Server from NHN :")
// spew.Dump(server)
// cblogger.Infof("\n\n")

convertedTime, err := ConvertTimeToKTC(server.Created)
if err != nil {
newErr := fmt.Errorf("Failed to Get Converted Time. [%v]", err)
return irs.VMInfo{}, newErr
}

vmInfo := irs.VMInfo{
IId: irs.IID{
NameId: server.Name,
Expand All @@ -846,7 +857,7 @@ func (vmHandler *NhnCloudVMHandler) MappingVMInfo(server servers.Server) (irs.VM
VMUserPasswd: "N/A",
NetworkInterface: server.HostID,
}
vmInfo.StartTime = server.Created
vmInfo.StartTime = convertedTime

// Image Info
imageId := server.Image["id"].(string)
Expand Down
6 changes: 4 additions & 2 deletions cloud-driver-libs/.cloud-init-ktcloud/cloud-init-windows
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
#ps1
net user Administrator {{PASSWORD}}
<powershell>
net user "Administrator" "{{PASSWORD}}"
</powershell>
<persist>true</persist>
8 changes: 8 additions & 0 deletions cloud-driver-libs/.cloud-init-ktcloudvpc/cloud-init-ubuntu
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
#### add Cloud-Barista user
useradd -s /bin/bash {{username}} -rm -G sudo;
chown -R {{username}}:{{username}} /home/{{username}};
echo "{{username}} ALL=(ALL:ALL) NOPASSWD: ALL" >> /etc/sudoers;
mkdir /home/{{username}}/.ssh;
echo "{{public_key}}"> /home/{{username}}/.ssh/authorized_keys;
chown -R {{username}}:{{username}} /home/{{username}}/.ssh/authorized_keys;
4 changes: 4 additions & 0 deletions cloud-driver-libs/.cloud-init-nhncloud/cloud-init-windows
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<powershell>
net user "Administrator" "{{PASSWORD}}"
</powershell>
<persist>true</persist>
Loading