Skip to content

Commit

Permalink
Update for VM Status check when running GetVM(), ListVM()
Browse files Browse the repository at this point in the history
  • Loading branch information
innodreamer committed Jul 16, 2024
1 parent 9d8fc09 commit c52d140
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -533,11 +533,11 @@ func (vmHandler *NcpVMHandler) GetVM(vmIID irs.IID) (irs.VMInfo, error) {

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

regionNo, err := vmHandler.GetRegionNo(vmHandler.RegionInfo.Region)
Expand Down Expand Up @@ -969,7 +969,7 @@ func ConvertVMStatusString(vmStatus string) (irs.VMStatus, error) {
//Caution!!
resultStatus = "Booting"
} else if strings.EqualFold(vmStatus, "setting up") {
resultStatus = "Creating"
resultStatus = "Setting_up"
} else if strings.EqualFold(vmStatus, "running") {
resultStatus = "Running"
} else if strings.EqualFold(vmStatus, "shutting down") {
Expand Down Expand Up @@ -1136,29 +1136,23 @@ func (vmHandler *NcpVMHandler) ListVM() ([]*irs.VMInfo, error) {
cblogger.Debug(newErr.Error())
return nil, nil // Not returns Error message
} else {
cblogger.Info("Succeeded in Getting ServerInstanceList!!")
cblogger.Info("Succeeded in Getting ServerInstanceList from NCP!!")
}

var vmInfoList []*irs.VMInfo
for _, vm := range result.ServerInstanceList {
cblogger.Info("NCP VM Instance Info. inquiry : ", *vm.ServerInstanceNo)

curStatus, errStatus := vmHandler.GetVMStatus(irs.IID{SystemId: *vm.ServerInstanceNo})
if errStatus != nil {
rtnErr := logAndReturnError(callLogInfo, "Failed to Get the VM Status : ", errStatus)
return nil, rtnErr
curStatus, statusErr := vmHandler.GetVMStatus(irs.IID{SystemId: *vm.ServerInstanceNo})
if statusErr != nil {
newErr := fmt.Errorf("Failed to Get the Status of VM : [%s], [%v]", *vm.ServerInstanceNo, statusErr.Error())
cblogger.Error(newErr.Error())
return nil, newErr
} else {
cblogger.Infof("Succeeded to Get the VM Status of [%s] : [%s]", irs.IID{SystemId: *vm.ServerInstanceNo}, curStatus)
cblogger.Infof("Succeeded to Get the Status of VM [%s] : [%s]", *vm.ServerInstanceNo, string(curStatus))
}
cblogger.Info("===> VM Status : ", curStatus)
cblogger.Infof("===> VM Status : [%s]", string(curStatus))

switch string(curStatus) {
case "Creating", "Booting":
cblogger.Errorf("The VM status : [%s], Can Not Get the VM info.", string(curStatus))
return nil, nil

default:
cblogger.Infof("===> The VM status not 'Creating' or 'Booting', you can get the VM info.")
if (string(curStatus) != "Creating") && (string(curStatus) != "Terminating") {
cblogger.Infof("===> The VM Status not 'Creating' or 'Terminating', you can get the VM info.")
vmInfo, error := vmHandler.GetVM(irs.IID{SystemId: *vm.ServerInstanceNo})
if error != nil {
cblogger.Error(error.Error())
Expand Down Expand Up @@ -1189,9 +1183,9 @@ func (vmHandler *NcpVMHandler) WaitToGetInfo(vmIID irs.IID) (irs.VMStatus, error
cblogger.Infof("===> VM Status : [%s]", curStatus)

switch string(curStatus) {
case "Creating", "Booting":
case "Creating", "Booting", "Setting_up":
curRetryCnt++
cblogger.Infof("The VM is still 'Creating', so wait for a second more before inquiring the VM info.")
cblogger.Infof("The VM is still 'Creating' and 'Booting', 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
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func init() {
func (vmHandler *NcpVpcVMHandler) StartVM(vmReqInfo irs.VMReqInfo) (irs.VMInfo, error) {
cblogger.Info("NCPVPC Cloud driver: called StartVM()!!")
InitLog()
callLogInfo := GetCallLogScheme(vmHandler.CredentialInfo.ClientId, call.VM, vmReqInfo.IId.NameId, "StartVM()")
callLogInfo := GetCallLogScheme(vmHandler.RegionInfo.Region, call.VM, vmReqInfo.IId.NameId, "StartVM()")

if strings.EqualFold(vmReqInfo.IId.NameId, "") {
newErr := fmt.Errorf("Invalid VM Name required")
Expand Down Expand Up @@ -334,11 +334,11 @@ func (vmHandler *NcpVpcVMHandler) GetVM(vmIID irs.IID) (irs.VMInfo, error) {

// Since it's impossible to get VM info. during Creation, ...
switch string(curStatus) {
case "Creating", "Booting":
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' or 'Booting', so wait for the VM creation before inquiring the info. : " + vmIID.SystemId)
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' or 'Booting', you can get the VM info.")
cblogger.Infof("===> The VM status is not 'Creating', you can get the VM info.")
}

/*
Expand Down Expand Up @@ -776,7 +776,7 @@ func ConvertVMStatusString(vmStatus string) (irs.VMStatus, error) {
//Caution!!
resultStatus = "Booting"
} else if strings.EqualFold(vmStatus, "setting up") {
resultStatus = "Creating"
resultStatus = "Setting_up"
} else if strings.EqualFold(vmStatus, "running") {
resultStatus = "Running"
} else if strings.EqualFold(vmStatus, "shutting down") {
Expand Down Expand Up @@ -901,36 +901,30 @@ func (vmHandler *NcpVpcVMHandler) ListVM() ([]*irs.VMInfo, error) {
return nil, newErr
}
LoggingInfo(callLogInfo, callLogStart)
cblogger.Info("Succeeded in Getting ServerInstanceList from NCP VPC!!")
cblogger.Info("Succeeded in Getting ServerInstanceList from NCP!!")

var vmInfoList []*irs.VMInfo
for _, vm := range result.ServerInstanceList {
cblogger.Infof("Inquiry of NCP VM Instance info : [%s]", *vm.ServerInstanceNo)

curStatus, statusErr := vmHandler.GetVMStatus(irs.IID{SystemId: *vm.ServerInstanceNo})
if statusErr != nil {
cblogger.Errorf("Failed to Get the VM Status of VM : [%s]", *vm.ServerInstanceNo)
cblogger.Error(statusErr.Error())
newErr := fmt.Errorf("Failed to Get the Status of VM : [%s], [%v]", *vm.ServerInstanceNo, statusErr.Error())
cblogger.Error(newErr.Error())
return nil, newErr
} else {
cblogger.Infof("Succeed in Getting the VM Status of [%s] : [%s]", *vm.ServerInstanceNo, curStatus)
cblogger.Infof("Succeeded in Getting the Status of VM [%s] : [%s]", *vm.ServerInstanceNo, string(curStatus))
}
cblogger.Infof("===> VM Status : [%s]", curStatus)

switch string(curStatus) {
case "Creating", "Booting":
return []*irs.VMInfo{}, nil
cblogger.Infof("===> VM Status : [%s]", string(curStatus))

default:
cblogger.Infof("===> The VM status not 'Creating' or 'Booting', you can get the VM info.")
if (string(curStatus) != "Creating") && (string(curStatus) != "Terminating") {
cblogger.Infof("===> The VM Status not 'Creating' or 'Terminating', you can get the VM info.")
vmInfo, error := vmHandler.GetVM(irs.IID{SystemId: *vm.ServerInstanceNo})
if error != nil {
cblogger.Error(error.Error())
return []*irs.VMInfo{}, error
return nil, error
}
vmInfoList = append(vmInfoList, &vmInfo)
}
}

return vmInfoList, nil
}

Expand Down Expand Up @@ -1349,9 +1343,9 @@ func (vmHandler *NcpVpcVMHandler) WaitToGetInfo(vmIID irs.IID) (irs.VMStatus, er
cblogger.Infof("===> VM Status : [%s]", curStatus)

switch string(curStatus) {
case "Creating", "Booting":
case "Creating", "Booting", "Setting_up":
curRetryCnt++
cblogger.Infof("The VM is 'Creating', so wait for a second more before inquiring the VM info.")
cblogger.Infof("The VM is 'Creating' and 'Booting', 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

0 comments on commit c52d140

Please sign in to comment.