diff --git a/cmd/execute/watch.go b/cmd/execute/watch.go index 134f2fb..ddb5590 100644 --- a/cmd/execute/watch.go +++ b/cmd/execute/watch.go @@ -73,9 +73,7 @@ func WatchRun(runID uuid.UUID, downloadPath string, nodesToDownload map[string]o out := "" out += fmt.Sprintf(fmtStr, "Name:", run.WorkflowName) out += fmt.Sprintf(fmtStr, "Status:", strings.ToLower(run.Status)) - availableMachines := GetAvailableMachines(fleetName) - out += fmt.Sprintf(fmtStr, "Machines:", FormatMachines(*machines, true)+ - " (currently available: "+FormatMachines(availableMachines, true)+")") + out += fmt.Sprintf(fmtStr, "Machines:", FormatMachines(*machines, true)) out += fmt.Sprintf(fmtStr, "Created:", run.CreatedDate.In(time.Local).Format(time.RFC1123)+ " ("+util.FormatDuration(time.Since(run.CreatedDate))+" ago)") if run.Status != "PENDING" { diff --git a/cmd/get/get.go b/cmd/get/get.go index d9d4bd4..5be033b 100644 --- a/cmd/get/get.go +++ b/cmd/get/get.go @@ -3,9 +3,11 @@ package get import ( "encoding/json" "fmt" + "net/http" "strings" "time" + "github.com/trickest/trickest-cli/client/request" "github.com/trickest/trickest-cli/cmd/execute" "github.com/trickest/trickest-cli/cmd/output" "github.com/trickest/trickest-cli/types" @@ -57,11 +59,19 @@ var GetCmd = &cobra.Command{ runs = []types.Run{*run} } if len(runs) > 0 && (runs[0].Status == "RUNNING" || runs[0].Status == "COMPLETED") { - if runs[0].Status == "COMPLETED" && runs[0].CompletedDate.IsZero() { - runs[0].Status = "RUNNING" + run := runs[0] + if run.Status == "COMPLETED" && run.CompletedDate.IsZero() { + run.Status = "RUNNING" } + + ipAddresses, err := getRunIPAddresses(*run.ID) + if err != nil { + fmt.Printf("Warning: Couldn't get the run IP addresses: %s", err) + } + run.IPAddresses = ipAddresses + if jsonOutput { - data, err := json.Marshal(runs[0]) + data, err := json.Marshal(run) if err != nil { fmt.Println("Error marshalling project data") return @@ -69,7 +79,7 @@ var GetCmd = &cobra.Command{ output := string(data) fmt.Println(output) } else { - execute.WatchRun(*runs[0].ID, "", map[string]output.NodeInfo{}, []string{}, !watch, &runs[0].Machines, showNodeParams) + execute.WatchRun(*run.ID, "", map[string]output.NodeInfo{}, []string{}, !watch, &runs[0].Machines, showNodeParams) } return } else { @@ -105,3 +115,18 @@ func init() { GetCmd.Flags().StringVar(&runID, "run", "", "Get the status of a specific run") GetCmd.Flags().BoolVar(&jsonOutput, "json", false, "Display output in JSON format") } + +func getRunIPAddresses(runID uuid.UUID) ([]string, error) { + resp := request.Trickest.Get().DoF("execution/%s/ips/", runID) + if resp == nil || resp.Status() != http.StatusOK { + return nil, fmt.Errorf("unexpected response status code: %d", resp.Status()) + } + + var ipAddresses []string + err := json.Unmarshal(resp.Body(), &ipAddresses) + if err != nil { + return nil, fmt.Errorf("couldn't unmarshal IP addresses response: %s", err) + } + + return ipAddresses, nil +} diff --git a/types/list.go b/types/list.go index ddebd36..03b42a6 100644 --- a/types/list.go +++ b/types/list.go @@ -124,6 +124,7 @@ type Run struct { Finished bool `json:"finished,omitempty"` Author string `json:"author,omitempty"` Fleet *uuid.UUID `json:"fleet,omitempty"` + IPAddresses []string `json:"ip_addresses,omitempty"` } type Machines struct {