- Updated vmware/govmomi godep (Needs for vsan support)

- Fix unmount for vsanDatastore
- Add support for vsan datastore
This commit is contained in:
Abrar Shivani
2016-07-18 23:20:30 -07:00
parent 2301ab7e0e
commit 87e7535e94
31 changed files with 658 additions and 200 deletions

View File

@@ -20,6 +20,7 @@ import (
"fmt"
"io"
"math/rand"
"os"
"path"
"strings"
@@ -57,8 +58,6 @@ func (e DatastoreNoSuchFileError) Error() string {
type Datastore struct {
Common
InventoryPath string
}
func NewDatastore(c *vim25.Client, ref types.ManagedObjectReference) *Datastore {
@@ -67,10 +66,6 @@ func NewDatastore(c *vim25.Client, ref types.ManagedObjectReference) *Datastore
}
}
func (d Datastore) Name() string {
return path.Base(d.InventoryPath)
}
func (d Datastore) Path(path string) string {
name := d.Name()
if name == "" {
@@ -116,6 +111,42 @@ func (d Datastore) Browser(ctx context.Context) (*HostDatastoreBrowser, error) {
return NewHostDatastoreBrowser(d.c, do.Browser), nil
}
func (d Datastore) useServiceTicketHostName(name string) bool {
// No need if talking directly to ESX.
if !d.c.IsVC() {
return false
}
// If version happens to be < 5.1
if name == "" {
return false
}
// If the HostSystem is using DHCP on a network without dynamic DNS,
// HostSystem.Config.Network.DnsConfig.HostName is set to "localhost" by default.
// This resolves to "localhost.localdomain" by default via /etc/hosts on ESX.
// In that case, we will stick with the HostSystem.Name which is the IP address that
// was used to connect the host to VC.
if name == "localhost.localdomain" {
return false
}
// Still possible to have HostName that don't resolve via DNS,
// so we default to false.
key := "GOVMOMI_USE_SERVICE_TICKET_HOSTNAME"
val := d.c.URL().Query().Get(key)
if val == "" {
val = os.Getenv(key)
}
if val == "1" || val == "true" {
return true
}
return false
}
// ServiceTicket obtains a ticket via AcquireGenericServiceTicket and returns it an http.Cookie with the url.URL
// that can be used along with the ticket cookie to access the given path.
func (d Datastore) ServiceTicket(ctx context.Context, path string, method string) (*url.URL, *http.Cookie, error) {
@@ -142,7 +173,7 @@ func (d Datastore) ServiceTicket(ctx context.Context, path string, method string
// Pick a random attached host
host := hosts[rand.Intn(len(hosts))]
name, err := host.Name(ctx)
name, err := host.ObjectName(ctx)
if err != nil {
return nil, nil, err
}
@@ -167,6 +198,10 @@ func (d Datastore) ServiceTicket(ctx context.Context, path string, method string
Value: ticket.Id,
}
if d.useServiceTicketHostName(ticket.HostName) {
u.Host = ticket.HostName
}
return u, cookie, nil
}