Skip to content

Commit

Permalink
Unify NCP VPC VM Creating Status (Booting / Setting up -> Creating)
Browse files Browse the repository at this point in the history
  • Loading branch information
innodreamer committed Jul 24, 2024
1 parent 05c6d43 commit 26cf6c4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ func init() {

func (vmHandler *NcpVMHandler) StartVM(vmReqInfo irs.VMReqInfo) (irs.VMInfo, error) {
cblogger.Info("NCP Classic Cloud driver: called StartVM()!!")

InitLog()
callLogInfo := GetCallLogScheme(vmHandler.RegionInfo.Zone, call.VM, vmReqInfo.IId.NameId, "StartVM()")

Expand Down Expand Up @@ -481,7 +480,6 @@ func (vmHandler *NcpVMHandler) MappingServerInfo(NcpInstance *server.ServerInsta
} else {
// To get the VPC info.
vpcHandler := NcpVPCHandler {
CredentialInfo: vmHandler.CredentialInfo,
RegionInfo: vmHandler.RegionInfo,
VMClient: vmHandler.VMClient,
}
Expand All @@ -502,7 +500,7 @@ func (vmHandler *NcpVMHandler) MappingServerInfo(NcpInstance *server.ServerInsta
}
}
}
cblogger.Infof("NCP Instance Uptime : [%s]", *NcpInstance.Uptime)
// cblogger.Infof("NCP Instance Uptime : [%s]", *NcpInstance.Uptime)

// Note : NCP VPC PlatformType : LNX32, LNX64, WND32, WND64, UBD64, UBS64
if strings.Contains(*NcpInstance.PlatformType.Code, "LNX") || strings.Contains(*NcpInstance.PlatformType.Code, "UB") {
Expand Down Expand Up @@ -543,8 +541,6 @@ func (vmHandler *NcpVMHandler) GetVM(vmIID irs.IID) (irs.VMInfo, error) {

func (vmHandler *NcpVMHandler) SuspendVM(vmIID irs.IID) (irs.VMStatus, error) {
cblogger.Info("NCP Classic Cloud driver: called SuspendVM()!!")
cblogger.Infof("vmID : [%s]", vmIID.SystemId)

InitLog()
callLogInfo := GetCallLogScheme(vmHandler.RegionInfo.Zone, call.VM, vmIID.NameId, "SuspendVM()")

Expand Down Expand Up @@ -605,8 +601,6 @@ func (vmHandler *NcpVMHandler) SuspendVM(vmIID irs.IID) (irs.VMStatus, error) {

func (vmHandler *NcpVMHandler) ResumeVM(vmIID irs.IID) (irs.VMStatus, error) {
cblogger.Info("NCP Classic Cloud driver: called ResumeVM()!")
cblogger.Infof("vmID : " + vmIID.SystemId)

InitLog()
callLogInfo := GetCallLogScheme(vmHandler.RegionInfo.Zone, call.VM, vmIID.NameId, "ResumeVM()")

Expand Down Expand Up @@ -673,8 +667,6 @@ func (vmHandler *NcpVMHandler) ResumeVM(vmIID irs.IID) (irs.VMStatus, error) {

func (vmHandler *NcpVMHandler) RebootVM(vmIID irs.IID) (irs.VMStatus, error) {
cblogger.Info("NCP Classic Cloud driver: called RebootVM()!")
cblogger.Infof("vmID : [%s]", vmIID.SystemId)

InitLog()
callLogInfo := GetCallLogScheme(vmHandler.RegionInfo.Zone, call.VM, vmIID.NameId, "RebootVM()")

Expand Down Expand Up @@ -742,8 +734,6 @@ func (vmHandler *NcpVMHandler) RebootVM(vmIID irs.IID) (irs.VMStatus, error) {

func (vmHandler *NcpVMHandler) TerminateVM(vmIID irs.IID) (irs.VMStatus, error) {
cblogger.Info("NCP Classic Cloud driver: called TerminateVM()!")
cblogger.Infof("vmID : [%s]", vmIID.SystemId)

InitLog()
callLogInfo := GetCallLogScheme(vmHandler.RegionInfo.Zone, call.VM, vmIID.NameId, "TerminateVM()")

Expand Down Expand Up @@ -961,7 +951,6 @@ func ConvertVMStatusString(vmStatus string) (irs.VMStatus, error) {

func (vmHandler *NcpVMHandler) GetVMStatus(vmIID irs.IID) (irs.VMStatus, error) {
cblogger.Info("NCP Classic Cloud driver: called GetVMStatus()!")

InitLog()
callLogInfo := GetCallLogScheme(vmHandler.RegionInfo.Zone, call.VM, vmIID.NameId, "GetVMStatus()")

Expand Down Expand Up @@ -1000,13 +989,12 @@ func (vmHandler *NcpVMHandler) GetVMStatus(vmIID irs.IID) (irs.VMStatus, error)
// cblogger.Info("Succeeded in Getting ServerInstanceList!!")

vmStatus, errStatus := ConvertVMStatusString(*result.ServerInstanceList[0].ServerInstanceStatusName)
cblogger.Info("# Converted VM Status : " + vmStatus)
// cblogger.Info("# Converted VM Status : " + vmStatus)
return vmStatus, errStatus
}

func (vmHandler *NcpVMHandler) ListVMStatus() ([]*irs.VMStatusInfo, error) {
cblogger.Info("NCP Classic Cloud driver: called ListVMStatus()!")

InitLog()
callLogInfo := GetCallLogScheme(vmHandler.RegionInfo.Zone, call.VM, "ListVMStatus()", "ListVMStatus()")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,63 +323,19 @@ func (vmHandler *NcpVpcVMHandler) GetVM(vmIID irs.IID) (irs.VMInfo, error) {
return irs.VMInfo{}, newErr
}

curStatus, statusErr := vmHandler.GetVMStatus(vmIID)
if statusErr != nil {
newErr := fmt.Errorf("Failed to Get the VM Status with the VM ID : [%s], [%v]", vmIID.SystemId, statusErr)
cblogger.Error(newErr.Error())
LoggingError(callLogInfo, newErr)
return irs.VMInfo{}, newErr
}
cblogger.Infof("===> VM Status : [%s]", curStatus)

// Since it's impossible to get VM info. during Creation, ...
switch string(curStatus) {
case "Creating":
cblogger.Infof("The VM status is '%s', so wait for the VM creation before inquiring the info.", string(curStatus))
return irs.VMInfo{}, errors.New("The VM status is 'Creating', so wait for the VM creation before inquiring the info. : " + vmIID.SystemId)
default:
cblogger.Infof("===> The VM status is not 'Creating', you can get the VM info.")
}

/*
newVMIID := irs.IID{SystemId: systemId}
curStatus, statusErr := vmHandler.WaitToGetInfo(newVMIID)
if statusErr != nil {
cblogger.Error(statusErr.Error())
return irs.VMInfo{}, nil
}
*/
instanceNumList := []*string{ncloud.String(vmIID.SystemId),}
instanceReq := vserver.GetServerInstanceListRequest{
RegionCode: ncloud.String(vmHandler.RegionInfo.Region), // $$$ Caution!!
ServerInstanceNoList: instanceNumList,
}
start := call.Start()
result, err := vmHandler.VMClient.V2Api.GetServerInstanceList(&instanceReq)
ncpVMInfo, err := vmHandler.GetNcpVMInfo(vmIID.SystemId)
if err != nil {
newErr := fmt.Errorf("Failed to Find VM Instance List from NCP VPC!! : [%v]", err)
newErr := fmt.Errorf("Failed to Get the VM Info : [%v]", err)
cblogger.Error(newErr.Error())
LoggingError(callLogInfo, newErr)
return irs.VMInfo{}, newErr
}
LoggingInfo(callLogInfo, start)

if len(result.ServerInstanceList) < 1 {
newErr := fmt.Errorf("Failed to Find the VM Info. The VM does Not Exist!!")
cblogger.Error(newErr.Error())
LoggingError(callLogInfo, newErr)
return irs.VMInfo{}, newErr
}

vmInfo, err := vmHandler.MappingServerInfo(result.ServerInstanceList[0])
vmInfo, err := vmHandler.MappingServerInfo(ncpVMInfo)
if err != nil {
newErr := fmt.Errorf("Failed to Map the VM Info!! : [%v]", err)
cblogger.Error(newErr.Error())
LoggingError(callLogInfo, newErr)
return irs.VMInfo{}, newErr
LoggingError(callLogInfo, err)
return irs.VMInfo{}, err
}
return vmInfo, nil
return vmInfo, nil
}

func (vmHandler *NcpVpcVMHandler) SuspendVM(vmIID irs.IID) (irs.VMStatus, error) {
Expand Down Expand Up @@ -774,9 +730,9 @@ func ConvertVMStatusString(vmStatus string) (irs.VMStatus, error) {
resultStatus = "Creating"
} else if strings.EqualFold(vmStatus, "booting") {
//Caution!!
resultStatus = "Booting"
resultStatus = "Creating"
} else if strings.EqualFold(vmStatus, "setting up") {
resultStatus = "Setting_up"
resultStatus = "Creating"
} else if strings.EqualFold(vmStatus, "running") {
resultStatus = "Running"
} else if strings.EqualFold(vmStatus, "shutting down") {
Expand Down Expand Up @@ -838,7 +794,7 @@ func (vmHandler *NcpVpcVMHandler) GetVMStatus(vmIID irs.IID) (irs.VMStatus, erro
}

vmStatus, statusErr := ConvertVMStatusString(*result.ServerInstanceList[0].ServerInstanceStatusName)
cblogger.Infof("VM Status of [%s] : [%s]", vmIID.SystemId, vmStatus)
// cblogger.Infof("VM Status of [%s] : [%s]", vmIID.SystemId, vmStatus)
return vmStatus, statusErr
}

Expand Down Expand Up @@ -1338,14 +1294,13 @@ func (vmHandler *NcpVpcVMHandler) WaitToGetInfo(vmIID irs.IID) (irs.VMStatus, er
cblogger.Errorf("Failed to Get the VM Status of [%s]", vmIID.SystemId)
cblogger.Error(statusErr.Error())
} else {
cblogger.Infof("Succeeded in Getting the Status of VM [%s] : [%s]", vmIID.SystemId, curStatus)
cblogger.Infof("===> VM Status : [%s]", curStatus)
}
cblogger.Infof("===> VM Status : [%s]", curStatus)

switch string(curStatus) {
case "Creating", "Booting", "Setting_up":
case "Creating":
curRetryCnt++
cblogger.Infof("The VM is 'Creating' and 'Booting', so wait for a second more before inquiring the VM info.")
cblogger.Infof("The VM is 'Creating', so wait for a second more before inquiring the VM info.")
time.Sleep(time.Second * 5)
if curRetryCnt > maxRetryCnt {
cblogger.Errorf("Despite waiting for a long time(%d sec), the VM status is '%s', so it is forcibly finishied.", maxRetryCnt, curStatus)
Expand Down Expand Up @@ -1375,7 +1330,7 @@ func (vmHandler *NcpVpcVMHandler) WaitToDelPublicIp(vmIID irs.IID) (irs.VMStatus
} else {
cblogger.Infof("Succeeded in Getting the VM Status of [%s]", vmIID.SystemId)
}
cblogger.Infof("===> VM Status [%s] : ", curStatus)
cblogger.Infof("===> VM Status : [%s]", curStatus)

switch string(curStatus) {
case "Suspended", "Terminating":
Expand Down

0 comments on commit 26cf6c4

Please sign in to comment.