godep: update vmware/govmomi
This commit is contained in:
105
vendor/github.com/vmware/govmomi/simulator/simulator.go
generated
vendored
105
vendor/github.com/vmware/govmomi/simulator/simulator.go
generated
vendored
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2017 VMware, Inc. All Rights Reserved.
|
||||
Copyright (c) 2017-2018 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@@ -59,10 +59,12 @@ type Method struct {
|
||||
// Service decodes incoming requests and dispatches to a Handler
|
||||
type Service struct {
|
||||
client *vim25.Client
|
||||
sm *SessionManager
|
||||
|
||||
readAll func(io.Reader) ([]byte, error)
|
||||
|
||||
TLS *tls.Config
|
||||
TLS *tls.Config
|
||||
ServeMux *http.ServeMux
|
||||
}
|
||||
|
||||
// Server provides a simulator Service over HTTP
|
||||
@@ -77,6 +79,7 @@ type Server struct {
|
||||
func New(instance *ServiceInstance) *Service {
|
||||
s := &Service{
|
||||
readAll: ioutil.ReadAll,
|
||||
sm: Map.SessionManager(),
|
||||
}
|
||||
|
||||
s.client, _ = vim25.NewClient(context.Background(), s)
|
||||
@@ -106,8 +109,29 @@ func Fault(msg string, fault types.BaseMethodFault) *soap.Fault {
|
||||
return f
|
||||
}
|
||||
|
||||
func (s *Service) call(method *Method) soap.HasFault {
|
||||
func (s *Service) call(ctx *Context, method *Method) soap.HasFault {
|
||||
handler := Map.Get(method.This)
|
||||
session := ctx.Session
|
||||
|
||||
if session == nil {
|
||||
switch method.Name {
|
||||
case "RetrieveServiceContent", "Login", "RetrieveProperties", "RetrievePropertiesEx", "CloneSession":
|
||||
// ok for now, TODO: authz
|
||||
default:
|
||||
fault := &types.NotAuthenticated{
|
||||
NoPermission: types.NoPermission{
|
||||
Object: method.This,
|
||||
PrivilegeId: "System.View",
|
||||
},
|
||||
}
|
||||
return &serverFaultBody{Reason: Fault("", fault)}
|
||||
}
|
||||
} else {
|
||||
// Prefer the Session.Registry, ServiceContent.PropertyCollector filter field for example is per-session
|
||||
if h := session.Get(method.This); h != nil {
|
||||
handler = h
|
||||
}
|
||||
}
|
||||
|
||||
if handler == nil {
|
||||
msg := fmt.Sprintf("managed object not found: %s", method.This)
|
||||
@@ -141,7 +165,14 @@ func (s *Service) call(method *Method) soap.HasFault {
|
||||
}
|
||||
}
|
||||
|
||||
res := m.Call([]reflect.Value{reflect.ValueOf(method.Body)})
|
||||
var args, res []reflect.Value
|
||||
if m.Type().NumIn() == 2 {
|
||||
args = append(args, reflect.ValueOf(ctx))
|
||||
}
|
||||
args = append(args, reflect.ValueOf(method.Body))
|
||||
Map.WithLock(handler, func() {
|
||||
res = m.Call(args)
|
||||
})
|
||||
|
||||
return res[0].Interface().(soap.HasFault)
|
||||
}
|
||||
@@ -165,7 +196,10 @@ func (s *Service) RoundTrip(ctx context.Context, request, response soap.HasFault
|
||||
Body: req.Interface(),
|
||||
}
|
||||
|
||||
res := s.call(method)
|
||||
res := s.call(&Context{
|
||||
Context: ctx,
|
||||
Session: internalContext.Session,
|
||||
}, method)
|
||||
|
||||
if err := res.Fault(); err != nil {
|
||||
return soap.WrapSoapFault(err)
|
||||
@@ -226,7 +260,11 @@ func (s *Service) About(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
seen[m.Name] = true
|
||||
|
||||
if m.Type.NumIn() != 2 || m.Type.NumOut() != 1 || m.Type.Out(0) != f {
|
||||
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
|
||||
}
|
||||
|
||||
@@ -262,6 +300,15 @@ func (s *Service) ServeSDK(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintf(os.Stderr, "Request: %s\n", string(body))
|
||||
}
|
||||
|
||||
ctx := &Context{
|
||||
req: r,
|
||||
res: w,
|
||||
m: s.sm,
|
||||
|
||||
Context: context.Background(),
|
||||
}
|
||||
Map.WithLock(s.sm, ctx.mapSession)
|
||||
|
||||
var res soap.HasFault
|
||||
var soapBody interface{}
|
||||
|
||||
@@ -269,7 +316,7 @@ func (s *Service) ServeSDK(w http.ResponseWriter, r *http.Request) {
|
||||
if err != nil {
|
||||
res = serverFault(err.Error())
|
||||
} else {
|
||||
res = s.call(method)
|
||||
res = s.call(ctx, method)
|
||||
}
|
||||
|
||||
if f := res.Fault(); f != nil {
|
||||
@@ -349,20 +396,10 @@ func (s *Service) ServeDatastore(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
file := strings.TrimPrefix(r.URL.Path, folderPrefix)
|
||||
p := path.Join(ds.Info.GetDatastoreInfo().Url, file)
|
||||
r.URL.Path = strings.TrimPrefix(r.URL.Path, folderPrefix)
|
||||
p := path.Join(ds.Info.GetDatastoreInfo().Url, r.URL.Path)
|
||||
|
||||
switch r.Method {
|
||||
case "GET":
|
||||
f, err := os.Open(p)
|
||||
if err != nil {
|
||||
log.Printf("failed to %s '%s': %s", r.Method, p, err)
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
_, _ = io.Copy(w, f)
|
||||
case "POST":
|
||||
_, err := os.Stat(p)
|
||||
if err == nil {
|
||||
@@ -384,7 +421,9 @@ func (s *Service) ServeDatastore(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
_, _ = io.Copy(f, r.Body)
|
||||
default:
|
||||
w.WriteHeader(http.StatusMethodNotAllowed)
|
||||
fs := http.FileServer(http.Dir(ds.Info.GetDatastoreInfo().Url))
|
||||
|
||||
fs.ServeHTTP(w, r)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -408,7 +447,11 @@ func (*Service) ServiceVersions(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// NewServer returns an http Server instance for the given service
|
||||
func (s *Service) NewServer() *Server {
|
||||
mux := http.NewServeMux()
|
||||
mux := s.ServeMux
|
||||
if mux == nil {
|
||||
mux = http.NewServeMux()
|
||||
}
|
||||
|
||||
path := "/sdk"
|
||||
|
||||
mux.HandleFunc(path, s.ServeSDK)
|
||||
@@ -428,7 +471,7 @@ func (s *Service) NewServer() *Server {
|
||||
}
|
||||
|
||||
// Redirect clients to this http server, rather than HostSystem.Name
|
||||
Map.Get(*s.client.ServiceContent.SessionManager).(*SessionManager).ServiceHostName = u.Host
|
||||
Map.SessionManager().ServiceHostName = u.Host
|
||||
|
||||
if f := flag.Lookup("httptest.serve"); f != nil {
|
||||
// Avoid the blocking behaviour of httptest.Server.Start() when this flag is set
|
||||
@@ -491,7 +534,23 @@ func (s *Server) Close() {
|
||||
}
|
||||
}
|
||||
|
||||
var typeFunc = types.TypeFunc()
|
||||
var (
|
||||
vim25MapType = types.TypeFunc()
|
||||
typeFunc = defaultMapType
|
||||
)
|
||||
|
||||
func defaultMapType(name string) (reflect.Type, bool) {
|
||||
typ, ok := vim25MapType(name)
|
||||
if !ok {
|
||||
// See TestIssue945, in which case Go does not resolve the namespace and name == "ns1:TraversalSpec"
|
||||
// Without this hack, the SelectSet would be all nil's
|
||||
kind := strings.SplitN(name, ":", 2)
|
||||
if len(kind) == 2 {
|
||||
typ, ok = vim25MapType(kind[1])
|
||||
}
|
||||
}
|
||||
return typ, ok
|
||||
}
|
||||
|
||||
// UnmarshalBody extracts the Body from a soap.Envelope and unmarshals to the corresponding govmomi type
|
||||
func UnmarshalBody(data []byte) (*Method, error) {
|
||||
|
||||
Reference in New Issue
Block a user