option_manager.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. Copyright (c) 2016 VMware, Inc. All Rights Reserved.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package object
  14. import (
  15. "context"
  16. "github.com/vmware/govmomi/vim25"
  17. "github.com/vmware/govmomi/vim25/methods"
  18. "github.com/vmware/govmomi/vim25/types"
  19. )
  20. type OptionManager struct {
  21. Common
  22. }
  23. func NewOptionManager(c *vim25.Client, ref types.ManagedObjectReference) *OptionManager {
  24. return &OptionManager{
  25. Common: NewCommon(c, ref),
  26. }
  27. }
  28. func (m OptionManager) Query(ctx context.Context, name string) ([]types.BaseOptionValue, error) {
  29. req := types.QueryOptions{
  30. This: m.Reference(),
  31. Name: name,
  32. }
  33. res, err := methods.QueryOptions(ctx, m.Client(), &req)
  34. if err != nil {
  35. return nil, err
  36. }
  37. return res.Returnval, nil
  38. }
  39. func (m OptionManager) Update(ctx context.Context, value []types.BaseOptionValue) error {
  40. req := types.UpdateOptions{
  41. This: m.Reference(),
  42. ChangedValue: value,
  43. }
  44. _, err := methods.UpdateOptions(ctx, m.Client(), &req)
  45. return err
  46. }