本文整理汇总了Golang中github.com/vmware/govmomi/license.NewManager函数的典型用法代码示例。如果您正苦于以下问题:Golang NewManager函数的具体用法?Golang NewManager怎么用?Golang NewManager使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewManager函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: checkLicense
func (v *Validator) checkLicense(ctx context.Context) error {
var invalidLic []string
client := v.Session.Client.Client
lm := license.NewManager(client)
licenses, err := lm.List(ctx)
if err != nil {
return err
}
v.checkEvalLicense(licenses)
features := []string{"serialuri"}
for _, feature := range features {
if len(licenses.WithFeature(feature)) == 0 {
msg := fmt.Sprintf("Host license missing feature %q", feature)
invalidLic = append(invalidLic, msg)
}
}
if len(invalidLic) > 0 {
log.Errorf("License check FAILED:")
for _, h := range invalidLic {
log.Errorf(" %q", h)
}
msg := "License does not meet minimum requirements to use VIC"
return errors.New(msg)
}
log.Infof("License check OK")
return nil
}
示例2: checkAssignedLicenses
func (v *Validator) checkAssignedLicenses(ctx context.Context) error {
var hosts []*object.HostSystem
var invalidLic []string
var validLic []string
var err error
client := v.Session.Client.Client
if hosts, err = v.Session.Datastore.AttachedClusterHosts(ctx, v.Session.Cluster); err != nil {
log.Errorf("Unable to get the list of hosts attached to given storage: %s", err)
return err
}
lm := license.NewManager(client)
am, err := lm.AssignmentManager(ctx)
if err != nil {
return err
}
features := []string{"serialuri", "dvs"}
for _, host := range hosts {
valid := true
la, err := am.QueryAssigned(ctx, host.Reference().Value)
if err != nil {
return err
}
for _, feature := range features {
if !v.assignedLicenseHasFeature(la, feature) {
valid = false
msg := fmt.Sprintf("%q - license missing feature %q", host.InventoryPath, feature)
invalidLic = append(invalidLic, msg)
}
}
if valid == true {
validLic = append(validLic, host.InventoryPath)
}
}
if len(validLic) > 0 {
log.Infof("License check OK on hosts:")
for _, h := range validLic {
log.Infof(" %q", h)
}
}
if len(invalidLic) > 0 {
log.Errorf("License check FAILED on hosts:")
for _, h := range invalidLic {
log.Errorf(" %q", h)
}
msg := "License does not meet minimum requirements to use VIC"
return errors.New(msg)
}
return nil
}
示例3: Run
func (cmd *list) Run(f *flag.FlagSet) error {
client, err := cmd.Client()
if err != nil {
return err
}
m := license.NewManager(client)
result, err := m.List(context.TODO())
if err != nil {
return err
}
return cmd.WriteResult(licenseOutput(result))
}
示例4: Run
func (cmd *remove) Run(ctx context.Context, f *flag.FlagSet) error {
client, err := cmd.Client()
if err != nil {
return err
}
m := license.NewManager(client)
for _, v := range f.Args() {
err = m.Remove(context.TODO(), v)
if err != nil {
return err
}
}
return nil
}
示例5: Run
func (cmd *list) Run(ctx context.Context, f *flag.FlagSet) error {
client, err := cmd.Client()
if err != nil {
return err
}
m := license.NewManager(client)
result, err := m.List(ctx)
if err != nil {
return err
}
if cmd.feature != "" {
result = result.WithFeature(cmd.feature)
}
return cmd.WriteResult(licenseOutput(result))
}
示例6: Run
func (cmd *assigned) Run(ctx context.Context, f *flag.FlagSet) error {
client, err := cmd.Client()
if err != nil {
return err
}
m, err := license.NewManager(client).AssignmentManager(ctx)
if err != nil {
return err
}
assigned, err := m.QueryAssigned(ctx, cmd.id)
if err != nil {
return err
}
return cmd.WriteResult(assignedOutput(assigned))
}
示例7: Run
func (cmd *assign) Run(f *flag.FlagSet) error {
ctx := context.TODO()
if f.NArg() != 1 {
return flag.ErrHelp
}
key := f.Arg(0)
client, err := cmd.Client()
if err != nil {
return err
}
m, err := license.NewManager(client).AssignmentManager(ctx)
if err != nil {
return err
}
host, err := cmd.HostSystemIfSpecified()
if err != nil {
return err
}
var id string
if host == nil {
// Default to vCenter UUID
id = client.ServiceContent.About.InstanceUuid
} else {
id = host.Reference().Value
}
if cmd.remove {
return m.Remove(ctx, id)
}
info, err := m.Update(ctx, id, key, cmd.name)
if err != nil {
return err
}
return cmd.WriteResult(licenseOutput([]types.LicenseManagerLicenseInfo{*info}))
}
示例8: Run
func (cmd *decode) Run(ctx context.Context, f *flag.FlagSet) error {
client, err := cmd.Client()
if err != nil {
return err
}
var result license.InfoList
m := license.NewManager(client)
for _, v := range f.Args() {
license, err := m.Decode(ctx, v)
if err != nil {
return err
}
result = append(result, license)
}
if cmd.feature != "" {
result = result.WithFeature(cmd.feature)
}
return cmd.WriteResult(licenseOutput(result))
}
示例9: Run
func (cmd *add) Run(f *flag.FlagSet) error {
client, err := cmd.Client()
if err != nil {
return err
}
m := license.NewManager(client)
// From the vSphere 5.5 documentation:
//
// To specify the edition type and any optional functions, use
// updateLicense for ESX Server and addLicense follow by
// LicenseAssingmentManager.updateAssignedLicense for VirtualCenter.
//
var addFunc func(ctx context.Context, key string, labels map[string]string) (types.LicenseManagerLicenseInfo, error)
switch t := client.ServiceContent.About.ApiType; t {
case "HostAgent":
addFunc = m.Update
case "VirtualCenter":
addFunc = m.Add
default:
return fmt.Errorf("unsupported ApiType: %s", t)
}
result := make(licenseOutput, 0)
for _, v := range f.Args() {
license, err := addFunc(context.TODO(), v, nil)
if err != nil {
return err
}
result = append(result, license)
}
return cmd.WriteResult(licenseOutput(result))
}