This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var event cloudEvent | |
err := json.Unmarshal(req, &event) | |
if err != nil { | |
return cloudEvent{}, fmt.Errorf("unmarshalling json: %w", err) | |
} | |
return event, nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func isCpuOrMemoryAlarm(event cloudEvent) bool { | |
alarm := false | |
if event.Data.To == "red" && (event.Data.Alarm.Name == "VM Memory Usage" || event.Data.Alarm.Name == "VM CPU Usage") { | |
alarm = true | |
} | |
return alarm | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func newClient(ctx context.Context, cfg *vcConfig) (*vsClient, error) { | |
u := url.URL{ | |
Scheme: "https", | |
Host: cfg.VCenter.Server, | |
Path: "sdk", | |
} | |
u.User = url.UserPassword(cfg.VCenter.User, cfg.VCenter.Password) | |
insecure := cfg.VCenter.Insecure |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func eventVmMoRef(event cloudEvent) (types.ManagedObjectReference, error) { | |
moRef := types.ManagedObjectReference{ | |
Type: event.Data.Vm.Vm.Type, | |
Value: event.Data.Vm.Vm.Value, | |
} | |
return moRef, nil | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (c *vsClient) moVirtualMachine(ctx context.Context, mor types.ManagedObjectReference) (mo.VirtualMachine, error) { | |
var moVM mo.VirtualMachine | |
pc := property.DefaultCollector(c.govmomi.Client) | |
err := pc.Retrieve(ctx, []types.ManagedObjectReference{mor}, []string{}, &moVM) | |
if err != nil { | |
return mo.VirtualMachine{}, err | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
moVM.Config.Hardware.NumCPU | |
moVM.Config.Hardware.MemoryMB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func incCpuVal(numCPU int) string { | |
newNum := 4 | |
numCPU++ | |
if numCPU < newNum { | |
newNum = numCPU | |
} | |
return strconv.Itoa(newNum) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func incMemVal(mem float64) string { | |
// 2^13 = 8192. 8GB is max RAM. | |
maxExp := 13 | |
newMem := 1 << maxExp | |
exp := int(math.Round(math.Log10(mem) / math.Log10(2))) | |
exp++ | |
if exp < maxExp { | |
newMem = 1 << exp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tagList, err := clt.tagMgr.GetTagsForCategory(ctx, catName) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func findCatAndTagIDs(ts []tags.Tag, tn string) (string, string) { | |
for _, t := range ts { | |
if t.Name == tn { | |
return t.CategoryID, t.ID | |
} | |
} | |
return "", "" | |
} |
OlderNewer