Skip to content

Commit badf802

Browse files
Refactoring the vs ready command to check for transactions, not isPingable
1 parent cf8db63 commit badf802

2 files changed

Lines changed: 15 additions & 21 deletions

File tree

plugin/commands/virtual/ready.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (cmd *ReadyCommand) Run(args []string) error {
5252
ready, message, err := cmd.VirtualServerManager.InstanceIsReady(vsID, until)
5353
subs := map[string]interface{}{"VsID": vsID, "VsId": vsID}
5454
if err != nil {
55-
return slErrors.NewAPIError(T("Failed to check virtual server instance {{.VsID}} is ready.\n", subs), err.Error(), 2)
55+
return err
5656
}
5757
if ready {
5858
cmd.UI.Print(T("Virtual server instance: {{.VsId}} is ready.", subs))

plugin/managers/virtualserver.go

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
11771175
func (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

Comments
 (0)