@@ -1170,41 +1170,35 @@ func getPriceIdForUpgrade(packageItems []datatypes.Product_Item_Price, option st
11701170 return - 1
11711171}
11721172
1173- //Check the virtual server instance is ready for use
1174- //param1: bool, indicate whether the instance is ready
1175- //param2: string, indicate a possible reason if the instance is not ready
1176- //param3: error, any error may happen when getting the status of the instance
1173+ // Check the virtual server instance is ready for use
1174+ // A Virtual server is ready when there are no active transaction, and it is not doing an OS reload.
11771175func (vs virtualServerManager ) InstanceIsReady (id int , until time.Time ) (bool , string , error ) {
1176+ mask := `mask[id, lastOperatingSystemReload[id,modifyDate], activeTransaction[id,transactionStatus[name]]
1177+ provisionDate, powerState[keyName]`
11781178 for {
1179- virtualGuest , err := vs .GetInstance (id , "id, lastOperatingSystemReload[id,modifyDate], activeTransaction[id,transactionStatus.name], provisionDate, powerState.keyName" )
1179+ virtualGuest , err := vs .GetInstance (id , mask )
11801180 if err != nil {
1181- return false , T ( "Failed to get this virtual guest instance." ) , err
1181+ return false , "" , err
11821182 }
11831183
11841184 lastReload := virtualGuest .LastOperatingSystemReload
11851185 activeTxn := virtualGuest .ActiveTransaction
11861186 provisionDate := virtualGuest .ProvisionDate
11871187
1188- // if lastReload != nil && lastReload.ModifyDate != nil {
1189- // fmt.Println("lastReload: ", (*lastReload.ModifyDate).Format(time.RFC3339))
1190- // }
1191- // if activeTxn != nil && activeTxn.TransactionStatus != nil && activeTxn.TransactionStatus.Name != nil {
1192- // fmt.Println("activeTxn: ", *activeTxn.TransactionStatus.Name)
1193- // }
1194- // if provisionDate != nil {
1195- // fmt.Println("provisionDate: ", (*provisionDate).Format(time.RFC3339))
1196- // }
11971188 var reloading bool
11981189 if activeTxn != nil && activeTxn .Id != nil && lastReload != nil && lastReload .Id != nil {
11991190 reloading = activeTxn != nil && lastReload != nil && * activeTxn .Id == * lastReload .Id
12001191 }
12011192 if provisionDate != nil && ! reloading {
12021193 //fmt.Println("power state:", *virtualGuest.PowerState.KeyName)
1203- if virtualGuest .PowerState != nil && virtualGuest .PowerState .KeyName != nil && * virtualGuest .PowerState .KeyName == "HALTED" {
1204- return false , T ("Virtual guest instance {{.Id}} is power off." , map [string ]interface {}{"Id" : id }), nil
1205- }
1206- if virtualGuest .PowerState != nil && virtualGuest .PowerState .KeyName != nil && * virtualGuest .PowerState .KeyName == "PAUSED" {
1207- return false , T ("Virtual guest instance {{.Id}} is paused." , map [string ]interface {}{"Id" : id }), nil
1194+ if virtualGuest .PowerState != nil && virtualGuest .PowerState .KeyName != nil {
1195+ sub_map := map [string ]interface {}{"Id" : id , "State" : * virtualGuest .PowerState .KeyName }
1196+ if * virtualGuest .PowerState .KeyName == "HALTED" {
1197+ return false , T ("Virtual guest instance {{.Id}} is {{.State}}." , sub_map ), nil
1198+ }
1199+ if * virtualGuest .PowerState .KeyName == "PAUSED" {
1200+ return false , T ("Virtual guest instance {{.Id}} is {{.State}}." , sub_map ), nil
1201+ }
12081202 }
12091203
12101204 pingable , err := vs .VirtualGuestService .Id (id ).IsPingable ()
0 commit comments