tests: upload & test in vCenter. Closes #338
This commit is contained in:
parent
02346faff8
commit
9cce43d384
255 changed files with 127290 additions and 3 deletions
130
vendor/github.com/vmware/govmomi/view/container_view.go
generated
vendored
Normal file
130
vendor/github.com/vmware/govmomi/view/container_view.go
generated
vendored
Normal file
|
|
@ -0,0 +1,130 @@
|
|||
/*
|
||||
Copyright (c) 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.
|
||||
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 view
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/vmware/govmomi/property"
|
||||
"github.com/vmware/govmomi/vim25"
|
||||
"github.com/vmware/govmomi/vim25/mo"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
type ContainerView struct {
|
||||
ManagedObjectView
|
||||
}
|
||||
|
||||
func NewContainerView(c *vim25.Client, ref types.ManagedObjectReference) *ContainerView {
|
||||
return &ContainerView{
|
||||
ManagedObjectView: *NewManagedObjectView(c, ref),
|
||||
}
|
||||
}
|
||||
|
||||
// Retrieve populates dst as property.Collector.Retrieve does, for all entities in the view of types specified by kind.
|
||||
func (v ContainerView) Retrieve(ctx context.Context, kind []string, ps []string, dst interface{}) error {
|
||||
pc := property.DefaultCollector(v.Client())
|
||||
|
||||
ospec := types.ObjectSpec{
|
||||
Obj: v.Reference(),
|
||||
Skip: types.NewBool(true),
|
||||
SelectSet: []types.BaseSelectionSpec{
|
||||
&types.TraversalSpec{
|
||||
Type: v.Reference().Type,
|
||||
Path: "view",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
var pspec []types.PropertySpec
|
||||
|
||||
if len(kind) == 0 {
|
||||
kind = []string{"ManagedEntity"}
|
||||
}
|
||||
|
||||
for _, t := range kind {
|
||||
spec := types.PropertySpec{
|
||||
Type: t,
|
||||
}
|
||||
|
||||
if len(ps) == 0 {
|
||||
spec.All = types.NewBool(true)
|
||||
} else {
|
||||
spec.PathSet = ps
|
||||
}
|
||||
|
||||
pspec = append(pspec, spec)
|
||||
}
|
||||
|
||||
req := types.RetrieveProperties{
|
||||
SpecSet: []types.PropertyFilterSpec{
|
||||
{
|
||||
ObjectSet: []types.ObjectSpec{ospec},
|
||||
PropSet: pspec,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
res, err := pc.RetrieveProperties(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if d, ok := dst.(*[]types.ObjectContent); ok {
|
||||
*d = res.Returnval
|
||||
return nil
|
||||
}
|
||||
|
||||
return mo.LoadObjectContent(res.Returnval, dst)
|
||||
}
|
||||
|
||||
// RetrieveWithFilter populates dst as Retrieve does, but only for entities matching the given filter.
|
||||
func (v ContainerView) RetrieveWithFilter(ctx context.Context, kind []string, ps []string, dst interface{}, filter property.Filter) error {
|
||||
if len(filter) == 0 {
|
||||
return v.Retrieve(ctx, kind, ps, dst)
|
||||
}
|
||||
|
||||
var content []types.ObjectContent
|
||||
|
||||
err := v.Retrieve(ctx, kind, filter.Keys(), &content)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
objs := filter.MatchObjectContent(content)
|
||||
|
||||
pc := property.DefaultCollector(v.Client())
|
||||
|
||||
return pc.Retrieve(ctx, objs, ps, dst)
|
||||
}
|
||||
|
||||
// Find returns object references for entities of type kind, matching the given filter.
|
||||
func (v ContainerView) Find(ctx context.Context, kind []string, filter property.Filter) ([]types.ManagedObjectReference, error) {
|
||||
if len(filter) == 0 {
|
||||
// Ensure we have at least 1 filter to avoid retrieving all properties.
|
||||
filter = property.Filter{"name": "*"}
|
||||
}
|
||||
|
||||
var content []types.ObjectContent
|
||||
|
||||
err := v.Retrieve(ctx, kind, filter.Keys(), &content)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return filter.MatchObjectContent(content), nil
|
||||
}
|
||||
62
vendor/github.com/vmware/govmomi/view/list_view.go
generated
vendored
Normal file
62
vendor/github.com/vmware/govmomi/view/list_view.go
generated
vendored
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
Copyright (c) 2015-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.
|
||||
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 view
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/vmware/govmomi/vim25"
|
||||
"github.com/vmware/govmomi/vim25/methods"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
type ListView struct {
|
||||
ManagedObjectView
|
||||
}
|
||||
|
||||
func NewListView(c *vim25.Client, ref types.ManagedObjectReference) *ListView {
|
||||
return &ListView{
|
||||
ManagedObjectView: *NewManagedObjectView(c, ref),
|
||||
}
|
||||
}
|
||||
|
||||
func (v ListView) Add(ctx context.Context, refs []types.ManagedObjectReference) error {
|
||||
req := types.ModifyListView{
|
||||
This: v.Reference(),
|
||||
Add: refs,
|
||||
}
|
||||
_, err := methods.ModifyListView(ctx, v.Client(), &req)
|
||||
return err
|
||||
}
|
||||
|
||||
func (v ListView) Remove(ctx context.Context, refs []types.ManagedObjectReference) error {
|
||||
req := types.ModifyListView{
|
||||
This: v.Reference(),
|
||||
Remove: refs,
|
||||
}
|
||||
_, err := methods.ModifyListView(ctx, v.Client(), &req)
|
||||
return err
|
||||
}
|
||||
|
||||
func (v ListView) Reset(ctx context.Context, refs []types.ManagedObjectReference) error {
|
||||
req := types.ResetListView{
|
||||
This: v.Reference(),
|
||||
Obj: refs,
|
||||
}
|
||||
_, err := methods.ResetListView(ctx, v.Client(), &req)
|
||||
return err
|
||||
}
|
||||
52
vendor/github.com/vmware/govmomi/view/managed_object_view.go
generated
vendored
Normal file
52
vendor/github.com/vmware/govmomi/view/managed_object_view.go
generated
vendored
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
Copyright (c) 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.
|
||||
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 view
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/vmware/govmomi/object"
|
||||
"github.com/vmware/govmomi/vim25"
|
||||
"github.com/vmware/govmomi/vim25/methods"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
type ManagedObjectView struct {
|
||||
object.Common
|
||||
}
|
||||
|
||||
func NewManagedObjectView(c *vim25.Client, ref types.ManagedObjectReference) *ManagedObjectView {
|
||||
return &ManagedObjectView{
|
||||
Common: object.NewCommon(c, ref),
|
||||
}
|
||||
}
|
||||
|
||||
func (v *ManagedObjectView) TraversalSpec() *types.TraversalSpec {
|
||||
return &types.TraversalSpec{
|
||||
Path: "view",
|
||||
Type: v.Reference().Type,
|
||||
}
|
||||
}
|
||||
|
||||
func (v *ManagedObjectView) Destroy(ctx context.Context) error {
|
||||
req := types.DestroyView{
|
||||
This: v.Reference(),
|
||||
}
|
||||
|
||||
_, err := methods.DestroyView(ctx, v.Client(), &req)
|
||||
return err
|
||||
}
|
||||
69
vendor/github.com/vmware/govmomi/view/manager.go
generated
vendored
Normal file
69
vendor/github.com/vmware/govmomi/view/manager.go
generated
vendored
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
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 view
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/vmware/govmomi/object"
|
||||
"github.com/vmware/govmomi/vim25"
|
||||
"github.com/vmware/govmomi/vim25/methods"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
type Manager struct {
|
||||
object.Common
|
||||
}
|
||||
|
||||
func NewManager(c *vim25.Client) *Manager {
|
||||
m := Manager{
|
||||
object.NewCommon(c, *c.ServiceContent.ViewManager),
|
||||
}
|
||||
|
||||
return &m
|
||||
}
|
||||
|
||||
func (m Manager) CreateListView(ctx context.Context, objects []types.ManagedObjectReference) (*ListView, error) {
|
||||
req := types.CreateListView{
|
||||
This: m.Common.Reference(),
|
||||
Obj: objects,
|
||||
}
|
||||
|
||||
res, err := methods.CreateListView(ctx, m.Client(), &req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return NewListView(m.Client(), res.Returnval), nil
|
||||
}
|
||||
|
||||
func (m Manager) CreateContainerView(ctx context.Context, container types.ManagedObjectReference, managedObjectTypes []string, recursive bool) (*ContainerView, error) {
|
||||
|
||||
req := types.CreateContainerView{
|
||||
This: m.Common.Reference(),
|
||||
Container: container,
|
||||
Recursive: recursive,
|
||||
Type: managedObjectTypes,
|
||||
}
|
||||
|
||||
res, err := methods.CreateContainerView(ctx, m.Client(), &req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return NewContainerView(m.Client(), res.Returnval), nil
|
||||
}
|
||||
125
vendor/github.com/vmware/govmomi/view/task_view.go
generated
vendored
Normal file
125
vendor/github.com/vmware/govmomi/view/task_view.go
generated
vendored
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
/*
|
||||
Copyright (c) 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.
|
||||
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 view
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/vmware/govmomi/property"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
// TaskView extends ListView such that it can follow a ManagedEntity's recentTask updates.
|
||||
type TaskView struct {
|
||||
*ListView
|
||||
|
||||
Follow bool
|
||||
|
||||
Watch *types.ManagedObjectReference
|
||||
}
|
||||
|
||||
// CreateTaskView creates a new ListView that optionally watches for a ManagedEntity's recentTask updates.
|
||||
func (m Manager) CreateTaskView(ctx context.Context, watch *types.ManagedObjectReference) (*TaskView, error) {
|
||||
l, err := m.CreateListView(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
tv := &TaskView{
|
||||
ListView: l,
|
||||
Watch: watch,
|
||||
}
|
||||
|
||||
return tv, nil
|
||||
}
|
||||
|
||||
// Collect calls function f for each Task update.
|
||||
func (v TaskView) Collect(ctx context.Context, f func([]types.TaskInfo)) error {
|
||||
// Using TaskHistoryCollector would be less clunky, but it isn't supported on ESX at all.
|
||||
ref := v.Reference()
|
||||
filter := new(property.WaitFilter).Add(ref, "Task", []string{"info"}, v.TraversalSpec())
|
||||
|
||||
if v.Watch != nil {
|
||||
filter.Add(*v.Watch, v.Watch.Type, []string{"recentTask"})
|
||||
}
|
||||
|
||||
pc := property.DefaultCollector(v.Client())
|
||||
|
||||
completed := make(map[string]bool)
|
||||
|
||||
return property.WaitForUpdates(ctx, pc, filter, func(updates []types.ObjectUpdate) bool {
|
||||
var infos []types.TaskInfo
|
||||
var prune []types.ManagedObjectReference
|
||||
var tasks []types.ManagedObjectReference
|
||||
var reset func()
|
||||
|
||||
for _, update := range updates {
|
||||
for _, change := range update.ChangeSet {
|
||||
if change.Name == "recentTask" {
|
||||
tasks = change.Val.(types.ArrayOfManagedObjectReference).ManagedObjectReference
|
||||
if len(tasks) != 0 {
|
||||
reset = func() {
|
||||
_ = v.Reset(ctx, tasks)
|
||||
|
||||
// Remember any tasks we've reported as complete already,
|
||||
// to avoid reporting multiple times when Reset is triggered.
|
||||
rtasks := make(map[string]bool)
|
||||
for i := range tasks {
|
||||
if _, ok := completed[tasks[i].Value]; ok {
|
||||
rtasks[tasks[i].Value] = true
|
||||
}
|
||||
}
|
||||
completed = rtasks
|
||||
}
|
||||
}
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
info, ok := change.Val.(types.TaskInfo)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
if !completed[info.Task.Value] {
|
||||
infos = append(infos, info)
|
||||
}
|
||||
|
||||
if v.Follow && info.CompleteTime != nil {
|
||||
prune = append(prune, info.Task)
|
||||
completed[info.Task.Value] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(infos) != 0 {
|
||||
f(infos)
|
||||
}
|
||||
|
||||
if reset != nil {
|
||||
reset()
|
||||
} else if len(prune) != 0 {
|
||||
_ = v.Remove(ctx, prune)
|
||||
}
|
||||
|
||||
if len(tasks) != 0 && len(infos) == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
return !v.Follow
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue