11/*
2- Copyright (c) 2014-2023 VMware, Inc. All Rights Reserved.
2+ Copyright (c) 2024-2024 VMware, Inc. All Rights Reserved.
33
44Licensed under the Apache License, Version 2.0 (the "License");
55you may not use this file except in compliance with the License.
@@ -49,6 +49,8 @@ type Executor struct {
4949 mme * internal.ReflectManagedMethodExecuter
5050 dtm * internal.InternalDynamicTypeManager
5151 info map [string ]* CommandInfo
52+
53+ Trace func (* internal.ExecuteSoapRequest , * internal.ExecuteSoapResponse )
5254}
5355
5456func NewExecutor (c * vim25.Client , host * object.HostSystem ) (* Executor , error ) {
@@ -88,32 +90,42 @@ func NewExecutor(c *vim25.Client, host *object.HostSystem) (*Executor, error) {
8890 return e , nil
8991}
9092
91- func (e * Executor ) CommandInfo (c * Command ) (* CommandInfoMethod , error ) {
92- ns := c .Namespace ()
93- var info * CommandInfo
94- var ok bool
95-
96- if info , ok = e .info [ns ]; ! ok {
97- req := internal.ExecuteSoapRequest {
98- Moid : "ha-dynamic-type-manager-local-cli-cliinfo" ,
99- Method : "vim.CLIInfo.FetchCLIInfo" ,
100- Argument : []internal.ReflectManagedMethodExecuterSoapArgument {
101- c .Argument ("typeName" , "vim.EsxCLI." + ns ),
102- },
103- }
93+ func (e * Executor ) CommandInfo (ns string ) (* CommandInfo , error ) {
94+ info , ok := e .info [ns ]
95+ if ok {
96+ return info , nil
97+ }
10498
105- info = new (CommandInfo )
106- if err := e .Execute (& req , info ); err != nil {
107- return nil , err
108- }
99+ req := internal.ExecuteSoapRequest {
100+ Moid : "ha-dynamic-type-manager-local-cli-cliinfo" ,
101+ Method : "vim.CLIInfo.FetchCLIInfo" ,
102+ Argument : []internal.ReflectManagedMethodExecuterSoapArgument {
103+ NewCommand (nil ).Argument ("typeName" , "vim.EsxCLI." + ns ),
104+ },
105+ }
109106
110- e .info [ns ] = info
107+ info = new (CommandInfo )
108+ if err := e .Execute (& req , info ); err != nil {
109+ return nil , err
110+ }
111+
112+ e .info [ns ] = info
113+
114+ return info , nil
115+ }
116+
117+ func (e * Executor ) CommandInfoMethod (c * Command ) (* CommandInfoMethod , error ) {
118+ ns := c .Namespace ()
119+
120+ info , err := e .CommandInfo (ns )
121+ if err != nil {
122+ return nil , err
111123 }
112124
113125 name := c .Name ()
114126 for _ , method := range info .Method {
115127 if method .Name == name {
116- return method , nil
128+ return & method , nil
117129 }
118130 }
119131
@@ -123,7 +135,7 @@ func (e *Executor) CommandInfo(c *Command) (*CommandInfoMethod, error) {
123135func (e * Executor ) NewRequest (args []string ) (* internal.ExecuteSoapRequest , * CommandInfoMethod , error ) {
124136 c := NewCommand (args )
125137
126- info , err := e .CommandInfo (c )
138+ info , err := e .CommandInfoMethod (c )
127139 if err != nil {
128140 return nil , nil , err
129141 }
@@ -152,6 +164,10 @@ func (e *Executor) Execute(req *internal.ExecuteSoapRequest, res interface{}) er
152164 return err
153165 }
154166
167+ if e .Trace != nil {
168+ e .Trace (req , x )
169+ }
170+
155171 if x .Returnval != nil {
156172 if x .Returnval .Fault != nil {
157173 return & Fault {
0 commit comments