github.com/vmware/govmomi@v0.37.2/license/assignment_manager.go (about)

     1  /*
     2  Copyright (c) 2015 VMware, Inc. All Rights Reserved.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package license
    18  
    19  import (
    20  	"context"
    21  
    22  	"github.com/vmware/govmomi/object"
    23  	"github.com/vmware/govmomi/vim25/methods"
    24  	"github.com/vmware/govmomi/vim25/types"
    25  )
    26  
    27  type AssignmentManager struct {
    28  	object.Common
    29  }
    30  
    31  func (m AssignmentManager) QueryAssigned(ctx context.Context, id string) ([]types.LicenseAssignmentManagerLicenseAssignment, error) {
    32  	req := types.QueryAssignedLicenses{
    33  		This:     m.Reference(),
    34  		EntityId: id,
    35  	}
    36  
    37  	res, err := methods.QueryAssignedLicenses(ctx, m.Client(), &req)
    38  	if err != nil {
    39  		return nil, err
    40  	}
    41  
    42  	return res.Returnval, nil
    43  }
    44  
    45  func (m AssignmentManager) Remove(ctx context.Context, id string) error {
    46  	req := types.RemoveAssignedLicense{
    47  		This:     m.Reference(),
    48  		EntityId: id,
    49  	}
    50  
    51  	_, err := methods.RemoveAssignedLicense(ctx, m.Client(), &req)
    52  
    53  	return err
    54  }
    55  
    56  func (m AssignmentManager) Update(ctx context.Context, id string, key string, name string) (*types.LicenseManagerLicenseInfo, error) {
    57  	req := types.UpdateAssignedLicense{
    58  		This:              m.Reference(),
    59  		Entity:            id,
    60  		LicenseKey:        key,
    61  		EntityDisplayName: name,
    62  	}
    63  
    64  	res, err := methods.UpdateAssignedLicense(ctx, m.Client(), &req)
    65  	if err != nil {
    66  		return nil, err
    67  	}
    68  
    69  	return &res.Returnval, nil
    70  }