@@ -10,9 +10,10 @@ import (
1010 "log"
1111 "time"
1212
13- "github.com/vmware/govmomi/session "
13+ "github.com/vmware/govmomi"
1414 "github.com/vmware/govmomi/session/keepalive"
1515 "github.com/vmware/govmomi/simulator"
16+ "github.com/vmware/govmomi/simulator/sim25"
1617 "github.com/vmware/govmomi/vapi/rest"
1718 "github.com/vmware/govmomi/vim25"
1819)
@@ -23,14 +24,21 @@ var (
2324 keepAliveIdle = sessionIdleTimeout / 2
2425)
2526
26- func init () {
27- simulator .SessionIdleTimeout = sessionIdleTimeout
28- }
29-
3027func ExampleHandlerSOAP () {
31- simulator .Run (func (ctx context.Context , c * vim25.Client ) error {
32- // No need for initial Login() here as simulator.Run already has
33- m := session .NewManager (c )
28+ simulator .Run (func (ctx context.Context , vc * vim25.Client ) error {
29+ // Using the authenticated vc client, timeout will apply to new sessions.
30+ sim25 .SetSessionTimeout (ctx , vc , sessionIdleTimeout )
31+
32+ c , err := govmomi .NewClient (ctx , vc .URL (), true )
33+ if err != nil {
34+ return err
35+ }
36+ m := c .SessionManager
37+
38+ err = m .Login (ctx , simulator .DefaultLogin ) // New session
39+ if err != nil {
40+ return err
41+ }
3442
3543 // check twice if session is valid, sleeping > SessionIdleTimeout in between
3644 check := func () {
@@ -53,7 +61,7 @@ func ExampleHandlerSOAP() {
5361 // this starts the keep alive handler when Login is called, and stops the handler when Logout is called
5462 c .RoundTripper = keepalive .NewHandlerSOAP (c .RoundTripper , keepAliveIdle , nil )
5563
56- err : = m .Login (ctx , simulator .DefaultLogin )
64+ err = m .Login (ctx , simulator .DefaultLogin )
5765 if err != nil {
5866 return err
5967 }
@@ -82,8 +90,11 @@ func ExampleHandlerSOAP() {
8290
8391func ExampleHandlerREST () {
8492 simulator .Run (func (ctx context.Context , vc * vim25.Client ) error {
93+ // Using the authenticated vc client, timeout will apply to new sessions.
94+ sim25 .SetSessionTimeout (ctx , vc , sessionIdleTimeout )
95+
8596 c := rest .NewClient (vc )
86- err := c .Login (ctx , simulator .DefaultLogin )
97+ err := c .Login (ctx , simulator .DefaultLogin ) // New session
8798 if err != nil {
8899 return err
89100 }
0 commit comments