provider/vsphere: govmomi v0.6.1 update and fixes (#6479)

* vendor: Update dependency vmware/govmomi

* fixed data types

* fixed RemoveDevice

* fixed CreateDisk usage
This commit is contained in:
thetuxkeeper 2016-05-13 16:27:45 +02:00 committed by Paul Stack
parent c07f1ff0c6
commit 390b0d5ab9
41 changed files with 1774 additions and 1264 deletions

60
Godeps/Godeps.json generated
View File

@ -1266,78 +1266,78 @@
}, },
{ {
"ImportPath": "github.com/vmware/govmomi", "ImportPath": "github.com/vmware/govmomi",
"Comment": "v0.3.0-18-g3b66976", "Comment": "v0.6.1",
"Rev": "3b669760f460befb135048aea80d2f5fa13885ca" "Rev": "18154e511bc8f6bc1fffe2e47d11ef4f1931a044"
}, },
{ {
"ImportPath": "github.com/vmware/govmomi/find", "ImportPath": "github.com/vmware/govmomi/find",
"Comment": "v0.3.0-18-g3b66976", "Comment": "v0.6.1",
"Rev": "3b669760f460befb135048aea80d2f5fa13885ca" "Rev": "18154e511bc8f6bc1fffe2e47d11ef4f1931a044"
}, },
{ {
"ImportPath": "github.com/vmware/govmomi/list", "ImportPath": "github.com/vmware/govmomi/list",
"Comment": "v0.3.0-18-g3b66976", "Comment": "v0.6.1",
"Rev": "3b669760f460befb135048aea80d2f5fa13885ca" "Rev": "18154e511bc8f6bc1fffe2e47d11ef4f1931a044"
}, },
{ {
"ImportPath": "github.com/vmware/govmomi/object", "ImportPath": "github.com/vmware/govmomi/object",
"Comment": "v0.3.0-18-g3b66976", "Comment": "v0.6.1",
"Rev": "3b669760f460befb135048aea80d2f5fa13885ca" "Rev": "18154e511bc8f6bc1fffe2e47d11ef4f1931a044"
}, },
{ {
"ImportPath": "github.com/vmware/govmomi/property", "ImportPath": "github.com/vmware/govmomi/property",
"Comment": "v0.3.0-18-g3b66976", "Comment": "v0.6.1",
"Rev": "3b669760f460befb135048aea80d2f5fa13885ca" "Rev": "18154e511bc8f6bc1fffe2e47d11ef4f1931a044"
}, },
{ {
"ImportPath": "github.com/vmware/govmomi/session", "ImportPath": "github.com/vmware/govmomi/session",
"Comment": "v0.3.0-18-g3b66976", "Comment": "v0.6.1",
"Rev": "3b669760f460befb135048aea80d2f5fa13885ca" "Rev": "18154e511bc8f6bc1fffe2e47d11ef4f1931a044"
}, },
{ {
"ImportPath": "github.com/vmware/govmomi/task", "ImportPath": "github.com/vmware/govmomi/task",
"Comment": "v0.3.0-18-g3b66976", "Comment": "v0.6.1",
"Rev": "3b669760f460befb135048aea80d2f5fa13885ca" "Rev": "18154e511bc8f6bc1fffe2e47d11ef4f1931a044"
}, },
{ {
"ImportPath": "github.com/vmware/govmomi/vim25", "ImportPath": "github.com/vmware/govmomi/vim25",
"Comment": "v0.3.0-18-g3b66976", "Comment": "v0.6.1",
"Rev": "3b669760f460befb135048aea80d2f5fa13885ca" "Rev": "18154e511bc8f6bc1fffe2e47d11ef4f1931a044"
}, },
{ {
"ImportPath": "github.com/vmware/govmomi/vim25/debug", "ImportPath": "github.com/vmware/govmomi/vim25/debug",
"Comment": "v0.3.0-18-g3b66976", "Comment": "v0.6.1",
"Rev": "3b669760f460befb135048aea80d2f5fa13885ca" "Rev": "18154e511bc8f6bc1fffe2e47d11ef4f1931a044"
}, },
{ {
"ImportPath": "github.com/vmware/govmomi/vim25/methods", "ImportPath": "github.com/vmware/govmomi/vim25/methods",
"Comment": "v0.3.0-18-g3b66976", "Comment": "v0.6.1",
"Rev": "3b669760f460befb135048aea80d2f5fa13885ca" "Rev": "18154e511bc8f6bc1fffe2e47d11ef4f1931a044"
}, },
{ {
"ImportPath": "github.com/vmware/govmomi/vim25/mo", "ImportPath": "github.com/vmware/govmomi/vim25/mo",
"Comment": "v0.3.0-18-g3b66976", "Comment": "v0.6.1",
"Rev": "3b669760f460befb135048aea80d2f5fa13885ca" "Rev": "18154e511bc8f6bc1fffe2e47d11ef4f1931a044"
}, },
{ {
"ImportPath": "github.com/vmware/govmomi/vim25/progress", "ImportPath": "github.com/vmware/govmomi/vim25/progress",
"Comment": "v0.3.0-18-g3b66976", "Comment": "v0.6.1",
"Rev": "3b669760f460befb135048aea80d2f5fa13885ca" "Rev": "18154e511bc8f6bc1fffe2e47d11ef4f1931a044"
}, },
{ {
"ImportPath": "github.com/vmware/govmomi/vim25/soap", "ImportPath": "github.com/vmware/govmomi/vim25/soap",
"Comment": "v0.3.0-18-g3b66976", "Comment": "v0.6.1",
"Rev": "3b669760f460befb135048aea80d2f5fa13885ca" "Rev": "18154e511bc8f6bc1fffe2e47d11ef4f1931a044"
}, },
{ {
"ImportPath": "github.com/vmware/govmomi/vim25/types", "ImportPath": "github.com/vmware/govmomi/vim25/types",
"Comment": "v0.3.0-18-g3b66976", "Comment": "v0.6.1",
"Rev": "3b669760f460befb135048aea80d2f5fa13885ca" "Rev": "18154e511bc8f6bc1fffe2e47d11ef4f1931a044"
}, },
{ {
"ImportPath": "github.com/vmware/govmomi/vim25/xml", "ImportPath": "github.com/vmware/govmomi/vim25/xml",
"Comment": "v0.3.0-18-g3b66976", "Comment": "v0.6.1",
"Rev": "3b669760f460befb135048aea80d2f5fa13885ca" "Rev": "18154e511bc8f6bc1fffe2e47d11ef4f1931a044"
}, },
{ {
"ImportPath": "github.com/xanzy/go-cloudstack/cloudstack", "ImportPath": "github.com/xanzy/go-cloudstack/cloudstack",

View File

@ -72,7 +72,7 @@ type virtualMachine struct {
cluster string cluster string
resourcePool string resourcePool string
datastore string datastore string
vcpu int vcpu int32
memoryMb int64 memoryMb int64
memoryAllocation memoryAllocation memoryAllocation memoryAllocation
template string template string
@ -423,7 +423,7 @@ func resourceVSphereVirtualMachineUpdate(d *schema.ResourceData, meta interface{
configSpec := types.VirtualMachineConfigSpec{} configSpec := types.VirtualMachineConfigSpec{}
if d.HasChange("vcpu") { if d.HasChange("vcpu") {
configSpec.NumCPUs = d.Get("vcpu").(int) configSpec.NumCPUs = int32(d.Get("vcpu").(int))
hasChanges = true hasChanges = true
rebootRequired = true rebootRequired = true
} }
@ -505,7 +505,7 @@ func resourceVSphereVirtualMachineCreate(d *schema.ResourceData, meta interface{
vm := virtualMachine{ vm := virtualMachine{
name: d.Get("name").(string), name: d.Get("name").(string),
vcpu: d.Get("vcpu").(int), vcpu: int32(d.Get("vcpu").(int)),
memoryMb: int64(d.Get("memory").(int)), memoryMb: int64(d.Get("memory").(int)),
memoryAllocation: memoryAllocation{ memoryAllocation: memoryAllocation{
reservation: int64(d.Get("memory_reservation").(int)), reservation: int64(d.Get("memory_reservation").(int)),
@ -958,15 +958,7 @@ func addHardDisk(vm *object.VirtualMachine, size, iops int64, diskType string, d
} }
log.Printf("[DEBUG] disk controller: %#v\n", controller) log.Printf("[DEBUG] disk controller: %#v\n", controller)
// If diskPath is not specified, pass empty string to CreateDisk() disk := devices.CreateDisk(controller, datastore.Reference(), diskPath)
var newDiskPath string
if diskPath == "" {
newDiskPath = ""
} else {
// TODO Check if diskPath & datastore exist
newDiskPath = fmt.Sprintf("[%v] %v", datastore.Name(), diskPath)
}
disk := devices.CreateDisk(controller, newDiskPath)
existing := devices.SelectByBackingInfo(disk.Backing) existing := devices.SelectByBackingInfo(disk.Backing)
log.Printf("[DEBUG] disk: %#v\n", disk) log.Printf("[DEBUG] disk: %#v\n", disk)
@ -1071,7 +1063,7 @@ func buildNetworkDevice(f *find.Finder, label, adapterType string) (*types.Virtu
// buildVMRelocateSpec builds VirtualMachineRelocateSpec to set a place for a new VirtualMachine. // buildVMRelocateSpec builds VirtualMachineRelocateSpec to set a place for a new VirtualMachine.
func buildVMRelocateSpec(rp *object.ResourcePool, ds *object.Datastore, vm *object.VirtualMachine, linkedClone bool, initType string) (types.VirtualMachineRelocateSpec, error) { func buildVMRelocateSpec(rp *object.ResourcePool, ds *object.Datastore, vm *object.VirtualMachine, linkedClone bool, initType string) (types.VirtualMachineRelocateSpec, error) {
var key int var key int32
var moveType string var moveType string
if linkedClone { if linkedClone {
moveType = "createNewChildDiskBacking" moveType = "createNewChildDiskBacking"
@ -1086,7 +1078,7 @@ func buildVMRelocateSpec(rp *object.ResourcePool, ds *object.Datastore, vm *obje
} }
for _, d := range devices { for _, d := range devices {
if devices.Type(d) == "disk" { if devices.Type(d) == "disk" {
key = d.GetVirtualDevice().Key key = int32(d.GetVirtualDevice().Key)
} }
} }
@ -1164,9 +1156,9 @@ func buildStoragePlacementSpecClone(c *govmomi.Client, f *object.DatacenterFolde
return types.StoragePlacementSpec{} return types.StoragePlacementSpec{}
} }
var key int var key int32
for _, d := range devices.SelectByType((*types.VirtualDisk)(nil)) { for _, d := range devices.SelectByType((*types.VirtualDisk)(nil)) {
key = d.GetVirtualDevice().Key key = int32(d.GetVirtualDevice().Key)
log.Printf("[DEBUG] findDatastore: virtual devices: %#v\n", d.GetVirtualDevice()) log.Printf("[DEBUG] findDatastore: virtual devices: %#v\n", d.GetVirtualDevice())
} }
@ -1558,7 +1550,7 @@ func (vm *virtualMachine) deployVirtualMachine(c *govmomi.Client) error {
ipv6Spec.Ip = []types.BaseCustomizationIpV6Generator{ ipv6Spec.Ip = []types.BaseCustomizationIpV6Generator{
&types.CustomizationFixedIpV6{ &types.CustomizationFixedIpV6{
IpAddress: network.ipv6Address, IpAddress: network.ipv6Address,
SubnetMask: network.ipv6PrefixLength, SubnetMask: int32(network.ipv6PrefixLength),
}, },
} }
ipv6Spec.Gateway = []string{network.ipv6Gateway} ipv6Spec.Gateway = []string{network.ipv6Gateway}
@ -1620,7 +1612,7 @@ func (vm *virtualMachine) deployVirtualMachine(c *govmomi.Client) error {
guiUnattended := types.CustomizationGuiUnattended{ guiUnattended := types.CustomizationGuiUnattended{
AutoLogon: false, AutoLogon: false,
AutoLogonCount: 1, AutoLogonCount: 1,
TimeZone: timeZone, TimeZone: int32(timeZone),
} }
customIdentification := types.CustomizationIdentification{} customIdentification := types.CustomizationIdentification{}
@ -1720,7 +1712,7 @@ func (vm *virtualMachine) deployVirtualMachine(c *govmomi.Client) error {
for _, dvc := range devices { for _, dvc := range devices {
// Issue 3559/3560: Delete all ethernet devices to add the correct ones later // Issue 3559/3560: Delete all ethernet devices to add the correct ones later
if devices.Type(dvc) == "ethernet" { if devices.Type(dvc) == "ethernet" {
err := newVM.RemoveDevice(context.TODO(), dvc) err := newVM.RemoveDevice(context.TODO(), false, dvc)
if err != nil { if err != nil {
return err return err
} }

1
vendor/github.com/vmware/govmomi/.drone.sec generated vendored Normal file
View File

@ -0,0 +1 @@
eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkExMjhHQ00ifQ.kK6pryC8R-O1R0Gj9ydLvQuIZlcYLGze23WdW7xbpiEEKdz6nweJrMm7ysy8lgu1tM47JVo19p2_b26bNKSQshCUOETvd7Hb2UMZOjnyUnqdyAAyoi6UkIquXfUUbHTNS0iMxwSxxW9KMp2GXNq8-o6T8xQZTDirBJFKKd8ZNUasTaoa5j8U9IfdR1aCavTBuOhvk8IVs-jSbY5TVJMJiE0IOPXois7aRJ6uAiANQBk9VKLegEcZD_qAewecXHDsHi-u0jbmg3o3PPaJaK_Qv5dsPlR2M-E2kE3AGUn0-zn5zYRngoAZ8WZr2O4GvLdltJKq9i2z7jOrdOzzRcDRow.96qvwl_E1Hj15u7Q.hWs-jQ8FsqQFD7pE9N-UEP1BWQ9rsJIcCaPvQRIp8Fukm_vvlw9YEaEq0ERLrsUWsJWpd1ca8_h8x7xD6f_d5YppwRqRHIeGIsdBOTMhNs0lG8ikkQXLat-UroCpy8EC17nuUtDE2E2Kdxrk4Cdd6Bk-dKk0Ta4w3Ud0YBKa.P8zrO7xizgv0i98eVWWzEg

17
vendor/github.com/vmware/govmomi/.drone.yml generated vendored Normal file
View File

@ -0,0 +1,17 @@
clone:
tags: true
path: github.com/vmware/govmomi
build:
image: golang:1.6
pull: true
environment:
- GOVC_TEST_URL=$$GOVC_TEST_URL
- GOVC_INSECURE=1
- VCA=1
commands:
- make all install
- git clone https://github.com/sstephenson/bats.git /tmp/bats
- /tmp/bats/install.sh /usr/local
- apt-get -qq update && apt-get install -yqq uuid-runtime bsdmainutils jq
- govc/test/images/update.sh
- bats govc/test

1
vendor/github.com/vmware/govmomi/.gitignore generated vendored Normal file
View File

@ -0,0 +1 @@
secrets.yml

View File

@ -1,10 +1,12 @@
sudo: false sudo: false
language: go language: go
go: 1.4
go:
- 1.6
before_install: before_install:
- go get golang.org/x/tools/cmd/vet - make vendor
- go get golang.org/x/tools/cmd/goimports
script: script:
- make check test - make check test

View File

@ -1,5 +1,46 @@
# changelog # changelog
### 0.6.1 (2016-04-30)
* Fix mo.Entity interface
### 0.6.0 (2016-04-29)
* Add Common.Rename method
* Add mo.Entity interface
* Add OptionManager
* Add Finder.FolderList method
* Add VirtualMachine.WaitForNetIP method
* Add VirtualMachine.RevertToSnapshot method
* Add Datastore.Download method
### 0.5.0 (2016-03-30)
Generated fields using xsd type 'int' change to Go type 'int32'
VirtualDevice.UnitNumber field changed to pointer type
### 0.4.0 (2016-02-26)
* Add method to convert virtual device list to array with virtual device
changes that can be used in the VirtualMachineConfigSpec.
* Make datastore cluster traversable in lister
* Add finder.DatastoreCluster methods (also known as storage pods)
* Add Drone CI check
* Add object.Datastore Type and AttachedClusterHosts methods
* Add finder.*OrDefault methods
### 0.3.0 (2016-01-16) ### 0.3.0 (2016-01-16)
* Add object.VirtualNicManager wrapper * Add object.VirtualNicManager wrapper

92
vendor/github.com/vmware/govmomi/CONTRIBUTING.md generated vendored Normal file
View File

@ -0,0 +1,92 @@
# Contributing to govmomi
## Getting started
First, fork the repository on GitHub to your personal account.
Note that _GOPATH_ can be any directory, the example below uses _$HOME/govmomi_.
Change _$USER_ below to your github username if they are not the same.
``` shell
export GOPATH=$HOME/govmomi
mkdir -p $GOPATH/src/github.com/vmware
cd $GOPATH/src/github.com/vmware
git clone git@github.com:vmware/govmomi.git
cd govmomi
git config push.default nothing # anything to avoid pushing to vmware/govmomi by default
git remote rename origin vmware
git remote add $USER git@github.com:$USER/govmomi.git
git fetch $USER
```
## Contribution flow
This is a rough outline of what a contributor's workflow looks like:
- Create a topic branch from where you want to base your work.
- Make commits of logical units.
- Make sure your commit messages are in the proper format (see below).
- Push your changes to a topic branch in your fork of the repository.
- Submit a pull request to vmware/govmomi.
Example:
``` shell
git checkout -b my-new-feature vmware/master
git commit -a
git push $USER my-new-feature
```
### Stay in sync with upstream
When your branch gets out of sync with the vmware/master branch, use the following to update:
``` shell
git checkout my-new-feature
git fetch -a
git rebase vmware/master
git push --force-with-lease $USER my-new-feature
```
### Updating pull requests
If your PR fails to pass CI or needs changes based on code review, you'll most likely want to squash these changes into
existing commits.
If your pull request contains a single commit or your changes are related to the most recent commit, you can simply
amend the commit.
``` shell
git add .
git commit --amend
git push --force-with-lease $USER my-new-feature
```
If you need to squash changes into an earlier commit, you can use:
``` shell
git add .
git commit --fixup <commit>
git rebase -i --autosquash vmware/master
git push --force-with-lease $USER my-new-feature
```
Be sure to add a comment to the PR indicating your new changes are ready to review, as github does not generate a
notification when you git push.
### Code style
The coding style suggested by the Golang community is used in govmomi. See the
[style doc](https://github.com/golang/go/wiki/CodeReviewComments) for details.
Try to limit column width to 120 characters for both code and markdown documents such as this one.
### Format of the Commit Message
We follow the conventions on [How to Write a Git Commit Message](http://chris.beams.io/posts/git-commit/).
Be sure to include any related GitHub issue references in the commit message.
## Reporting Bugs and Creating Issues
When opening a new issue, try to roughly follow the commit message format conventions above.

View File

@ -4,23 +4,35 @@
# #
Alvaro Miranda <kikitux@gmail.com> Alvaro Miranda <kikitux@gmail.com>
Amit Bathla <abathla@vmware.com> Amit Bathla <abathla@.vmware.com>
Andrew Chin <andrew@andrewtchin.com>
Arran Walker <arran.walker@zopa.com>
Bob Killen <killen.bob@gmail.com> Bob Killen <killen.bob@gmail.com>
Bruce Downs <bdowns@vmware.com> Bruce Downs <bdowns@vmware.com>
Clint Greenwood <cgreenwood@vmware.com> <clint.greenwood@gmail.com> Clint Greenwood <cgreenwood@vmware.com> <clint.greenwood@gmail.com>
Cédric Blomart <cblomart@gmail.com>
Danny Lockard <danny.lockard@banno.com> Danny Lockard <danny.lockard@banno.com>
Dave Tucker <dave@dtucker.co.uk>
Doug MacEachern <dougm@vmware.com> Doug MacEachern <dougm@vmware.com>
Eloy Coto <eloy.coto@gmail.com> Eloy Coto <eloy.coto@gmail.com>
Eric Yutao <eric.yutao@gmail.com> Eric Yutao <eric.yutao@gmail.com>
Fabio Rapposelli <fabio@vmware.com>
Faiyaz Ahmed <ahmedf@vmware.com> Faiyaz Ahmed <ahmedf@vmware.com>
Gavin Gray <gavin@infinio.com> Gavin Gray <gavin@infinio.com>
Gavrie Philipson <gavrie@philipson.co.il> <gavrie.philipson@elastifile.com> Gavrie Philipson <gavrie@philipson.co.il> <gavrie.philipson@elastifile.com>
George Hicken <ghicken@vmware.com>
Gerrit Renker <Gerrit.Renker@ctl.io>
gthombare <gthombare@vmware.com>
Isaac Rodman <isaac@eyz.us>
Louie Jiang <jiangl@vmware.com> Louie Jiang <jiangl@vmware.com>
Mevan Samaratunga <mevansam@gmail.com> Mevan Samaratunga <mevansam@gmail.com>
Pieter Noordhuis <pnoordhuis@vmware.com> <pcnoordhuis@gmail.com> Pieter Noordhuis <pnoordhuis@vmware.com> <pcnoordhuis@gmail.com>
runner.mei <runner.mei@gmail.com> runner.mei <runner.mei@gmail.com>
S.Çağlar Onur <conur@vmware.com> S.Çağlar Onur <conur@vmware.com>
Sergey Ignatov <sergey.ignatov@jetbrains.com>
Takaaki Furukawa <takaaki.frkw@gmail.com> <takaaki.furukawa@mail.rakuten.com> Takaaki Furukawa <takaaki.frkw@gmail.com> <takaaki.furukawa@mail.rakuten.com>
Steve Purcell <steve@sanityinc.com>
Yang Yang <yangy@vmware.com> Yang Yang <yangy@vmware.com>
Yuya Kusakabe <yuya.kusakabe@gmail.com> Yuya Kusakabe <yuya.kusakabe@gmail.com>
Zach Tucker <ztucker@vmware.com>
Zee Yang <zeey@vmware.com> <zee.yang@gmail.com> Zee Yang <zeey@vmware.com> <zee.yang@gmail.com>

View File

@ -4,7 +4,12 @@ all: check test
check: goimports govet check: goimports govet
goimports: vendor:
go get golang.org/x/tools/cmd/goimports
go get github.com/davecgh/go-spew/spew
go get golang.org/x/net/context
goimports: vendor
@echo checking go imports... @echo checking go imports...
@! goimports -d . 2>&1 | egrep -v '^$$' @! goimports -d . 2>&1 | egrep -v '^$$'
@ -12,9 +17,8 @@ govet:
@echo checking go vet... @echo checking go vet...
@go tool vet -structtags=false -methods=false . @go tool vet -structtags=false -methods=false .
test: test: vendor
go get
go test -v $(TEST_OPTS) ./... go test -v $(TEST_OPTS) ./...
install: install: vendor
go install github.com/vmware/govmomi/govc go install github.com/vmware/govmomi/govc

View File

@ -1,4 +1,5 @@
[![Build Status](https://travis-ci.org/vmware/govmomi.png?branch=master)](https://travis-ci.org/vmware/govmomi) [![Build Status](https://travis-ci.org/vmware/govmomi.png?branch=master)](https://travis-ci.org/vmware/govmomi)
[![Build Status](https://ci.vmware.run/api/badges/vmware/govmomi/status.svg)](https://ci.vmware.run/vmware/govmomi)
# govmomi # govmomi
@ -24,6 +25,17 @@ See [godoc.org][godoc] for documentation.
[apiref]:http://pubs.vmware.com/vsphere-60/index.jsp#com.vmware.wssdk.apiref.doc/right-pane.html [apiref]:http://pubs.vmware.com/vsphere-60/index.jsp#com.vmware.wssdk.apiref.doc/right-pane.html
[godoc]:http://godoc.org/github.com/vmware/govmomi [godoc]:http://godoc.org/github.com/vmware/govmomi
[drone]:https://drone.io
[dronesrc]:https://github.com/drone/drone
[dronecli]:http://readme.drone.io/devs/cli/
#### Building with CI
Merges to this repository will trigger builds in both Travis and [Drone][drone].
To build locally with Drone:
- Ensure that you have Docker 1.6 or higher installed.
- Install the [Drone command line tools][dronecli].
- Run `drone exec` from within the root directory of the govmomi repository.
## Status ## Status
@ -31,6 +43,12 @@ Changes to the API are subject to [semantic versioning](http://semver.org).
Refer to the [CHANGELOG](CHANGELOG.md) for version to version changes. Refer to the [CHANGELOG](CHANGELOG.md) for version to version changes.
## Projects using govmomi
* [Docker Machine](https://github.com/docker/machine/tree/master/drivers/vmwarevsphere)
* [Terraform](https://github.com/hashicorp/terraform/tree/master/builtin/providers/vsphere)
## License ## License
govmomi is available under the [Apache 2 license](LICENSE). govmomi is available under the [Apache 2 license](LICENSE).

View File

@ -1,5 +1,5 @@
/* /*
Copyright (c) 2014-2015 VMware, Inc. All Rights Reserved. Copyright (c) 2014-2016 VMware, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/* /*
Copyright (c) 2014-2015 VMware, Inc. All Rights Reserved. Copyright (c) 2014-2016 VMware, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -313,6 +313,63 @@ func (f *Finder) DatastoreOrDefault(ctx context.Context, path string) (*object.D
return f.DefaultDatastore(ctx) return f.DefaultDatastore(ctx)
} }
func (f *Finder) DatastoreClusterList(ctx context.Context, path string) ([]*object.StoragePod, error) {
es, err := f.find(ctx, f.datastoreFolder, false, path)
if err != nil {
return nil, err
}
var sps []*object.StoragePod
for _, e := range es {
ref := e.Object.Reference()
if ref.Type == "StoragePod" {
sp := object.NewStoragePod(f.client, ref)
sp.InventoryPath = e.Path
sps = append(sps, sp)
}
}
if len(sps) == 0 {
return nil, &NotFoundError{"datastore cluster", path}
}
return sps, nil
}
func (f *Finder) DatastoreCluster(ctx context.Context, path string) (*object.StoragePod, error) {
sps, err := f.DatastoreClusterList(ctx, path)
if err != nil {
return nil, err
}
if len(sps) > 1 {
return nil, &MultipleFoundError{"datastore cluster", path}
}
return sps[0], nil
}
func (f *Finder) DefaultDatastoreCluster(ctx context.Context) (*object.StoragePod, error) {
sp, err := f.DatastoreCluster(ctx, "*")
if err != nil {
return nil, toDefaultError(err)
}
return sp, nil
}
func (f *Finder) DatastoreClusterOrDefault(ctx context.Context, path string) (*object.StoragePod, error) {
if path != "" {
sp, err := f.DatastoreCluster(ctx, path)
if err != nil {
return nil, err
}
return sp, nil
}
return f.DefaultDatastoreCluster(ctx)
}
func (f *Finder) ComputeResourceList(ctx context.Context, path string) ([]*object.ComputeResource, error) { func (f *Finder) ComputeResourceList(ctx context.Context, path string) ([]*object.ComputeResource, error) {
es, err := f.find(ctx, f.hostFolder, false, path) es, err := f.find(ctx, f.hostFolder, false, path)
if err != nil { if err != nil {
@ -612,6 +669,27 @@ func (f *Finder) ResourcePoolOrDefault(ctx context.Context, path string) (*objec
return f.DefaultResourcePool(ctx) return f.DefaultResourcePool(ctx)
} }
func (f *Finder) DefaultFolder(ctx context.Context) (*object.Folder, error) {
ref, err := f.vmFolder(ctx)
if err != nil {
return nil, toDefaultError(err)
}
folder := object.NewFolder(f.client, ref.Reference())
return folder, nil
}
func (f *Finder) FolderOrDefault(ctx context.Context, path string) (*object.Folder, error) {
if path != "" {
folder, err := f.Folder(ctx, path)
if err != nil {
return nil, err
}
return folder, nil
}
return f.DefaultFolder(ctx)
}
func (f *Finder) VirtualMachineList(ctx context.Context, path string) ([]*object.VirtualMachine, error) { func (f *Finder) VirtualMachineList(ctx context.Context, path string) ([]*object.VirtualMachine, error) {
es, err := f.find(ctx, f.vmFolder, false, path) es, err := f.find(ctx, f.vmFolder, false, path)
if err != nil { if err != nil {
@ -684,28 +762,42 @@ func (f *Finder) VirtualApp(ctx context.Context, path string) (*object.VirtualAp
return apps[0], nil return apps[0], nil
} }
func (f *Finder) Folder(ctx context.Context, path string) (*object.Folder, error) { func (f *Finder) FolderList(ctx context.Context, path string) ([]*object.Folder, error) {
mo, err := f.ManagedObjectList(ctx, path) es, err := f.ManagedObjectList(ctx, path)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if len(mo) == 0 { var folders []*object.Folder
for _, e := range es {
switch o := e.Object.(type) {
case mo.Folder:
folder := object.NewFolder(f.client, o.Reference())
folder.InventoryPath = e.Path
folders = append(folders, folder)
case *object.Folder:
// RootFolder
folders = append(folders, o)
}
}
if len(folders) == 0 {
return nil, &NotFoundError{"folder", path} return nil, &NotFoundError{"folder", path}
} }
if len(mo) > 1 { return folders, nil
}
func (f *Finder) Folder(ctx context.Context, path string) (*object.Folder, error) {
folders, err := f.FolderList(ctx, path)
if err != nil {
return nil, err
}
if len(folders) > 1 {
return nil, &MultipleFoundError{"folder", path} return nil, &MultipleFoundError{"folder", path}
} }
ref := mo[0].Object.Reference() return folders[0], nil
if ref.Type != "Folder" {
return nil, &NotFoundError{"folder", path}
}
folder := object.NewFolder(f.client, ref)
folder.InventoryPath = mo[0].Path
return folder, nil
} }

View File

@ -1,5 +1,5 @@
/* /*
Copyright (c) 2014-2015 VMware, Inc. All Rights Reserved. Copyright (c) 2014-2016 VMware, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -119,6 +119,7 @@ func traversable(ref types.ManagedObjectReference) bool {
// It doesn't matter from the perspective of the lister. // It doesn't matter from the perspective of the lister.
case "HostSystem": case "HostSystem":
case "VirtualApp": case "VirtualApp":
case "StoragePod":
default: default:
return false return false
} }

View File

@ -38,7 +38,7 @@ func NewAuthorizationManager(c *vim25.Client) *AuthorizationManager {
type AuthorizationRoleList []types.AuthorizationRole type AuthorizationRoleList []types.AuthorizationRole
func (l AuthorizationRoleList) ById(id int) *types.AuthorizationRole { func (l AuthorizationRoleList) ById(id int32) *types.AuthorizationRole {
for _, role := range l { for _, role := range l {
if role.RoleId == id { if role.RoleId == id {
return &role return &role

View File

@ -69,3 +69,17 @@ func (c Common) Destroy(ctx context.Context) (*Task, error) {
return NewTask(c.c, res.Returnval), nil return NewTask(c.c, res.Returnval), nil
} }
func (c Common) Rename(ctx context.Context, name string) (*Task, error) {
req := types.Rename_Task{
This: c.Reference(),
NewName: name,
}
res, err := methods.Rename_Task(ctx, c.c, &req)
if err != nil {
return nil, err
}
return NewTask(c.c, res.Returnval), nil
}

View File

@ -69,7 +69,7 @@ func (m CustomFieldsManager) Add(ctx context.Context, name string, moType string
return &res.Returnval, nil return &res.Returnval, nil
} }
func (m CustomFieldsManager) Remove(ctx context.Context, key int) error { func (m CustomFieldsManager) Remove(ctx context.Context, key int32) error {
req := types.RemoveCustomFieldDef{ req := types.RemoveCustomFieldDef{
This: m.Reference(), This: m.Reference(),
Key: key, Key: key,
@ -79,7 +79,7 @@ func (m CustomFieldsManager) Remove(ctx context.Context, key int) error {
return err return err
} }
func (m CustomFieldsManager) Rename(ctx context.Context, key int, name string) error { func (m CustomFieldsManager) Rename(ctx context.Context, key int32, name string) error {
req := types.RenameCustomFieldDef{ req := types.RenameCustomFieldDef{
This: m.Reference(), This: m.Reference(),
Key: key, Key: key,
@ -90,7 +90,7 @@ func (m CustomFieldsManager) Rename(ctx context.Context, key int, name string) e
return err return err
} }
func (m CustomFieldsManager) Set(ctx context.Context, entity types.ManagedObjectReference, key int, value string) error { func (m CustomFieldsManager) Set(ctx context.Context, entity types.ManagedObjectReference, key int32, value string) error {
req := types.SetField{ req := types.SetField{
This: m.Reference(), This: m.Reference(),
Entity: entity, Entity: entity,
@ -113,7 +113,7 @@ func (m CustomFieldsManager) Field(ctx context.Context) ([]types.CustomFieldDef,
return fm.Field, nil return fm.Field, nil
} }
func (m CustomFieldsManager) FindKey(ctx context.Context, key string) (int, error) { func (m CustomFieldsManager) FindKey(ctx context.Context, key string) (int32, error) {
field, err := m.Field(ctx) field, err := m.Field(ctx)
if err != nil { if err != nil {
return -1, err return -1, err
@ -128,7 +128,7 @@ func (m CustomFieldsManager) FindKey(ctx context.Context, key string) (int, erro
k, err := strconv.Atoi(key) k, err := strconv.Atoi(key)
if err == nil { if err == nil {
// assume literal int key // assume literal int key
return k, nil return int32(k), nil
} }
return -1, ErrKeyNameNotFound return -1, ErrKeyNameNotFound

View File

@ -1,5 +1,5 @@
/* /*
Copyright (c) 2015 VMware, Inc. All Rights Reserved. Copyright (c) 2015-2016 VMware, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -220,7 +220,16 @@ func (d Datastore) UploadFile(ctx context.Context, file string, path string, par
return d.Client().UploadFile(file, u, p) return d.Client().UploadFile(file, u, p)
} }
// DownloadFile via soap.Upload with an http service ticket // Download via soap.Download with an http service ticket
func (d Datastore) Download(ctx context.Context, path string, param *soap.Download) (io.ReadCloser, int64, error) {
u, p, err := d.downloadTicket(ctx, path, param)
if err != nil {
return nil, 0, err
}
return d.Client().Download(u, p)
}
// DownloadFile via soap.Download with an http service ticket
func (d Datastore) DownloadFile(ctx context.Context, path string, file string, param *soap.Download) error { func (d Datastore) DownloadFile(ctx context.Context, path string, file string, param *soap.Download) error {
u, p, err := d.downloadTicket(ctx, path, param) u, p, err := d.downloadTicket(ctx, path, param)
if err != nil { if err != nil {

View File

@ -35,7 +35,7 @@ func NewDiagnosticManager(c *vim25.Client) *DiagnosticManager {
return &m return &m
} }
func (m DiagnosticManager) BrowseLog(ctx context.Context, host *HostSystem, key string, start, lines int) (*types.DiagnosticManagerLogHeader, error) { func (m DiagnosticManager) BrowseLog(ctx context.Context, host *HostSystem, key string, start, lines int32) (*types.DiagnosticManagerLogHeader, error) {
req := types.BrowseDiagnosticLog{ req := types.BrowseDiagnosticLog{
This: m.Reference(), This: m.Reference(),
Key: key, Key: key,

View File

@ -37,7 +37,9 @@ func NewFolder(c *vim25.Client, ref types.ManagedObjectReference) *Folder {
} }
func NewRootFolder(c *vim25.Client) *Folder { func NewRootFolder(c *vim25.Client) *Folder {
return NewFolder(c, c.ServiceContent.RootFolder) f := NewFolder(c, c.ServiceContent.RootFolder)
f.InventoryPath = "/"
return f
} }
func (f Folder) Children(ctx context.Context) ([]Reference, error) { func (f Folder) Children(ctx context.Context) ([]Reference, error) {
@ -196,3 +198,17 @@ func (f Folder) CreateDVS(ctx context.Context, spec types.DVSCreateSpec) (*Task,
return NewTask(f.c, res.Returnval), nil return NewTask(f.c, res.Returnval), nil
} }
func (f Folder) MoveInto(ctx context.Context, list []types.ManagedObjectReference) (*Task, error) {
req := types.MoveIntoFolder_Task{
This: f.Reference(),
List: list,
}
res, err := methods.MoveIntoFolder_Task(ctx, f.c, &req)
if err != nil {
return nil, err
}
return NewTask(f.c, res.Returnval), nil
}

View File

@ -60,7 +60,7 @@ func (h HistoryCollector) Rewind(ctx context.Context) error {
return err return err
} }
func (h HistoryCollector) SetPageSize(ctx context.Context, maxCount int) error { func (h HistoryCollector) SetPageSize(ctx context.Context, maxCount int32) error {
req := types.SetCollectorPageSize{ req := types.SetCollectorPageSize{
This: h.Reference(), This: h.Reference(),
MaxCount: maxCount, MaxCount: maxCount,

View File

@ -0,0 +1,64 @@
/*
Copyright (c) 2016 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 object
import (
"github.com/vmware/govmomi/vim25"
"github.com/vmware/govmomi/vim25/methods"
"github.com/vmware/govmomi/vim25/types"
"golang.org/x/net/context"
)
type HostAccountManager struct {
Common
}
func NewHostAccountManager(c *vim25.Client, ref types.ManagedObjectReference) *HostAccountManager {
return &HostAccountManager{
Common: NewCommon(c, ref),
}
}
func (m HostAccountManager) Create(ctx context.Context, user *types.HostAccountSpec) error {
req := types.CreateUser{
This: m.Reference(),
User: user,
}
_, err := methods.CreateUser(ctx, m.Client(), &req)
return err
}
func (m HostAccountManager) Update(ctx context.Context, user *types.HostAccountSpec) error {
req := types.UpdateUser{
This: m.Reference(),
User: user,
}
_, err := methods.UpdateUser(ctx, m.Client(), &req)
return err
}
func (m HostAccountManager) Remove(ctx context.Context, userName string) error {
req := types.RemoveUser{
This: m.Reference(),
UserName: userName,
}
_, err := methods.RemoveUser(ctx, m.Client(), &req)
return err
}

View File

@ -98,3 +98,25 @@ func (m HostConfigManager) VsanSystem(ctx context.Context) (*HostVsanSystem, err
return NewHostVsanSystem(m.c, *h.ConfigManager.VsanSystem), nil return NewHostVsanSystem(m.c, *h.ConfigManager.VsanSystem), nil
} }
func (m HostConfigManager) AccountManager(ctx context.Context) (*HostAccountManager, error) {
var h mo.HostSystem
err := m.Properties(ctx, m.Reference(), []string{"configManager.accountManager"}, &h)
if err != nil {
return nil, err
}
return NewHostAccountManager(m.c, *h.ConfigManager.AccountManager), nil
}
func (m HostConfigManager) OptionManager(ctx context.Context) (*OptionManager, error) {
var h mo.HostSystem
err := m.Properties(ctx, m.Reference(), []string{"configManager.advancedOption"}, &h)
if err != nil {
return nil, err
}
return NewOptionManager(m.c, *h.ConfigManager.AdvancedOption), nil
}

View File

@ -142,7 +142,7 @@ func (h HostSystem) Reconnect(ctx context.Context, cnxSpec *types.HostConnectSpe
return NewTask(h.c, res.Returnval), nil return NewTask(h.c, res.Returnval), nil
} }
func (h HostSystem) EnterMaintenanceMode(ctx context.Context, timeout int, evacuate bool, spec *types.HostMaintenanceSpec) (*Task, error) { func (h HostSystem) EnterMaintenanceMode(ctx context.Context, timeout int32, evacuate bool, spec *types.HostMaintenanceSpec) (*Task, error) {
req := types.EnterMaintenanceMode_Task{ req := types.EnterMaintenanceMode_Task{
This: h.Reference(), This: h.Reference(),
Timeout: timeout, Timeout: timeout,
@ -158,7 +158,7 @@ func (h HostSystem) EnterMaintenanceMode(ctx context.Context, timeout int, evacu
return NewTask(h.c, res.Returnval), nil return NewTask(h.c, res.Returnval), nil
} }
func (h HostSystem) ExitMaintenanceMode(ctx context.Context, timeout int) (*Task, error) { func (h HostSystem) ExitMaintenanceMode(ctx context.Context, timeout int32) (*Task, error) {
req := types.ExitMaintenanceMode_Task{ req := types.ExitMaintenanceMode_Task{
This: h.Reference(), This: h.Reference(),
Timeout: timeout, Timeout: timeout,

View File

@ -82,7 +82,7 @@ func (o HttpNfcLease) HttpNfcLeaseGetManifest(ctx context.Context) error {
} }
// HttpNfcLeaseProgress wraps methods.HttpNfcLeaseProgress // HttpNfcLeaseProgress wraps methods.HttpNfcLeaseProgress
func (o HttpNfcLease) HttpNfcLeaseProgress(ctx context.Context, percent int) error { func (o HttpNfcLease) HttpNfcLeaseProgress(ctx context.Context, percent int32) error {
req := types.HttpNfcLeaseProgress{ req := types.HttpNfcLeaseProgress{
This: o.Reference(), This: o.Reference(),
Percent: percent, Percent: percent,

43
vendor/github.com/vmware/govmomi/object/list_view.go generated vendored Normal file
View File

@ -0,0 +1,43 @@
/*
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 object
import (
"github.com/vmware/govmomi/vim25"
"github.com/vmware/govmomi/vim25/methods"
"github.com/vmware/govmomi/vim25/types"
"golang.org/x/net/context"
)
type ListView struct {
Common
}
func NewListView(c *vim25.Client, ref types.ManagedObjectReference) *ListView {
return &ListView{
Common: NewCommon(c, ref),
}
}
func (v ListView) Destroy(ctx context.Context) error {
req := types.DestroyView{
This: v.Reference(),
}
_, err := methods.DestroyView(ctx, v.c, &req)
return err
}

View File

@ -0,0 +1,58 @@
/*
Copyright (c) 2016 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 object
import (
"github.com/vmware/govmomi/vim25"
"github.com/vmware/govmomi/vim25/methods"
"github.com/vmware/govmomi/vim25/types"
"golang.org/x/net/context"
)
type OptionManager struct {
Common
}
func NewOptionManager(c *vim25.Client, ref types.ManagedObjectReference) *OptionManager {
return &OptionManager{
Common: NewCommon(c, ref),
}
}
func (m OptionManager) Query(ctx context.Context, name string) ([]types.BaseOptionValue, error) {
req := types.QueryOptions{
This: m.Reference(),
Name: name,
}
res, err := methods.QueryOptions(ctx, m.Client(), &req)
if err != nil {
return nil, err
}
return res.Returnval, nil
}
func (m OptionManager) Update(ctx context.Context, value []types.BaseOptionValue) error {
req := types.UpdateOptions{
This: m.Reference(),
ChangedValue: value,
}
_, err := methods.UpdateOptions(ctx, m.Client(), &req)
return err
}

View File

@ -16,6 +16,19 @@ limitations under the License.
package object package object
import (
"github.com/vmware/govmomi/vim25"
"github.com/vmware/govmomi/vim25/types"
)
type StoragePod struct { type StoragePod struct {
*Folder *Folder
} }
func NewStoragePod(c *vim25.Client, ref types.ManagedObjectReference) *StoragePod {
return &StoragePod{
Folder: &Folder{
Common: NewCommon(c, ref),
},
}
}

View File

@ -63,7 +63,6 @@ func EthernetCardTypes() VirtualDeviceList {
&types.VirtualVmxnet3{}, &types.VirtualVmxnet3{},
}).Select(func(device types.BaseVirtualDevice) bool { }).Select(func(device types.BaseVirtualDevice) bool {
c := device.(types.BaseVirtualEthernetCard).GetVirtualEthernetCard() c := device.(types.BaseVirtualEthernetCard).GetVirtualEthernetCard()
c.AddressType = string(types.VirtualEthernetCardMacTypeGenerated)
c.GetVirtualDevice().Key = -1 c.GetVirtualDevice().Key = -1
return true return true
}) })
@ -126,7 +125,8 @@ func (l VirtualDeviceList) SelectByBackingInfo(backing types.BaseVirtualDeviceBa
return a.DeviceName == b.DeviceName return a.DeviceName == b.DeviceName
case *types.VirtualEthernetCardDistributedVirtualPortBackingInfo: case *types.VirtualEthernetCardDistributedVirtualPortBackingInfo:
b := backing.(*types.VirtualEthernetCardDistributedVirtualPortBackingInfo) b := backing.(*types.VirtualEthernetCardDistributedVirtualPortBackingInfo)
return a.Port.SwitchUuid == b.Port.SwitchUuid return a.Port.SwitchUuid == b.Port.SwitchUuid &&
a.Port.PortgroupKey == b.Port.PortgroupKey
case *types.VirtualDiskFlatVer2BackingInfo: case *types.VirtualDiskFlatVer2BackingInfo:
b := backing.(*types.VirtualDiskFlatVer2BackingInfo) b := backing.(*types.VirtualDiskFlatVer2BackingInfo)
if a.Parent != nil && b.Parent != nil { if a.Parent != nil && b.Parent != nil {
@ -156,7 +156,7 @@ func (l VirtualDeviceList) Find(name string) types.BaseVirtualDevice {
} }
// FindByKey returns the device matching the given key. // FindByKey returns the device matching the given key.
func (l VirtualDeviceList) FindByKey(key int) types.BaseVirtualDevice { func (l VirtualDeviceList) FindByKey(key int32) types.BaseVirtualDevice {
for _, device := range l { for _, device := range l {
if device.GetVirtualDevice().Key == key { if device.GetVirtualDevice().Key == key {
return device return device
@ -188,6 +188,13 @@ func (l VirtualDeviceList) FindIDEController(name string) (*types.VirtualIDECont
return c.(*types.VirtualIDEController), nil return c.(*types.VirtualIDEController), nil
} }
// CreateIDEController creates a new IDE controller.
func (l VirtualDeviceList) CreateIDEController() (types.BaseVirtualDevice, error) {
ide := &types.VirtualIDEController{}
ide.Key = l.NewKey()
return ide, nil
}
// FindSCSIController will find the named SCSI controller if given, otherwise will pick an available controller. // FindSCSIController will find the named SCSI controller if given, otherwise will pick an available controller.
// An error is returned if the named controller is not found or not an SCSI controller. Or, if name is not // An error is returned if the named controller is not found or not an SCSI controller. Or, if name is not
// given and no available controller can be found. // given and no available controller can be found.
@ -233,9 +240,8 @@ func (l VirtualDeviceList) CreateSCSIController(name string) (types.BaseVirtualD
} }
scsi := c.GetVirtualSCSIController() scsi := c.GetVirtualSCSIController()
scsi.BusNumber = l.newSCSIBusNumber() scsi.BusNumber = l.newSCSIBusNumber()
scsi.Key = l.NewKey()
return c.(types.BaseVirtualDevice), nil return c.(types.BaseVirtualDevice), nil
} }
@ -243,13 +249,13 @@ var scsiBusNumbers = []int{0, 1, 2, 3}
// newSCSIBusNumber returns the bus number to use for adding a new SCSI bus device. // newSCSIBusNumber returns the bus number to use for adding a new SCSI bus device.
// -1 is returned if there are no bus numbers available. // -1 is returned if there are no bus numbers available.
func (l VirtualDeviceList) newSCSIBusNumber() int { func (l VirtualDeviceList) newSCSIBusNumber() int32 {
var used []int var used []int
for _, d := range l.SelectByType((*types.VirtualSCSIController)(nil)) { for _, d := range l.SelectByType((*types.VirtualSCSIController)(nil)) {
num := d.(types.BaseVirtualSCSIController).GetVirtualSCSIController().BusNumber num := d.(types.BaseVirtualSCSIController).GetVirtualSCSIController().BusNumber
if num >= 0 { if num >= 0 {
used = append(used, num) used = append(used, int(num))
} // else caller is creating a new vm using SCSIControllerTypes } // else caller is creating a new vm using SCSIControllerTypes
} }
@ -257,7 +263,7 @@ func (l VirtualDeviceList) newSCSIBusNumber() int {
for i, n := range scsiBusNumbers { for i, n := range scsiBusNumbers {
if i == len(used) || n != used[i] { if i == len(used) || n != used[i] {
return n return int32(n)
} }
} }
@ -303,16 +309,16 @@ func (l VirtualDeviceList) PickController(kind types.BaseVirtualController) type
} }
// newUnitNumber returns the unit number to use for attaching a new device to the given controller. // newUnitNumber returns the unit number to use for attaching a new device to the given controller.
func (l VirtualDeviceList) newUnitNumber(c types.BaseVirtualController) int { func (l VirtualDeviceList) newUnitNumber(c types.BaseVirtualController) int32 {
key := c.GetVirtualController().Key key := c.GetVirtualController().Key
max := -1 var max int32 = -1
for _, device := range l { for _, device := range l {
d := device.GetVirtualDevice() d := device.GetVirtualDevice()
if d.ControllerKey == key { if d.ControllerKey == key {
if d.UnitNumber > max { if d.UnitNumber != nil && *d.UnitNumber > max {
max = d.UnitNumber max = *d.UnitNumber
} }
} }
} }
@ -320,16 +326,37 @@ func (l VirtualDeviceList) newUnitNumber(c types.BaseVirtualController) int {
return max + 1 return max + 1
} }
// NewKey returns the key to use for adding a new device to the device list.
// The device list we're working with here may not be complete (e.g. when
// we're only adding new devices), so any positive keys could conflict with device keys
// that are already in use. To avoid this type of conflict, we can use negative keys
// here, which will be resolved to positive keys by vSphere as the reconfiguration is done.
func (l VirtualDeviceList) NewKey() int32 {
var key int32 = -200
for _, device := range l {
d := device.GetVirtualDevice()
if d.Key < key {
key = d.Key
}
}
return key - 1
}
// AssignController assigns a device to a controller. // AssignController assigns a device to a controller.
func (l VirtualDeviceList) AssignController(device types.BaseVirtualDevice, c types.BaseVirtualController) { func (l VirtualDeviceList) AssignController(device types.BaseVirtualDevice, c types.BaseVirtualController) {
d := device.GetVirtualDevice() d := device.GetVirtualDevice()
d.ControllerKey = c.GetVirtualController().Key d.ControllerKey = c.GetVirtualController().Key
d.UnitNumber = l.newUnitNumber(c) d.UnitNumber = new(int32)
d.Key = -1 *d.UnitNumber = l.newUnitNumber(c)
if d.Key == 0 {
d.Key = -1
}
} }
// CreateDisk creates a new VirtualDisk device which can be added to a VM. // CreateDisk creates a new VirtualDisk device which can be added to a VM.
func (l VirtualDeviceList) CreateDisk(c types.BaseVirtualController, name string) *types.VirtualDisk { func (l VirtualDeviceList) CreateDisk(c types.BaseVirtualController, ds types.ManagedObjectReference, name string) *types.VirtualDisk {
// If name is not specified, one will be chosen for you. // If name is not specified, one will be chosen for you.
// But if when given, make sure it ends in .vmdk, otherwise it will be treated as a directory. // But if when given, make sure it ends in .vmdk, otherwise it will be treated as a directory.
if len(name) > 0 && filepath.Ext(name) != ".vmdk" { if len(name) > 0 && filepath.Ext(name) != ".vmdk" {
@ -342,18 +369,14 @@ func (l VirtualDeviceList) CreateDisk(c types.BaseVirtualController, name string
DiskMode: string(types.VirtualDiskModePersistent), DiskMode: string(types.VirtualDiskModePersistent),
ThinProvisioned: types.NewBool(true), ThinProvisioned: types.NewBool(true),
VirtualDeviceFileBackingInfo: types.VirtualDeviceFileBackingInfo{ VirtualDeviceFileBackingInfo: types.VirtualDeviceFileBackingInfo{
FileName: name, FileName: name,
Datastore: &ds,
}, },
}, },
}, },
} }
l.AssignController(device, c) l.AssignController(device, c)
if device.UnitNumber == 0 {
device.UnitNumber = -1 // TODO: this field is annotated as omitempty
}
return device return device
} }
@ -366,7 +389,8 @@ func (l VirtualDeviceList) ChildDisk(parent *types.VirtualDisk) *types.VirtualDi
// Use specified disk as parent backing to a new disk. // Use specified disk as parent backing to a new disk.
disk.Backing = &types.VirtualDiskFlatVer2BackingInfo{ disk.Backing = &types.VirtualDiskFlatVer2BackingInfo{
VirtualDeviceFileBackingInfo: types.VirtualDeviceFileBackingInfo{ VirtualDeviceFileBackingInfo: types.VirtualDeviceFileBackingInfo{
FileName: fmt.Sprintf("[%s]", ds[0]), FileName: fmt.Sprintf("[%s]", ds[0]),
Datastore: backing.Datastore,
}, },
Parent: backing, Parent: backing,
DiskMode: backing.DiskMode, DiskMode: backing.DiskMode,
@ -738,17 +762,66 @@ func (l VirtualDeviceList) Type(device types.BaseVirtualDevice) string {
// Name returns a stable, human-readable name for the given device // Name returns a stable, human-readable name for the given device
func (l VirtualDeviceList) Name(device types.BaseVirtualDevice) string { func (l VirtualDeviceList) Name(device types.BaseVirtualDevice) string {
var key string var key string
var UnitNumber int32
d := device.GetVirtualDevice() d := device.GetVirtualDevice()
dtype := l.Type(device) if d.UnitNumber != nil {
UnitNumber = *d.UnitNumber
}
dtype := l.Type(device)
switch dtype { switch dtype {
case DeviceTypeEthernet: case DeviceTypeEthernet:
key = fmt.Sprintf("%d", d.UnitNumber-7) key = fmt.Sprintf("%d", UnitNumber-7)
case DeviceTypeDisk: case DeviceTypeDisk:
key = fmt.Sprintf("%d-%d", d.ControllerKey, d.UnitNumber) key = fmt.Sprintf("%d-%d", d.ControllerKey, UnitNumber)
default: default:
key = fmt.Sprintf("%d", d.Key) key = fmt.Sprintf("%d", d.Key)
} }
return fmt.Sprintf("%s-%s", dtype, key) return fmt.Sprintf("%s-%s", dtype, key)
} }
// ConfigSpec creates a virtual machine configuration spec for
// the specified operation, for the list of devices in the device list.
func (l VirtualDeviceList) ConfigSpec(op types.VirtualDeviceConfigSpecOperation) ([]types.BaseVirtualDeviceConfigSpec, error) {
var fop types.VirtualDeviceConfigSpecFileOperation
switch op {
case types.VirtualDeviceConfigSpecOperationAdd:
fop = types.VirtualDeviceConfigSpecFileOperationCreate
case types.VirtualDeviceConfigSpecOperationEdit:
fop = types.VirtualDeviceConfigSpecFileOperationReplace
case types.VirtualDeviceConfigSpecOperationRemove:
fop = types.VirtualDeviceConfigSpecFileOperationDestroy
default:
panic("unknown op")
}
var res []types.BaseVirtualDeviceConfigSpec
for _, device := range l {
config := &types.VirtualDeviceConfigSpec{
Device: device,
Operation: op,
}
if disk, ok := device.(*types.VirtualDisk); ok {
config.FileOperation = fop
// Special case to attach an existing disk
if op == types.VirtualDeviceConfigSpecOperationAdd && disk.CapacityInKB == 0 {
childDisk := false
if b, ok := disk.Backing.(*types.VirtualDiskFlatVer2BackingInfo); ok {
childDisk = b.Parent != nil
}
if !childDisk {
// Existing disk, clear file operation
config.FileOperation = ""
}
}
}
res = append(res, config)
}
return res, nil
}

View File

@ -19,6 +19,7 @@ package object
import ( import (
"errors" "errors"
"fmt" "fmt"
"net"
"github.com/vmware/govmomi/property" "github.com/vmware/govmomi/property"
"github.com/vmware/govmomi/vim25" "github.com/vmware/govmomi/vim25"
@ -245,6 +246,77 @@ func (v VirtualMachine) WaitForIP(ctx context.Context) (string, error) {
return ip, nil return ip, nil
} }
// WaitForNetIP waits for the VM guest.net property to report an IP address for all VM NICs.
// Only consider IPv4 addresses if the v4 param is true.
// Returns a map with MAC address as the key and IP address list as the value.
func (v VirtualMachine) WaitForNetIP(ctx context.Context, v4 bool) (map[string][]string, error) {
macs := make(map[string][]string)
p := property.DefaultCollector(v.c)
// Wait for all NICs to have a MacAddress, which may not be generated yet.
err := property.Wait(ctx, p, v.Reference(), []string{"config.hardware.device"}, func(pc []types.PropertyChange) bool {
for _, c := range pc {
if c.Op != types.PropertyChangeOpAssign {
continue
}
devices := c.Val.(types.ArrayOfVirtualDevice).VirtualDevice
for _, device := range devices {
if nic, ok := device.(types.BaseVirtualEthernetCard); ok {
mac := nic.GetVirtualEthernetCard().MacAddress
if mac == "" {
return false
}
macs[mac] = nil
}
}
}
return true
})
err = property.Wait(ctx, p, v.Reference(), []string{"guest.net"}, func(pc []types.PropertyChange) bool {
for _, c := range pc {
if c.Op != types.PropertyChangeOpAssign {
continue
}
nics := c.Val.(types.ArrayOfGuestNicInfo).GuestNicInfo
for _, nic := range nics {
mac := nic.MacAddress
if mac == "" || nic.IpConfig == nil {
continue
}
for _, ip := range nic.IpConfig.IpAddress {
if _, ok := macs[mac]; !ok {
continue // Ignore any that don't correspond to a VM device
}
if v4 && net.ParseIP(ip.IpAddress).To4() == nil {
continue // Ignore non IPv4 address
}
macs[mac] = append(macs[mac], ip.IpAddress)
}
}
}
for _, ips := range macs {
if len(ips) == 0 {
return false
}
}
return true
})
if err != nil {
return nil, err
}
return macs, nil
}
// Device returns the VirtualMachine's config.hardware.device property. // Device returns the VirtualMachine's config.hardware.device property.
func (v VirtualMachine) Device(ctx context.Context) (VirtualDeviceList, error) { func (v VirtualMachine) Device(ctx context.Context) (VirtualDeviceList, error) {
var o mo.VirtualMachine var o mo.VirtualMachine
@ -336,8 +408,12 @@ func (v VirtualMachine) EditDevice(ctx context.Context, device ...types.BaseVirt
} }
// RemoveDevice removes the given devices on the VirtualMachine // RemoveDevice removes the given devices on the VirtualMachine
func (v VirtualMachine) RemoveDevice(ctx context.Context, device ...types.BaseVirtualDevice) error { func (v VirtualMachine) RemoveDevice(ctx context.Context, keepFiles bool, device ...types.BaseVirtualDevice) error {
return v.configureDevice(ctx, types.VirtualDeviceConfigSpecOperationRemove, types.VirtualDeviceConfigSpecFileOperationDestroy, device...) fop := types.VirtualDeviceConfigSpecFileOperationDestroy
if keepFiles {
fop = ""
}
return v.configureDevice(ctx, types.VirtualDeviceConfigSpecOperationRemove, fop, device...)
} }
// BootOptions returns the VirtualMachine's config.bootOptions property. // BootOptions returns the VirtualMachine's config.bootOptions property.
@ -400,6 +476,61 @@ func (v VirtualMachine) CreateSnapshot(ctx context.Context, name string, descrip
return NewTask(v.c, res.Returnval), nil return NewTask(v.c, res.Returnval), nil
} }
// RevertToSnapshot reverts to a named snapshot
func (v VirtualMachine) RevertToSnapshot(ctx context.Context, name string, suppressPowerOn bool) (*Task, error) {
var o mo.VirtualMachine
err := v.Properties(ctx, v.Reference(), []string{"snapshot"}, &o)
snapshotTree := o.Snapshot.RootSnapshotList
if len(snapshotTree) < 1 {
return nil, errors.New("No snapshots for this VM")
}
snapshot, err := traverseSnapshotInTree(snapshotTree, name)
if err != nil {
return nil, err
}
req := types.RevertToSnapshot_Task{
This: snapshot,
SuppressPowerOn: types.NewBool(suppressPowerOn),
}
res, err := methods.RevertToSnapshot_Task(ctx, v.c, &req)
if err != nil {
return nil, err
}
return NewTask(v.c, res.Returnval), nil
}
// traverseSnapshotInTree is a recursive function that will traverse a snapshot tree to find a given snapshot
func traverseSnapshotInTree(tree []types.VirtualMachineSnapshotTree, name string) (types.ManagedObjectReference, error) {
var o types.ManagedObjectReference
if tree == nil {
return o, errors.New("Snapshot tree is empty")
}
for _, s := range tree {
if s.Name == name {
o = s.Snapshot
break
} else {
childTree := s.ChildSnapshotList
var err error
o, err = traverseSnapshotInTree(childTree, name)
if err != nil {
return o, err
}
}
}
if o.Value == "" {
return o, errors.New("Snapshot not found")
}
return o, nil
}
// IsToolsRunning returns true if VMware Tools is currently running in the guest OS, and false otherwise. // IsToolsRunning returns true if VMware Tools is currently running in the guest OS, and false otherwise.
func (v VirtualMachine) IsToolsRunning(ctx context.Context) (bool, error) { func (v VirtualMachine) IsToolsRunning(ctx context.Context) (bool, error) {
var o mo.VirtualMachine var o mo.VirtualMachine

View File

@ -64,9 +64,66 @@ func Wait(ctx context.Context, c *Collector, obj types.ManagedObjectReference, p
if err != nil { if err != nil {
return err return err
} }
return waitLoop(ctx, p, f)
}
// WaitForView waits for any of the specified properties of the managed
// objects in the View to change. It calls the specified function for every update it
// receives. If this function returns false, it continues waiting for
// subsequent updates. If this function returns true, it stops waiting and
// returns.
//
// To only receive updates for the View's specified managed objects, the function
// creates a new property collector and calls CreateFilter. A new property
// collector is required because filters can only be added, not removed.
//
// The newly created collector is destroyed before this function returns (both
// in case of success or error).
//
// The code assumes that all objects in the View are the same type
func WaitForView(ctx context.Context, c *Collector, view types.ManagedObjectReference, obj types.ManagedObjectReference, ps []string, f func([]types.PropertyChange) bool) error {
p, err := c.Create(ctx)
if err != nil {
return err
}
// Attempt to destroy the collector using the background context, as the
// specified context may have timed out or have been cancelled.
defer p.Destroy(context.Background())
req := types.CreateFilter{
Spec: types.PropertyFilterSpec{
ObjectSet: []types.ObjectSpec{
{
Obj: view,
SelectSet: []types.BaseSelectionSpec{
&types.TraversalSpec{
SelectionSpec: types.SelectionSpec{
Name: "traverseEntities",
},
Path: "view",
Type: view.Type}},
},
},
PropSet: []types.PropertySpec{
types.PropertySpec{
Type: obj.Type,
PathSet: ps,
},
},
}}
err = p.CreateFilter(ctx, req)
if err != nil {
return err
}
return waitLoop(ctx, p, f)
}
func waitLoop(ctx context.Context, c *Collector, f func([]types.PropertyChange) bool) error {
for version := ""; ; { for version := ""; ; {
res, err := p.WaitForUpdates(ctx, version) res, err := c.WaitForUpdates(ctx, version)
if err != nil { if err != nil {
return err return err
} }
@ -80,12 +137,11 @@ func Wait(ctx context.Context, c *Collector, obj types.ManagedObjectReference, p
for _, fs := range res.FilterSet { for _, fs := range res.FilterSet {
for _, os := range fs.ObjectSet { for _, os := range fs.ObjectSet {
if os.Obj == obj { if f(os.ChangeSet) {
if f(os.ChangeSet) { return nil
return nil
}
} }
} }
} }
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
Copyright (c) 2015 VMware, Inc. All Rights Reserved. Copyright (c) 2015-2016 VMware, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
/* /*
Copyright (c) 2014-2015 VMware, Inc. All Rights Reserved. Copyright (c) 2014-2016 VMware, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -2682,26 +2682,6 @@ func CreateVM_Task(ctx context.Context, r soap.RoundTripper, req *types.CreateVM
return resBody.Res, nil return resBody.Res, nil
} }
type CreateVRPBody struct {
Req *types.CreateVRP `xml:"urn:vim25 CreateVRP,omitempty"`
Res *types.CreateVRPResponse `xml:"urn:vim25 CreateVRPResponse,omitempty"`
Fault_ *soap.Fault `xml:"http://schemas.xmlsoap.org/soap/envelope/ Fault,omitempty"`
}
func (b *CreateVRPBody) Fault() *soap.Fault { return b.Fault_ }
func CreateVRP(ctx context.Context, r soap.RoundTripper, req *types.CreateVRP) (*types.CreateVRPResponse, error) {
var reqBody, resBody CreateVRPBody
reqBody.Req = req
if err := r.RoundTrip(ctx, &reqBody, &resBody); err != nil {
return nil, err
}
return resBody.Res, nil
}
type CreateVirtualDisk_TaskBody struct { type CreateVirtualDisk_TaskBody struct {
Req *types.CreateVirtualDisk_Task `xml:"urn:vim25 CreateVirtualDisk_Task,omitempty"` Req *types.CreateVirtualDisk_Task `xml:"urn:vim25 CreateVirtualDisk_Task,omitempty"`
Res *types.CreateVirtualDisk_TaskResponse `xml:"urn:vim25 CreateVirtualDisk_TaskResponse,omitempty"` Res *types.CreateVirtualDisk_TaskResponse `xml:"urn:vim25 CreateVirtualDisk_TaskResponse,omitempty"`
@ -3202,26 +3182,6 @@ func DeleteScsiLunState(ctx context.Context, r soap.RoundTripper, req *types.Del
return resBody.Res, nil return resBody.Res, nil
} }
type DeleteVRPBody struct {
Req *types.DeleteVRP `xml:"urn:vim25 DeleteVRP,omitempty"`
Res *types.DeleteVRPResponse `xml:"urn:vim25 DeleteVRPResponse,omitempty"`
Fault_ *soap.Fault `xml:"http://schemas.xmlsoap.org/soap/envelope/ Fault,omitempty"`
}
func (b *DeleteVRPBody) Fault() *soap.Fault { return b.Fault_ }
func DeleteVRP(ctx context.Context, r soap.RoundTripper, req *types.DeleteVRP) (*types.DeleteVRPResponse, error) {
var reqBody, resBody DeleteVRPBody
reqBody.Req = req
if err := r.RoundTrip(ctx, &reqBody, &resBody); err != nil {
return nil, err
}
return resBody.Res, nil
}
type DeleteVffsVolumeStateBody struct { type DeleteVffsVolumeStateBody struct {
Req *types.DeleteVffsVolumeState `xml:"urn:vim25 DeleteVffsVolumeState,omitempty"` Req *types.DeleteVffsVolumeState `xml:"urn:vim25 DeleteVffsVolumeState,omitempty"`
Res *types.DeleteVffsVolumeStateResponse `xml:"urn:vim25 DeleteVffsVolumeStateResponse,omitempty"` Res *types.DeleteVffsVolumeStateResponse `xml:"urn:vim25 DeleteVffsVolumeStateResponse,omitempty"`
@ -3302,26 +3262,6 @@ func DeleteVsanObjects(ctx context.Context, r soap.RoundTripper, req *types.Dele
return resBody.Res, nil return resBody.Res, nil
} }
type DeployVMBody struct {
Req *types.DeployVM `xml:"urn:vim25 DeployVM,omitempty"`
Res *types.DeployVMResponse `xml:"urn:vim25 DeployVMResponse,omitempty"`
Fault_ *soap.Fault `xml:"http://schemas.xmlsoap.org/soap/envelope/ Fault,omitempty"`
}
func (b *DeployVMBody) Fault() *soap.Fault { return b.Fault_ }
func DeployVM(ctx context.Context, r soap.RoundTripper, req *types.DeployVM) (*types.DeployVMResponse, error) {
var reqBody, resBody DeployVMBody
reqBody.Req = req
if err := r.RoundTrip(ctx, &reqBody, &resBody); err != nil {
return nil, err
}
return resBody.Res, nil
}
type DeselectVnicBody struct { type DeselectVnicBody struct {
Req *types.DeselectVnic `xml:"urn:vim25 DeselectVnic,omitempty"` Req *types.DeselectVnic `xml:"urn:vim25 DeselectVnic,omitempty"`
Res *types.DeselectVnicResponse `xml:"urn:vim25 DeselectVnicResponse,omitempty"` Res *types.DeselectVnicResponse `xml:"urn:vim25 DeselectVnicResponse,omitempty"`
@ -4962,46 +4902,6 @@ func GetAlarmState(ctx context.Context, r soap.RoundTripper, req *types.GetAlarm
return resBody.Res, nil return resBody.Res, nil
} }
type GetAllVRPIdsBody struct {
Req *types.GetAllVRPIds `xml:"urn:vim25 GetAllVRPIds,omitempty"`
Res *types.GetAllVRPIdsResponse `xml:"urn:vim25 GetAllVRPIdsResponse,omitempty"`
Fault_ *soap.Fault `xml:"http://schemas.xmlsoap.org/soap/envelope/ Fault,omitempty"`
}
func (b *GetAllVRPIdsBody) Fault() *soap.Fault { return b.Fault_ }
func GetAllVRPIds(ctx context.Context, r soap.RoundTripper, req *types.GetAllVRPIds) (*types.GetAllVRPIdsResponse, error) {
var reqBody, resBody GetAllVRPIdsBody
reqBody.Req = req
if err := r.RoundTrip(ctx, &reqBody, &resBody); err != nil {
return nil, err
}
return resBody.Res, nil
}
type GetChildRPforHubBody struct {
Req *types.GetChildRPforHub `xml:"urn:vim25 GetChildRPforHub,omitempty"`
Res *types.GetChildRPforHubResponse `xml:"urn:vim25 GetChildRPforHubResponse,omitempty"`
Fault_ *soap.Fault `xml:"http://schemas.xmlsoap.org/soap/envelope/ Fault,omitempty"`
}
func (b *GetChildRPforHubBody) Fault() *soap.Fault { return b.Fault_ }
func GetChildRPforHub(ctx context.Context, r soap.RoundTripper, req *types.GetChildRPforHub) (*types.GetChildRPforHubResponse, error) {
var reqBody, resBody GetChildRPforHubBody
reqBody.Req = req
if err := r.RoundTrip(ctx, &reqBody, &resBody); err != nil {
return nil, err
}
return resBody.Res, nil
}
type GetCustomizationSpecBody struct { type GetCustomizationSpecBody struct {
Req *types.GetCustomizationSpec `xml:"urn:vim25 GetCustomizationSpec,omitempty"` Req *types.GetCustomizationSpec `xml:"urn:vim25 GetCustomizationSpec,omitempty"`
Res *types.GetCustomizationSpecResponse `xml:"urn:vim25 GetCustomizationSpecResponse,omitempty"` Res *types.GetCustomizationSpecResponse `xml:"urn:vim25 GetCustomizationSpecResponse,omitempty"`
@ -5042,26 +4942,6 @@ func GetPublicKey(ctx context.Context, r soap.RoundTripper, req *types.GetPublic
return resBody.Res, nil return resBody.Res, nil
} }
type GetRPSettingsBody struct {
Req *types.GetRPSettings `xml:"urn:vim25 GetRPSettings,omitempty"`
Res *types.GetRPSettingsResponse `xml:"urn:vim25 GetRPSettingsResponse,omitempty"`
Fault_ *soap.Fault `xml:"http://schemas.xmlsoap.org/soap/envelope/ Fault,omitempty"`
}
func (b *GetRPSettingsBody) Fault() *soap.Fault { return b.Fault_ }
func GetRPSettings(ctx context.Context, r soap.RoundTripper, req *types.GetRPSettings) (*types.GetRPSettingsResponse, error) {
var reqBody, resBody GetRPSettingsBody
reqBody.Req = req
if err := r.RoundTrip(ctx, &reqBody, &resBody); err != nil {
return nil, err
}
return resBody.Res, nil
}
type GetResourceUsageBody struct { type GetResourceUsageBody struct {
Req *types.GetResourceUsage `xml:"urn:vim25 GetResourceUsage,omitempty"` Req *types.GetResourceUsage `xml:"urn:vim25 GetResourceUsage,omitempty"`
Res *types.GetResourceUsageResponse `xml:"urn:vim25 GetResourceUsageResponse,omitempty"` Res *types.GetResourceUsageResponse `xml:"urn:vim25 GetResourceUsageResponse,omitempty"`
@ -5082,66 +4962,6 @@ func GetResourceUsage(ctx context.Context, r soap.RoundTripper, req *types.GetRe
return resBody.Res, nil return resBody.Res, nil
} }
type GetVRPSettingsBody struct {
Req *types.GetVRPSettings `xml:"urn:vim25 GetVRPSettings,omitempty"`
Res *types.GetVRPSettingsResponse `xml:"urn:vim25 GetVRPSettingsResponse,omitempty"`
Fault_ *soap.Fault `xml:"http://schemas.xmlsoap.org/soap/envelope/ Fault,omitempty"`
}
func (b *GetVRPSettingsBody) Fault() *soap.Fault { return b.Fault_ }
func GetVRPSettings(ctx context.Context, r soap.RoundTripper, req *types.GetVRPSettings) (*types.GetVRPSettingsResponse, error) {
var reqBody, resBody GetVRPSettingsBody
reqBody.Req = req
if err := r.RoundTrip(ctx, &reqBody, &resBody); err != nil {
return nil, err
}
return resBody.Res, nil
}
type GetVRPUsageBody struct {
Req *types.GetVRPUsage `xml:"urn:vim25 GetVRPUsage,omitempty"`
Res *types.GetVRPUsageResponse `xml:"urn:vim25 GetVRPUsageResponse,omitempty"`
Fault_ *soap.Fault `xml:"http://schemas.xmlsoap.org/soap/envelope/ Fault,omitempty"`
}
func (b *GetVRPUsageBody) Fault() *soap.Fault { return b.Fault_ }
func GetVRPUsage(ctx context.Context, r soap.RoundTripper, req *types.GetVRPUsage) (*types.GetVRPUsageResponse, error) {
var reqBody, resBody GetVRPUsageBody
reqBody.Req = req
if err := r.RoundTrip(ctx, &reqBody, &resBody); err != nil {
return nil, err
}
return resBody.Res, nil
}
type GetVRPofVMBody struct {
Req *types.GetVRPofVM `xml:"urn:vim25 GetVRPofVM,omitempty"`
Res *types.GetVRPofVMResponse `xml:"urn:vim25 GetVRPofVMResponse,omitempty"`
Fault_ *soap.Fault `xml:"http://schemas.xmlsoap.org/soap/envelope/ Fault,omitempty"`
}
func (b *GetVRPofVMBody) Fault() *soap.Fault { return b.Fault_ }
func GetVRPofVM(ctx context.Context, r soap.RoundTripper, req *types.GetVRPofVM) (*types.GetVRPofVMResponse, error) {
var reqBody, resBody GetVRPofVMBody
reqBody.Req = req
if err := r.RoundTrip(ctx, &reqBody, &resBody); err != nil {
return nil, err
}
return resBody.Res, nil
}
type GetVsanObjExtAttrsBody struct { type GetVsanObjExtAttrsBody struct {
Req *types.GetVsanObjExtAttrs `xml:"urn:vim25 GetVsanObjExtAttrs,omitempty"` Req *types.GetVsanObjExtAttrs `xml:"urn:vim25 GetVsanObjExtAttrs,omitempty"`
Res *types.GetVsanObjExtAttrsResponse `xml:"urn:vim25 GetVsanObjExtAttrsResponse,omitempty"` Res *types.GetVsanObjExtAttrsResponse `xml:"urn:vim25 GetVsanObjExtAttrsResponse,omitempty"`
@ -11862,26 +11682,6 @@ func SetLocale(ctx context.Context, r soap.RoundTripper, req *types.SetLocale) (
return resBody.Res, nil return resBody.Res, nil
} }
type SetManagedByVDCBody struct {
Req *types.SetManagedByVDC `xml:"urn:vim25 SetManagedByVDC,omitempty"`
Res *types.SetManagedByVDCResponse `xml:"urn:vim25 SetManagedByVDCResponse,omitempty"`
Fault_ *soap.Fault `xml:"http://schemas.xmlsoap.org/soap/envelope/ Fault,omitempty"`
}
func (b *SetManagedByVDCBody) Fault() *soap.Fault { return b.Fault_ }
func SetManagedByVDC(ctx context.Context, r soap.RoundTripper, req *types.SetManagedByVDC) (*types.SetManagedByVDCResponse, error) {
var reqBody, resBody SetManagedByVDCBody
reqBody.Req = req
if err := r.RoundTrip(ctx, &reqBody, &resBody); err != nil {
return nil, err
}
return resBody.Res, nil
}
type SetMultipathLunPolicyBody struct { type SetMultipathLunPolicyBody struct {
Req *types.SetMultipathLunPolicy `xml:"urn:vim25 SetMultipathLunPolicy,omitempty"` Req *types.SetMultipathLunPolicy `xml:"urn:vim25 SetMultipathLunPolicy,omitempty"`
Res *types.SetMultipathLunPolicyResponse `xml:"urn:vim25 SetMultipathLunPolicyResponse,omitempty"` Res *types.SetMultipathLunPolicyResponse `xml:"urn:vim25 SetMultipathLunPolicyResponse,omitempty"`
@ -12522,26 +12322,6 @@ func UnbindVnic(ctx context.Context, r soap.RoundTripper, req *types.UnbindVnic)
return resBody.Res, nil return resBody.Res, nil
} }
type UndeployVMBody struct {
Req *types.UndeployVM `xml:"urn:vim25 UndeployVM,omitempty"`
Res *types.UndeployVMResponse `xml:"urn:vim25 UndeployVMResponse,omitempty"`
Fault_ *soap.Fault `xml:"http://schemas.xmlsoap.org/soap/envelope/ Fault,omitempty"`
}
func (b *UndeployVMBody) Fault() *soap.Fault { return b.Fault_ }
func UndeployVM(ctx context.Context, r soap.RoundTripper, req *types.UndeployVM) (*types.UndeployVMResponse, error) {
var reqBody, resBody UndeployVMBody
reqBody.Req = req
if err := r.RoundTrip(ctx, &reqBody, &resBody); err != nil {
return nil, err
}
return resBody.Res, nil
}
type UninstallHostPatch_TaskBody struct { type UninstallHostPatch_TaskBody struct {
Req *types.UninstallHostPatch_Task `xml:"urn:vim25 UninstallHostPatch_Task,omitempty"` Req *types.UninstallHostPatch_Task `xml:"urn:vim25 UninstallHostPatch_Task,omitempty"`
Res *types.UninstallHostPatch_TaskResponse `xml:"urn:vim25 UninstallHostPatch_TaskResponse,omitempty"` Res *types.UninstallHostPatch_TaskResponse `xml:"urn:vim25 UninstallHostPatch_TaskResponse,omitempty"`
@ -13982,26 +13762,6 @@ func UpdateVAppConfig(ctx context.Context, r soap.RoundTripper, req *types.Updat
return resBody.Res, nil return resBody.Res, nil
} }
type UpdateVRPBody struct {
Req *types.UpdateVRP `xml:"urn:vim25 UpdateVRP,omitempty"`
Res *types.UpdateVRPResponse `xml:"urn:vim25 UpdateVRPResponse,omitempty"`
Fault_ *soap.Fault `xml:"http://schemas.xmlsoap.org/soap/envelope/ Fault,omitempty"`
}
func (b *UpdateVRPBody) Fault() *soap.Fault { return b.Fault_ }
func UpdateVRP(ctx context.Context, r soap.RoundTripper, req *types.UpdateVRP) (*types.UpdateVRPResponse, error) {
var reqBody, resBody UpdateVRPBody
reqBody.Req = req
if err := r.RoundTrip(ctx, &reqBody, &resBody); err != nil {
return nil, err
}
return resBody.Res, nil
}
type UpdateVirtualMachineFiles_TaskBody struct { type UpdateVirtualMachineFiles_TaskBody struct {
Req *types.UpdateVirtualMachineFiles_Task `xml:"urn:vim25 UpdateVirtualMachineFiles_Task,omitempty"` Req *types.UpdateVirtualMachineFiles_Task `xml:"urn:vim25 UpdateVirtualMachineFiles_Task,omitempty"`
Res *types.UpdateVirtualMachineFiles_TaskResponse `xml:"urn:vim25 UpdateVirtualMachineFiles_TaskResponse,omitempty"` Res *types.UpdateVirtualMachineFiles_TaskResponse `xml:"urn:vim25 UpdateVirtualMachineFiles_TaskResponse,omitempty"`

24
vendor/github.com/vmware/govmomi/vim25/mo/entity.go generated vendored Normal file
View File

@ -0,0 +1,24 @@
/*
Copyright (c) 2016 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 mo
// Entity is the interface that is implemented by all managed objects
// that extend ManagedEntity.
type Entity interface {
Reference
Entity() *ManagedEntity
}

View File

@ -1,5 +1,5 @@
/* /*
Copyright (c) 2014 VMware, Inc. All Rights Reserved. Copyright (c) 2014-2016 VMware, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -64,6 +64,18 @@ func init() {
t["AuthorizationManager"] = reflect.TypeOf((*AuthorizationManager)(nil)).Elem() t["AuthorizationManager"] = reflect.TypeOf((*AuthorizationManager)(nil)).Elem()
} }
type CertificateManager struct {
Self types.ManagedObjectReference
}
func (m CertificateManager) Reference() types.ManagedObjectReference {
return m.Self
}
func init() {
t["CertificateManager"] = reflect.TypeOf((*CertificateManager)(nil)).Elem()
}
type ClusterComputeResource struct { type ClusterComputeResource struct {
ComputeResource ComputeResource
@ -79,6 +91,17 @@ func init() {
t["ClusterComputeResource"] = reflect.TypeOf((*ClusterComputeResource)(nil)).Elem() t["ClusterComputeResource"] = reflect.TypeOf((*ClusterComputeResource)(nil)).Elem()
} }
type ClusterEVCManager struct {
ExtensibleManagedObject
ManagedCluster types.ManagedObjectReference `mo:"managedCluster"`
EvcState types.ClusterEVCManagerEVCState `mo:"evcState"`
}
func init() {
t["ClusterEVCManager"] = reflect.TypeOf((*ClusterEVCManager)(nil)).Elem()
}
type ClusterProfile struct { type ClusterProfile struct {
Profile Profile
} }
@ -107,6 +130,10 @@ type ComputeResource struct {
ConfigurationEx types.BaseComputeResourceConfigInfo `mo:"configurationEx"` ConfigurationEx types.BaseComputeResourceConfigInfo `mo:"configurationEx"`
} }
func (m *ComputeResource) Entity() *ManagedEntity {
return &m.ManagedEntity
}
func init() { func init() {
t["ComputeResource"] = reflect.TypeOf((*ComputeResource)(nil)).Elem() t["ComputeResource"] = reflect.TypeOf((*ComputeResource)(nil)).Elem()
} }
@ -164,6 +191,10 @@ type Datacenter struct {
Configuration types.DatacenterConfigInfo `mo:"configuration"` Configuration types.DatacenterConfigInfo `mo:"configuration"`
} }
func (m *Datacenter) Entity() *ManagedEntity {
return &m.ManagedEntity
}
func init() { func init() {
t["Datacenter"] = reflect.TypeOf((*Datacenter)(nil)).Elem() t["Datacenter"] = reflect.TypeOf((*Datacenter)(nil)).Elem()
} }
@ -180,6 +211,10 @@ type Datastore struct {
IormConfiguration *types.StorageIORMInfo `mo:"iormConfiguration"` IormConfiguration *types.StorageIORMInfo `mo:"iormConfiguration"`
} }
func (m *Datastore) Entity() *ManagedEntity {
return &m.ManagedEntity
}
func init() { func init() {
t["Datastore"] = reflect.TypeOf((*Datastore)(nil)).Elem() t["Datastore"] = reflect.TypeOf((*Datastore)(nil)).Elem()
} }
@ -232,6 +267,10 @@ type DistributedVirtualSwitch struct {
Runtime *types.DVSRuntimeInfo `mo:"runtime"` Runtime *types.DVSRuntimeInfo `mo:"runtime"`
} }
func (m *DistributedVirtualSwitch) Entity() *ManagedEntity {
return &m.ManagedEntity
}
func init() { func init() {
t["DistributedVirtualSwitch"] = reflect.TypeOf((*DistributedVirtualSwitch)(nil)).Elem() t["DistributedVirtualSwitch"] = reflect.TypeOf((*DistributedVirtualSwitch)(nil)).Elem()
} }
@ -277,7 +316,7 @@ type EventManager struct {
Description types.EventDescription `mo:"description"` Description types.EventDescription `mo:"description"`
LatestEvent types.BaseEvent `mo:"latestEvent"` LatestEvent types.BaseEvent `mo:"latestEvent"`
MaxCollector int `mo:"maxCollector"` MaxCollector int32 `mo:"maxCollector"`
} }
func (m EventManager) Reference() types.ManagedObjectReference { func (m EventManager) Reference() types.ManagedObjectReference {
@ -336,10 +375,26 @@ type Folder struct {
ChildEntity []types.ManagedObjectReference `mo:"childEntity"` ChildEntity []types.ManagedObjectReference `mo:"childEntity"`
} }
func (m *Folder) Entity() *ManagedEntity {
return &m.ManagedEntity
}
func init() { func init() {
t["Folder"] = reflect.TypeOf((*Folder)(nil)).Elem() t["Folder"] = reflect.TypeOf((*Folder)(nil)).Elem()
} }
type GuestAliasManager struct {
Self types.ManagedObjectReference
}
func (m GuestAliasManager) Reference() types.ManagedObjectReference {
return m.Self
}
func init() {
t["GuestAliasManager"] = reflect.TypeOf((*GuestAliasManager)(nil)).Elem()
}
type GuestAuthManager struct { type GuestAuthManager struct {
Self types.ManagedObjectReference Self types.ManagedObjectReference
} }
@ -367,9 +422,11 @@ func init() {
type GuestOperationsManager struct { type GuestOperationsManager struct {
Self types.ManagedObjectReference Self types.ManagedObjectReference
AuthManager *types.ManagedObjectReference `mo:"authManager"` AuthManager *types.ManagedObjectReference `mo:"authManager"`
FileManager *types.ManagedObjectReference `mo:"fileManager"` FileManager *types.ManagedObjectReference `mo:"fileManager"`
ProcessManager *types.ManagedObjectReference `mo:"processManager"` ProcessManager *types.ManagedObjectReference `mo:"processManager"`
GuestWindowsRegistryManager *types.ManagedObjectReference `mo:"guestWindowsRegistryManager"`
AliasManager *types.ManagedObjectReference `mo:"aliasManager"`
} }
func (m GuestOperationsManager) Reference() types.ManagedObjectReference { func (m GuestOperationsManager) Reference() types.ManagedObjectReference {
@ -392,6 +449,18 @@ func init() {
t["GuestProcessManager"] = reflect.TypeOf((*GuestProcessManager)(nil)).Elem() t["GuestProcessManager"] = reflect.TypeOf((*GuestProcessManager)(nil)).Elem()
} }
type GuestWindowsRegistryManager struct {
Self types.ManagedObjectReference
}
func (m GuestWindowsRegistryManager) Reference() types.ManagedObjectReference {
return m.Self
}
func init() {
t["GuestWindowsRegistryManager"] = reflect.TypeOf((*GuestWindowsRegistryManager)(nil)).Elem()
}
type HistoryCollector struct { type HistoryCollector struct {
Self types.ManagedObjectReference Self types.ManagedObjectReference
@ -406,6 +475,20 @@ func init() {
t["HistoryCollector"] = reflect.TypeOf((*HistoryCollector)(nil)).Elem() t["HistoryCollector"] = reflect.TypeOf((*HistoryCollector)(nil)).Elem()
} }
type HostAccessManager struct {
Self types.ManagedObjectReference
LockdownMode types.HostLockdownMode `mo:"lockdownMode"`
}
func (m HostAccessManager) Reference() types.ManagedObjectReference {
return m.Self
}
func init() {
t["HostAccessManager"] = reflect.TypeOf((*HostAccessManager)(nil)).Elem()
}
type HostActiveDirectoryAuthentication struct { type HostActiveDirectoryAuthentication struct {
HostDirectoryStore HostDirectoryStore
} }
@ -483,6 +566,20 @@ func init() {
t["HostCacheConfigurationManager"] = reflect.TypeOf((*HostCacheConfigurationManager)(nil)).Elem() t["HostCacheConfigurationManager"] = reflect.TypeOf((*HostCacheConfigurationManager)(nil)).Elem()
} }
type HostCertificateManager struct {
Self types.ManagedObjectReference
CertificateInfo types.HostCertificateManagerCertificateInfo `mo:"certificateInfo"`
}
func (m HostCertificateManager) Reference() types.ManagedObjectReference {
return m.Self
}
func init() {
t["HostCertificateManager"] = reflect.TypeOf((*HostCertificateManager)(nil)).Elem()
}
type HostCpuSchedulerSystem struct { type HostCpuSchedulerSystem struct {
ExtensibleManagedObject ExtensibleManagedObject
@ -598,7 +695,8 @@ func init() {
type HostGraphicsManager struct { type HostGraphicsManager struct {
ExtensibleManagedObject ExtensibleManagedObject
GraphicsInfo []types.HostGraphicsInfo `mo:"graphicsInfo"` GraphicsInfo []types.HostGraphicsInfo `mo:"graphicsInfo"`
SharedPassthruGpuTypes []string `mo:"sharedPassthruGpuTypes"`
} }
func init() { func init() {
@ -800,6 +898,10 @@ type HostSystem struct {
SystemResources *types.HostSystemResourceInfo `mo:"systemResources"` SystemResources *types.HostSystemResourceInfo `mo:"systemResources"`
} }
func (m *HostSystem) Entity() *ManagedEntity {
return &m.ManagedEntity
}
func init() { func init() {
t["HostSystem"] = reflect.TypeOf((*HostSystem)(nil)).Elem() t["HostSystem"] = reflect.TypeOf((*HostSystem)(nil)).Elem()
} }
@ -868,7 +970,7 @@ func init() {
type HttpNfcLease struct { type HttpNfcLease struct {
Self types.ManagedObjectReference Self types.ManagedObjectReference
InitializeProgress int `mo:"initializeProgress"` InitializeProgress int32 `mo:"initializeProgress"`
Info *types.HttpNfcLeaseInfo `mo:"info"` Info *types.HttpNfcLeaseInfo `mo:"info"`
State types.HttpNfcLeaseState `mo:"state"` State types.HttpNfcLeaseState `mo:"state"`
Error *types.LocalizedMethodFault `mo:"error"` Error *types.LocalizedMethodFault `mo:"error"`
@ -882,18 +984,6 @@ func init() {
t["HttpNfcLease"] = reflect.TypeOf((*HttpNfcLease)(nil)).Elem() 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 { type InventoryView struct {
ManagedObjectView ManagedObjectView
} }
@ -902,6 +992,18 @@ func init() {
t["InventoryView"] = reflect.TypeOf((*InventoryView)(nil)).Elem() t["InventoryView"] = reflect.TypeOf((*InventoryView)(nil)).Elem()
} }
type IoFilterManager struct {
Self types.ManagedObjectReference
}
func (m IoFilterManager) Reference() types.ManagedObjectReference {
return m.Self
}
func init() {
t["IoFilterManager"] = reflect.TypeOf((*IoFilterManager)(nil)).Elem()
}
type IpPoolManager struct { type IpPoolManager struct {
Self types.ManagedObjectReference Self types.ManagedObjectReference
} }
@ -989,7 +1091,7 @@ type ManagedEntity struct {
OverallStatus types.ManagedEntityStatus `mo:"overallStatus"` OverallStatus types.ManagedEntityStatus `mo:"overallStatus"`
ConfigStatus types.ManagedEntityStatus `mo:"configStatus"` ConfigStatus types.ManagedEntityStatus `mo:"configStatus"`
ConfigIssue []types.BaseEvent `mo:"configIssue"` ConfigIssue []types.BaseEvent `mo:"configIssue"`
EffectiveRole []int `mo:"effectiveRole"` EffectiveRole []int32 `mo:"effectiveRole"`
Permission []types.Permission `mo:"permission"` Permission []types.Permission `mo:"permission"`
Name string `mo:"name"` Name string `mo:"name"`
DisabledMethod []string `mo:"disabledMethod"` DisabledMethod []string `mo:"disabledMethod"`
@ -1018,6 +1120,18 @@ func init() {
t["ManagedObjectView"] = reflect.TypeOf((*ManagedObjectView)(nil)).Elem() t["ManagedObjectView"] = reflect.TypeOf((*ManagedObjectView)(nil)).Elem()
} }
type MessageBusProxy struct {
Self types.ManagedObjectReference
}
func (m MessageBusProxy) Reference() types.ManagedObjectReference {
return m.Self
}
func init() {
t["MessageBusProxy"] = reflect.TypeOf((*MessageBusProxy)(nil)).Elem()
}
type Network struct { type Network struct {
ManagedEntity ManagedEntity
@ -1027,6 +1141,10 @@ type Network struct {
Vm []types.ManagedObjectReference `mo:"vm"` Vm []types.ManagedObjectReference `mo:"vm"`
} }
func (m *Network) Entity() *ManagedEntity {
return &m.ManagedEntity
}
func init() { func init() {
t["Network"] = reflect.TypeOf((*Network)(nil)).Elem() t["Network"] = reflect.TypeOf((*Network)(nil)).Elem()
} }
@ -1054,6 +1172,18 @@ func init() {
t["OptionManager"] = reflect.TypeOf((*OptionManager)(nil)).Elem() t["OptionManager"] = reflect.TypeOf((*OptionManager)(nil)).Elem()
} }
type OverheadMemoryManager struct {
Self types.ManagedObjectReference
}
func (m OverheadMemoryManager) Reference() types.ManagedObjectReference {
return m.Self
}
func init() {
t["OverheadMemoryManager"] = reflect.TypeOf((*OverheadMemoryManager)(nil)).Elem()
}
type OvfManager struct { type OvfManager struct {
Self types.ManagedObjectReference Self types.ManagedObjectReference
@ -1160,18 +1290,6 @@ func init() {
t["PropertyFilter"] = reflect.TypeOf((*PropertyFilter)(nil)).Elem() 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 { type ResourcePlanningManager struct {
Self types.ManagedObjectReference Self types.ManagedObjectReference
} }
@ -1196,6 +1314,10 @@ type ResourcePool struct {
ChildConfiguration []types.ResourceConfigSpec `mo:"childConfiguration"` ChildConfiguration []types.ResourceConfigSpec `mo:"childConfiguration"`
} }
func (m *ResourcePool) Entity() *ManagedEntity {
return &m.ManagedEntity
}
func init() { func init() {
t["ResourcePool"] = reflect.TypeOf((*ResourcePool)(nil)).Elem() t["ResourcePool"] = reflect.TypeOf((*ResourcePool)(nil)).Elem()
} }
@ -1349,7 +1471,7 @@ type TaskManager struct {
RecentTask []types.ManagedObjectReference `mo:"recentTask"` RecentTask []types.ManagedObjectReference `mo:"recentTask"`
Description types.TaskDescription `mo:"description"` Description types.TaskDescription `mo:"description"`
MaxCollector int `mo:"maxCollector"` MaxCollector int32 `mo:"maxCollector"`
} }
func (m TaskManager) Reference() types.ManagedObjectReference { func (m TaskManager) Reference() types.ManagedObjectReference {
@ -1374,6 +1496,18 @@ func init() {
t["UserDirectory"] = reflect.TypeOf((*UserDirectory)(nil)).Elem() t["UserDirectory"] = reflect.TypeOf((*UserDirectory)(nil)).Elem()
} }
type VRPResourceManager struct {
Self types.ManagedObjectReference
}
func (m VRPResourceManager) Reference() types.ManagedObjectReference {
return m.Self
}
func init() {
t["VRPResourceManager"] = reflect.TypeOf((*VRPResourceManager)(nil)).Elem()
}
type View struct { type View struct {
Self types.ManagedObjectReference Self types.ManagedObjectReference
} }
@ -1449,6 +1583,10 @@ type VirtualMachine struct {
GuestHeartbeatStatus types.ManagedEntityStatus `mo:"guestHeartbeatStatus"` GuestHeartbeatStatus types.ManagedEntityStatus `mo:"guestHeartbeatStatus"`
} }
func (m *VirtualMachine) Entity() *ManagedEntity {
return &m.ManagedEntity
}
func init() { func init() {
t["VirtualMachine"] = reflect.TypeOf((*VirtualMachine)(nil)).Elem() t["VirtualMachine"] = reflect.TypeOf((*VirtualMachine)(nil)).Elem()
} }
@ -1482,6 +1620,7 @@ type VirtualMachineSnapshot struct {
Config types.VirtualMachineConfigInfo `mo:"config"` Config types.VirtualMachineConfigInfo `mo:"config"`
ChildSnapshot []types.ManagedObjectReference `mo:"childSnapshot"` ChildSnapshot []types.ManagedObjectReference `mo:"childSnapshot"`
Vm types.ManagedObjectReference `mo:"vm"`
} }
func init() { func init() {
@ -1507,3 +1646,15 @@ type VmwareDistributedVirtualSwitch struct {
func init() { func init() {
t["VmwareDistributedVirtualSwitch"] = reflect.TypeOf((*VmwareDistributedVirtualSwitch)(nil)).Elem() t["VmwareDistributedVirtualSwitch"] = reflect.TypeOf((*VmwareDistributedVirtualSwitch)(nil)).Elem()
} }
type VsanUpgradeSystem struct {
Self types.ManagedObjectReference
}
func (m VsanUpgradeSystem) Reference() types.ManagedObjectReference {
return m.Self
}
func init() {
t["VsanUpgradeSystem"] = reflect.TypeOf((*VsanUpgradeSystem)(nil)).Elem()
}

View File

@ -32,6 +32,9 @@ func ignoreMissingProperty(ref types.ManagedObjectReference, p types.MissingProp
case "environmentBrowser": case "environmentBrowser":
// See https://github.com/vmware/govmomi/pull/242 // See https://github.com/vmware/govmomi/pull/242
return true return true
case "alarmActionsEnabled":
// Seen with vApp child VM
return true
} }
} }

View File

@ -21,6 +21,7 @@ import (
"crypto/tls" "crypto/tls"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt"
"io" "io"
"net" "net"
"net/http" "net/http"
@ -45,6 +46,9 @@ type RoundTripper interface {
RoundTrip(ctx context.Context, req, res HasFault) error RoundTrip(ctx context.Context, req, res HasFault) error
} }
var DefaultVimNamespace = "urn:vim25"
var DefaultVimVersion = "6.0"
type Client struct { type Client struct {
http.Client http.Client
@ -53,6 +57,9 @@ type Client struct {
d *debugContainer d *debugContainer
t *http.Transport t *http.Transport
p *url.URL p *url.URL
Namespace string // Vim namespace
Version string // Vim version
} }
var schemeMatch = regexp.MustCompile(`^\w+://`) var schemeMatch = regexp.MustCompile(`^\w+://`)
@ -114,6 +121,9 @@ func NewClient(u *url.URL, insecure bool) *Client {
c.u = c.URL() c.u = c.URL()
c.u.User = nil c.u.User = nil
c.Namespace = DefaultVimNamespace
c.Version = DefaultVimVersion
return &c return &c
} }
@ -255,7 +265,8 @@ func (c *Client) RoundTrip(ctx context.Context, reqBody, resBody HasFault) error
} }
req.Header.Set(`Content-Type`, `text/xml; charset="utf-8"`) req.Header.Set(`Content-Type`, `text/xml; charset="utf-8"`)
req.Header.Set(`SOAPAction`, `urn:vim25/6.0`) soapAction := fmt.Sprintf("%s/%s", c.Namespace, c.Version)
req.Header.Set(`SOAPAction`, soapAction)
if d.enabled() { if d.enabled() {
d.debugRequest(req) d.debugRequest(req)
@ -417,23 +428,12 @@ var DefaultDownload = Download{
Method: "GET", Method: "GET",
} }
// DownloadFile GETs the given URL to a local file // Download GETs the remote file from the given URL
func (c *Client) DownloadFile(file string, u *url.URL, param *Download) error { func (c *Client) Download(u *url.URL, param *Download) (io.ReadCloser, int64, error) {
var err error
if param == nil {
param = &DefaultDownload
}
fh, err := os.Create(file)
if err != nil {
return err
}
defer fh.Close()
req, err := http.NewRequest(param.Method, u.String(), nil) req, err := http.NewRequest(param.Method, u.String(), nil)
if err != nil { if err != nil {
return err return nil, 0, err
} }
if param.Ticket != nil { if param.Ticket != nil {
@ -442,11 +442,9 @@ func (c *Client) DownloadFile(file string, u *url.URL, param *Download) error {
res, err := c.Client.Do(req) res, err := c.Client.Do(req)
if err != nil { if err != nil {
return err return nil, 0, err
} }
defer res.Body.Close()
switch res.StatusCode { switch res.StatusCode {
case http.StatusOK: case http.StatusOK:
default: default:
@ -454,12 +452,37 @@ func (c *Client) DownloadFile(file string, u *url.URL, param *Download) error {
} }
if err != nil { if err != nil {
return err return nil, 0, err
} }
var r io.Reader = res.Body var r io.ReadCloser = res.Body
return r, res.ContentLength, nil
}
// DownloadFile GETs the given URL to a local file
func (c *Client) DownloadFile(file string, u *url.URL, param *Download) error {
var err error
if param == nil {
param = &DefaultDownload
}
rc, contentLength, err := c.Download(u, param)
if err != nil {
return err
}
defer rc.Close()
var r io.Reader = rc
fh, err := os.Create(file)
if err != nil {
return err
}
defer fh.Close()
if param.Progress != nil { if param.Progress != nil {
pr := progress.NewReader(param.Progress, res.Body, res.ContentLength) pr := progress.NewReader(param.Progress, r, contentLength)
r = pr r = pr
// Mark progress reader as done when returning from this function. // Mark progress reader as done when returning from this function.

View File

@ -1,5 +1,5 @@
/* /*
Copyright (c) 2014-2015 VMware, Inc. All Rights Reserved. Copyright (c) 2014-2016 VMware, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -1033,6 +1033,7 @@ const (
HostConfigChangeOperationAdd = HostConfigChangeOperation("add") HostConfigChangeOperationAdd = HostConfigChangeOperation("add")
HostConfigChangeOperationRemove = HostConfigChangeOperation("remove") HostConfigChangeOperationRemove = HostConfigChangeOperation("remove")
HostConfigChangeOperationEdit = HostConfigChangeOperation("edit") HostConfigChangeOperationEdit = HostConfigChangeOperation("edit")
HostConfigChangeOperationIgnore = HostConfigChangeOperation("ignore")
) )
func init() { func init() {

View File

@ -19,3 +19,7 @@ package types
func NewBool(v bool) *bool { func NewBool(v bool) *bool {
return &v return &v
} }
func NewReference(r ManagedObjectReference) *ManagedObjectReference {
return &r
}

View File

@ -1,5 +1,5 @@
/* /*
Copyright (c) 2014-2015 VMware, Inc. All Rights Reserved. Copyright (c) 2014-2016 VMware, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.

File diff suppressed because it is too large Load Diff