forked from IBM-Cloud/bluemix-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
121 lines (97 loc) · 2.76 KB
/
main.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
116
117
118
119
120
121
package main
import (
"flag"
"fmt"
"log"
"os"
bluemix "github.com/IBM-Cloud/bluemix-go"
"github.com/IBM-Cloud/bluemix-go/session"
v1 "github.com/IBM-Cloud/bluemix-go/api/container/containerv1"
"github.com/IBM-Cloud/bluemix-go/trace"
)
func main() {
c := new(bluemix.Config)
var zone string
flag.StringVar(&zone, "zone", "", "Zone")
var privateVlan string
flag.StringVar(&privateVlan, "privateVlan", "", "Zone Private Vlan")
var publicVlan string
flag.StringVar(&publicVlan, "publicVlan", "", "Zone Public vlan")
var updatePrivateVlan string
flag.StringVar(&updatePrivateVlan, "updatePrivateVlan", "", "Zone Private vlan to be updated")
var updatePublicVlan string
flag.StringVar(&updatePublicVlan, "updatePublicVlan", "", "Zone Public vlan to be updated")
var location string
flag.StringVar(&location, "location", "", "location")
var region string
flag.StringVar(&location, "region", "us-south", "region")
var skipDeletion bool
flag.BoolVar(&skipDeletion, "no-delete", false, "If provided will delete the resources created")
flag.Parse()
trace.Logger = trace.NewLogger("true")
if privateVlan == "" || publicVlan == "" || updatePrivateVlan == "" || updatePublicVlan == "" || zone == "" || location == "" {
flag.Usage()
os.Exit(1)
}
var clusterInfo = v1.ClusterCreateRequest{
Name: "my_cluster",
Datacenter: location,
MachineType: "u2c.2x4",
WorkerNum: 1,
PrivateVlan: privateVlan,
PublicVlan: publicVlan,
Isolation: "public",
}
sess, err := session.New(c)
if err != nil {
log.Fatal(err)
}
if err != nil {
log.Fatal(err)
}
target := v1.ClusterTargetHeader{}
target.Region = region
clusterClient, err := v1.New(sess)
if err != nil {
log.Fatal(err)
}
clustersAPI := clusterClient.Clusters()
out, err := clustersAPI.Create(clusterInfo, target)
if err != nil {
log.Fatal(err)
}
workerPoolAPI := clusterClient.WorkerPools()
workerPoolRequest := v1.WorkerPoolRequest{
WorkerPoolConfig: v1.WorkerPoolConfig{
Name: "test-workerpool",
Size: 2,
MachineType: "u2c.2x4",
Isolation: "public",
},
DiskEncryption: true,
}
resp, err := workerPoolAPI.CreateWorkerPool(out.ID, workerPoolRequest, target)
if err != nil {
log.Fatal(err)
}
workerPoolZone := v1.WorkerPoolZone{
ID: zone,
WorkerPoolZoneNetwork: v1.WorkerPoolZoneNetwork{
PrivateVLAN: privateVlan,
PublicVLAN: publicVlan,
},
}
err = workerPoolAPI.AddZone(out.ID, resp.ID, workerPoolZone, target)
if err != nil {
log.Fatal(err)
}
err = workerPoolAPI.UpdateZoneNetwork(out.ID, zone, resp.ID, updatePrivateVlan, updatePublicVlan, target)
if err != nil {
log.Fatal(err)
}
pool, err := workerPoolAPI.GetWorkerPool(out.ID, resp.ID, target)
if err != nil {
log.Fatal(err)
}
fmt.Println("Pool id is ", pool.ID)
}