mirror of
https://github.com/nikdoof/vsphere-influxdb-go.git
synced 2025-12-20 05:59:21 +00:00
add vendoring with go dep
This commit is contained in:
22
vendor/github.com/vmware/govmomi/test/doc.go
generated
vendored
Normal file
22
vendor/github.com/vmware/govmomi/test/doc.go
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
Copyright (c) 2015 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.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
Package test contains functions that implement common functionality between
|
||||
tests. The code (non-test) in this package intentionally does not take any
|
||||
dependendies outside the vim25 tree.
|
||||
*/
|
||||
package test
|
||||
130
vendor/github.com/vmware/govmomi/test/functional/helper.go
generated
vendored
Normal file
130
vendor/github.com/vmware/govmomi/test/functional/helper.go
generated
vendored
Normal file
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
Copyright (c) 2015 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.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package functional
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/vmware/govmomi/find"
|
||||
"github.com/vmware/govmomi/object"
|
||||
"github.com/vmware/govmomi/property"
|
||||
"github.com/vmware/govmomi/test"
|
||||
"github.com/vmware/govmomi/vim25"
|
||||
"github.com/vmware/govmomi/vim25/mo"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
type Helper struct {
|
||||
*testing.T
|
||||
|
||||
c *vim25.Client
|
||||
f *find.Finder
|
||||
fns []func()
|
||||
}
|
||||
|
||||
func NewHelper(t *testing.T) *Helper {
|
||||
h := &Helper{
|
||||
T: t,
|
||||
|
||||
c: test.NewAuthenticatedClient(t),
|
||||
fns: make([]func(), 0),
|
||||
}
|
||||
|
||||
h.f = find.NewFinder(h.c, true)
|
||||
|
||||
return h
|
||||
}
|
||||
|
||||
func (h *Helper) Defer(fn func()) {
|
||||
h.fns = append(h.fns, fn)
|
||||
}
|
||||
|
||||
func (h *Helper) Teardown() {
|
||||
for _, fn := range h.fns {
|
||||
fn()
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Helper) RequireVirtualCenter() {
|
||||
var expect = "VirtualCenter"
|
||||
var actual = h.c.ServiceContent.About.ApiType
|
||||
if actual != expect {
|
||||
h.Skipf("Requires %s, running against %s", expect, actual)
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Helper) Datacenter() *object.Datacenter {
|
||||
dc, err := h.f.DefaultDatacenter(context.Background())
|
||||
if err != nil {
|
||||
h.Fatal(err)
|
||||
}
|
||||
|
||||
h.f.SetDatacenter(dc)
|
||||
|
||||
return dc
|
||||
}
|
||||
|
||||
func (h *Helper) DatacenterFolders() *object.DatacenterFolders {
|
||||
df, err := h.Datacenter().Folders(context.Background())
|
||||
if err != nil {
|
||||
h.Fatal(err)
|
||||
}
|
||||
|
||||
return df
|
||||
}
|
||||
|
||||
func (h *Helper) ComputeResource() *object.ComputeResource {
|
||||
cr, err := h.f.DefaultComputeResource(context.Background())
|
||||
if err != nil {
|
||||
h.Fatal(err)
|
||||
}
|
||||
|
||||
return cr
|
||||
}
|
||||
|
||||
func (h *Helper) LocalDatastores(ctx context.Context, cr *object.ComputeResource) ([]*object.Datastore, error) {
|
||||
// List datastores for compute resource
|
||||
dss, err := cr.Datastores(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Filter local datastores
|
||||
var ldss []*object.Datastore
|
||||
for _, ds := range dss {
|
||||
var mds mo.Datastore
|
||||
err = property.DefaultCollector(h.c).RetrieveOne(ctx, ds.Reference(), nil, &mds)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
switch i := mds.Info.(type) {
|
||||
case *types.VmfsDatastoreInfo:
|
||||
if i.Vmfs.Local != nil && *i.Vmfs.Local == true {
|
||||
break
|
||||
}
|
||||
default:
|
||||
continue
|
||||
}
|
||||
|
||||
ds.InventoryPath = mds.Name
|
||||
ldss = append(ldss, ds)
|
||||
}
|
||||
|
||||
return ldss, nil
|
||||
}
|
||||
104
vendor/github.com/vmware/govmomi/test/functional/issue_242_test.go
generated
vendored
Normal file
104
vendor/github.com/vmware/govmomi/test/functional/issue_242_test.go
generated
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
Copyright (c) 2015 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.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package functional
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/vmware/govmomi/object"
|
||||
"github.com/vmware/govmomi/property"
|
||||
"github.com/vmware/govmomi/vim25/mo"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
func TestIssue242(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
h := NewHelper(t)
|
||||
defer h.Teardown()
|
||||
|
||||
h.RequireVirtualCenter()
|
||||
|
||||
df, err := h.Datacenter().Folders(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
cr := h.ComputeResource()
|
||||
|
||||
// Get local datastores for compute resource
|
||||
dss, err := h.LocalDatastores(ctx, cr)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(dss) == 0 {
|
||||
t.Fatalf("No local datastores")
|
||||
}
|
||||
|
||||
// Get root resource pool for compute resource
|
||||
rp, err := cr.ResourcePool(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
spec := types.VirtualMachineConfigSpec{
|
||||
Name: fmt.Sprintf("govmomi-test-%s", time.Now().Format(time.RFC3339)),
|
||||
Files: &types.VirtualMachineFileInfo{VmPathName: fmt.Sprintf("[%s]", dss[0].Name())},
|
||||
NumCPUs: 1,
|
||||
MemoryMB: 32,
|
||||
}
|
||||
|
||||
// Create new VM
|
||||
task, err := df.VmFolder.CreateVM(context.Background(), spec, rp, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
info, err := task.WaitForResult(context.Background(), nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
vm := object.NewVirtualMachine(h.c, info.Result.(types.ManagedObjectReference))
|
||||
defer func() {
|
||||
task, err := vm.Destroy(context.Background())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = task.Wait(context.Background())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}()
|
||||
|
||||
// Mark VM as template
|
||||
err = vm.MarkAsTemplate(context.Background())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Get "environmentBrowser" property for VM template
|
||||
var mvm mo.VirtualMachine
|
||||
err = property.DefaultCollector(h.c).RetrieveOne(ctx, vm.Reference(), []string{"environmentBrowser"}, &mvm)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
73
vendor/github.com/vmware/govmomi/test/helper.go
generated
vendored
Normal file
73
vendor/github.com/vmware/govmomi/test/helper.go
generated
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
Copyright (c) 2014-2015 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.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/vmware/govmomi/vim25"
|
||||
"github.com/vmware/govmomi/vim25/methods"
|
||||
"github.com/vmware/govmomi/vim25/soap"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
// URL parses the GOVMOMI_TEST_URL environment variable if set.
|
||||
func URL() *url.URL {
|
||||
s := os.Getenv("GOVMOMI_TEST_URL")
|
||||
if s == "" {
|
||||
return nil
|
||||
}
|
||||
u, err := soap.ParseURL(s)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return u
|
||||
}
|
||||
|
||||
// NewAuthenticatedClient creates a new vim25.Client, authenticates the user
|
||||
// specified in the test URL, and returns it.
|
||||
func NewAuthenticatedClient(t *testing.T) *vim25.Client {
|
||||
u := URL()
|
||||
if u == nil {
|
||||
t.SkipNow()
|
||||
}
|
||||
|
||||
soapClient := soap.NewClient(u, true)
|
||||
vimClient, err := vim25.NewClient(context.Background(), soapClient)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
req := types.Login{
|
||||
This: *vimClient.ServiceContent.SessionManager,
|
||||
}
|
||||
|
||||
req.UserName = u.User.Username()
|
||||
if pw, ok := u.User.Password(); ok {
|
||||
req.Password = pw
|
||||
}
|
||||
|
||||
_, err = methods.Login(context.Background(), vimClient, &req)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
return vimClient
|
||||
}
|
||||
Reference in New Issue
Block a user