opaque_network.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. // EthernetCardBackingInfo returns the VirtualDeviceBackingInfo for this Network
  30. func (n OpaqueNetwork) EthernetCardBackingInfo(ctx context.Context) (types.BaseVirtualDeviceBackingInfo, error) {
  31. var net mo.OpaqueNetwork
  32. if err := n.Properties(ctx, n.Reference(), []string{"summary"}, &net); err != nil {
  33. return nil, err
  34. }
  35. summary, ok := net.Summary.(*types.OpaqueNetworkSummary)
  36. if !ok {
  37. return nil, fmt.Errorf("%s unsupported network type: %T", n, net.Summary)
  38. }
  39. backing := &types.VirtualEthernetCardOpaqueNetworkBackingInfo{
  40. OpaqueNetworkId: summary.OpaqueNetworkId,
  41. OpaqueNetworkType: summary.OpaqueNetworkType,
  42. }
  43. return backing, nil
  44. }