This repository has been archived by the owner on Jun 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
cli_executor.go
65 lines (56 loc) · 1.63 KB
/
cli_executor.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
package main
import (
"fmt"
"os"
"os/exec"
)
type CliExecutor struct {
AppID string
TenantID string
Password string
AksName string
ResourceGroup string
LoggedIn bool
}
func NewCliExecutor(appID string, password string, tenantID string, aksName string, resourceGroup string) *CliExecutor {
if appID == "" {
panic("appId cannot be empty")
} else if password == "" {
panic("password cannot be empty")
} else if tenantID == "" {
panic("tenantId cannot be empty")
} else if aksName == "" {
panic("aksName cannot be empty")
} else if resourceGroup == "" {
panic("resourceGroup cannot be empty")
} else {
return &CliExecutor{AppID: appID, Password: password, TenantID: tenantID, AksName: aksName, ResourceGroup: resourceGroup}
}
}
func (c *CliExecutor) Scale(agents int32) {
// TODO: Parse return message and return true or false
if c.LoggedIn {
fmt.Println("scaling to " + fmt.Sprint(agents) + " nodes")
cmd := "az"
cmdArgs := []string{"aks", "scale", "-g", c.ResourceGroup, "-n", c.AksName, "--node-count", fmt.Sprint(agents)}
_, err := exec.Command(cmd, cmdArgs...).Output()
if err != nil {
fmt.Println(err.Error())
}
fmt.Println("scale operation successful")
} else {
panic("Must be logged in before executing commands")
}
}
func (c *CliExecutor) Login() {
if !c.LoggedIn {
cmd := "az"
cmdArgs := []string{"login", "--service-principal", "-u", c.AppID, "-p", c.Password, "-t", c.TenantID}
if err := exec.Command(cmd, cmdArgs...).Run(); err != nil {
fmt.Fprintln(os.Stderr, err)
panic("az login failed")
}
fmt.Println("login successful")
c.LoggedIn = true
}
}