PBM govmomi dependencies

This commit is contained in:
Balu Dontu
2017-05-22 11:20:12 -07:00
committed by System Administrator
parent 199465c3a5
commit 23ee1745d3
50 changed files with 5272 additions and 297 deletions

View File

@@ -58,6 +58,10 @@ const (
DefaultMinVimVersion = "5.5"
)
type header struct {
Cookie string `xml:"vcSessionCookie,omitempty"`
}
type Client struct {
http.Client
@@ -73,6 +77,8 @@ type Client struct {
Namespace string // Vim namespace
Version string // Vim version
UserAgent string
header *header
}
var schemeMatch = regexp.MustCompile(`^\w+://`)
@@ -147,6 +153,32 @@ func NewClient(u *url.URL, insecure bool) *Client {
return &c
}
// NewServiceClient creates a NewClient with the given URL.Path and namespace.
func (c *Client) NewServiceClient(path string, namespace string) *Client {
u := c.URL()
u.Path = path
client := NewClient(u, c.k)
client.Namespace = namespace
// Copy the cookies
client.Client.Jar.SetCookies(u, c.Client.Jar.Cookies(u))
// Set SOAP Header cookie
for _, cookie := range client.Jar.Cookies(u) {
if cookie.Name == "vmware_soap_session" {
client.header = &header{
Cookie: cookie.Value,
}
break
}
}
return client
}
// SetRootCAs defines the set of root certificate authorities
// that clients use when verifying server certificates.
// By default TLS uses the host's root CA set.
@@ -401,6 +433,8 @@ func (c *Client) RoundTrip(ctx context.Context, reqBody, resBody HasFault) error
reqEnv := Envelope{Body: reqBody}
resEnv := Envelope{Body: resBody}
reqEnv.Header = c.header
// Create debugging context for this round trip
d := c.d.newRoundTrip()
if d.enabled() {

View File

@@ -36,7 +36,13 @@ type soapFaultError struct {
}
func (s soapFaultError) Error() string {
return fmt.Sprintf("%s: %s", s.fault.Code, s.fault.String)
msg := s.fault.String
if msg == "" {
msg = reflect.TypeOf(s.fault.Detail.Fault).Name()
}
return fmt.Sprintf("%s: %s", s.fault.Code, msg)
}
type vimFaultError struct {

View File

@@ -22,15 +22,11 @@ import (
)
type Envelope struct {
XMLName xml.Name `xml:"http://schemas.xmlsoap.org/soap/envelope/ Envelope"`
Header *Header `xml:",omitempty"`
XMLName xml.Name `xml:"http://schemas.xmlsoap.org/soap/envelope/ Envelope"`
Header interface{} `xml:",omitempty"`
Body interface{}
}
type Header struct {
XMLName xml.Name `xml:"http://schemas.xmlsoap.org/soap/envelope/ Header"`
}
type Fault struct {
XMLName xml.Name `xml:"http://schemas.xmlsoap.org/soap/envelope/ Fault"`
Code string `xml:"faultcode"`