1
- /*
2
- Copyright (c) 2018 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
- */
1
+ // © Broadcom. All Rights Reserved.
2
+ // The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
3
+ // SPDX-License-Identifier: Apache-2.0
16
4
17
5
package simulator
18
6
@@ -52,12 +40,10 @@ func New() *simulator.Registry {
52
40
r .Put (& ServiceInstance {
53
41
ManagedObjectReference : lookup .ServiceInstance ,
54
42
Content : content ,
55
- register : func () {
56
- r .Put (& ServiceRegistration {
57
- ManagedObjectReference : * content .ServiceRegistration ,
58
- Info : registrationInfo (),
59
- })
60
- },
43
+ })
44
+
45
+ r .Put (& ServiceRegistration {
46
+ ManagedObjectReference : * content .ServiceRegistration ,
61
47
})
62
48
63
49
return r
@@ -67,15 +53,11 @@ type ServiceInstance struct {
67
53
vim.ManagedObjectReference
68
54
69
55
Content types.LookupServiceContent
70
-
71
- instance sync.Once
72
- register func ()
73
56
}
74
57
75
- func (s * ServiceInstance ) RetrieveServiceContent (_ * types.RetrieveServiceContent ) soap.HasFault {
76
- // defer register to this point to ensure we can include vcsim's cert in ServiceEndpoints.SslTrust
77
- // TODO: we should be able to register within New(), but this is the only place that currently depends on vcsim's cert.
78
- s .instance .Do (s .register )
58
+ func (s * ServiceInstance ) RetrieveServiceContent (ctx * simulator.Context , _ * types.RetrieveServiceContent ) soap.HasFault {
59
+ // Initialize prior to List() being called (see ExampleServiceRegistration)
60
+ ctx .Map .Get (* content .ServiceRegistration ).(* ServiceRegistration ).info (ctx )
79
61
80
62
return & methods.RetrieveServiceContentBody {
81
63
Res : & types.RetrieveServiceContentResponse {
@@ -88,6 +70,8 @@ type ServiceRegistration struct {
88
70
vim.ManagedObjectReference
89
71
90
72
Info []types.LookupServiceRegistrationInfo
73
+
74
+ register sync.Once
91
75
}
92
76
93
77
func (s * ServiceRegistration ) GetSiteId (_ * types.GetSiteId ) soap.HasFault {
@@ -130,7 +114,16 @@ func matchEndpointType(filter, info *types.LookupServiceRegistrationEndpointType
130
114
return true
131
115
}
132
116
133
- func (s * ServiceRegistration ) List (req * types.List ) soap.HasFault {
117
+ // defer register to this point to ensure we can include vcsim's cert in ServiceEndpoints.SslTrust
118
+ // TODO: we should be able to register within New(), but this is the only place that currently depends on vcsim's cert
119
+ func (s * ServiceRegistration ) info (ctx * simulator.Context ) []types.LookupServiceRegistrationInfo {
120
+ s .register .Do (func () {
121
+ s .Info = registrationInfo (ctx )
122
+ })
123
+ return s .Info
124
+ }
125
+
126
+ func (s * ServiceRegistration ) List (ctx * simulator.Context , req * types.List ) soap.HasFault {
134
127
body := new (methods.ListBody )
135
128
filter := req .FilterCriteria
136
129
@@ -143,7 +136,7 @@ func (s *ServiceRegistration) List(req *types.List) soap.HasFault {
143
136
}
144
137
body .Res = new (types.ListResponse )
145
138
146
- for _ , info := range s .Info {
139
+ for _ , info := range s .info ( ctx ) {
147
140
if filter .SiteId != "" {
148
141
if filter .SiteId != info .SiteId {
149
142
continue
0 commit comments