forked from jenkins-x/jx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.go
115 lines (85 loc) · 2.18 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package iks
import (
"strconv"
"strings"
"github.com/IBM-Cloud/bluemix-go/api/container/containerv1"
)
func GetRegions(regions Regions) ([]string, error) {
regionarr, err := regions.GetRegions()
if err != nil {
return nil, err
}
strregions := make([]string, len(regionarr))
for i, region := range regionarr {
strregions[i] = region.Name
}
return strregions, nil
}
func GetZones(region Region, zones Zones) ([]string, error) {
zonearr, err := zones.GetZones(region)
if err != nil {
return nil, err
}
strzones := make([]string, len(zonearr))
for i, zone := range zonearr {
strzones[i] = zone.ID
}
return strzones, nil
}
func GetKubeVersions(versions containerv1.KubeVersions) ([]string, string, error) {
target := containerv1.ClusterTargetHeader{}
versionarr, err := versions.List(target)
var def string
if err != nil {
return nil, "", err
}
strversions := make([]string, len(versionarr))
for i, version := range versionarr {
strversions[i] = strconv.Itoa(version.Major) + "." + strconv.Itoa(version.Minor) + "." + strconv.Itoa(version.Patch)
if version.Default {
def = strversions[i]
}
}
return strversions, def, nil
}
func GetMachineTypes(zone Zone, machinetypes MachineTypes) ([]string, error) {
machinetypesarr, err := machinetypes.GetMachineTypes(zone)
if err != nil {
return nil, err
}
strmachinetype := make([]string, len(machinetypesarr))
for i, machinetype := range machinetypesarr {
strmachinetype[i] = machinetype.Name
}
return strmachinetype, nil
}
func GetPrivateVLANs(zone Zone, vlans VLANs) ([]string, error) {
vlansarr, err := vlans.GetVLANs(zone)
if err != nil {
return nil, err
}
strvlans := make([]string, len(vlansarr))
var i = 0
for _, vlan := range vlansarr {
if strings.Compare(vlan.Type, "private") == 0 {
strvlans[i] = vlan.ID
i++
}
}
return strvlans[0:i], nil
}
func GetPublicVLANs(zone Zone, vlans VLANs) ([]string, error) {
vlansarr, err := vlans.GetVLANs(zone)
if err != nil {
return nil, err
}
strvlans := make([]string, len(vlansarr))
var i = 0
for _, vlan := range vlansarr {
if strings.Compare(vlan.Type, "public") == 0 {
strvlans[i] = vlan.ID
i++
}
}
return strvlans[0:i], nil
}