Skip to content

Commit c7440c2

Browse files
#330 updated 'vs ready' to check for transaction status only
1 parent badf802 commit c7440c2

4 files changed

Lines changed: 12 additions & 30 deletions

File tree

plugin/commands/virtual/create.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package virtual
33
import (
44
"encoding/json"
55
"errors"
6-
"fmt"
6+
77
"io/ioutil"
88
"strconv"
99
"time"
@@ -363,7 +363,6 @@ func (cmd *CreateCommand) verifyParams() (map[string]interface{}, error) {
363363

364364
if cmd.Flavor != "" {
365365
if cmd.CPU != 0 {
366-
fmt.Printf("Returning an error....\n")
367366
return nil, slErrors.NewExclusiveFlagsError("[-c|--cpu]", "[--flavor]")
368367
}
369368
if cmd.Memory != 0 {
@@ -488,12 +487,10 @@ func (cmd *CreateCommand) verifyParams() (map[string]interface{}, error) {
488487
}
489488

490489
if len(cmd.PubSecGroup) > 0 {
491-
fmt.Printf("PubSecGroup(%v): %v\n", cmd.Domain, cmd.PubSecGroup)
492490
params["public-security-group"] = cmd.PubSecGroup
493491
}
494492

495493
if len(cmd.PriSecGroup) > 0 {
496-
fmt.Printf("PriSecGroup: %v\n", cmd.PriSecGroup)
497494
params["private-security-group"] = cmd.PriSecGroup
498495
}
499496

plugin/commands/virtual/ready.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,8 @@ func NewReadyCommand(sl *metadata.SoftlayerCommand) (cmd *ReadyCommand) {
2727
cobraCmd := &cobra.Command{
2828
Use: "ready " + T("IDENTIFIER"),
2929
Short: T("Check if a virtual server instance is ready for use"),
30-
Long: T(`${COMMAND_NAME} sl vs ready IDENTIFIER [OPTIONS]
31-
32-
EXAMPLE:
33-
${COMMAND_NAME} sl vs ready 12345678 --wait 30
34-
This command checks virtual server instance with ID 12345678 status to see if it is ready for use continuously and waits up to 30 seconds.`),
30+
Long: T(`Will periodically check the status of a virtual server's active transaction.
31+
When the transcation is finished the virtual server should be ready for use.`),
3532
Args: metadata.OneArgs,
3633
RunE: func(cmd *cobra.Command, args []string) error {
3734
return thisCmd.Run(args)

plugin/commands/virtual/ready_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ var _ = Describe("VS ready", func() {
5454
It("return error", func() {
5555
err := testhelpers.RunCobraCommand(cliCommand.Command, "1234")
5656
Expect(err).To(HaveOccurred())
57-
Expect(err.Error()).To(ContainSubstring("Failed to check virtual server instance 1234 is ready."))
5857
Expect(err.Error()).To(ContainSubstring("Internal Server Error"))
5958
})
6059
})

plugin/managers/virtualserver.go

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,8 +1173,8 @@ func getPriceIdForUpgrade(packageItems []datatypes.Product_Item_Price, option st
11731173
// Check the virtual server instance is ready for use
11741174
// A Virtual server is ready when there are no active transaction, and it is not doing an OS reload.
11751175
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]`
1176+
mask := `mask[id, lastOperatingSystemReload[id,modifyDate], activeTransaction[id,transactionStatus[name]],
1177+
provisionDate, powerState[keyName]]`
11781178
for {
11791179
virtualGuest, err := vs.GetInstance(id, mask)
11801180
if err != nil {
@@ -1184,37 +1184,26 @@ provisionDate, powerState[keyName]`
11841184
lastReload := virtualGuest.LastOperatingSystemReload
11851185
activeTxn := virtualGuest.ActiveTransaction
11861186
provisionDate := virtualGuest.ProvisionDate
1187-
1187+
txnMessage := "-"
1188+
if activeTxn != nil && activeTxn.TransactionStatus != nil && activeTxn.TransactionStatus.Name != nil {
1189+
txnMessage = *activeTxn.TransactionStatus.Name
1190+
}
11881191
var reloading bool
11891192
if activeTxn != nil && activeTxn.Id != nil && lastReload != nil && lastReload.Id != nil {
11901193
reloading = activeTxn != nil && lastReload != nil && *activeTxn.Id == *lastReload.Id
11911194
}
11921195
if provisionDate != nil && !reloading {
1193-
//fmt.Println("power state:", *virtualGuest.PowerState.KeyName)
11941196
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
1197+
if *virtualGuest.PowerState.KeyName == "HALTED" || *virtualGuest.PowerState.KeyName == "PAUSED" {
1198+
return false, *virtualGuest.PowerState.KeyName , nil
11981199
}
1199-
if *virtualGuest.PowerState.KeyName == "PAUSED" {
1200-
return false, T("Virtual guest instance {{.Id}} is {{.State}}.", sub_map), nil
1201-
}
1202-
}
1203-
1204-
pingable, err := vs.VirtualGuestService.Id(id).IsPingable()
1205-
if err != nil {
1206-
return false, T("Failed to reach virtual guest instance {{.Id}}.", map[string]interface{}{"Id": id}), err
1207-
}
1208-
//fmt.Println("pingable:", pingable)
1209-
if pingable == false {
1210-
return false, T("Virtual guest instance {{.Id}} is not reachable.", map[string]interface{}{"Id": id}), nil
12111200
}
12121201
return true, "", nil
12131202
}
12141203

12151204
now := time.Now()
12161205
if now.After(until) {
1217-
return false, T("Virtual guest instance {{.Id}} is loading operating system.", map[string]interface{}{"Id": id}), nil
1206+
return false, txnMessage, nil
12181207
}
12191208

12201209
min := math.Min(float64(1.0), float64(until.Sub(now)))

0 commit comments

Comments
 (0)