distributed_virtual_switch.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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/methods"
  18. "github.com/vmware/govmomi/vim25/types"
  19. )
  20. type DistributedVirtualSwitch struct {
  21. Common
  22. }
  23. func NewDistributedVirtualSwitch(c *vim25.Client, ref types.ManagedObjectReference) *DistributedVirtualSwitch {
  24. return &DistributedVirtualSwitch{
  25. Common: NewCommon(c, ref),
  26. }
  27. }
  28. func (s DistributedVirtualSwitch) EthernetCardBackingInfo(ctx context.Context) (types.BaseVirtualDeviceBackingInfo, error) {
  29. return nil, ErrNotSupported // TODO: just to satisfy NetworkReference interface for the finder
  30. }
  31. func (s DistributedVirtualSwitch) Reconfigure(ctx context.Context, spec types.BaseDVSConfigSpec) (*Task, error) {
  32. req := types.ReconfigureDvs_Task{
  33. This: s.Reference(),
  34. Spec: spec,
  35. }
  36. res, err := methods.ReconfigureDvs_Task(ctx, s.Client(), &req)
  37. if err != nil {
  38. return nil, err
  39. }
  40. return NewTask(s.Client(), res.Returnval), nil
  41. }
  42. func (s DistributedVirtualSwitch) AddPortgroup(ctx context.Context, spec []types.DVPortgroupConfigSpec) (*Task, error) {
  43. req := types.AddDVPortgroup_Task{
  44. This: s.Reference(),
  45. Spec: spec,
  46. }
  47. res, err := methods.AddDVPortgroup_Task(ctx, s.Client(), &req)
  48. if err != nil {
  49. return nil, err
  50. }
  51. return NewTask(s.Client(), res.Returnval), nil
  52. }
  53. func (s DistributedVirtualSwitch) FetchDVPorts(ctx context.Context, criteria *types.DistributedVirtualSwitchPortCriteria) ([]types.DistributedVirtualPort, error) {
  54. req := &types.FetchDVPorts{
  55. This: s.Reference(),
  56. Criteria: criteria,
  57. }
  58. res, err := methods.FetchDVPorts(ctx, s.Client(), req)
  59. if err != nil {
  60. return nil, err
  61. }
  62. return res.Returnval, nil
  63. }