github.com/vmware/govmomi@v0.37.2/simulator/dvs_manager.go (about)

     1  /*
     2     Copyright (c) 2020 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 DistributedVirtualSwitchManager struct {
    27  	mo.DistributedVirtualSwitchManager
    28  }
    29  
    30  func (m *DistributedVirtualSwitchManager) DVSManagerLookupDvPortGroup(ctx *Context, req *types.DVSManagerLookupDvPortGroup) soap.HasFault {
    31  	body := &methods.DVSManagerLookupDvPortGroupBody{}
    32  
    33  	for _, obj := range ctx.Map.All("DistributedVirtualSwitch") {
    34  		dvs := obj.(*DistributedVirtualSwitch)
    35  		if dvs.Uuid == req.SwitchUuid {
    36  			for _, ref := range dvs.Portgroup {
    37  				pg := ctx.Map.Get(ref).(*DistributedVirtualPortgroup)
    38  				if pg.Key == req.PortgroupKey {
    39  					body.Res = &types.DVSManagerLookupDvPortGroupResponse{
    40  						Returnval: &ref,
    41  					}
    42  					return body
    43  				}
    44  			}
    45  		}
    46  	}
    47  
    48  	body.Fault_ = Fault("", new(types.NotFound))
    49  
    50  	return body
    51  }