github.com/vmware/govmomi@v0.43.0/simulator/portgroup.go (about) 1 /* 2 Copyright (c) 2017 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 simulator 18 19 import ( 20 "github.com/vmware/govmomi/vim25/methods" 21 "github.com/vmware/govmomi/vim25/mo" 22 "github.com/vmware/govmomi/vim25/soap" 23 "github.com/vmware/govmomi/vim25/types" 24 ) 25 26 type DistributedVirtualPortgroup struct { 27 mo.DistributedVirtualPortgroup 28 } 29 30 func (p *DistributedVirtualPortgroup) event(ctx *Context) types.DVPortgroupEvent { 31 dvs := ctx.Map.Get(*p.Config.DistributedVirtualSwitch).(*DistributedVirtualSwitch) 32 33 return types.DVPortgroupEvent{ 34 Event: types.Event{ 35 Datacenter: datacenterEventArgument(p), 36 Net: &types.NetworkEventArgument{ 37 EntityEventArgument: types.EntityEventArgument{ 38 Name: p.Name, 39 }, 40 Network: p.Self, 41 }, 42 Dvs: dvs.eventArgument(), 43 }, 44 } 45 } 46 47 func (s *DistributedVirtualPortgroup) RenameTask(ctx *Context, req *types.Rename_Task) soap.HasFault { 48 canDup := s.DistributedVirtualPortgroup.Config.BackingType == string(types.DistributedVirtualPortgroupBackingTypeNsx) 49 50 return RenameTask(ctx, s, req, canDup) 51 } 52 53 func (s *DistributedVirtualPortgroup) ReconfigureDVPortgroupTask(ctx *Context, req *types.ReconfigureDVPortgroup_Task) soap.HasFault { 54 task := CreateTask(s, "reconfigureDvPortgroup", func(t *Task) (types.AnyType, types.BaseMethodFault) { 55 s.Config.DefaultPortConfig = req.Spec.DefaultPortConfig 56 s.Config.NumPorts = req.Spec.NumPorts 57 s.Config.AutoExpand = req.Spec.AutoExpand 58 s.Config.Type = req.Spec.Type 59 s.Config.Description = req.Spec.Description 60 s.Config.DynamicData = req.Spec.DynamicData 61 s.Config.Name = req.Spec.Name 62 s.Config.Policy = req.Spec.Policy 63 s.Config.PortNameFormat = req.Spec.PortNameFormat 64 s.Config.VmVnicNetworkResourcePoolKey = req.Spec.VmVnicNetworkResourcePoolKey 65 s.Config.LogicalSwitchUuid = req.Spec.LogicalSwitchUuid 66 s.Config.BackingType = req.Spec.BackingType 67 68 return nil, nil 69 }) 70 71 return &methods.ReconfigureDVPortgroup_TaskBody{ 72 Res: &types.ReconfigureDVPortgroup_TaskResponse{ 73 Returnval: task.Run(ctx), 74 }, 75 } 76 } 77 78 func (s *DistributedVirtualPortgroup) DestroyTask(ctx *Context, req *types.Destroy_Task) soap.HasFault { 79 task := CreateTask(s, "destroy", func(t *Task) (types.AnyType, types.BaseMethodFault) { 80 vswitch := ctx.Map.Get(*s.Config.DistributedVirtualSwitch).(*DistributedVirtualSwitch) 81 ctx.Map.RemoveReference(ctx, vswitch, &vswitch.Portgroup, s.Reference()) 82 ctx.Map.removeString(ctx, vswitch, &vswitch.Summary.PortgroupName, s.Name) 83 84 f := ctx.Map.getEntityParent(vswitch, "Folder").(*Folder) 85 folderRemoveChild(ctx, &f.Folder, s.Reference()) 86 ctx.postEvent(&types.DVPortgroupDestroyedEvent{DVPortgroupEvent: s.event(ctx)}) 87 88 return nil, nil 89 }) 90 91 return &methods.Destroy_TaskBody{ 92 Res: &types.Destroy_TaskResponse{ 93 Returnval: task.Run(ctx), 94 }, 95 } 96 97 }