forked from jenkins-x/jx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.go
79 lines (70 loc) · 1.46 KB
/
helper.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package gke
import (
"os/exec"
"sort"
"strings"
"github.com/jenkins-x/jx/pkg/util"
)
var PROJECT_LIST_HEADER = "PROJECT_ID"
func GetGoogleZones() ([]string, error) {
var zones []string
out, err := exec.Command("gcloud", "compute", "zones", "list").Output()
if err != nil {
return nil, err
}
for _, item := range strings.Split(string(out), "\n") {
zone := strings.Split(item, " ")[0]
if strings.Contains(zone, "-") {
zones = append(zones, zone)
}
sort.Strings(zones)
}
return zones, nil
}
func GetGoogleProjects() ([]string, error) {
cmd := util.Command{
Name: "gcloud",
Args: []string{"projects", "list"},
}
out, err := cmd.RunWithoutRetry()
if err != nil {
return nil, err
}
lines := strings.Split(string(out), "\n")
var existingProjects []string
for _, l := range lines {
if strings.Contains(l, PROJECT_LIST_HEADER) {
continue
}
fields := strings.Fields(l)
existingProjects = append(existingProjects, fields[0])
}
return existingProjects, nil
}
func GetGoogleMachineTypes() []string {
return []string{
"g1-small",
"n1-standard-1",
"n1-standard-2",
"n1-standard-4",
"n1-standard-8",
"n1-standard-16",
"n1-standard-32",
"n1-standard-64",
"n1-standard-96",
"n1-highmem-2",
"n1-highmem-4",
"n1-highmem-8",
"n1-highmem-16",
"n1-highmem-32",
"n1-highmem-64",
"n1-highmem-96",
"n1-highcpu-2",
"n1-highcpu-4",
"n1-highcpu-8",
"n1-highcpu-16",
"n1-highcpu-32",
"n1-highcpu-64",
"n1-highcpu-96",
}
}