/
admin_actions.go
41 lines (33 loc) · 1.15 KB
/
admin_actions.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
package cluster
import (
"context"
"strings"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-10-01/compute"
"github.com/Azure/go-autorest/autorest/to"
)
func (u *Upgrade) Reimage(ctx context.Context, scaleset, instanceID string) error {
return u.Vmc.Reimage(ctx, u.Cs.Properties.AzProfile.ResourceGroup, scaleset, instanceID, nil)
}
func (u *Upgrade) ListVMHostnames(ctx context.Context) ([]string, error) {
scalesets, err := u.Ssc.List(ctx, u.Cs.Properties.AzProfile.ResourceGroup)
if err != nil {
return nil, err
}
var hostnames []string
for _, ss := range scalesets {
vms, err := u.Vmc.List(ctx, u.Cs.Properties.AzProfile.ResourceGroup, *ss.Name, "", "", "")
if err != nil {
return nil, err
}
for _, vm := range vms {
hostnames = append(hostnames, strings.ToLower(*vm.OsProfile.ComputerName))
}
}
return hostnames, nil
}
func (u *Upgrade) RunCommand(ctx context.Context, scaleset, instanceID, command string) error {
return u.Vmc.RunCommand(ctx, u.Cs.Properties.AzProfile.ResourceGroup, scaleset, instanceID, compute.RunCommandInput{
CommandID: to.StringPtr("RunShellScript"),
Script: &[]string{command},
})
}