godeps: update vmware/govmomi

Update required to continue work on #64021

- The govmomi tag API changed

- Pulling in the new vapi/simulator package for testing the VCP Zones impl
This commit is contained in:
Doug MacEachern
2018-08-22 11:11:11 -07:00
parent c0be4cc09c
commit 5816a8bc18
21 changed files with 1853 additions and 930 deletions

View File

@@ -449,12 +449,51 @@ func (c *Client) UnmarshalJSON(b []byte) error {
return nil
}
func (c *Client) do(ctx context.Context, req *http.Request) (*http.Response, error) {
if nil == ctx || nil == ctx.Done() { // ctx.Done() is for ctx
return c.Client.Do(req)
type kindContext struct{}
func (c *Client) Do(ctx context.Context, req *http.Request, f func(*http.Response) error) error {
if ctx == nil {
ctx = context.Background()
}
// Create debugging context for this round trip
d := c.d.newRoundTrip()
if d.enabled() {
defer d.done()
}
return c.Client.Do(req.WithContext(ctx))
if c.UserAgent != "" {
req.Header.Set(`User-Agent`, c.UserAgent)
}
if d.enabled() {
d.debugRequest(req)
}
tstart := time.Now()
res, err := c.Client.Do(req.WithContext(ctx))
tstop := time.Now()
if d.enabled() {
var name string
if kind, ok := ctx.Value(kindContext{}).(HasFault); ok {
name = fmt.Sprintf("%T", kind)
} else {
name = fmt.Sprintf("%s %s", req.Method, req.URL)
}
d.logf("%6dms (%s)", tstop.Sub(tstart)/time.Millisecond, name)
}
if err != nil {
return err
}
defer res.Body.Close()
if d.enabled() {
d.debugResponse(res)
}
return f(res)
}
// Signer can be implemented by soap.Header.Security to sign requests.
@@ -493,12 +532,6 @@ func (c *Client) RoundTrip(ctx context.Context, reqBody, resBody HasFault) error
reqEnv.Header = &h // XML marshal header only if a field is set
}
// Create debugging context for this round trip
d := c.d.newRoundTrip()
if d.enabled() {
defer d.done()
}
if signer, ok := h.Security.(Signer); ok {
b, err = signer.Sign(reqEnv)
if err != nil {
@@ -517,8 +550,6 @@ func (c *Client) RoundTrip(ctx context.Context, reqBody, resBody HasFault) error
panic(err)
}
req = req.WithContext(ctx)
req.Header.Set(`Content-Type`, `text/xml; charset="utf-8"`)
action := h.Action
@@ -527,54 +558,29 @@ func (c *Client) RoundTrip(ctx context.Context, reqBody, resBody HasFault) error
}
req.Header.Set(`SOAPAction`, action)
if c.UserAgent != "" {
req.Header.Set(`User-Agent`, c.UserAgent)
}
return c.Do(context.WithValue(ctx, kindContext{}, resBody), req, func(res *http.Response) error {
switch res.StatusCode {
case http.StatusOK:
// OK
case http.StatusInternalServerError:
// Error, but typically includes a body explaining the error
default:
return errors.New(res.Status)
}
if d.enabled() {
d.debugRequest(req)
}
dec := xml.NewDecoder(res.Body)
dec.TypeFunc = types.TypeFunc()
err = dec.Decode(&resEnv)
if err != nil {
return err
}
tstart := time.Now()
res, err := c.do(ctx, req)
tstop := time.Now()
if f := resBody.Fault(); f != nil {
return WrapSoapFault(f)
}
if d.enabled() {
d.logf("%6dms (%T)", tstop.Sub(tstart)/time.Millisecond, resBody)
}
if err != nil {
return err
}
if d.enabled() {
d.debugResponse(res)
}
// Close response regardless of what happens next
defer res.Body.Close()
switch res.StatusCode {
case http.StatusOK:
// OK
case http.StatusInternalServerError:
// Error, but typically includes a body explaining the error
default:
return errors.New(res.Status)
}
dec := xml.NewDecoder(res.Body)
dec.TypeFunc = types.TypeFunc()
err = dec.Decode(&resEnv)
if err != nil {
return err
}
if f := resBody.Fault(); f != nil {
return WrapSoapFault(f)
}
return err
})
}
func (c *Client) CloseIdleConnections() {

View File

@@ -21,6 +21,7 @@ import (
"io"
"net/http"
"net/http/httputil"
"strings"
"sync/atomic"
"time"
@@ -69,6 +70,14 @@ func (d *debugRoundTrip) newFile(suffix string) io.WriteCloser {
return debug.NewFile(fmt.Sprintf("%d-%04d.%s", d.cn, d.rn, suffix))
}
func (d *debugRoundTrip) ext(h http.Header) string {
ext := "xml"
if strings.Contains(h.Get("Content-Type"), "/json") {
ext = "json"
}
return ext
}
func (d *debugRoundTrip) debugRequest(req *http.Request) {
if d == nil {
return
@@ -83,7 +92,7 @@ func (d *debugRoundTrip) debugRequest(req *http.Request) {
wc.Close()
// Capture body
wc = d.newFile("req.xml")
wc = d.newFile("req." + d.ext(req.Header))
req.Body = newTeeReader(req.Body, wc)
// Delay closing until marked done
@@ -104,7 +113,7 @@ func (d *debugRoundTrip) debugResponse(res *http.Response) {
wc.Close()
// Capture body
wc = d.newFile("res.xml")
wc = d.newFile("res." + d.ext(res.Header))
res.Body = newTeeReader(res.Body, wc)
// Delay closing until marked done