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

@@ -1,5 +1,5 @@
/*
Copyright (c) 2014-2016 VMware, Inc. All Rights Reserved.
Copyright (c) 2014-2017 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.

View File

@@ -104,6 +104,8 @@ func Ancestors(ctx context.Context, rt soap.RoundTripper, pc, obj types.ManagedO
me.Name = x.Name
case DistributedVirtualPortgroup:
me.Name = x.Name
case OpaqueNetwork:
me.Name = x.Name
default:
// ManagedEntity always has a Name, if we hit this point we missed a case above.
panic(fmt.Sprintf("%#v Name is empty", me.Reference()))

View File

@@ -1,5 +1,5 @@
/*
Copyright (c) 2014-2016 VMware, Inc. All Rights Reserved.
Copyright (c) 2014-2017 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.
@@ -150,6 +150,30 @@ func init() {
t["ContainerView"] = reflect.TypeOf((*ContainerView)(nil)).Elem()
}
type CryptoManager struct {
Self types.ManagedObjectReference
Enabled bool `mo:"enabled"`
}
func (m CryptoManager) Reference() types.ManagedObjectReference {
return m.Self
}
func init() {
t["CryptoManager"] = reflect.TypeOf((*CryptoManager)(nil)).Elem()
}
type CryptoManagerKmip struct {
CryptoManager
KmipServers []types.KmipClusterInfo `mo:"kmipServers"`
}
func init() {
t["CryptoManagerKmip"] = reflect.TypeOf((*CryptoManagerKmip)(nil)).Elem()
}
type CustomFieldsManager struct {
Self types.ManagedObjectReference
@@ -356,6 +380,34 @@ func init() {
t["ExtensionManager"] = reflect.TypeOf((*ExtensionManager)(nil)).Elem()
}
type FailoverClusterConfigurator struct {
Self types.ManagedObjectReference
DisabledConfigureMethod []string `mo:"disabledConfigureMethod"`
}
func (m FailoverClusterConfigurator) Reference() types.ManagedObjectReference {
return m.Self
}
func init() {
t["FailoverClusterConfigurator"] = reflect.TypeOf((*FailoverClusterConfigurator)(nil)).Elem()
}
type FailoverClusterManager struct {
Self types.ManagedObjectReference
DisabledClusterMethod []string `mo:"disabledClusterMethod"`
}
func (m FailoverClusterManager) Reference() types.ManagedObjectReference {
return m.Self
}
func init() {
t["FailoverClusterManager"] = reflect.TypeOf((*FailoverClusterManager)(nil)).Elem()
}
type FileManager struct {
Self types.ManagedObjectReference
}
@@ -461,6 +513,18 @@ func init() {
t["GuestWindowsRegistryManager"] = reflect.TypeOf((*GuestWindowsRegistryManager)(nil)).Elem()
}
type HealthUpdateManager struct {
Self types.ManagedObjectReference
}
func (m HealthUpdateManager) Reference() types.ManagedObjectReference {
return m.Self
}
func init() {
t["HealthUpdateManager"] = reflect.TypeOf((*HealthUpdateManager)(nil)).Elem()
}
type HistoryCollector struct {
Self types.ManagedObjectReference
@@ -695,8 +759,9 @@ func init() {
type HostGraphicsManager struct {
ExtensibleManagedObject
GraphicsInfo []types.HostGraphicsInfo `mo:"graphicsInfo"`
SharedPassthruGpuTypes []string `mo:"sharedPassthruGpuTypes"`
GraphicsInfo []types.HostGraphicsInfo `mo:"graphicsInfo"`
GraphicsConfig *types.HostGraphicsConfig `mo:"graphicsConfig"`
SharedPassthruGpuTypes []string `mo:"sharedPassthruGpuTypes"`
}
func init() {
@@ -803,7 +868,8 @@ func init() {
type HostPciPassthruSystem struct {
ExtensibleManagedObject
PciPassthruInfo []types.BaseHostPciPassthruInfo `mo:"pciPassthruInfo"`
PciPassthruInfo []types.BaseHostPciPassthruInfo `mo:"pciPassthruInfo"`
SriovDevicePoolInfo []types.BaseHostSriovDevicePoolInfo `mo:"sriovDevicePoolInfo"`
}
func init() {
@@ -868,6 +934,18 @@ func init() {
t["HostSnmpSystem"] = reflect.TypeOf((*HostSnmpSystem)(nil)).Elem()
}
type HostSpecificationManager struct {
Self types.ManagedObjectReference
}
func (m HostSpecificationManager) Reference() types.ManagedObjectReference {
return m.Self
}
func init() {
t["HostSpecificationManager"] = reflect.TypeOf((*HostSpecificationManager)(nil)).Elem()
}
type HostStorageSystem struct {
ExtensibleManagedObject
@@ -931,6 +1009,14 @@ func init() {
t["HostVMotionSystem"] = reflect.TypeOf((*HostVMotionSystem)(nil)).Elem()
}
type HostVStorageObjectManager struct {
VStorageObjectManagerBase
}
func init() {
t["HostVStorageObjectManager"] = reflect.TypeOf((*HostVStorageObjectManager)(nil)).Elem()
}
type HostVirtualNicManager struct {
ExtensibleManagedObject
@@ -984,18 +1070,6 @@ func init() {
t["HttpNfcLease"] = reflect.TypeOf((*HttpNfcLease)(nil)).Elem()
}
type InternalDynamicTypeManager struct {
Self types.ManagedObjectReference
}
func (m InternalDynamicTypeManager) Reference() types.ManagedObjectReference {
return m.Self
}
func init() {
t["InternalDynamicTypeManager"] = reflect.TypeOf((*InternalDynamicTypeManager)(nil)).Elem()
}
type InventoryView struct {
ManagedObjectView
}
@@ -1163,6 +1237,9 @@ func init() {
type OpaqueNetwork struct {
Network
Capability *types.OpaqueNetworkCapability `mo:"capability"`
ExtraConfig []types.BaseOptionValue `mo:"extraConfig"`
}
func init() {
@@ -1302,18 +1379,6 @@ func init() {
t["PropertyFilter"] = reflect.TypeOf((*PropertyFilter)(nil)).Elem()
}
type ReflectManagedMethodExecuter struct {
Self types.ManagedObjectReference
}
func (m ReflectManagedMethodExecuter) Reference() types.ManagedObjectReference {
return m.Self
}
func init() {
t["ReflectManagedMethodExecuter"] = reflect.TypeOf((*ReflectManagedMethodExecuter)(nil)).Elem()
}
type ResourcePlanningManager struct {
Self types.ManagedObjectReference
}
@@ -1520,6 +1585,26 @@ func init() {
t["UserDirectory"] = reflect.TypeOf((*UserDirectory)(nil)).Elem()
}
type VStorageObjectManagerBase struct {
Self types.ManagedObjectReference
}
func (m VStorageObjectManagerBase) Reference() types.ManagedObjectReference {
return m.Self
}
func init() {
t["VStorageObjectManagerBase"] = reflect.TypeOf((*VStorageObjectManagerBase)(nil)).Elem()
}
type VcenterVStorageObjectManager struct {
VStorageObjectManagerBase
}
func init() {
t["VcenterVStorageObjectManager"] = reflect.TypeOf((*VcenterVStorageObjectManager)(nil)).Elem()
}
type View struct {
Self types.ManagedObjectReference
}

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"`

View File

@@ -1,5 +1,5 @@
/*
Copyright (c) 2014-2016 VMware, Inc. All Rights Reserved.
Copyright (c) 2014-2017 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.

View File

@@ -46,3 +46,7 @@ func (r *ManagedObjectReference) FromString(o string) bool {
return true
}
func (c *PerfCounterInfo) Name() string {
return c.GroupInfo.GetElementDescription().Key + "." + c.NameInfo.GetElementDescription().Key + "." + string(c.RollupType)
}

View File

@@ -1,5 +1,5 @@
/*
Copyright (c) 2014-2016 VMware, Inc. All Rights Reserved.
Copyright (c) 2014-2017 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.

View File

@@ -16,15 +16,28 @@ limitations under the License.
package types
import "reflect"
import (
"reflect"
"strings"
)
var t = map[string]reflect.Type{}
func Add(name string, kind reflect.Type) {
t[name] = kind
}
type Func func(string) (reflect.Type, bool)
func TypeFunc() Func {
return func(name string) (reflect.Type, bool) {
typ, ok := t[name]
if !ok {
// The /sdk endpoint does not prefix types with the namespace,
// but extension endpoints, such as /pbm/sdk do.
name = strings.TrimPrefix(name, "vim25:")
typ, ok = t[name]
}
return typ, ok
}
}

View File

@@ -1,5 +1,5 @@
/*
Copyright (c) 2014-2016 VMware, Inc. All Rights Reserved.
Copyright (c) 2014-2017 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.

View File

@@ -23,6 +23,8 @@ import (
var xmlSchemaInstance = Name{Space: "http://www.w3.org/2001/XMLSchema-instance", Local: "type"}
var xsiType = Name{Space: "xsi", Local: "type"}
var stringToTypeMap = map[string]reflect.Type{
"xsd:boolean": reflect.TypeOf((*bool)(nil)).Elem(),
"xsd:byte": reflect.TypeOf((*int8)(nil)).Elem(),

View File

@@ -272,13 +272,15 @@ var (
func (p *Decoder) typeForElement(val reflect.Value, start *StartElement) reflect.Type {
t := ""
for i, a := range start.Attr {
if a.Name == xmlSchemaInstance {
if a.Name == xmlSchemaInstance || a.Name == xsiType {
t = a.Value
// HACK: ensure xsi:type is last in the list to avoid using that value for
// a "type" attribute, such as ManagedObjectReference.Type for example.
// Note that xsi:type is already the last attribute in VC/ESX responses.
// This is only an issue with govmomi simulator generated responses.
// Proper fix will require finding a few needles in this xml package haystack.
// Note: govmomi uses xmlSchemaInstance, other clients (e.g. rbvmomi) use xsiType.
// They are the same thing to XML parsers, but not to this hack here.
x := len(start.Attr) - 1
if i != x {
start.Attr[i] = start.Attr[x]