network.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. Copyright (c) 2015 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/mo"
  18. "github.com/vmware/govmomi/vim25/types"
  19. )
  20. type Network struct {
  21. Common
  22. }
  23. func NewNetwork(c *vim25.Client, ref types.ManagedObjectReference) *Network {
  24. return &Network{
  25. Common: NewCommon(c, ref),
  26. }
  27. }
  28. // EthernetCardBackingInfo returns the VirtualDeviceBackingInfo for this Network
  29. func (n Network) EthernetCardBackingInfo(ctx context.Context) (types.BaseVirtualDeviceBackingInfo, error) {
  30. var e mo.Network
  31. // Use Network.Name rather than Common.Name as the latter does not return the complete name if it contains a '/'
  32. // We can't use Common.ObjectName here either as we need the ManagedEntity.Name field is not set since mo.Network
  33. // has its own Name field.
  34. err := n.Properties(ctx, n.Reference(), []string{"name"}, &e)
  35. if err != nil {
  36. return nil, err
  37. }
  38. backing := &types.VirtualEthernetCardNetworkBackingInfo{
  39. VirtualDeviceDeviceBackingInfo: types.VirtualDeviceDeviceBackingInfo{
  40. DeviceName: e.Name,
  41. },
  42. }
  43. return backing, nil
  44. }