github.com/vmware/govmomi@v0.37.1/object/distributed_virtual_switch.go (about) 1 /* 2 Copyright (c) 2015 VMware, Inc. All Rights Reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package object 18 19 import ( 20 "context" 21 "fmt" 22 23 "github.com/vmware/govmomi/vim25" 24 "github.com/vmware/govmomi/vim25/methods" 25 "github.com/vmware/govmomi/vim25/types" 26 ) 27 28 type DistributedVirtualSwitch struct { 29 Common 30 } 31 32 func NewDistributedVirtualSwitch(c *vim25.Client, ref types.ManagedObjectReference) *DistributedVirtualSwitch { 33 return &DistributedVirtualSwitch{ 34 Common: NewCommon(c, ref), 35 } 36 } 37 38 func (s DistributedVirtualSwitch) GetInventoryPath() string { 39 return s.InventoryPath 40 } 41 42 func (s DistributedVirtualSwitch) EthernetCardBackingInfo(ctx context.Context) (types.BaseVirtualDeviceBackingInfo, error) { 43 ref := s.Reference() 44 name := s.InventoryPath 45 if name == "" { 46 name = ref.String() 47 } 48 return nil, fmt.Errorf("type %s (%s) cannot be used for EthernetCardBackingInfo", ref.Type, name) 49 } 50 51 func (s DistributedVirtualSwitch) Reconfigure(ctx context.Context, spec types.BaseDVSConfigSpec) (*Task, error) { 52 req := types.ReconfigureDvs_Task{ 53 This: s.Reference(), 54 Spec: spec, 55 } 56 57 res, err := methods.ReconfigureDvs_Task(ctx, s.Client(), &req) 58 if err != nil { 59 return nil, err 60 } 61 62 return NewTask(s.Client(), res.Returnval), nil 63 } 64 65 func (s DistributedVirtualSwitch) AddPortgroup(ctx context.Context, spec []types.DVPortgroupConfigSpec) (*Task, error) { 66 req := types.AddDVPortgroup_Task{ 67 This: s.Reference(), 68 Spec: spec, 69 } 70 71 res, err := methods.AddDVPortgroup_Task(ctx, s.Client(), &req) 72 if err != nil { 73 return nil, err 74 } 75 76 return NewTask(s.Client(), res.Returnval), nil 77 } 78 79 func (s DistributedVirtualSwitch) FetchDVPorts(ctx context.Context, criteria *types.DistributedVirtualSwitchPortCriteria) ([]types.DistributedVirtualPort, error) { 80 req := &types.FetchDVPorts{ 81 This: s.Reference(), 82 Criteria: criteria, 83 } 84 85 res, err := methods.FetchDVPorts(ctx, s.Client(), req) 86 if err != nil { 87 return nil, err 88 } 89 return res.Returnval, nil 90 } 91 92 func (s DistributedVirtualSwitch) ReconfigureDVPort(ctx context.Context, spec []types.DVPortConfigSpec) (*Task, error) { 93 req := types.ReconfigureDVPort_Task{ 94 This: s.Reference(), 95 Port: spec, 96 } 97 98 res, err := methods.ReconfigureDVPort_Task(ctx, s.Client(), &req) 99 if err != nil { 100 return nil, err 101 } 102 103 return NewTask(s.Client(), res.Returnval), nil 104 } 105 106 func (s DistributedVirtualSwitch) ReconfigureLACP(ctx context.Context, spec []types.VMwareDvsLacpGroupSpec) (*Task, error) { 107 req := types.UpdateDVSLacpGroupConfig_Task{ 108 This: s.Reference(), 109 LacpGroupSpec: spec, 110 } 111 112 res, err := methods.UpdateDVSLacpGroupConfig_Task(ctx, s.Client(), &req) 113 if err != nil { 114 return nil, err 115 } 116 117 return NewTask(s.Client(), res.Returnval), nil 118 }