Skip to content

Commit

Permalink
Add support for SOAP request operation ID header
Browse files Browse the repository at this point in the history
  • Loading branch information
dougm committed Sep 26, 2017
1 parent afc0002 commit c4cab69
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
7 changes: 7 additions & 0 deletions govc/cli/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"os"
"sort"
"text/tabwriter"

"github.com/vmware/govmomi/vim25/types"
)

type HasFlags interface {
Expand Down Expand Up @@ -136,6 +138,11 @@ func Run(args []string) int {
fs.SetOutput(ioutil.Discard)

ctx := context.Background()

if id := os.Getenv("GOVC_OPERATION_ID"); id != "" {
ctx = context.WithValue(ctx, types.ID{}, id)
}

cmd.Register(ctx, fs)

if err = fs.Parse(args[1:]); err != nil {
Expand Down
11 changes: 11 additions & 0 deletions govc/test/logs.bats
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,14 @@ load test_helper
run govc logs.ls -host enoent
assert_success
}

@test "logs opid" {
esx_env

id=$(new_id)

run env GOVC_OPERATION_ID="$id" govc events
assert_success

govc logs | grep "$id"
}
18 changes: 12 additions & 6 deletions vim25/soap/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const (

type header struct {
Cookie string `xml:"vcSessionCookie,omitempty"`
ID string `xml:"operationID,omitempty"`
}

type Client struct {
Expand All @@ -78,7 +79,7 @@ type Client struct {
Version string // Vim version
UserAgent string

header *header
cookie string
}

var schemeMatch = regexp.MustCompile(`^\w+://`)
Expand Down Expand Up @@ -168,10 +169,7 @@ func (c *Client) NewServiceClient(path string, namespace string) *Client {
// Set SOAP Header cookie
for _, cookie := range client.Jar.Cookies(u) {
if cookie.Name == "vmware_soap_session" {
client.header = &header{
Cookie: cookie.Value,
}

client.cookie = cookie.Value
break
}
}
Expand Down Expand Up @@ -433,7 +431,15 @@ func (c *Client) RoundTrip(ctx context.Context, reqBody, resBody HasFault) error
reqEnv := Envelope{Body: reqBody}
resEnv := Envelope{Body: resBody}

reqEnv.Header = c.header
h := &header{
Cookie: c.cookie,
}

if id, ok := ctx.Value(types.ID{}).(string); ok {
h.ID = id
}

reqEnv.Header = h

// Create debugging context for this round trip
d := c.d.newRoundTrip()
Expand Down

0 comments on commit c4cab69

Please sign in to comment.