opaque_network.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. Copyright (c) 2017 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. "fmt"
  17. "github.com/vmware/govmomi/vim25"
  18. "github.com/vmware/govmomi/vim25/mo"
  19. "github.com/vmware/govmomi/vim25/types"
  20. )
  21. type OpaqueNetwork struct {
  22. Common
  23. }
  24. func NewOpaqueNetwork(c *vim25.Client, ref types.ManagedObjectReference) *OpaqueNetwork {
  25. return &OpaqueNetwork{
  26. Common: NewCommon(c, ref),
  27. }
  28. }
  29. func (n OpaqueNetwork) GetInventoryPath() string {
  30. return n.InventoryPath
  31. }
  32. // EthernetCardBackingInfo returns the VirtualDeviceBackingInfo for this Network
  33. func (n OpaqueNetwork) EthernetCardBackingInfo(ctx context.Context) (types.BaseVirtualDeviceBackingInfo, error) {
  34. summary, err := n.Summary(ctx)
  35. if err != nil {
  36. return nil, err
  37. }
  38. backing := &types.VirtualEthernetCardOpaqueNetworkBackingInfo{
  39. OpaqueNetworkId: summary.OpaqueNetworkId,
  40. OpaqueNetworkType: summary.OpaqueNetworkType,
  41. }
  42. return backing, nil
  43. }
  44. // Summary returns the mo.OpaqueNetwork.Summary property
  45. func (n OpaqueNetwork) Summary(ctx context.Context) (*types.OpaqueNetworkSummary, error) {
  46. var props mo.OpaqueNetwork
  47. err := n.Properties(ctx, n.Reference(), []string{"summary"}, &props)
  48. if err != nil {
  49. return nil, err
  50. }
  51. summary, ok := props.Summary.(*types.OpaqueNetworkSummary)
  52. if !ok {
  53. return nil, fmt.Errorf("%s unsupported network summary type: %T", n, props.Summary)
  54. }
  55. return summary, nil
  56. }