github.com/vmware/govmomi@v0.37.1/eam/simulator/simulator.go (about)

     1  /*
     2  Copyright (c) 2021 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/eam"
    21  	"github.com/vmware/govmomi/eam/types"
    22  	"github.com/vmware/govmomi/simulator"
    23  	vimmo "github.com/vmware/govmomi/vim25/mo"
    24  	vim "github.com/vmware/govmomi/vim25/types"
    25  )
    26  
    27  func init() {
    28  	simulator.RegisterEndpoint(func(s *simulator.Service, r *simulator.Registry) {
    29  		if r.IsVPX() {
    30  			s.RegisterSDK(New())
    31  		}
    32  	})
    33  }
    34  
    35  func New() *simulator.Registry {
    36  	r := simulator.NewRegistry()
    37  	r.Namespace = eam.Namespace
    38  	r.Path = eam.Path
    39  	r.Handler = invalidLoginForNilSessionFn
    40  
    41  	r.Put(&EsxAgentManager{
    42  		EamObject: EamObject{
    43  			Self: eam.EsxAgentManager,
    44  		},
    45  	})
    46  
    47  	return r
    48  }
    49  
    50  // invalidLoginForNilSessionFn returns EamInvalidLogin if the provided
    51  // ctx.Session is nil. This is for validating all calls to EAM methods
    52  // have a valid credential.
    53  func invalidLoginForNilSessionFn(
    54  	ctx *simulator.Context,
    55  	_ *simulator.Method) (vimmo.Reference, vim.BaseMethodFault) {
    56  
    57  	if ctx.Session == nil {
    58  		return nil, new(types.EamInvalidLogin)
    59  	}
    60  	return nil, nil
    61  }