distributed_virtual_switch.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. "fmt"
  17. "github.com/vmware/govmomi/vim25"
  18. "github.com/vmware/govmomi/vim25/methods"
  19. "github.com/vmware/govmomi/vim25/types"
  20. )
  21. type DistributedVirtualSwitch struct {
  22. Common
  23. }
  24. func NewDistributedVirtualSwitch(c *vim25.Client, ref types.ManagedObjectReference) *DistributedVirtualSwitch {
  25. return &DistributedVirtualSwitch{
  26. Common: NewCommon(c, ref),
  27. }
  28. }
  29. func (s DistributedVirtualSwitch) GetInventoryPath() string {
  30. return s.InventoryPath
  31. }
  32. func (s DistributedVirtualSwitch) EthernetCardBackingInfo(ctx context.Context) (types.BaseVirtualDeviceBackingInfo, error) {
  33. ref := s.Reference()
  34. name := s.InventoryPath
  35. if name == "" {
  36. name = ref.String()
  37. }
  38. return nil, fmt.Errorf("type %s (%s) cannot be used for EthernetCardBackingInfo", ref.Type, name)
  39. }
  40. func (s DistributedVirtualSwitch) Reconfigure(ctx context.Context, spec types.BaseDVSConfigSpec) (*Task, error) {
  41. req := types.ReconfigureDvs_Task{
  42. This: s.Reference(),
  43. Spec: spec,
  44. }
  45. res, err := methods.ReconfigureDvs_Task(ctx, s.Client(), &req)
  46. if err != nil {
  47. return nil, err
  48. }
  49. return NewTask(s.Client(), res.Returnval), nil
  50. }
  51. func (s DistributedVirtualSwitch) AddPortgroup(ctx context.Context, spec []types.DVPortgroupConfigSpec) (*Task, error) {
  52. req := types.AddDVPortgroup_Task{
  53. This: s.Reference(),
  54. Spec: spec,
  55. }
  56. res, err := methods.AddDVPortgroup_Task(ctx, s.Client(), &req)
  57. if err != nil {
  58. return nil, err
  59. }
  60. return NewTask(s.Client(), res.Returnval), nil
  61. }
  62. func (s DistributedVirtualSwitch) FetchDVPorts(ctx context.Context, criteria *types.DistributedVirtualSwitchPortCriteria) ([]types.DistributedVirtualPort, error) {
  63. req := &types.FetchDVPorts{
  64. This: s.Reference(),
  65. Criteria: criteria,
  66. }
  67. res, err := methods.FetchDVPorts(ctx, s.Client(), req)
  68. if err != nil {
  69. return nil, err
  70. }
  71. return res.Returnval, nil
  72. }
  73. func (s DistributedVirtualSwitch) ReconfigureDVPort(ctx context.Context, spec []types.DVPortConfigSpec) (*Task, error) {
  74. req := types.ReconfigureDVPort_Task{
  75. This: s.Reference(),
  76. Port: spec,
  77. }
  78. res, err := methods.ReconfigureDVPort_Task(ctx, s.Client(), &req)
  79. if err != nil {
  80. return nil, err
  81. }
  82. return NewTask(s.Client(), res.Returnval), nil
  83. }
  84. func (s DistributedVirtualSwitch) ReconfigureLACP(ctx context.Context, spec []types.VMwareDvsLacpGroupSpec) (*Task, error) {
  85. req := types.UpdateDVSLacpGroupConfig_Task{
  86. This: s.Reference(),
  87. LacpGroupSpec: spec,
  88. }
  89. res, err := methods.UpdateDVSLacpGroupConfig_Task(ctx, s.Client(), &req)
  90. if err != nil {
  91. return nil, err
  92. }
  93. return NewTask(s.Client(), res.Returnval), nil
  94. }