/
computeStart.go
60 lines (51 loc) · 1.43 KB
/
computeStart.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package daiteapcli
import (
"encoding/json"
"fmt"
"os"
"github.com/Daiteap/daiteapcli/pkg/daiteapcli"
"github.com/spf13/cobra"
)
var computeStartCmd = &cobra.Command{
SilenceUsage: true,
SilenceErrors: true,
Use: "start",
Aliases: []string{},
Short: "Command to start Compute (VMs)",
Args: cobra.ExactArgs(0),
PreRunE: func(cmd *cobra.Command, args []string) error {
requiredFlags := []string{"compute"}
checkForRequiredFlags(requiredFlags, cmd)
return nil
},
Run: func(cmd *cobra.Command, args []string) {
verbose, _ := cmd.Flags().GetString("verbose")
dryRun, _ := cmd.Flags().GetString("dry-run")
clusterID, _ := cmd.Flags().GetString("compute")
isCompute, err := IsCompute(clusterID)
if err != nil {
fmt.Println(err)
os.Exit(0)
}
if isCompute == false {
fmt.Println("Please enter valid Compute (VMs) ID")
os.Exit(0)
}
method := "POST"
endpoint := "/clusters/" + clusterID + "/start"
responseBody, err := daiteapcli.SendDaiteapRequest(method, endpoint, "", "true", verbose, dryRun)
if err != nil {
fmt.Println(err)
} else if dryRun == "false" {
output, _ := json.MarshalIndent(responseBody, "", " ")
fmt.Println(string(output))
}
},
}
func init() {
computeCmd.AddCommand(computeStartCmd)
parameters := [][]interface{}{
[]interface{}{"compute", "ID of the Compute (VMs)", "string"},
}
addParameterFlags(parameters, computeStartCmd)
}