Skip to content

Commit

Permalink
Add and Apply ConvertTimeToKTC() function
Browse files Browse the repository at this point in the history
  • Loading branch information
innodreamer committed Feb 2, 2024
1 parent d5d6480 commit 1680128
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
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 @@ -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

0 comments on commit 1680128

Please sign in to comment.