Skip to content

Commit

Permalink
vcsim: include all namespaces in /about info
Browse files Browse the repository at this point in the history
List types and methods for all namespaces, not just vim25
  • Loading branch information
dougm committed May 11, 2021
1 parent 659fd51 commit 4fea687
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
2 changes: 2 additions & 0 deletions govc/test/vcsim.bats
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ EOF
run curl -skf "$url/about"
assert_matches "CurrentTime" # 1 param (without Context)
assert_matches "TerminateSession" # 2 params (with Context)
assert_matches "CnsAttachVolume" # method from namespace vsan
assert_matches "PbmCreate" # method from namespace pbm

run curl -skf "$url/debug/vars"
assert_success
Expand Down
46 changes: 24 additions & 22 deletions simulator/simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,32 +335,34 @@ func (s *Service) About(w http.ResponseWriter, r *http.Request) {

f := reflect.TypeOf((*soap.HasFault)(nil)).Elem()

for _, obj := range Map.objects {
kind := obj.Reference().Type
if seen[kind] {
continue
}
seen[kind] = true

about.Types = append(about.Types, kind)

t := reflect.TypeOf(obj)
for i := 0; i < t.NumMethod(); i++ {
m := t.Method(i)
if seen[m.Name] {
for _, sdk := range s.sdk {
for _, obj := range sdk.objects {
kind := obj.Reference().Type
if seen[kind] {
continue
}
seen[m.Name] = true
seen[kind] = true

in := m.Type.NumIn()
if in < 2 || in > 3 { // at least 2 params (receiver and request), optionally a 3rd param (context)
continue
}
if m.Type.NumOut() != 1 || m.Type.Out(0) != f { // all methods return soap.HasFault
continue
}
about.Types = append(about.Types, kind)

t := reflect.TypeOf(obj)
for i := 0; i < t.NumMethod(); i++ {
m := t.Method(i)
if seen[m.Name] {
continue
}
seen[m.Name] = true

about.Methods = append(about.Methods, strings.Replace(m.Name, "Task", "_Task", 1))
in := m.Type.NumIn()
if in < 2 || in > 3 { // at least 2 params (receiver and request), optionally a 3rd param (context)
continue
}
if m.Type.NumOut() != 1 || m.Type.Out(0) != f { // all methods return soap.HasFault
continue
}

about.Methods = append(about.Methods, strings.Replace(m.Name, "Task", "_Task", 1))
}
}
}

Expand Down

0 comments on commit 4fea687

Please sign in to comment.