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 currentConfigs(ctx context.Context, moVM mo.VirtualMachine) []vmConfig { | |
configs := make([]vmConfig, 6) | |
configs[0] = vmConfig{name: "numCPU", valInt: int(moVM.Config.Hardware.NumCPU)} | |
configs[1] = vmConfig{name: "memoryMB", valInt: int(moVM.Config.Hardware.MemoryMB)} | |
configs[2] = vmConfig{name: "numCoresPerSocket", valInt: int(moVM.Config.Hardware.NumCoresPerSocket)} | |
if moVM.Config.MemoryHotAddEnabled != nil { | |
configs[3] = vmConfig{name: "memoryHotAddEnabled", valBool: *moVM.Config.MemoryHotAddEnabled} | |
} |
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
tagObjs, err := vsClt.attachedTags(ctx, *vmMOR) |
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 eventVmMOR(req []byte) (*types.ManagedObjectReference, error) { | |
var ce cloudEvent | |
var mor types.ManagedObjectReference | |
err := json.Unmarshal(req, &ce) | |
if err != nil { | |
return nil, fmt.Errorf("parse request: %w", err) | |
} | |
if ce.Data.Vm == nil || ce.Data.Vm.Vm.Value == "" { |
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
err = vsClient.tagMgr.AttachTag(ctx, tagID, vmMOR) |
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
for _, t := range tagList { | |
if t.CategoryID == catID && t.ID != tagID { | |
if err := clt.tagMgr.DetachTag(ctx, t.ID, mor); err != nil { | |
return 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
tagList, err := clt.tagMgr.GetAttachedTags(ctx, mor) |
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 "", "" | |
} |
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 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 |