VMware vSphere Integrated Containers provider (#206)
* Add Virtual Kubelet provider for VIC Initial virtual kubelet provider for VMware VIC. This provider currently handles creating and starting of a pod VM via the VIC portlayer and persona server. Image store handling via the VIC persona server. This provider currently requires the feature/wolfpack branch of VIC. * Added pod stop and delete. Also added node capacity. Added the ability to stop and delete pod VMs via VIC. Also retrieve node capacity information from the VCH. * Cleanup and readme file Some file clean up and added a Readme.md markdown file for the VIC provider. * Cleaned up errors, added function comments, moved operation code 1. Cleaned up error handling. Set standard for creating errors. 2. Added method prototype comments for all interface functions. 3. Moved PodCreator, PodStarter, PodStopper, and PodDeleter to a new folder. * Add mocking code and unit tests for podcache, podcreator, and podstarter Used the unit test framework used in VIC to handle assertions in the provider's unit test. Mocking code generated using OSS project mockery, which is compatible with the testify assertion framework. * Vendored packages for the VIC provider Requires feature/wolfpack branch of VIC and a few specific commit sha of projects used within VIC. * Implementation of POD Stopper and Deleter unit tests (#4) * Updated files for initial PR
This commit is contained in:
2
vendor/github.com/vmware/govmomi/.gitignore
generated
vendored
Normal file
2
vendor/github.com/vmware/govmomi/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
secrets.yml
|
||||
dist/
|
||||
57
vendor/github.com/vmware/govmomi/.goreleaser.yml
generated
vendored
Normal file
57
vendor/github.com/vmware/govmomi/.goreleaser.yml
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
---
|
||||
project_name: govc
|
||||
builds:
|
||||
- goos:
|
||||
- linux
|
||||
- darwin
|
||||
- windows
|
||||
- freebsd
|
||||
goarch:
|
||||
- amd64
|
||||
- 386
|
||||
env:
|
||||
- CGO_ENABLED=0
|
||||
main: ./govc/main.go
|
||||
binary: govc
|
||||
flags: -compiler gc
|
||||
ldflags: -X github.com/vmware/govmomi/govc/flags.GitVersion={{.Version}}
|
||||
archive:
|
||||
name_template: '{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}'
|
||||
format: tar.gz
|
||||
format_overrides:
|
||||
- goos: windows
|
||||
format: zip
|
||||
files:
|
||||
- none*
|
||||
checksum:
|
||||
name_template: '{{ .ProjectName }}_{{ .Version }}_checksums.txt'
|
||||
changelog:
|
||||
sort: asc
|
||||
filters:
|
||||
exclude:
|
||||
- '^docs:'
|
||||
- '^test:'
|
||||
- Merge pull request
|
||||
- Merge branch
|
||||
brew:
|
||||
github:
|
||||
owner: govmomi
|
||||
name: homebrew-tap
|
||||
commit_author:
|
||||
name: Alfred the Narwhal
|
||||
email: cna-alfred@vmware.com
|
||||
folder: Formula
|
||||
homepage: "https://github.com/vmware/govmomi/blob/master/govc/README.md"
|
||||
description: "govc is a vSphere CLI built on top of govmomi."
|
||||
test: |
|
||||
system "#{bin}/govc version"
|
||||
dockers:
|
||||
- image: vmware/govc
|
||||
goos: linux
|
||||
goarch: amd64
|
||||
binary: govc
|
||||
tag_templates:
|
||||
- "{{ .Tag }}"
|
||||
- "v{{ .Major }}"
|
||||
- "v{{ .Major }}.{{ .Minor }}"
|
||||
- latest
|
||||
19
vendor/github.com/vmware/govmomi/.mailmap
generated
vendored
Normal file
19
vendor/github.com/vmware/govmomi/.mailmap
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
Amit Bathla <abathla@.vmware.com> <abathla@promb-1s-dhcp216.eng.vmware.com>
|
||||
Bruce Downs <bruceadowns@gmail.com> <bdowns@vmware.com>
|
||||
Bruce Downs <bruceadowns@gmail.com> <bruce.downs@jivesoftware.com>
|
||||
Clint Greenwood <cgreenwood@vmware.com> <clint.greenwood@gmail.com>
|
||||
Cédric Blomart <cblomart@gmail.com> <cedric.blomart@minfin.fed.be>
|
||||
Cédric Blomart <cblomart@gmail.com> cedric <cblomart@gmail.com>
|
||||
David Stark <dave@davidstark.name> <david.stark@bskyb.com>
|
||||
Eric Gray <egray@vmware.com> <ericgray@users.noreply.github.com>
|
||||
Eric Yutao <eric.yutao@gmail.com> eric <eric.yutao@gmail.com>
|
||||
Henrik Hodne <henrik@travis-ci.com> <henrik@hodne.io>
|
||||
Jeremy Canady <jcanady@jackhenry.com> <jcanady@gmail.com>
|
||||
Pieter Noordhuis <pnoordhuis@vmware.com> <pcnoordhuis@gmail.com>
|
||||
Takaaki Furukawa <takaaki.frkw@gmail.com> takaaki.furukawa <takaaki.furukawa@mail.rakuten.com>
|
||||
Takaaki Furukawa <takaaki.frkw@gmail.com> tkak <takaaki.frkw@gmail.com>
|
||||
Vadim Egorov <vegorov@vmware.com> <egorovv@gmail.com>
|
||||
Anfernee Yongkun Gui <agui@vmware.com> <anfernee.gui@gmail.com>
|
||||
Anfernee Yongkun Gui <agui@vmware.com> Yongkun Anfernee Gui <agui@vmware.com>
|
||||
Zach Tucker <ztucker@vmware.com> <jzt@users.noreply.github.com>
|
||||
Zee Yang <zeey@vmware.com> <zee.yang@gmail.com>
|
||||
28
vendor/github.com/vmware/govmomi/.travis.yml
generated
vendored
Normal file
28
vendor/github.com/vmware/govmomi/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
sudo: false
|
||||
|
||||
language: go
|
||||
|
||||
go:
|
||||
- 1.8.x
|
||||
- 1.9.x
|
||||
- '1.10'
|
||||
go_import_path: github.com/vmware/govmomi
|
||||
|
||||
before_install:
|
||||
- make vendor
|
||||
|
||||
script:
|
||||
- make check test
|
||||
- GOOS=windows make install
|
||||
|
||||
after_success:
|
||||
- test -n "$TRAVIS_TAG" && docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"
|
||||
|
||||
deploy:
|
||||
- provider: script
|
||||
skip_cleanup: true
|
||||
script: curl -sL http://git.io/goreleaser | bash
|
||||
on:
|
||||
tags: true
|
||||
condition: $TRAVIS_OS_NAME = linux
|
||||
go: '1.10'
|
||||
293
vendor/github.com/vmware/govmomi/CHANGELOG.md
generated
vendored
Normal file
293
vendor/github.com/vmware/govmomi/CHANGELOG.md
generated
vendored
Normal file
@@ -0,0 +1,293 @@
|
||||
# changelog
|
||||
|
||||
### 0.17.1 (2018-03-19)
|
||||
|
||||
* vcsim: add Destroy method for Folder and Datacenter types
|
||||
|
||||
* In progress.Reader emit final report on EOF.
|
||||
|
||||
* vcsim: add EventManager.QueryEvents
|
||||
|
||||
### 0.17.0 (2018-02-28)
|
||||
|
||||
* Add HostStorageSystem.AttachScsiLun method
|
||||
|
||||
* Avoid possible panic in Datastore.Stat (#969)
|
||||
|
||||
* Destroy event history collectors (#962)
|
||||
|
||||
* Add VirtualDiskManager.CreateChildDisk method
|
||||
|
||||
### 0.16.0 (2017-11-08)
|
||||
|
||||
* Add support for SOAP request operation ID header
|
||||
|
||||
* Moved ovf helpers from govc import.ovf command to ovf and nfc packages
|
||||
|
||||
* Added guest/toolbox (client) package
|
||||
|
||||
* Added toolbox package and toolbox command
|
||||
|
||||
* Added simulator package and vcsim command
|
||||
|
||||
### 0.15.0 (2017-06-19)
|
||||
|
||||
* WaitOptions.MaxWaitSeconds is now optional
|
||||
|
||||
* Support removal of ExtraConfig entries
|
||||
|
||||
* GuestPosixFileAttributes OwnerId and GroupId fields are now pointers,
|
||||
rather than omitempty ints to allow chown with root uid:gid
|
||||
|
||||
* Updated examples/ using view package
|
||||
|
||||
* Add DatastoreFile.TailFunc method
|
||||
|
||||
* Export VirtualMachine.FindSnapshot method
|
||||
|
||||
* Add AuthorizationManager {Enable,Disable}Methods
|
||||
|
||||
* Add PBM client
|
||||
|
||||
### 0.14.0 (2017-04-08)
|
||||
|
||||
* Add view.ContainerView type and methods
|
||||
|
||||
* Add Collector.RetrieveWithFilter method
|
||||
|
||||
* Add property.Filter type
|
||||
|
||||
* Implement EthernetCardBackingInfo for OpaqueNetwork
|
||||
|
||||
* Finder: support changing object root in find mode
|
||||
|
||||
* Add VirtualDiskManager.QueryVirtualDiskInfo
|
||||
|
||||
* Add performance.Manager APIs
|
||||
|
||||
### 0.13.0 (2017-03-02)
|
||||
|
||||
* Add DatastoreFileManager API wrapper
|
||||
|
||||
* Add HostVsanInternalSystem API wrappers
|
||||
|
||||
* Add Container support to view package
|
||||
|
||||
* Finder supports Folder recursion without specifying a path
|
||||
|
||||
* Add VirtualMachine.QueryConfigTarget method
|
||||
|
||||
* Add device option to VirtualMachine.WaitForNetIP
|
||||
|
||||
* Remove _Task suffix from vapp methods
|
||||
|
||||
### 0.12.1 (2016-12-19)
|
||||
|
||||
* Add DiagnosticLog helper
|
||||
|
||||
* Add DatastorePath helper
|
||||
|
||||
### 0.12.0 (2016-12-01)
|
||||
|
||||
* Disable use of service ticket for datastore HTTP access by default
|
||||
|
||||
* Attach context to HTTP requests for cancellations
|
||||
|
||||
* Update to vim25/6.5 API
|
||||
|
||||
### 0.11.4 (2016-11-15)
|
||||
|
||||
* Add object.AuthorizationManager methods: RetrieveRolePermissions, RetrieveAllPermissions, AddRole, RemoveRole, UpdateRole
|
||||
|
||||
### 0.11.3 (2016-11-08)
|
||||
|
||||
* Allow DatastoreFile.Follow reader to drain current body after stopping
|
||||
|
||||
### 0.11.2 (2016-11-01)
|
||||
|
||||
* Avoid possible NPE in VirtualMachine.Device method
|
||||
|
||||
* Add support for OpaqueNetwork type to Finder
|
||||
|
||||
* Add HostConfigManager.AccountManager support for ESX 5.5
|
||||
|
||||
### 0.11.1 (2016-10-27)
|
||||
|
||||
* Add Finder.ResourcePoolListAll method
|
||||
|
||||
### 0.11.0 (2016-10-25)
|
||||
|
||||
* Add object.DistributedVirtualPortgroup.Reconfigure method
|
||||
|
||||
### 0.10.0 (2016-10-20)
|
||||
|
||||
* Add option to set soap.Client.UserAgent
|
||||
|
||||
* Add service ticket thumbprint validation
|
||||
|
||||
* Update use of http.DefaultTransport fields to 1.7
|
||||
|
||||
* Set default locale to en_US (override with GOVMOMI_LOCALE env var)
|
||||
|
||||
* Add object.HostCertificateInfo (types.HostCertificateManagerCertificateInfo helpers)
|
||||
|
||||
* Add object.HostCertificateManager type and HostConfigManager.CertificateManager method
|
||||
|
||||
* Add soap.Client SetRootCAs and SetDialTLS methods
|
||||
|
||||
### 0.9.0 (2016-09-09)
|
||||
|
||||
* Add object.DatastoreFile helpers for streaming and tailing datastore files
|
||||
|
||||
* Add object VirtualMachine.Unregister method
|
||||
|
||||
* Add object.ListView methods: Add, Remove, Reset
|
||||
|
||||
* Update to Go 1.7 - using stdlib's context package
|
||||
|
||||
### 0.8.0 (2016-06-30)
|
||||
|
||||
* Add session.Manager.AcquireLocalTicket
|
||||
|
||||
* Include StoragePod in Finder.FolderList
|
||||
|
||||
* Add Finder methods for finding by ManagedObjectReference: Element, ObjectReference
|
||||
|
||||
* Add mo.ManagedObjectReference methods: Reference, String, FromString
|
||||
|
||||
* Add support using SessionManagerGenericServiceTicket.HostName for Datastore HTTP access
|
||||
|
||||
### 0.7.1 (2016-06-03)
|
||||
|
||||
* Fix object.ObjectName method
|
||||
|
||||
### 0.7.0 (2016-06-02)
|
||||
|
||||
* Move InventoryPath field to object.Common
|
||||
|
||||
* Add HostDatastoreSystem.CreateLocalDatastore method
|
||||
|
||||
* Add DatastoreNamespaceManager methods: CreateDirectory, DeleteDirectory
|
||||
|
||||
* Add HostServiceSystem
|
||||
|
||||
* Add HostStorageSystem methods: MarkAsSdd, MarkAsNonSdd, MarkAsLocal, MarkAsNonLocal
|
||||
|
||||
* Add HostStorageSystem.RescanAllHba method
|
||||
|
||||
### 0.6.2 (2016-05-11)
|
||||
|
||||
* Get complete file details in Datastore.Stat
|
||||
|
||||
* SOAP decoding fixes
|
||||
|
||||
* Add VirtualMachine.RemoveAllSnapshot
|
||||
|
||||
### 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)
|
||||
|
||||
* Add object.VirtualNicManager wrapper
|
||||
|
||||
* Add object.HostVsanSystem wrapper
|
||||
|
||||
* Add object.HostSystem methods: EnterMaintenanceMode, ExitMaintenanceMode, Disconnect, Reconnect
|
||||
|
||||
* Add finder.Folder method
|
||||
|
||||
* Add object.Common.Destroy method
|
||||
|
||||
* Add object.ComputeResource.Reconfigure method
|
||||
|
||||
* Add license.AssignmentManager wrapper
|
||||
|
||||
* Add object.HostFirewallSystem wrapper
|
||||
|
||||
* Add object.DiagnosticManager wrapper
|
||||
|
||||
* Add LoginExtensionByCertificate support
|
||||
|
||||
* Add object.ExtensionManager
|
||||
|
||||
...
|
||||
|
||||
### 0.2.0 (2015-09-15)
|
||||
|
||||
* Update to vim25/6.0 API
|
||||
|
||||
* Stop returning children from `ManagedObjectList`
|
||||
|
||||
Change the `ManagedObjectList` function in the `find` package to only
|
||||
return the managed objects specified by the path argument and not their
|
||||
children. The original behavior was used by govc's `ls` command and is
|
||||
now available in the newly added function `ManagedObjectListChildren`.
|
||||
|
||||
* Add retry functionality to vim25 package
|
||||
|
||||
* Change finder functions to no longer take varargs
|
||||
|
||||
The `find` package had functions to return a list of objects, given a
|
||||
variable number of patterns. This makes it impossible to distinguish which
|
||||
patterns produced results and which ones didn't.
|
||||
|
||||
In particular for govc, where multiple arguments can be passed from the
|
||||
command line, it is useful to let the user know which ones produce results
|
||||
and which ones don't.
|
||||
|
||||
To evaluate multiple patterns, the user should call the find functions
|
||||
multiple times (either serially or in parallel).
|
||||
|
||||
* Make optional boolean fields pointers (`vim25/types`).
|
||||
|
||||
False is the zero value of a boolean field, which means they are not serialized
|
||||
if the field is marked "omitempty". If the field is a pointer instead, the zero
|
||||
value will be the nil pointer, and both true and false values are serialized.
|
||||
|
||||
### 0.1.0 (2015-03-17)
|
||||
|
||||
Prior to this version the API of this library was in flux.
|
||||
|
||||
Notable changes w.r.t. the state of this library before March 2015 are:
|
||||
|
||||
* All functions that may execute a request take a `context.Context` parameter.
|
||||
* The `vim25` package contains a minimal client implementation.
|
||||
* The property collector and its convenience functions live in the `property` package.
|
||||
101
vendor/github.com/vmware/govmomi/CONTRIBUTING.md
generated
vendored
Normal file
101
vendor/github.com/vmware/govmomi/CONTRIBUTING.md
generated
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
# 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
|
||||
go get github.com/vmware/govmomi
|
||||
cd $GOPATH/src/github.com/vmware/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
|
||||
```
|
||||
|
||||
## Installing from source
|
||||
|
||||
Compile the govmomi libraries and install govc using:
|
||||
|
||||
``` shell
|
||||
go install -v github.com/vmware/govmomi/govc
|
||||
```
|
||||
|
||||
Note that **govc/build.sh** is only used for building release binaries.
|
||||
|
||||
## 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).
|
||||
- Update CHANGELOG.md and/or govc/CHANGELOG.md when appropriate.
|
||||
- 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.
|
||||
77
vendor/github.com/vmware/govmomi/CONTRIBUTORS
generated
vendored
Normal file
77
vendor/github.com/vmware/govmomi/CONTRIBUTORS
generated
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
# People who can (and typically have) contributed to this repository.
|
||||
#
|
||||
# This script is generated by contributors.sh
|
||||
#
|
||||
|
||||
Abhijeet Kasurde <akasurde@redhat.com>
|
||||
abrarshivani <abrarshivani@users.noreply.github.com>
|
||||
Adam Shannon <adamkshannon@gmail.com>
|
||||
Alessandro Cortiana <alessandro.cortiana@gmail.com>
|
||||
Alex Bozhenko <alexbozhenko@fb.com>
|
||||
Alvaro Miranda <kikitux@gmail.com>
|
||||
Amanda H. L. de Andrade <amanda.andrade@serpro.gov.br>
|
||||
Amit Bathla <abathla@.vmware.com>
|
||||
amit bezalel <amit.bezalel@hpe.com>
|
||||
Andrew Chin <andrew@andrewtchin.com>
|
||||
Anfernee Yongkun Gui <agui@vmware.com>
|
||||
aniketGslab <aniket.shinde@gslab.com>
|
||||
Arran Walker <arran.walker@zopa.com>
|
||||
Aryeh Weinreb <aryehweinreb@gmail.com>
|
||||
Austin Parker <aparker@apprenda.com>
|
||||
Balu Dontu <bdontu@vmware.com>
|
||||
bastienbc <bastien.barbe.creuly@gmail.com>
|
||||
Bob Killen <killen.bob@gmail.com>
|
||||
Brad Fitzpatrick <bradfitz@golang.org>
|
||||
Bruce Downs <bruceadowns@gmail.com>
|
||||
Chris Marchesi <chrism@vancluevertech.com>
|
||||
Christian Höltje <docwhat@gerf.org>
|
||||
Clint Greenwood <cgreenwood@vmware.com>
|
||||
Cédric Blomart <cblomart@gmail.com>
|
||||
Danny Lockard <danny.lockard@banno.com>
|
||||
Dave Tucker <dave@dtucker.co.uk>
|
||||
David Stark <dave@davidstark.name>
|
||||
Davide Agnello <dagnello@hp.com>
|
||||
Doug MacEachern <dougm@vmware.com>
|
||||
Eloy Coto <eloy.coto@gmail.com>
|
||||
Eric Gray <egray@vmware.com>
|
||||
Eric Yutao <eric.yutao@gmail.com>
|
||||
Erik Hollensbe <github@hollensbe.org>
|
||||
Fabio Rapposelli <fabio@vmware.com>
|
||||
Faiyaz Ahmed <ahmedf@vmware.com>
|
||||
forkbomber <forkbomber@users.noreply.github.com>
|
||||
Gavin Gray <gavin@infinio.com>
|
||||
Gavrie Philipson <gavrie.philipson@elastifile.com>
|
||||
George Hicken <ghicken@vmware.com>
|
||||
Gerrit Renker <Gerrit.Renker@ctl.io>
|
||||
gthombare <gthombare@vmware.com>
|
||||
Hasan Mahmood <mahmoodh@vmware.com>
|
||||
Henrik Hodne <henrik@travis-ci.com>
|
||||
Isaac Rodman <isaac@eyz.us>
|
||||
Ivan Porto Carrero <icarrero@vmware.com>
|
||||
Jason Kincl <jkincl@gmail.com>
|
||||
Jeremy Canady <jcanady@jackhenry.com>
|
||||
jeremy-clerc <jeremy@clerc.io>
|
||||
João Pereira <joaodrp@gmail.com>
|
||||
Louie Jiang <jiangl@vmware.com>
|
||||
Marc Carmier <mcarmier@gmail.com>
|
||||
Matthew Cosgrove <matthew.cosgrove@dell.com>
|
||||
Mevan Samaratunga <mevansam@gmail.com>
|
||||
Nicolas Lamirault <nicolas.lamirault@gmail.com>
|
||||
Parham Alvani <parham.alvani@gmail.com>
|
||||
Pieter Noordhuis <pnoordhuis@vmware.com>
|
||||
runner.mei <runner.mei@gmail.com>
|
||||
S.Çağlar Onur <conur@vmware.com>
|
||||
Sergey Ignatov <sergey.ignatov@jetbrains.com>
|
||||
Steve Purcell <steve@sanityinc.com>
|
||||
Takaaki Furukawa <takaaki.frkw@gmail.com>
|
||||
tanishi <tanishi503@gmail.com>
|
||||
Ted Zlatanov <tzz@lifelogs.com>
|
||||
Thibaut Ackermann <thibaut.ackermann@alcatel-lucent.com>
|
||||
Trevor Dawe <trevor.dawe@gmail.com>
|
||||
Vadim Egorov <vegorov@vmware.com>
|
||||
Volodymyr Bobyr <pupsua@gmail.com>
|
||||
Witold Krecicki <wpk@culm.net>
|
||||
Yang Yang <yangy@vmware.com>
|
||||
Yuya Kusakabe <yuya.kusakabe@gmail.com>
|
||||
Zach Tucker <ztucker@vmware.com>
|
||||
Zee Yang <zeey@vmware.com>
|
||||
4
vendor/github.com/vmware/govmomi/Dockerfile
generated
vendored
Normal file
4
vendor/github.com/vmware/govmomi/Dockerfile
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
FROM scratch
|
||||
LABEL maintainer="fabio@vmware.com"
|
||||
COPY govc /
|
||||
ENTRYPOINT [ "/govc" ]
|
||||
202
vendor/github.com/vmware/govmomi/LICENSE.txt
generated
vendored
Normal file
202
vendor/github.com/vmware/govmomi/LICENSE.txt
generated
vendored
Normal file
@@ -0,0 +1,202 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
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.
|
||||
29
vendor/github.com/vmware/govmomi/Makefile
generated
vendored
Normal file
29
vendor/github.com/vmware/govmomi/Makefile
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
.PHONY: test
|
||||
|
||||
all: check test
|
||||
|
||||
check: goimports govet
|
||||
|
||||
goimports:
|
||||
@echo checking go imports...
|
||||
@go get golang.org/x/tools/cmd/goimports
|
||||
@! goimports -d . 2>&1 | egrep -v '^$$'
|
||||
|
||||
govet:
|
||||
@echo checking go vet...
|
||||
@go tool vet -structtags=false -methods=false $$(find . -mindepth 1 -maxdepth 1 -type d -not -name vendor)
|
||||
|
||||
install:
|
||||
go install -v github.com/vmware/govmomi/govc
|
||||
go install -v github.com/vmware/govmomi/vcsim
|
||||
|
||||
go-test:
|
||||
go test -race -v $(TEST_OPTS) ./...
|
||||
|
||||
govc-test: install
|
||||
(cd govc/test && ./vendor/github.com/sstephenson/bats/libexec/bats -t .)
|
||||
|
||||
test: go-test govc-test
|
||||
|
||||
doc: install
|
||||
./govc/usage.sh > ./govc/USAGE.md
|
||||
86
vendor/github.com/vmware/govmomi/README.md
generated
vendored
Normal file
86
vendor/github.com/vmware/govmomi/README.md
generated
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
[](https://travis-ci.org/vmware/govmomi)
|
||||
[](https://goreportcard.com/report/github.com/vmware/govmomi)
|
||||
|
||||
# govmomi
|
||||
|
||||
A Go library for interacting with VMware vSphere APIs (ESXi and/or vCenter).
|
||||
|
||||
In addition to the vSphere API client, this repository includes:
|
||||
|
||||
* [govc](./govc) - vSphere CLI
|
||||
|
||||
* [vcsim](./vcsim) - vSphere API mock framework
|
||||
|
||||
* [toolbox](./toolbox) - VM guest tools framework
|
||||
|
||||
## Compatibility
|
||||
|
||||
This library is built for and tested against ESXi and vCenter 6.0 and 6.5.
|
||||
|
||||
It should work with versions 5.5 and 5.1, but neither are officially supported.
|
||||
|
||||
## Documentation
|
||||
|
||||
The APIs exposed by this library very closely follow the API described in the [VMware vSphere API Reference Documentation][apiref].
|
||||
Refer to this document to become familiar with the upstream API.
|
||||
|
||||
The code in the `govmomi` package is a wrapper for the code that is generated from the vSphere API description.
|
||||
It primarily provides convenience functions for working with the vSphere API.
|
||||
See [godoc.org][godoc] for documentation.
|
||||
|
||||
[apiref]:http://pubs.vmware.com/vsphere-6-5/index.jsp#com.vmware.wssdk.apiref.doc/right-pane.html
|
||||
[godoc]:http://godoc.org/github.com/vmware/govmomi
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
go get -u github.com/vmware/govmomi
|
||||
```
|
||||
|
||||
## Discussion
|
||||
|
||||
Contributors and users are encouraged to collaborate using GitHub issues and/or
|
||||
[Slack](https://vmwarecode.slack.com/messages/govmomi).
|
||||
Access to Slack requires a [VMware {code} membership](https://code.vmware.com/join/).
|
||||
|
||||
## Status
|
||||
|
||||
Changes to the API are subject to [semantic versioning](http://semver.org).
|
||||
|
||||
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)
|
||||
|
||||
* [Docker InfraKit](https://github.com/docker/infrakit/tree/master/pkg/provider/vsphere)
|
||||
|
||||
* [Docker LinuxKit](https://github.com/linuxkit/linuxkit/tree/master/src/cmd/linuxkit)
|
||||
|
||||
* [Kubernetes](https://github.com/kubernetes/kubernetes/tree/master/pkg/cloudprovider/providers/vsphere)
|
||||
|
||||
* [Kubernetes kops](https://github.com/kubernetes/kops/tree/master/upup/pkg/fi/cloudup/vsphere)
|
||||
|
||||
* [Terraform](https://github.com/terraform-providers/terraform-provider-vsphere)
|
||||
|
||||
* [Packer](https://github.com/jetbrains-infra/packer-builder-vsphere)
|
||||
|
||||
* [VMware VIC Engine](https://github.com/vmware/vic)
|
||||
|
||||
* [Travis CI](https://github.com/travis-ci/jupiter-brain)
|
||||
|
||||
* [collectd-vsphere](https://github.com/travis-ci/collectd-vsphere)
|
||||
|
||||
* [Gru](https://github.com/dnaeon/gru)
|
||||
|
||||
* [Libretto](https://github.com/apcera/libretto/tree/master/virtualmachine/vsphere)
|
||||
|
||||
## Related projects
|
||||
|
||||
* [rbvmomi](https://github.com/vmware/rbvmomi)
|
||||
|
||||
* [pyvmomi](https://github.com/vmware/pyvmomi)
|
||||
|
||||
## License
|
||||
|
||||
govmomi is available under the [Apache 2 license](LICENSE).
|
||||
167
vendor/github.com/vmware/govmomi/client.go
generated
vendored
Normal file
167
vendor/github.com/vmware/govmomi/client.go
generated
vendored
Normal file
@@ -0,0 +1,167 @@
|
||||
/*
|
||||
Copyright (c) 2014-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.
|
||||
*/
|
||||
|
||||
/*
|
||||
This package is the root package of the govmomi library.
|
||||
|
||||
The library is structured as follows:
|
||||
|
||||
Package vim25
|
||||
|
||||
The minimal usable functionality is available through the vim25 package.
|
||||
It contains subpackages that contain generated types, managed objects, and all
|
||||
available methods. The vim25 package is entirely independent of the other
|
||||
packages in the govmomi tree -- it has no dependencies on its peers.
|
||||
|
||||
The vim25 package itself contains a client structure that is
|
||||
passed around throughout the entire library. It abstracts a session and its
|
||||
immutable state. See the vim25 package for more information.
|
||||
|
||||
Package session
|
||||
|
||||
The session package contains an abstraction for the session manager that allows
|
||||
a user to login and logout. It also provides access to the current session
|
||||
(i.e. to determine if the user is in fact logged in)
|
||||
|
||||
Package object
|
||||
|
||||
The object package contains wrappers for a selection of managed objects. The
|
||||
constructors of these objects all take a *vim25.Client, which they pass along
|
||||
to derived objects, if applicable.
|
||||
|
||||
Package govc
|
||||
|
||||
The govc package contains the govc CLI. The code in this tree is not intended
|
||||
to be used as a library. Any functionality that govc contains that _could_ be
|
||||
used as a library function but isn't, _should_ live in a root level package.
|
||||
|
||||
Other packages
|
||||
|
||||
Other packages, such as "event", "guest", or "license", provide wrappers for
|
||||
the respective subsystems. They are typically not needed in normal workflows so
|
||||
are kept outside the object package.
|
||||
*/
|
||||
package govmomi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"net/url"
|
||||
|
||||
"github.com/vmware/govmomi/property"
|
||||
"github.com/vmware/govmomi/session"
|
||||
"github.com/vmware/govmomi/vim25"
|
||||
"github.com/vmware/govmomi/vim25/soap"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
*vim25.Client
|
||||
|
||||
SessionManager *session.Manager
|
||||
}
|
||||
|
||||
// NewClient creates a new client from a URL. The client authenticates with the
|
||||
// server with username/password before returning if the URL contains user information.
|
||||
func NewClient(ctx context.Context, u *url.URL, insecure bool) (*Client, error) {
|
||||
soapClient := soap.NewClient(u, insecure)
|
||||
vimClient, err := vim25.NewClient(ctx, soapClient)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
c := &Client{
|
||||
Client: vimClient,
|
||||
SessionManager: session.NewManager(vimClient),
|
||||
}
|
||||
|
||||
// Only login if the URL contains user information.
|
||||
if u.User != nil {
|
||||
err = c.Login(ctx, u.User)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return c, nil
|
||||
}
|
||||
|
||||
// NewClientWithCertificate creates a new client from a URL. The client authenticates with the
|
||||
// server with the certificate before returning if the URL contains user information.
|
||||
func NewClientWithCertificate(ctx context.Context, u *url.URL, insecure bool, cert tls.Certificate) (*Client, error) {
|
||||
soapClient := soap.NewClient(u, insecure)
|
||||
soapClient.SetCertificate(cert)
|
||||
vimClient, err := vim25.NewClient(ctx, soapClient)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
c := &Client{
|
||||
Client: vimClient,
|
||||
SessionManager: session.NewManager(vimClient),
|
||||
}
|
||||
|
||||
if u.User != nil {
|
||||
err = c.LoginExtensionByCertificate(ctx, u.User.Username(), "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return c, nil
|
||||
}
|
||||
|
||||
// Login dispatches to the SessionManager.
|
||||
func (c *Client) Login(ctx context.Context, u *url.Userinfo) error {
|
||||
return c.SessionManager.Login(ctx, u)
|
||||
}
|
||||
|
||||
// Login dispatches to the SessionManager.
|
||||
func (c *Client) LoginExtensionByCertificate(ctx context.Context, key string, locale string) error {
|
||||
return c.SessionManager.LoginExtensionByCertificate(ctx, key, locale)
|
||||
}
|
||||
|
||||
// Logout dispatches to the SessionManager.
|
||||
func (c *Client) Logout(ctx context.Context) error {
|
||||
// Close any idle connections after logging out.
|
||||
defer c.Client.CloseIdleConnections()
|
||||
return c.SessionManager.Logout(ctx)
|
||||
}
|
||||
|
||||
// PropertyCollector returns the session's default property collector.
|
||||
func (c *Client) PropertyCollector() *property.Collector {
|
||||
return property.DefaultCollector(c.Client)
|
||||
}
|
||||
|
||||
// RetrieveOne dispatches to the Retrieve function on the default property collector.
|
||||
func (c *Client) RetrieveOne(ctx context.Context, obj types.ManagedObjectReference, p []string, dst interface{}) error {
|
||||
return c.PropertyCollector().RetrieveOne(ctx, obj, p, dst)
|
||||
}
|
||||
|
||||
// Retrieve dispatches to the Retrieve function on the default property collector.
|
||||
func (c *Client) Retrieve(ctx context.Context, objs []types.ManagedObjectReference, p []string, dst interface{}) error {
|
||||
return c.PropertyCollector().Retrieve(ctx, objs, p, dst)
|
||||
}
|
||||
|
||||
// Wait dispatches to property.Wait.
|
||||
func (c *Client) Wait(ctx context.Context, obj types.ManagedObjectReference, ps []string, f func([]types.PropertyChange) bool) error {
|
||||
return property.Wait(ctx, c.PropertyCollector(), obj, ps, f)
|
||||
}
|
||||
|
||||
// IsVC returns true if we are connected to a vCenter
|
||||
func (c *Client) IsVC() bool {
|
||||
return c.Client.IsVC()
|
||||
}
|
||||
138
vendor/github.com/vmware/govmomi/client_test.go
generated
vendored
Normal file
138
vendor/github.com/vmware/govmomi/client_test.go
generated
vendored
Normal file
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
Copyright (c) 2014-2015 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package govmomi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"testing"
|
||||
|
||||
"github.com/vmware/govmomi/test"
|
||||
"github.com/vmware/govmomi/vim25/mo"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
func TestNewClient(t *testing.T) {
|
||||
u := test.URL()
|
||||
if u == nil {
|
||||
t.SkipNow()
|
||||
}
|
||||
|
||||
c, err := NewClient(context.Background(), u, true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
f := func() error {
|
||||
var x mo.Folder
|
||||
err = mo.RetrieveProperties(context.Background(), c, c.ServiceContent.PropertyCollector, c.ServiceContent.RootFolder, &x)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(x.Name) == 0 {
|
||||
return errors.New("empty response")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// check cookie is valid with an sdk request
|
||||
if err := f(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// check cookie is valid with a non-sdk request
|
||||
u.User = nil // turn off Basic auth
|
||||
u.Path = "/folder"
|
||||
r, err := c.Client.Get(u.String())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if r.StatusCode != http.StatusOK {
|
||||
t.Fatal(r)
|
||||
}
|
||||
|
||||
// sdk request should fail w/o a valid cookie
|
||||
c.Client.Jar = nil
|
||||
if err := f(); err == nil {
|
||||
t.Fatal("should fail")
|
||||
}
|
||||
|
||||
// invalid login
|
||||
u.Path = "/sdk"
|
||||
u.User = url.UserPassword("ENOENT", "EINVAL")
|
||||
_, err = NewClient(context.Background(), u, true)
|
||||
if err == nil {
|
||||
t.Fatal("should fail")
|
||||
}
|
||||
}
|
||||
|
||||
func TestInvalidSdk(t *testing.T) {
|
||||
u := test.URL()
|
||||
if u == nil {
|
||||
t.SkipNow()
|
||||
}
|
||||
|
||||
// a URL other than a valid /sdk should error, not panic
|
||||
u.Path = "/mob"
|
||||
_, err := NewClient(context.Background(), u, true)
|
||||
if err == nil {
|
||||
t.Fatal("should fail")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPropertiesN(t *testing.T) {
|
||||
u := test.URL()
|
||||
if u == nil {
|
||||
t.SkipNow()
|
||||
}
|
||||
|
||||
c, err := NewClient(context.Background(), u, true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
var f mo.Folder
|
||||
err = c.RetrieveOne(context.Background(), c.ServiceContent.RootFolder, nil, &f)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
var dc mo.Datacenter
|
||||
err = c.RetrieveOne(context.Background(), f.ChildEntity[0], nil, &dc)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
var folderReferences = []types.ManagedObjectReference{
|
||||
dc.DatastoreFolder,
|
||||
dc.HostFolder,
|
||||
dc.NetworkFolder,
|
||||
dc.VmFolder,
|
||||
}
|
||||
|
||||
var folders []mo.Folder
|
||||
err = c.Retrieve(context.Background(), folderReferences, []string{"name"}, &folders)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if len(folders) != len(folderReferences) {
|
||||
t.Fatalf("Expected %d, got %d", len(folderReferences), len(folders))
|
||||
}
|
||||
}
|
||||
76
vendor/github.com/vmware/govmomi/event/history_collector.go
generated
vendored
Normal file
76
vendor/github.com/vmware/govmomi/event/history_collector.go
generated
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
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 event
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/vmware/govmomi/object"
|
||||
"github.com/vmware/govmomi/vim25"
|
||||
"github.com/vmware/govmomi/vim25/methods"
|
||||
"github.com/vmware/govmomi/vim25/mo"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
type HistoryCollector struct {
|
||||
*object.HistoryCollector
|
||||
}
|
||||
|
||||
func NewHistoryCollector(c *vim25.Client, ref types.ManagedObjectReference) *HistoryCollector {
|
||||
return &HistoryCollector{
|
||||
HistoryCollector: object.NewHistoryCollector(c, ref),
|
||||
}
|
||||
}
|
||||
|
||||
func (h HistoryCollector) LatestPage(ctx context.Context) ([]types.BaseEvent, error) {
|
||||
var o mo.EventHistoryCollector
|
||||
|
||||
err := h.Properties(ctx, h.Reference(), []string{"latestPage"}, &o)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return o.LatestPage, nil
|
||||
}
|
||||
|
||||
func (h HistoryCollector) ReadNextEvents(ctx context.Context, maxCount int32) ([]types.BaseEvent, error) {
|
||||
req := types.ReadNextEvents{
|
||||
This: h.Reference(),
|
||||
MaxCount: maxCount,
|
||||
}
|
||||
|
||||
res, err := methods.ReadNextEvents(ctx, h.Client(), &req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return res.Returnval, nil
|
||||
}
|
||||
|
||||
func (h HistoryCollector) ReadPreviousEvents(ctx context.Context, maxCount int32) ([]types.BaseEvent, error) {
|
||||
req := types.ReadPreviousEvents{
|
||||
This: h.Reference(),
|
||||
MaxCount: maxCount,
|
||||
}
|
||||
|
||||
res, err := methods.ReadPreviousEvents(ctx, h.Client(), &req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return res.Returnval, nil
|
||||
}
|
||||
186
vendor/github.com/vmware/govmomi/event/manager.go
generated
vendored
Normal file
186
vendor/github.com/vmware/govmomi/event/manager.go
generated
vendored
Normal file
@@ -0,0 +1,186 @@
|
||||
/*
|
||||
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 event
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"sync"
|
||||
|
||||
"github.com/vmware/govmomi/object"
|
||||
"github.com/vmware/govmomi/property"
|
||||
"github.com/vmware/govmomi/vim25"
|
||||
"github.com/vmware/govmomi/vim25/methods"
|
||||
"github.com/vmware/govmomi/vim25/mo"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
type Manager struct {
|
||||
object.Common
|
||||
|
||||
eventCategory map[string]string
|
||||
eventCategoryMu *sync.Mutex
|
||||
maxObjects int
|
||||
}
|
||||
|
||||
func NewManager(c *vim25.Client) *Manager {
|
||||
m := Manager{
|
||||
Common: object.NewCommon(c, *c.ServiceContent.EventManager),
|
||||
|
||||
eventCategory: make(map[string]string),
|
||||
eventCategoryMu: new(sync.Mutex),
|
||||
maxObjects: 10,
|
||||
}
|
||||
|
||||
return &m
|
||||
}
|
||||
|
||||
func (m Manager) CreateCollectorForEvents(ctx context.Context, filter types.EventFilterSpec) (*HistoryCollector, error) {
|
||||
req := types.CreateCollectorForEvents{
|
||||
This: m.Common.Reference(),
|
||||
Filter: filter,
|
||||
}
|
||||
|
||||
res, err := methods.CreateCollectorForEvents(ctx, m.Client(), &req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return NewHistoryCollector(m.Client(), res.Returnval), nil
|
||||
}
|
||||
|
||||
func (m Manager) LogUserEvent(ctx context.Context, entity types.ManagedObjectReference, msg string) error {
|
||||
req := types.LogUserEvent{
|
||||
This: m.Common.Reference(),
|
||||
Entity: entity,
|
||||
Msg: msg,
|
||||
}
|
||||
|
||||
_, err := methods.LogUserEvent(ctx, m.Client(), &req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m Manager) PostEvent(ctx context.Context, eventToPost types.BaseEvent, taskInfo types.TaskInfo) error {
|
||||
req := types.PostEvent{
|
||||
This: m.Common.Reference(),
|
||||
EventToPost: eventToPost,
|
||||
TaskInfo: &taskInfo,
|
||||
}
|
||||
|
||||
_, err := methods.PostEvent(ctx, m.Client(), &req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m Manager) QueryEvents(ctx context.Context, filter types.EventFilterSpec) ([]types.BaseEvent, error) {
|
||||
req := types.QueryEvents{
|
||||
This: m.Common.Reference(),
|
||||
Filter: filter,
|
||||
}
|
||||
|
||||
res, err := methods.QueryEvents(ctx, m.Client(), &req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return res.Returnval, nil
|
||||
}
|
||||
|
||||
func (m Manager) RetrieveArgumentDescription(ctx context.Context, eventTypeID string) ([]types.EventArgDesc, error) {
|
||||
req := types.RetrieveArgumentDescription{
|
||||
This: m.Common.Reference(),
|
||||
EventTypeId: eventTypeID,
|
||||
}
|
||||
|
||||
res, err := methods.RetrieveArgumentDescription(ctx, m.Client(), &req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return res.Returnval, nil
|
||||
}
|
||||
|
||||
func (m Manager) eventCategoryMap(ctx context.Context) (map[string]string, error) {
|
||||
m.eventCategoryMu.Lock()
|
||||
defer m.eventCategoryMu.Unlock()
|
||||
|
||||
if len(m.eventCategory) != 0 {
|
||||
return m.eventCategory, nil
|
||||
}
|
||||
|
||||
var o mo.EventManager
|
||||
|
||||
ps := []string{"description.eventInfo"}
|
||||
err := property.DefaultCollector(m.Client()).RetrieveOne(ctx, m.Common.Reference(), ps, &o)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, info := range o.Description.EventInfo {
|
||||
m.eventCategory[info.Key] = info.Category
|
||||
}
|
||||
|
||||
return m.eventCategory, nil
|
||||
}
|
||||
|
||||
// EventCategory returns the category for an event, such as "info" or "error" for example.
|
||||
func (m Manager) EventCategory(ctx context.Context, event types.BaseEvent) (string, error) {
|
||||
// Most of the event details are included in the Event.FullFormattedMessage, but the category
|
||||
// is only available via the EventManager description.eventInfo property. The value of this
|
||||
// property is static, so we fetch and once and cache.
|
||||
eventCategory, err := m.eventCategoryMap(ctx)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
switch e := event.(type) {
|
||||
case *types.EventEx:
|
||||
if e.Severity == "" {
|
||||
return "info", nil
|
||||
}
|
||||
return e.Severity, nil
|
||||
}
|
||||
|
||||
class := reflect.TypeOf(event).Elem().Name()
|
||||
|
||||
return eventCategory[class], nil
|
||||
}
|
||||
|
||||
// Get the events from the specified object(s) and optionanlly tail the event stream
|
||||
func (m Manager) Events(ctx context.Context, objects []types.ManagedObjectReference, pageSize int32, tail bool, force bool, f func(types.ManagedObjectReference, []types.BaseEvent) error, kind ...string) error {
|
||||
// TODO: deprecated this method and add one that uses a single config struct, so we can extend further without breaking the method signature.
|
||||
if len(objects) >= m.maxObjects && !force {
|
||||
return fmt.Errorf("Maximum number of objects to monitor (%d) exceeded, refine search", m.maxObjects)
|
||||
}
|
||||
|
||||
proc := newEventProcessor(m, pageSize, f, kind)
|
||||
for _, o := range objects {
|
||||
proc.addObject(ctx, o)
|
||||
}
|
||||
|
||||
defer proc.destroy()
|
||||
|
||||
return proc.run(ctx, tail)
|
||||
}
|
||||
192
vendor/github.com/vmware/govmomi/event/processor.go
generated
vendored
Normal file
192
vendor/github.com/vmware/govmomi/event/processor.go
generated
vendored
Normal file
@@ -0,0 +1,192 @@
|
||||
/*
|
||||
Copyright (c) 2016-2017 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package event
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/vmware/govmomi/property"
|
||||
"github.com/vmware/govmomi/view"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
type tailInfo struct {
|
||||
t *eventTailer
|
||||
obj types.ManagedObjectReference
|
||||
collector *HistoryCollector
|
||||
}
|
||||
|
||||
type eventProcessor struct {
|
||||
mgr Manager
|
||||
pageSize int32
|
||||
kind []string
|
||||
tailers map[types.ManagedObjectReference]*tailInfo // tailers by collector ref
|
||||
callback func(types.ManagedObjectReference, []types.BaseEvent) error
|
||||
}
|
||||
|
||||
func newEventProcessor(mgr Manager, pageSize int32, callback func(types.ManagedObjectReference, []types.BaseEvent) error, kind []string) *eventProcessor {
|
||||
return &eventProcessor{
|
||||
mgr: mgr,
|
||||
tailers: make(map[types.ManagedObjectReference]*tailInfo),
|
||||
callback: callback,
|
||||
pageSize: pageSize,
|
||||
kind: kind,
|
||||
}
|
||||
}
|
||||
|
||||
func (p *eventProcessor) addObject(ctx context.Context, obj types.ManagedObjectReference) error {
|
||||
filter := types.EventFilterSpec{
|
||||
Entity: &types.EventFilterSpecByEntity{
|
||||
Entity: obj,
|
||||
Recursion: types.EventFilterSpecRecursionOptionAll,
|
||||
},
|
||||
EventTypeId: p.kind,
|
||||
}
|
||||
|
||||
collector, err := p.mgr.CreateCollectorForEvents(ctx, filter)
|
||||
if err != nil {
|
||||
return fmt.Errorf("[%#v] %s", obj, err)
|
||||
}
|
||||
|
||||
err = collector.SetPageSize(ctx, p.pageSize)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
p.tailers[collector.Reference()] = &tailInfo{
|
||||
t: newEventTailer(),
|
||||
obj: obj,
|
||||
collector: collector,
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *eventProcessor) destroy() {
|
||||
for _, info := range p.tailers {
|
||||
_ = info.collector.Destroy(context.Background())
|
||||
}
|
||||
}
|
||||
|
||||
func (p *eventProcessor) run(ctx context.Context, tail bool) error {
|
||||
if len(p.tailers) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var collectors []types.ManagedObjectReference
|
||||
for ref := range p.tailers {
|
||||
collectors = append(collectors, ref)
|
||||
}
|
||||
|
||||
c := property.DefaultCollector(p.mgr.Client())
|
||||
props := []string{"latestPage"}
|
||||
|
||||
if len(collectors) == 1 {
|
||||
// only one object to follow, don't bother creating a view
|
||||
return property.Wait(ctx, c, collectors[0], props, func(pc []types.PropertyChange) bool {
|
||||
if err := p.process(collectors[0], pc); err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return !tail
|
||||
})
|
||||
}
|
||||
|
||||
// create and populate a ListView
|
||||
m := view.NewManager(p.mgr.Client())
|
||||
|
||||
list, err := m.CreateListView(ctx, collectors)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer list.Destroy(context.Background())
|
||||
|
||||
ref := list.Reference()
|
||||
filter := new(property.WaitFilter).Add(ref, collectors[0].Type, props, list.TraversalSpec())
|
||||
|
||||
return property.WaitForUpdates(ctx, c, filter, func(updates []types.ObjectUpdate) bool {
|
||||
for _, update := range updates {
|
||||
if err := p.process(update.Obj, update.ChangeSet); err != nil {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return !tail
|
||||
})
|
||||
}
|
||||
|
||||
func (p *eventProcessor) process(c types.ManagedObjectReference, pc []types.PropertyChange) error {
|
||||
t := p.tailers[c]
|
||||
if t == nil {
|
||||
return fmt.Errorf("unknown collector %s", c.String())
|
||||
}
|
||||
|
||||
for _, u := range pc {
|
||||
evs := t.t.newEvents(u.Val.(types.ArrayOfEvent).Event)
|
||||
if len(evs) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
if err := p.callback(t.obj, evs); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
const invalidKey = int32(-1)
|
||||
|
||||
type eventTailer struct {
|
||||
lastKey int32
|
||||
}
|
||||
|
||||
func newEventTailer() *eventTailer {
|
||||
return &eventTailer{
|
||||
lastKey: invalidKey,
|
||||
}
|
||||
}
|
||||
|
||||
func (t *eventTailer) newEvents(evs []types.BaseEvent) []types.BaseEvent {
|
||||
var ret []types.BaseEvent
|
||||
if t.lastKey == invalidKey {
|
||||
ret = evs
|
||||
} else {
|
||||
found := false
|
||||
for i := range evs {
|
||||
if evs[i].GetEvent().Key != t.lastKey {
|
||||
continue
|
||||
}
|
||||
|
||||
found = true
|
||||
ret = evs[:i]
|
||||
break
|
||||
}
|
||||
|
||||
if !found {
|
||||
ret = evs
|
||||
}
|
||||
}
|
||||
|
||||
if len(ret) > 0 {
|
||||
t.lastKey = ret[0].GetEvent().Key
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
45
vendor/github.com/vmware/govmomi/event/sort.go
generated
vendored
Normal file
45
vendor/github.com/vmware/govmomi/event/sort.go
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
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 event
|
||||
|
||||
import (
|
||||
"sort"
|
||||
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
// Sort events in ascending order base on Key
|
||||
// From the EventHistoryCollector.latestPage sdk docs:
|
||||
// The "oldest event" is the one with the smallest key (event ID).
|
||||
// The events in the returned page are unordered.
|
||||
func Sort(events []types.BaseEvent) {
|
||||
sort.Sort(baseEvent(events))
|
||||
}
|
||||
|
||||
type baseEvent []types.BaseEvent
|
||||
|
||||
func (d baseEvent) Len() int {
|
||||
return len(d)
|
||||
}
|
||||
|
||||
func (d baseEvent) Less(i, j int) bool {
|
||||
return d[i].GetEvent().Key < d[j].GetEvent().Key
|
||||
}
|
||||
|
||||
func (d baseEvent) Swap(i, j int) {
|
||||
d[i], d[j] = d[j], d[i]
|
||||
}
|
||||
80
vendor/github.com/vmware/govmomi/examples/datastores/main.go
generated
vendored
Normal file
80
vendor/github.com/vmware/govmomi/examples/datastores/main.go
generated
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
Copyright (c) 2015-2017 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
This example program shows how the `view` and `property` packages can
|
||||
be used to navigate a vSphere inventory structure using govmomi.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"text/tabwriter"
|
||||
|
||||
"github.com/vmware/govmomi/examples"
|
||||
"github.com/vmware/govmomi/units"
|
||||
"github.com/vmware/govmomi/view"
|
||||
"github.com/vmware/govmomi/vim25/mo"
|
||||
)
|
||||
|
||||
func main() {
|
||||
ctx := context.Background()
|
||||
|
||||
// Connect and log in to ESX or vCenter
|
||||
c, err := examples.NewClient(ctx)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
defer c.Logout(ctx)
|
||||
|
||||
// Create a view of Datastore objects
|
||||
m := view.NewManager(c.Client)
|
||||
|
||||
v, err := m.CreateContainerView(ctx, c.ServiceContent.RootFolder, []string{"Datastore"}, true)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
defer v.Destroy(ctx)
|
||||
|
||||
// Retrieve summary property for all datastores
|
||||
// Reference: http://pubs.vmware.com/vsphere-60/topic/com.vmware.wssdk.apiref.doc/vim.Datastore.html
|
||||
var dss []mo.Datastore
|
||||
err = v.Retrieve(ctx, []string{"Datastore"}, []string{"summary"}, &dss)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Print summary per datastore (see also: govc/datastore/info.go)
|
||||
|
||||
tw := tabwriter.NewWriter(os.Stdout, 2, 0, 2, ' ', 0)
|
||||
fmt.Fprintf(tw, "Name:\tType:\tCapacity:\tFree:\n")
|
||||
|
||||
for _, ds := range dss {
|
||||
fmt.Fprintf(tw, "%s\t", ds.Summary.Name)
|
||||
fmt.Fprintf(tw, "%s\t", ds.Summary.Type)
|
||||
fmt.Fprintf(tw, "%s\t", units.ByteSize(ds.Summary.Capacity))
|
||||
fmt.Fprintf(tw, "%s\t", units.ByteSize(ds.Summary.FreeSpace))
|
||||
fmt.Fprintf(tw, "\n")
|
||||
}
|
||||
|
||||
_ = tw.Flush()
|
||||
}
|
||||
116
vendor/github.com/vmware/govmomi/examples/examples.go
generated
vendored
Normal file
116
vendor/github.com/vmware/govmomi/examples/examples.go
generated
vendored
Normal file
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
Copyright (c) 2017 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package examples
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/vmware/govmomi"
|
||||
"github.com/vmware/govmomi/vim25/soap"
|
||||
)
|
||||
|
||||
// getEnvString returns string from environment variable.
|
||||
func getEnvString(v string, def string) string {
|
||||
r := os.Getenv(v)
|
||||
if r == "" {
|
||||
return def
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
// getEnvBool returns boolean from environment variable.
|
||||
func getEnvBool(v string, def bool) bool {
|
||||
r := os.Getenv(v)
|
||||
if r == "" {
|
||||
return def
|
||||
}
|
||||
|
||||
switch strings.ToLower(r[0:1]) {
|
||||
case "t", "y", "1":
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
const (
|
||||
envURL = "GOVMOMI_URL"
|
||||
envUserName = "GOVMOMI_USERNAME"
|
||||
envPassword = "GOVMOMI_PASSWORD"
|
||||
envInsecure = "GOVMOMI_INSECURE"
|
||||
)
|
||||
|
||||
var urlDescription = fmt.Sprintf("ESX or vCenter URL [%s]", envURL)
|
||||
var urlFlag = flag.String("url", getEnvString(envURL, "https://username:password@host/sdk"), urlDescription)
|
||||
|
||||
var insecureDescription = fmt.Sprintf("Don't verify the server's certificate chain [%s]", envInsecure)
|
||||
var insecureFlag = flag.Bool("insecure", getEnvBool(envInsecure, false), insecureDescription)
|
||||
|
||||
func processOverride(u *url.URL) {
|
||||
envUsername := os.Getenv(envUserName)
|
||||
envPassword := os.Getenv(envPassword)
|
||||
|
||||
// Override username if provided
|
||||
if envUsername != "" {
|
||||
var password string
|
||||
var ok bool
|
||||
|
||||
if u.User != nil {
|
||||
password, ok = u.User.Password()
|
||||
}
|
||||
|
||||
if ok {
|
||||
u.User = url.UserPassword(envUsername, password)
|
||||
} else {
|
||||
u.User = url.User(envUsername)
|
||||
}
|
||||
}
|
||||
|
||||
// Override password if provided
|
||||
if envPassword != "" {
|
||||
var username string
|
||||
|
||||
if u.User != nil {
|
||||
username = u.User.Username()
|
||||
}
|
||||
|
||||
u.User = url.UserPassword(username, envPassword)
|
||||
}
|
||||
}
|
||||
|
||||
// NewClient creates a govmomi.Client for use in the examples
|
||||
func NewClient(ctx context.Context) (*govmomi.Client, error) {
|
||||
flag.Parse()
|
||||
|
||||
// Parse URL from string
|
||||
u, err := soap.ParseURL(*urlFlag)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Override username and/or password as required
|
||||
processOverride(u)
|
||||
|
||||
// Connect and log in to ESX or vCenter
|
||||
return govmomi.NewClient(ctx, u, *insecureFlag)
|
||||
}
|
||||
86
vendor/github.com/vmware/govmomi/examples/hosts/main.go
generated
vendored
Normal file
86
vendor/github.com/vmware/govmomi/examples/hosts/main.go
generated
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
Copyright (c) 2017 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
This example program shows how the `view` and `property` packages can
|
||||
be used to navigate a vSphere inventory structure using govmomi.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"text/tabwriter"
|
||||
|
||||
"github.com/vmware/govmomi/examples"
|
||||
"github.com/vmware/govmomi/units"
|
||||
"github.com/vmware/govmomi/view"
|
||||
"github.com/vmware/govmomi/vim25/mo"
|
||||
)
|
||||
|
||||
func main() {
|
||||
ctx := context.Background()
|
||||
|
||||
// Connect and login to ESX or vCenter
|
||||
c, err := examples.NewClient(ctx)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
defer c.Logout(ctx)
|
||||
|
||||
// Create a view of HostSystem objects
|
||||
m := view.NewManager(c.Client)
|
||||
|
||||
v, err := m.CreateContainerView(ctx, c.ServiceContent.RootFolder, []string{"HostSystem"}, true)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
defer v.Destroy(ctx)
|
||||
|
||||
// Retrieve summary property for all hosts
|
||||
// Reference: http://pubs.vmware.com/vsphere-60/topic/com.vmware.wssdk.apiref.doc/vim.HostSystem.html
|
||||
var hss []mo.HostSystem
|
||||
err = v.Retrieve(ctx, []string{"HostSystem"}, []string{"summary"}, &hss)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Print summary per host (see also: govc/host/info.go)
|
||||
|
||||
tw := tabwriter.NewWriter(os.Stdout, 2, 0, 2, ' ', 0)
|
||||
fmt.Fprintf(tw, "Name:\tUsed CPU:\tTotal CPU:\tFree CPU:\tUsed Memory:\tTotal Memory:\tFree Memory\t:\n")
|
||||
|
||||
for _, hs := range hss {
|
||||
totalCPU := int64(hs.Summary.Hardware.CpuMhz) * int64(hs.Summary.Hardware.NumCpuCores)
|
||||
freeCPU := int64(totalCPU) - int64(hs.Summary.QuickStats.OverallCpuUsage)
|
||||
freeMemory := int64(hs.Summary.Hardware.MemorySize) - (int64(hs.Summary.QuickStats.OverallMemoryUsage) * 1024 * 1024)
|
||||
fmt.Fprintf(tw, "%s\t", hs.Summary.Config.Name)
|
||||
fmt.Fprintf(tw, "%d\t", hs.Summary.QuickStats.OverallCpuUsage)
|
||||
fmt.Fprintf(tw, "%d\t", totalCPU)
|
||||
fmt.Fprintf(tw, "%d\t", freeCPU)
|
||||
fmt.Fprintf(tw, "%s\t", units.ByteSize(hs.Summary.QuickStats.OverallMemoryUsage))
|
||||
fmt.Fprintf(tw, "%s\t", units.ByteSize(hs.Summary.Hardware.MemorySize))
|
||||
fmt.Fprintf(tw, "%d\t", freeMemory)
|
||||
fmt.Fprintf(tw, "\n")
|
||||
}
|
||||
|
||||
_ = tw.Flush()
|
||||
}
|
||||
60
vendor/github.com/vmware/govmomi/examples/networks/main.go
generated
vendored
Normal file
60
vendor/github.com/vmware/govmomi/examples/networks/main.go
generated
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
Copyright (c) 2017 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/vmware/govmomi/examples"
|
||||
"github.com/vmware/govmomi/view"
|
||||
"github.com/vmware/govmomi/vim25/mo"
|
||||
)
|
||||
|
||||
func main() {
|
||||
ctx := context.Background()
|
||||
|
||||
// Connect and login to ESX or vCenter
|
||||
c, err := examples.NewClient(ctx)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
defer c.Logout(ctx)
|
||||
|
||||
// Create a view of Network types
|
||||
m := view.NewManager(c.Client)
|
||||
|
||||
v, err := m.CreateContainerView(ctx, c.ServiceContent.RootFolder, []string{"Network"}, true)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
defer v.Destroy(ctx)
|
||||
|
||||
// Reference: http://pubs.vmware.com/vsphere-60/topic/com.vmware.wssdk.apiref.doc/vim.Network.html
|
||||
var networks []mo.Network
|
||||
err = v.Retrieve(ctx, []string{"Network"}, nil, &networks)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
for _, net := range networks {
|
||||
fmt.Printf("%s: %s\n", net.Name, net.Reference())
|
||||
}
|
||||
}
|
||||
68
vendor/github.com/vmware/govmomi/examples/virtualmachines/main.go
generated
vendored
Normal file
68
vendor/github.com/vmware/govmomi/examples/virtualmachines/main.go
generated
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
Copyright (c) 2017 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
This example program shows how the `view` package can
|
||||
be used to navigate a vSphere inventory structure using govmomi.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/vmware/govmomi/examples"
|
||||
"github.com/vmware/govmomi/view"
|
||||
"github.com/vmware/govmomi/vim25/mo"
|
||||
)
|
||||
|
||||
func main() {
|
||||
ctx := context.Background()
|
||||
|
||||
// Connect and login to ESX or vCenter
|
||||
c, err := examples.NewClient(ctx)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
defer c.Logout(ctx)
|
||||
|
||||
// Create view of VirtualMachine objects
|
||||
m := view.NewManager(c.Client)
|
||||
|
||||
v, err := m.CreateContainerView(ctx, c.ServiceContent.RootFolder, []string{"VirtualMachine"}, true)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
defer v.Destroy(ctx)
|
||||
|
||||
// Retrieve summary property for all machines
|
||||
// Reference: http://pubs.vmware.com/vsphere-60/topic/com.vmware.wssdk.apiref.doc/vim.VirtualMachine.html
|
||||
var vms []mo.VirtualMachine
|
||||
err = v.Retrieve(ctx, []string{"VirtualMachine"}, []string{"summary"}, &vms)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Print summary per vm (see also: govc/vm/info.go)
|
||||
|
||||
for _, vm := range vms {
|
||||
fmt.Printf("%s: %s\n", vm.Summary.Config.Name, vm.Summary.Config.GuestFullName)
|
||||
}
|
||||
}
|
||||
37
vendor/github.com/vmware/govmomi/find/doc.go
generated
vendored
Normal file
37
vendor/github.com/vmware/govmomi/find/doc.go
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
Copyright (c) 2014-2017 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
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 find implements inventory listing and searching.
|
||||
|
||||
The Finder is an alternative to the object.SearchIndex FindByInventoryPath() and FindChild() methods.
|
||||
SearchIndex.FindByInventoryPath requires an absolute path, whereas the Finder also supports relative paths
|
||||
and patterns via path.Match.
|
||||
SearchIndex.FindChild requires a parent to find the child, whereas the Finder also supports an ancestor via
|
||||
recursive object traversal.
|
||||
|
||||
The various Finder methods accept a "path" argument, which can absolute or relative to the Folder for the object type.
|
||||
The Finder supports two modes, "list" and "find". The "list" mode behaves like the "ls" command, only searching within
|
||||
the immediate path. The "find" mode behaves like the "find" command, with the search starting at the immediate path but
|
||||
also recursing into sub Folders relative to the Datacenter. The default mode is "list" if the given path contains a "/",
|
||||
otherwise "find" mode is used.
|
||||
|
||||
The exception is to use a "..." wildcard with a path to find all objects recursively underneath any root object.
|
||||
For example: VirtualMachineList("/DC1/...")
|
||||
|
||||
See also: https://github.com/vmware/govmomi/blob/master/govc/README.md#usage
|
||||
*/
|
||||
package find
|
||||
64
vendor/github.com/vmware/govmomi/find/error.go
generated
vendored
Normal file
64
vendor/github.com/vmware/govmomi/find/error.go
generated
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
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 find
|
||||
|
||||
import "fmt"
|
||||
|
||||
type NotFoundError struct {
|
||||
kind string
|
||||
path string
|
||||
}
|
||||
|
||||
func (e *NotFoundError) Error() string {
|
||||
return fmt.Sprintf("%s '%s' not found", e.kind, e.path)
|
||||
}
|
||||
|
||||
type MultipleFoundError struct {
|
||||
kind string
|
||||
path string
|
||||
}
|
||||
|
||||
func (e *MultipleFoundError) Error() string {
|
||||
return fmt.Sprintf("path '%s' resolves to multiple %ss", e.path, e.kind)
|
||||
}
|
||||
|
||||
type DefaultNotFoundError struct {
|
||||
kind string
|
||||
}
|
||||
|
||||
func (e *DefaultNotFoundError) Error() string {
|
||||
return fmt.Sprintf("no default %s found", e.kind)
|
||||
}
|
||||
|
||||
type DefaultMultipleFoundError struct {
|
||||
kind string
|
||||
}
|
||||
|
||||
func (e DefaultMultipleFoundError) Error() string {
|
||||
return fmt.Sprintf("default %s resolves to multiple instances, please specify", e.kind)
|
||||
}
|
||||
|
||||
func toDefaultError(err error) error {
|
||||
switch e := err.(type) {
|
||||
case *NotFoundError:
|
||||
return &DefaultNotFoundError{e.kind}
|
||||
case *MultipleFoundError:
|
||||
return &DefaultMultipleFoundError{e.kind}
|
||||
default:
|
||||
return err
|
||||
}
|
||||
}
|
||||
1042
vendor/github.com/vmware/govmomi/find/finder.go
generated
vendored
Normal file
1042
vendor/github.com/vmware/govmomi/find/finder.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
253
vendor/github.com/vmware/govmomi/find/recurser.go
generated
vendored
Normal file
253
vendor/github.com/vmware/govmomi/find/recurser.go
generated
vendored
Normal file
@@ -0,0 +1,253 @@
|
||||
/*
|
||||
Copyright (c) 2014-2017 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
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 find
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/vmware/govmomi/list"
|
||||
"github.com/vmware/govmomi/object"
|
||||
"github.com/vmware/govmomi/property"
|
||||
"github.com/vmware/govmomi/vim25/mo"
|
||||
)
|
||||
|
||||
// spec is used to specify per-search configuration, independent of the Finder instance.
|
||||
type spec struct {
|
||||
// Relative returns the root object to resolve Relative paths (starts with ".")
|
||||
Relative func(ctx context.Context) (object.Reference, error)
|
||||
|
||||
// ListMode can be used to optionally force "ls" behavior, rather than "find" behavior
|
||||
ListMode *bool
|
||||
|
||||
// Contents configures the Recurser to list the Contents of traversable leaf nodes.
|
||||
// This is typically set to true when used from the ls command, where listing
|
||||
// a folder means listing its Contents. This is typically set to false for
|
||||
// commands that take managed entities that are not folders as input.
|
||||
Contents bool
|
||||
|
||||
// Parents specifies the types which can contain the child types being searched for.
|
||||
// for example, when searching for a HostSystem, parent types can be
|
||||
// "ComputeResource" or "ClusterComputeResource".
|
||||
Parents []string
|
||||
|
||||
// Include specifies which types to be included in the results, used only in "find" mode.
|
||||
Include []string
|
||||
|
||||
// Nested should be set to types that can be Nested, used only in "find" mode.
|
||||
Nested []string
|
||||
|
||||
// ChildType avoids traversing into folders that can't contain the Include types, used only in "find" mode.
|
||||
ChildType []string
|
||||
}
|
||||
|
||||
func (s *spec) traversable(o mo.Reference) bool {
|
||||
ref := o.Reference()
|
||||
|
||||
switch ref.Type {
|
||||
case "Datacenter":
|
||||
if len(s.Include) == 1 && s.Include[0] == "Datacenter" {
|
||||
// No point in traversing deeper as Datacenters cannot be nested
|
||||
return false
|
||||
}
|
||||
return true
|
||||
case "Folder":
|
||||
if f, ok := o.(mo.Folder); ok {
|
||||
// TODO: Not making use of this yet, but here we can optimize when searching the entire
|
||||
// inventory across Datacenters for specific types, for example: 'govc ls -t VirtualMachine /**'
|
||||
// should not traverse into a Datacenter's host, network or datatore folders.
|
||||
if !s.traversableChildType(f.ChildType) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
for _, kind := range s.Parents {
|
||||
if kind == ref.Type {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (s *spec) traversableChildType(ctypes []string) bool {
|
||||
if len(s.ChildType) == 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
for _, t := range ctypes {
|
||||
for _, c := range s.ChildType {
|
||||
if t == c {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (s *spec) wanted(e list.Element) bool {
|
||||
if len(s.Include) == 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
w := e.Object.Reference().Type
|
||||
|
||||
for _, kind := range s.Include {
|
||||
if w == kind {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// listMode is a global option to revert to the original Finder behavior,
|
||||
// disabling the newer "find" mode.
|
||||
var listMode = os.Getenv("GOVMOMI_FINDER_LIST_MODE") == "true"
|
||||
|
||||
func (s *spec) listMode(isPath bool) bool {
|
||||
if listMode {
|
||||
return true
|
||||
}
|
||||
|
||||
if s.ListMode != nil {
|
||||
return *s.ListMode
|
||||
}
|
||||
|
||||
return isPath
|
||||
}
|
||||
|
||||
type recurser struct {
|
||||
Collector *property.Collector
|
||||
|
||||
// All configures the recurses to fetch complete objects for leaf nodes.
|
||||
All bool
|
||||
}
|
||||
|
||||
func (r recurser) List(ctx context.Context, s *spec, root list.Element, parts []string) ([]list.Element, error) {
|
||||
if len(parts) == 0 {
|
||||
// Include non-traversable leaf elements in result. For example, consider
|
||||
// the pattern "./vm/my-vm-*", where the pattern should match the VMs and
|
||||
// not try to traverse them.
|
||||
//
|
||||
// Include traversable leaf elements in result, if the contents
|
||||
// field is set to false.
|
||||
//
|
||||
if !s.Contents || !s.traversable(root.Object.Reference()) {
|
||||
return []list.Element{root}, nil
|
||||
}
|
||||
}
|
||||
|
||||
k := list.Lister{
|
||||
Collector: r.Collector,
|
||||
Reference: root.Object.Reference(),
|
||||
Prefix: root.Path,
|
||||
}
|
||||
|
||||
if r.All && len(parts) < 2 {
|
||||
k.All = true
|
||||
}
|
||||
|
||||
in, err := k.List(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// This folder is a leaf as far as the glob goes.
|
||||
if len(parts) == 0 {
|
||||
return in, nil
|
||||
}
|
||||
|
||||
all := parts
|
||||
pattern := parts[0]
|
||||
parts = parts[1:]
|
||||
|
||||
var out []list.Element
|
||||
for _, e := range in {
|
||||
matched, err := path.Match(pattern, path.Base(e.Path))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !matched {
|
||||
matched = strings.HasSuffix(e.Path, "/"+path.Join(all...))
|
||||
if matched {
|
||||
// name contains a '/'
|
||||
out = append(out, e)
|
||||
}
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
nres, err := r.List(ctx, s, e, parts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
out = append(out, nres...)
|
||||
}
|
||||
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (r recurser) Find(ctx context.Context, s *spec, root list.Element, parts []string) ([]list.Element, error) {
|
||||
var out []list.Element
|
||||
|
||||
if len(parts) > 0 {
|
||||
pattern := parts[0]
|
||||
matched, err := path.Match(pattern, path.Base(root.Path))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if matched && s.wanted(root) {
|
||||
out = append(out, root)
|
||||
}
|
||||
}
|
||||
|
||||
if !s.traversable(root.Object) {
|
||||
return out, nil
|
||||
}
|
||||
|
||||
k := list.Lister{
|
||||
Collector: r.Collector,
|
||||
Reference: root.Object.Reference(),
|
||||
Prefix: root.Path,
|
||||
}
|
||||
|
||||
in, err := k.List(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, e := range in {
|
||||
nres, err := r.Find(ctx, s, e, parts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
out = append(out, nres...)
|
||||
}
|
||||
|
||||
return out, nil
|
||||
}
|
||||
4
vendor/github.com/vmware/govmomi/gen/Gemfile
generated
vendored
Normal file
4
vendor/github.com/vmware/govmomi/gen/Gemfile
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
source "https://rubygems.org"
|
||||
|
||||
gem "nokogiri"
|
||||
gem "test-unit"
|
||||
19
vendor/github.com/vmware/govmomi/gen/Gemfile.lock
generated
vendored
Normal file
19
vendor/github.com/vmware/govmomi/gen/Gemfile.lock
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
mini_portile (0.6.0)
|
||||
nokogiri (1.6.3.1)
|
||||
mini_portile (= 0.6.0)
|
||||
power_assert (0.4.1)
|
||||
test-unit (3.2.3)
|
||||
power_assert
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
nokogiri
|
||||
test-unit
|
||||
|
||||
BUNDLED WITH
|
||||
1.14.6
|
||||
53
vendor/github.com/vmware/govmomi/gen/gen.sh
generated
vendored
Executable file
53
vendor/github.com/vmware/govmomi/gen/gen.sh
generated
vendored
Executable file
@@ -0,0 +1,53 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Copyright (c) 2014 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.
|
||||
|
||||
set -e
|
||||
|
||||
generate() {
|
||||
dst="$1"
|
||||
wsdl="$2"
|
||||
modl="$3"
|
||||
|
||||
pkgs=(types methods)
|
||||
if [ -n "$modl" ] ; then
|
||||
pkgs+=(mo)
|
||||
fi
|
||||
|
||||
for p in "${pkgs[@]}"
|
||||
do
|
||||
mkdir -p "$dst/$p"
|
||||
done
|
||||
|
||||
echo "generating $dst/..."
|
||||
|
||||
bundle exec ruby gen_from_wsdl.rb "$dst" "$wsdl"
|
||||
if [ -n "$modl" ] ; then
|
||||
bundle exec ruby gen_from_vmodl.rb "$dst" "$wsdl" "$modl"
|
||||
fi
|
||||
|
||||
for p in "${pkgs[@]}"
|
||||
do
|
||||
pushd "$dst/$p" >/dev/null
|
||||
goimports -w ./*.go
|
||||
go install
|
||||
popd >/dev/null
|
||||
done
|
||||
}
|
||||
|
||||
# ./sdk/ contains the contents of wsdl.zip from vimbase build 5037323
|
||||
|
||||
generate "../vim25" "vim" "./rbvmomi/vmodl.db" # from github.com/vmware/rbvmomi@f6907e6
|
||||
generate "../pbm" "pbm"
|
||||
231
vendor/github.com/vmware/govmomi/gen/gen_from_vmodl.rb
generated
vendored
Normal file
231
vendor/github.com/vmware/govmomi/gen/gen_from_vmodl.rb
generated
vendored
Normal file
@@ -0,0 +1,231 @@
|
||||
# Copyright (c) 2014 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.
|
||||
|
||||
$:.unshift(File.expand_path(File.dirname(__FILE__)))
|
||||
|
||||
require "vim_wsdl"
|
||||
|
||||
require "test/unit"
|
||||
|
||||
def read(file)
|
||||
File.open(file)
|
||||
end
|
||||
|
||||
class Prop
|
||||
def initialize(vmodl, data)
|
||||
@vmodl = vmodl
|
||||
@data = data
|
||||
end
|
||||
|
||||
def slice?
|
||||
@data["is-array"]
|
||||
end
|
||||
|
||||
def optional?
|
||||
@data["is-optional"]
|
||||
end
|
||||
|
||||
def name
|
||||
@data["name"]
|
||||
end
|
||||
|
||||
def var_field
|
||||
n = name
|
||||
n[0].capitalize + n[1..-1]
|
||||
end
|
||||
|
||||
def var_type_prefix(base=false)
|
||||
if slice?
|
||||
"[]"
|
||||
else
|
||||
if optional? && !base
|
||||
"*"
|
||||
else
|
||||
""
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def var_type
|
||||
type = @data["wsdl_type"]
|
||||
if @vmodl.managed_hash.has_key?(type)
|
||||
type = "ManagedObjectReference"
|
||||
end
|
||||
|
||||
# Fix up type from vmodl
|
||||
case type
|
||||
when "TypeName", "MethodName"
|
||||
type = "xsd:string"
|
||||
when "ManagedObject"
|
||||
type = "ManagedObjectReference"
|
||||
when "xsd:anyType"
|
||||
type = "AnyType"
|
||||
end
|
||||
|
||||
if type =~ /^xsd:(.*)$/
|
||||
type = $1
|
||||
case type
|
||||
when "string"
|
||||
when "int"
|
||||
type = "int32"
|
||||
when "boolean"
|
||||
type ="bool"
|
||||
when "long"
|
||||
type ="int64"
|
||||
when "dateTime"
|
||||
type ="time.Time"
|
||||
prefix += "*" if !slice? && optional?
|
||||
when "byte"
|
||||
when "double"
|
||||
type ="float64"
|
||||
when "float"
|
||||
type ="float32"
|
||||
when "short"
|
||||
type ="int16"
|
||||
when "base64Binary"
|
||||
type ="[]byte"
|
||||
else
|
||||
raise "unknown type: %s" % type
|
||||
end
|
||||
else
|
||||
if Peek.base?(type)
|
||||
type = "Base" + type
|
||||
base = true
|
||||
end
|
||||
type = "types." + type
|
||||
end
|
||||
|
||||
var_type_prefix(base) + type
|
||||
end
|
||||
|
||||
def var_tag
|
||||
"mo:\"%s\"" % name
|
||||
end
|
||||
|
||||
def dump(io)
|
||||
io.print "%s %s `%s`\n" % [var_field, var_type, var_tag]
|
||||
end
|
||||
end
|
||||
|
||||
class Managed
|
||||
def initialize(vmodl, name, data)
|
||||
@vmodl = vmodl
|
||||
@name = name
|
||||
@data = data
|
||||
end
|
||||
|
||||
def name
|
||||
@name
|
||||
end
|
||||
|
||||
def props
|
||||
@data["props"].map do |p|
|
||||
Prop.new(@vmodl, p)
|
||||
end
|
||||
end
|
||||
|
||||
def dump(io)
|
||||
include_ref_getter = false
|
||||
include_ent_getter = false
|
||||
|
||||
io.print "type %s struct {\n" % name
|
||||
|
||||
case @data["wsdl_base"]
|
||||
when nil, "ManagedObject", "View"
|
||||
include_ref_getter = true
|
||||
io.print "Self types.ManagedObjectReference\n\n"
|
||||
else
|
||||
io.print "%s\n\n" % @data["wsdl_base"]
|
||||
if @data["wsdl_base"] == "ManagedEntity"
|
||||
include_ent_getter = true
|
||||
end
|
||||
end
|
||||
|
||||
props.each do |p|
|
||||
p.dump(io)
|
||||
end
|
||||
io.print "}\n\n"
|
||||
|
||||
if include_ref_getter
|
||||
io.print "func (m %s) Reference() types.ManagedObjectReference {\n" % [name]
|
||||
io.print "return m.Self\n"
|
||||
io.print "}\n\n"
|
||||
end
|
||||
|
||||
if include_ent_getter
|
||||
io.print "func (m *%s) Entity() *ManagedEntity {\n" % [name]
|
||||
io.print "return &m.ManagedEntity\n"
|
||||
io.print "}\n\n"
|
||||
end
|
||||
end
|
||||
|
||||
def dump_init(io)
|
||||
io.print "func init() {\n"
|
||||
io.print "t[\"%s\"] = reflect.TypeOf((*%s)(nil)).Elem()\n" % [name, name]
|
||||
io.print "}\n\n"
|
||||
end
|
||||
end
|
||||
|
||||
class Vmodl
|
||||
def initialize(data)
|
||||
@data = Marshal.load(data)
|
||||
end
|
||||
|
||||
def managed_hash
|
||||
@managed_hash ||= begin
|
||||
h = {}
|
||||
managed.each do |m|
|
||||
h[m.name] = m
|
||||
end
|
||||
h
|
||||
end
|
||||
end
|
||||
|
||||
def managed
|
||||
@data.map do |k,v|
|
||||
next if !v.is_a?(Hash)
|
||||
next if v["kind"] != "managed"
|
||||
# rbvmomi/vmodl.db includes pbm mo's, but we don't need the types as they have no properties
|
||||
next if k =~ /^pbm/i
|
||||
|
||||
Managed.new(self, k, v)
|
||||
end.compact
|
||||
end
|
||||
end
|
||||
|
||||
if !File.directory?(ARGV.first)
|
||||
raise "first argument not a directory"
|
||||
end
|
||||
|
||||
wsdl = WSDL.new(WSDL.read ARGV[1]+".wsdl")
|
||||
wsdl.validate_assumptions!
|
||||
wsdl.peek()
|
||||
|
||||
vmodl = Vmodl.new(read ARGV[2] || "./rbvmomi/vmodl.db")
|
||||
|
||||
File.open(File.join(ARGV.first, "mo/mo.go"), "w") do |io|
|
||||
io.print WSDL.header("mo")
|
||||
io.print <<EOF
|
||||
import (
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
EOF
|
||||
|
||||
vmodl.
|
||||
managed.
|
||||
sort_by { |m| m.name }.
|
||||
each { |m| m.dump(io); m.dump_init(io); }
|
||||
end
|
||||
|
||||
exit(0)
|
||||
90
vendor/github.com/vmware/govmomi/gen/gen_from_wsdl.rb
generated
vendored
Normal file
90
vendor/github.com/vmware/govmomi/gen/gen_from_wsdl.rb
generated
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
# Copyright (c) 2014 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.
|
||||
|
||||
$:.unshift(File.expand_path(File.dirname(__FILE__)))
|
||||
|
||||
require "vim_wsdl"
|
||||
|
||||
if !File.directory?(ARGV.first)
|
||||
raise "first argument not a directory"
|
||||
end
|
||||
|
||||
target = ARGV[1]
|
||||
wsdl = WSDL.new(WSDL.read target+".wsdl")
|
||||
wsdl.validate_assumptions!
|
||||
wsdl.peek()
|
||||
|
||||
ifs = Peek.types.keys.select { |name| Peek.base?(name) }.size()
|
||||
puts "%d classes, %d interfaces" % [Peek.types.size(), ifs]
|
||||
|
||||
File.open(File.join(ARGV.first, "types/enum.go"), "w") do |io|
|
||||
io.print WSDL.header("types")
|
||||
|
||||
wsdl.
|
||||
types.
|
||||
sort_by { |x| x.name }.
|
||||
uniq { |x| x.name }.
|
||||
select { |x| x.name[0] == x.name[0].upcase }. # Only capitalized methods for now...
|
||||
select { |t| t.is_enum? }.
|
||||
each { |e| e.dump(io); e.dump_init(io) }
|
||||
end
|
||||
|
||||
File.open(File.join(ARGV.first, "types/types.go"), "w") do |io|
|
||||
io.print WSDL.header("types")
|
||||
if target != "vim"
|
||||
io.print <<EOF
|
||||
import (
|
||||
"context"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
EOF
|
||||
end
|
||||
|
||||
wsdl.
|
||||
types.
|
||||
sort_by { |x| x.name }.
|
||||
uniq { |x| x.name }.
|
||||
select { |x| x.name[0] == x.name[0].upcase }. # Only capitalized methods for now...
|
||||
select { |t| !t.is_enum? }.
|
||||
each { |e| e.dump(io); e.dump_init(io) }
|
||||
end
|
||||
|
||||
File.open(File.join(ARGV.first, "types/if.go"), "w") do |io|
|
||||
io.print WSDL.header("types")
|
||||
|
||||
Peek.dump_interfaces(io)
|
||||
end
|
||||
|
||||
File.open(File.join(ARGV.first, "methods/methods.go"), "w") do |io|
|
||||
io.print WSDL.header("methods")
|
||||
if target == "vim"
|
||||
target += "25"
|
||||
end
|
||||
|
||||
io.print <<EOF
|
||||
import (
|
||||
"context"
|
||||
"github.com/vmware/govmomi/#{target}/types"
|
||||
"github.com/vmware/govmomi/vim25/soap"
|
||||
)
|
||||
EOF
|
||||
|
||||
wsdl.
|
||||
operations.
|
||||
sort_by { |x| x.name }.
|
||||
select { |x| x.name[0] == x.name[0].upcase }. # Only capitalized methods for now...
|
||||
each { |e| e.dump(io) }
|
||||
end
|
||||
|
||||
exit(0)
|
||||
871
vendor/github.com/vmware/govmomi/gen/vim_wsdl.rb
generated
vendored
Normal file
871
vendor/github.com/vmware/govmomi/gen/vim_wsdl.rb
generated
vendored
Normal file
@@ -0,0 +1,871 @@
|
||||
# Copyright (c) 2014-2017 VMware, Inc. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# 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.
|
||||
|
||||
require "nokogiri"
|
||||
require "test/unit"
|
||||
|
||||
$namespaces = %w(vim25)
|
||||
|
||||
def valid_ns?(t)
|
||||
$namespaces.include?(t)
|
||||
end
|
||||
|
||||
def init_type(io, name, kind)
|
||||
t = "reflect.TypeOf((*#{kind})(nil)).Elem()"
|
||||
|
||||
io.print "func init() {\n"
|
||||
|
||||
if $target == "vim25"
|
||||
io.print "t[\"#{name}\"] = #{t}\n"
|
||||
else
|
||||
unless name.start_with? "Base"
|
||||
name = "#{$target}:#{name}"
|
||||
end
|
||||
io.print "types.Add(\"#{name}\", #{t})\n"
|
||||
end
|
||||
|
||||
io.print "}\n\n"
|
||||
end
|
||||
|
||||
class Peek
|
||||
class Type
|
||||
attr_accessor :parent, :children, :klass
|
||||
|
||||
def initialize(name)
|
||||
@name = name
|
||||
@children = []
|
||||
end
|
||||
|
||||
def base?
|
||||
# VrpResourceAllocationInfo is removed in 6.7, so base will no longer generated
|
||||
return false if @name == "ResourceAllocationInfo"
|
||||
|
||||
return !children.empty?
|
||||
end
|
||||
end
|
||||
|
||||
@@types = {}
|
||||
@@refs = {}
|
||||
@@enums = {}
|
||||
|
||||
def self.types
|
||||
return @@types
|
||||
end
|
||||
|
||||
def self.refs
|
||||
return @@refs
|
||||
end
|
||||
|
||||
def self.enums
|
||||
return @@enums
|
||||
end
|
||||
|
||||
def self.ref(type)
|
||||
refs[type] = true
|
||||
end
|
||||
|
||||
def self.enum(type)
|
||||
enums[type] = true
|
||||
end
|
||||
|
||||
def self.enum?(type)
|
||||
enums[type]
|
||||
end
|
||||
|
||||
def self.register(name)
|
||||
raise unless name
|
||||
types[name] ||= Type.new(name)
|
||||
end
|
||||
|
||||
def self.base?(name)
|
||||
return unless c = types[name]
|
||||
c.base?
|
||||
end
|
||||
|
||||
def self.dump_interfaces(io)
|
||||
types.keys.sort.each do |name|
|
||||
next unless base?(name)
|
||||
klass = types[name].klass
|
||||
klass.dump_interface(io, name) if klass
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class EnumValue
|
||||
def initialize(type, value)
|
||||
@type = type
|
||||
@value = value
|
||||
end
|
||||
|
||||
def type_name
|
||||
@type.name
|
||||
end
|
||||
|
||||
def var_name
|
||||
n = @type.name
|
||||
v = var_value
|
||||
if v == ""
|
||||
n += "Null"
|
||||
else
|
||||
n += (v[0].capitalize + v[1..-1])
|
||||
end
|
||||
|
||||
return n
|
||||
end
|
||||
|
||||
def var_value
|
||||
@value
|
||||
end
|
||||
|
||||
def dump(io)
|
||||
io.print "%s = %s(\"%s\")\n" % [var_name, type_name, var_value]
|
||||
end
|
||||
end
|
||||
|
||||
class Simple
|
||||
include Test::Unit::Assertions
|
||||
|
||||
attr_accessor :name, :type
|
||||
|
||||
def initialize(node)
|
||||
@node = node
|
||||
end
|
||||
|
||||
def name
|
||||
@name || @node["name"]
|
||||
end
|
||||
|
||||
def type
|
||||
@type || @node["type"]
|
||||
end
|
||||
|
||||
def is_enum?
|
||||
false
|
||||
end
|
||||
|
||||
def dump_init(io)
|
||||
# noop
|
||||
end
|
||||
|
||||
def var_name
|
||||
n = self.name
|
||||
n = n[1..-1] if n[0] == "_" # Strip leading _
|
||||
n = n[0].capitalize + n[1..-1] # Capitalize
|
||||
return n
|
||||
end
|
||||
|
||||
def ns(t = self.type)
|
||||
t.split(":", 2)[0]
|
||||
end
|
||||
|
||||
def vim_type?
|
||||
valid_ns? ns
|
||||
end
|
||||
|
||||
def vim_type(t = self.type)
|
||||
ns, kind = t.split(":", 2)
|
||||
if ! valid_ns? ns
|
||||
raise
|
||||
end
|
||||
kind
|
||||
end
|
||||
|
||||
def base_type?
|
||||
vim_type? && Peek.base?(vim_type)
|
||||
end
|
||||
|
||||
def enum_type?
|
||||
vim_type? && Peek.enum?(vim_type)
|
||||
end
|
||||
|
||||
def any_type?
|
||||
self.type == "xsd:anyType"
|
||||
end
|
||||
|
||||
def pointer_type?
|
||||
["UnitNumber"].include?(var_name) or
|
||||
optional? && ["OwnerId", "GroupId", "MaxWaitSeconds", "Reservation", "Limit", "OverheadLimit"].include?(var_name)
|
||||
end
|
||||
|
||||
def var_type
|
||||
t = self.type
|
||||
prefix = ""
|
||||
|
||||
if slice?
|
||||
prefix += "[]"
|
||||
if ["AffinitySet"].include?(var_name)
|
||||
self.need_omitempty = false
|
||||
end
|
||||
end
|
||||
|
||||
if t =~ /^xsd:(.*)$/
|
||||
t = $1
|
||||
case t
|
||||
when "string"
|
||||
when "int"
|
||||
if pointer_type?
|
||||
prefix += "*"
|
||||
self.need_omitempty = false
|
||||
end
|
||||
t = "int32"
|
||||
when "boolean"
|
||||
t = "bool"
|
||||
if !slice? && optional?
|
||||
prefix += "*"
|
||||
self.need_omitempty = false
|
||||
end
|
||||
when "long"
|
||||
if pointer_type?
|
||||
prefix += "*"
|
||||
self.need_omitempty = false
|
||||
end
|
||||
t = "int64"
|
||||
when "dateTime"
|
||||
t = "time.Time"
|
||||
if !slice? && optional?
|
||||
prefix += "*"
|
||||
self.need_omitempty = false
|
||||
end
|
||||
when "anyType"
|
||||
pkg = ""
|
||||
if $target != "vim25"
|
||||
pkg = "types."
|
||||
end
|
||||
t = "#{pkg}AnyType"
|
||||
if ["Value", "Val"].include?(var_name)
|
||||
self.need_omitempty = false
|
||||
end
|
||||
when "byte"
|
||||
when "double"
|
||||
t = "float64"
|
||||
when "float"
|
||||
t = "float32"
|
||||
when "short"
|
||||
t = "int16"
|
||||
when "base64Binary"
|
||||
t = "[]byte"
|
||||
when "anyURI"
|
||||
t = "url.URL"
|
||||
else
|
||||
raise "unknown type: %s" % t
|
||||
end
|
||||
else
|
||||
pkg = ""
|
||||
if $target != self.ns
|
||||
pkg = "types."
|
||||
end
|
||||
|
||||
t = vim_type
|
||||
|
||||
if base_type?
|
||||
prefix += "#{pkg}Base"
|
||||
else
|
||||
t = pkg + t
|
||||
prefix += "*" if !slice? && !enum_type? && optional?
|
||||
end
|
||||
end
|
||||
|
||||
prefix + t
|
||||
end
|
||||
|
||||
def slice?
|
||||
test_attr("maxOccurs", "unbounded")
|
||||
end
|
||||
|
||||
def optional?
|
||||
test_attr("minOccurs", "0")
|
||||
end
|
||||
|
||||
def need_omitempty=(v)
|
||||
@need_omitempty = v
|
||||
end
|
||||
|
||||
def need_omitempty?
|
||||
var_type # HACK: trigger setting need_omitempty if necessary
|
||||
if @need_omitempty.nil?
|
||||
@need_omitempty = optional?
|
||||
else
|
||||
@need_omitempty
|
||||
end
|
||||
end
|
||||
|
||||
def need_typeattr?
|
||||
base_type? || any_type?
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def test_attr(attr, expected)
|
||||
actual = @node.attr(attr)
|
||||
if actual != nil
|
||||
case actual
|
||||
when expected
|
||||
true
|
||||
else
|
||||
raise "%s=%s" % [value, type.attr(value)]
|
||||
end
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Element < Simple
|
||||
def initialize(node)
|
||||
super(node)
|
||||
end
|
||||
|
||||
def has_type?
|
||||
!@node["type"].nil?
|
||||
end
|
||||
|
||||
def child
|
||||
cs = @node.element_children
|
||||
assert_equal 1, cs.length
|
||||
assert_equal "complexType", cs.first.name
|
||||
|
||||
t = ComplexType.new(cs.first)
|
||||
t.name = self.name
|
||||
t
|
||||
end
|
||||
|
||||
def dump(io)
|
||||
if has_type?
|
||||
io.print "type %s %s\n\n" % [name, var_type]
|
||||
else
|
||||
child.dump(io)
|
||||
end
|
||||
end
|
||||
|
||||
def dump_init(io)
|
||||
if has_type?
|
||||
init_type io, name, name
|
||||
end
|
||||
end
|
||||
|
||||
def dump_field(io)
|
||||
tag = name
|
||||
tag += ",omitempty" if need_omitempty?
|
||||
tag += ",typeattr" if need_typeattr?
|
||||
io.print "%s %s `xml:\"%s\"`\n" % [var_name, var_type, tag]
|
||||
end
|
||||
|
||||
def peek(type=nil)
|
||||
if has_type?
|
||||
return if self.type =~ /^xsd:/
|
||||
|
||||
Peek.ref(vim_type)
|
||||
else
|
||||
child.peek()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Attribute < Simple
|
||||
def dump_field(io)
|
||||
tag = name
|
||||
tag += ",omitempty" if need_omitempty?
|
||||
tag += ",attr"
|
||||
io.print "%s %s `xml:\"%s\"`\n" % [var_name, var_type, tag]
|
||||
end
|
||||
end
|
||||
|
||||
class SimpleType < Simple
|
||||
def is_enum?
|
||||
true
|
||||
end
|
||||
|
||||
def dump(io)
|
||||
enums = @node.xpath(".//xsd:enumeration").map do |n|
|
||||
EnumValue.new(self, n["value"])
|
||||
end
|
||||
|
||||
io.print "type %s string\n\n" % name
|
||||
io.print "const (\n"
|
||||
enums.each { |e| e.dump(io) }
|
||||
io.print ")\n\n"
|
||||
end
|
||||
|
||||
def dump_init(io)
|
||||
init_type io, name, name
|
||||
end
|
||||
|
||||
def peek
|
||||
Peek.enum(name)
|
||||
end
|
||||
end
|
||||
|
||||
class ComplexType < Simple
|
||||
class SimpleContent < Simple
|
||||
def dump(io)
|
||||
attr = Attribute.new(@node.at_xpath(".//xsd:attribute"))
|
||||
attr.dump_field(io)
|
||||
|
||||
# HACK DELUXE(PN)
|
||||
extension = @node.at_xpath(".//xsd:extension")
|
||||
type = extension["base"].split(":", 2)[1]
|
||||
io.print "Value %s `xml:\",chardata\"`\n" % type
|
||||
end
|
||||
|
||||
def peek
|
||||
end
|
||||
end
|
||||
|
||||
class ComplexContent < Simple
|
||||
def base
|
||||
extension = @node.at_xpath(".//xsd:extension")
|
||||
assert_not_nil extension
|
||||
|
||||
base = extension["base"]
|
||||
assert_not_nil base
|
||||
|
||||
base
|
||||
end
|
||||
|
||||
def dump(io)
|
||||
Sequence.new(@node).dump(io, base)
|
||||
end
|
||||
|
||||
def dump_interface(io, name)
|
||||
Sequence.new(@node).dump_interface(io, name)
|
||||
end
|
||||
|
||||
def peek
|
||||
Sequence.new(@node).peek(vim_type(base))
|
||||
end
|
||||
end
|
||||
|
||||
class Sequence < Simple
|
||||
def sequence
|
||||
sequence = @node.at_xpath(".//xsd:sequence")
|
||||
if sequence != nil
|
||||
sequence.element_children.map do |n|
|
||||
Element.new(n)
|
||||
end
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def dump(io, base = nil)
|
||||
return unless elements = sequence
|
||||
if base != nil
|
||||
kind = vim_type(base)
|
||||
|
||||
pkg = ""
|
||||
if $target != ns(base)
|
||||
pkg = "types."
|
||||
end
|
||||
io.print "#{pkg}#{kind}\n\n"
|
||||
end
|
||||
|
||||
elements.each do |e|
|
||||
e.dump_field(io)
|
||||
end
|
||||
end
|
||||
|
||||
def dump_interface(io, name)
|
||||
method = "Get%s() *%s" % [name, name]
|
||||
io.print "func (b *%s) %s { return b }\n" % [name, method]
|
||||
io.print "type Base%s interface {\n" % name
|
||||
io.print "%s\n" % method
|
||||
io.print "}\n\n"
|
||||
init_type io, "Base#{name}", name
|
||||
end
|
||||
|
||||
def peek(base = nil)
|
||||
return unless elements = sequence
|
||||
name = @node.attr("name")
|
||||
return unless name
|
||||
|
||||
elements.each do |e|
|
||||
e.peek(name)
|
||||
end
|
||||
|
||||
c = Peek.register(name)
|
||||
if base
|
||||
c.parent = base
|
||||
Peek.register(c.parent).children << name
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def klass
|
||||
@klass ||= begin
|
||||
cs = @node.element_children
|
||||
if !cs.empty?
|
||||
assert_equal 1, cs.length
|
||||
|
||||
case cs.first.name
|
||||
when "simpleContent"
|
||||
SimpleContent.new(@node)
|
||||
when "complexContent"
|
||||
ComplexContent.new(@node)
|
||||
when "sequence"
|
||||
Sequence.new(@node)
|
||||
else
|
||||
raise "don't know what to do for element: %s..." % cs.first.name
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def dump_init(io)
|
||||
init_type io, name, name
|
||||
end
|
||||
|
||||
def dump(io)
|
||||
io.print "type %s struct {\n" % name
|
||||
klass.dump(io) if klass
|
||||
io.print "}\n\n"
|
||||
end
|
||||
|
||||
def peek
|
||||
Peek.register(name).klass = klass
|
||||
klass.peek if klass
|
||||
end
|
||||
end
|
||||
|
||||
class Schema
|
||||
include Test::Unit::Assertions
|
||||
|
||||
attr_accessor :namespace
|
||||
|
||||
def initialize(xml)
|
||||
@xml = Nokogiri::XML.parse(xml)
|
||||
@namespace = @xml.root.attr("targetNamespace").split(":", 2)[1]
|
||||
@xml
|
||||
end
|
||||
|
||||
# We have some assumptions about structure, make sure they hold.
|
||||
def validate_assumptions!
|
||||
# Every enumeration is part of a restriction
|
||||
@xml.xpath(".//xsd:enumeration").each do |n|
|
||||
assert_equal "restriction", n.parent.name
|
||||
end
|
||||
|
||||
# See type == enum
|
||||
@xml.xpath(".//xsd:restriction").each do |n|
|
||||
# Every restriction has type xsd:string (it's an enum)
|
||||
assert_equal "xsd:string", n["base"]
|
||||
|
||||
# Every restriction is part of a simpleType
|
||||
assert_equal "simpleType", n.parent.name
|
||||
|
||||
# Every restriction is alone
|
||||
assert_equal 1, n.parent.element_children.size
|
||||
end
|
||||
|
||||
# See type == complex_content
|
||||
@xml.xpath(".//xsd:complexContent").each do |n|
|
||||
# complexContent is child of complexType
|
||||
assert_equal "complexType", n.parent.name
|
||||
|
||||
end
|
||||
|
||||
# See type == complex_type
|
||||
@xml.xpath(".//xsd:complexType").each do |n|
|
||||
cc = n.element_children
|
||||
|
||||
# OK to have an empty complexType
|
||||
next if cc.size == 0
|
||||
|
||||
# Require 1 element otherwise
|
||||
assert_equal 1, cc.size
|
||||
|
||||
case cc.first.name
|
||||
when "complexContent"
|
||||
# complexContent has 1 "extension" element
|
||||
cc = cc.first.element_children
|
||||
assert_equal 1, cc.size
|
||||
assert_equal "extension", cc.first.name
|
||||
|
||||
# extension has 1 "sequence" element
|
||||
ec = cc.first.element_children
|
||||
assert_equal 1, ec.size
|
||||
assert_equal "sequence", ec.first.name
|
||||
|
||||
# sequence has N "element" elements
|
||||
sc = ec.first.element_children
|
||||
assert sc.all? { |e| e.name == "element" }
|
||||
when "simpleContent"
|
||||
# simpleContent has 1 "extension" element
|
||||
cc = cc.first.element_children
|
||||
assert_equal 1, cc.size
|
||||
assert_equal "extension", cc.first.name
|
||||
|
||||
# extension has 1 or more "attribute" elements
|
||||
ec = cc.first.element_children
|
||||
assert_not_equal 0, ec.size
|
||||
assert_equal "attribute", ec.first.name
|
||||
when "sequence"
|
||||
# sequence has N "element" elements
|
||||
sc = cc.first.element_children
|
||||
assert sc.all? { |e| e.name == "element" }
|
||||
else
|
||||
raise "unknown element: %s" % cc.first.name
|
||||
end
|
||||
end
|
||||
|
||||
imports.each do |i|
|
||||
i.validate_assumptions!
|
||||
end
|
||||
|
||||
includes.each do |i|
|
||||
i.validate_assumptions!
|
||||
end
|
||||
end
|
||||
|
||||
def types
|
||||
return to_enum(:types) unless block_given?
|
||||
|
||||
if $target != self.namespace
|
||||
return
|
||||
end
|
||||
|
||||
imports.each do |i|
|
||||
i.types do |t|
|
||||
yield t
|
||||
end
|
||||
end
|
||||
|
||||
includes.each do |i|
|
||||
i.types do |t|
|
||||
yield t
|
||||
end
|
||||
end
|
||||
|
||||
@xml.root.children.each do |n|
|
||||
case n.class.to_s
|
||||
when "Nokogiri::XML::Text"
|
||||
next
|
||||
when "Nokogiri::XML::Element"
|
||||
case n.name
|
||||
when "include", "import"
|
||||
next
|
||||
when "element"
|
||||
e = Element.new(n)
|
||||
if e.has_type? && e.vim_type?
|
||||
if e.ns == $target
|
||||
yield e
|
||||
end
|
||||
else
|
||||
yield e
|
||||
end
|
||||
when "simpleType"
|
||||
yield SimpleType.new(n)
|
||||
when "complexType"
|
||||
yield ComplexType.new(n)
|
||||
else
|
||||
raise "unknown child: %s" % n.name
|
||||
end
|
||||
else
|
||||
raise "unknown type: %s" % n.class
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def imports
|
||||
@imports ||= @xml.root.xpath(".//xmlns:import").map do |n|
|
||||
Schema.new(WSDL.read n["schemaLocation"])
|
||||
end
|
||||
end
|
||||
|
||||
def includes
|
||||
@includes ||= @xml.root.xpath(".//xmlns:include").map do |n|
|
||||
Schema.new(WSDL.read n["schemaLocation"])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
class Operation
|
||||
include Test::Unit::Assertions
|
||||
|
||||
def initialize(wsdl, operation_node)
|
||||
@wsdl = wsdl
|
||||
@operation_node = operation_node
|
||||
end
|
||||
|
||||
def name
|
||||
@operation_node["name"]
|
||||
end
|
||||
|
||||
def namespace
|
||||
type = @operation_node.at_xpath("./xmlns:input").attr("message")
|
||||
keep_ns(type)
|
||||
end
|
||||
|
||||
def remove_ns(x)
|
||||
ns, x = x.split(":", 2)
|
||||
if ! valid_ns? ns
|
||||
raise
|
||||
end
|
||||
x
|
||||
end
|
||||
|
||||
def keep_ns(x)
|
||||
ns, x = x.split(":", 2)
|
||||
if ! valid_ns? ns
|
||||
raise
|
||||
end
|
||||
ns
|
||||
end
|
||||
|
||||
def find_type_for(type)
|
||||
type = remove_ns(type)
|
||||
|
||||
message = @wsdl.message(type)
|
||||
assert_not_nil message
|
||||
|
||||
part = message.at_xpath("./xmlns:part")
|
||||
assert_not_nil message
|
||||
|
||||
remove_ns(part["element"])
|
||||
end
|
||||
|
||||
def input
|
||||
type = @operation_node.at_xpath("./xmlns:input").attr("message")
|
||||
find_type_for(type)
|
||||
end
|
||||
|
||||
def go_input
|
||||
"types." + input
|
||||
end
|
||||
|
||||
def output
|
||||
type = @operation_node.at_xpath("./xmlns:output").attr("message")
|
||||
find_type_for(type)
|
||||
end
|
||||
|
||||
def go_output
|
||||
"types." + output
|
||||
end
|
||||
|
||||
def dump(io)
|
||||
io.print <<EOS
|
||||
type #{name}Body struct{
|
||||
Req *#{go_input} `xml:"urn:#{namespace} #{input},omitempty"`
|
||||
Res *#{go_output} `xml:"urn:#{namespace} #{output},omitempty"`
|
||||
Fault_ *soap.Fault `xml:"http://schemas.xmlsoap.org/soap/envelope/ Fault,omitempty"`
|
||||
}
|
||||
|
||||
func (b *#{name}Body) Fault() *soap.Fault { return b.Fault_ }
|
||||
|
||||
EOS
|
||||
|
||||
io.print "func %s(ctx context.Context, r soap.RoundTripper, req *%s) (*%s, error) {\n" % [name, go_input, go_output]
|
||||
io.print <<EOS
|
||||
var reqBody, resBody #{name}Body
|
||||
|
||||
reqBody.Req = req
|
||||
|
||||
if err := r.RoundTrip(ctx, &reqBody, &resBody); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return resBody.Res, nil
|
||||
EOS
|
||||
|
||||
io.print "}\n\n"
|
||||
end
|
||||
end
|
||||
|
||||
class WSDL
|
||||
attr_reader :xml
|
||||
|
||||
PATH = File.expand_path("../sdk", __FILE__)
|
||||
|
||||
def self.read(file)
|
||||
File.open(File.join(PATH, file))
|
||||
end
|
||||
|
||||
def initialize(xml)
|
||||
@xml = Nokogiri::XML.parse(xml)
|
||||
$target = @xml.root["targetNamespace"].split(":", 2)[1]
|
||||
|
||||
unless $namespaces.include? $target
|
||||
$namespaces.push $target
|
||||
end
|
||||
end
|
||||
|
||||
def validate_assumptions!
|
||||
schemas.each do |s|
|
||||
s.validate_assumptions!
|
||||
end
|
||||
end
|
||||
|
||||
def types(&blk)
|
||||
return to_enum(:types) unless block_given?
|
||||
|
||||
schemas.each do |s|
|
||||
s.types(&blk)
|
||||
end
|
||||
end
|
||||
|
||||
def schemas
|
||||
@schemas ||= @xml.xpath('.//xmlns:types/xsd:schema').map do |n|
|
||||
Schema.new(n.to_xml)
|
||||
end
|
||||
end
|
||||
|
||||
def operations
|
||||
@operations ||= @xml.xpath('.//xmlns:portType/xmlns:operation').map do |o|
|
||||
Operation.new(self, o)
|
||||
end
|
||||
end
|
||||
|
||||
def message(type)
|
||||
@messages ||= begin
|
||||
h = {}
|
||||
@xml.xpath('.//xmlns:message').each do |n|
|
||||
h[n.attr("name")] = n
|
||||
end
|
||||
h
|
||||
end
|
||||
|
||||
@messages[type]
|
||||
end
|
||||
|
||||
def peek
|
||||
types.
|
||||
sort_by { |x| x.name }.
|
||||
uniq { |x| x.name }.
|
||||
select { |x| x.name[0] == x.name[0].upcase }. # Only capitalized methods for now...
|
||||
each { |e| e.peek() }
|
||||
end
|
||||
|
||||
def self.header(name)
|
||||
return <<EOF
|
||||
/*
|
||||
Copyright (c) 2014-2017 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
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 #{name}
|
||||
|
||||
EOF
|
||||
end
|
||||
end
|
||||
1
vendor/github.com/vmware/govmomi/govc/.gitignore
generated
vendored
Normal file
1
vendor/github.com/vmware/govmomi/govc/.gitignore
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/govc*
|
||||
346
vendor/github.com/vmware/govmomi/govc/CHANGELOG.md
generated
vendored
Normal file
346
vendor/github.com/vmware/govmomi/govc/CHANGELOG.md
generated
vendored
Normal file
@@ -0,0 +1,346 @@
|
||||
# changelog
|
||||
|
||||
### 0.17.1 (2018-03-19)
|
||||
|
||||
* Avoid possible panic in QueryVirtualDiskInfo
|
||||
|
||||
* Add goreleaser to automate release process
|
||||
|
||||
* Fix dvs.portgroup.info filtering
|
||||
|
||||
### 0.17.0 (2018-02-28)
|
||||
|
||||
* The datastore cp and mv commands can target a different Datacenter and/or Datastore
|
||||
|
||||
* The datastore cp and mv commands now use VirtualDiskManager methods by default
|
||||
|
||||
* Add '-M' flag to vm.power command to use Datacenter.PowerOnMultiVM
|
||||
|
||||
* Add '-cluster' flag to license.assign command
|
||||
|
||||
* Add cluster vm override commands
|
||||
|
||||
* User server clock in session.ls
|
||||
|
||||
* Add session login and logout commands
|
||||
|
||||
* Add '-rescan-vmfs' option to host.storage.info
|
||||
|
||||
* Add datastore.disk inflate and shrink commands
|
||||
|
||||
* Add cluster.group and cluster.rule commands
|
||||
|
||||
* Add vm.upgrade command
|
||||
|
||||
* Add cpu + mem allocation support to vm.change
|
||||
|
||||
* Allow columns in password for guest login.
|
||||
|
||||
### 0.16.0 (2017-11-08)
|
||||
|
||||
* Add export.ovf command
|
||||
|
||||
* Add '-snapshot' and '-link' options to vm.clone
|
||||
|
||||
* Add vm.console command
|
||||
|
||||
* Add '-refresh' option to host.storage.info
|
||||
|
||||
* Add tasks and task.cancel commands
|
||||
|
||||
* The import.vmdk command now requires streamOptimized format
|
||||
|
||||
* Add view and filter support to object.collect command
|
||||
|
||||
* Add reboot option to host.shutdown
|
||||
|
||||
### 0.15.0 (2017-06-19)
|
||||
|
||||
* Remove FileAttr flags from guest.chmod command,
|
||||
chown functionality moved to its own command
|
||||
|
||||
* Add optional path to guest mktemp file methods
|
||||
|
||||
* Add guest.touch and guest.mv commands
|
||||
|
||||
* Add host.shutdown command
|
||||
|
||||
* Add option flags to host.autostart.add
|
||||
|
||||
* Add object.method command
|
||||
|
||||
* Add options.{ls,set} commands
|
||||
|
||||
### 0.14.0 (2017-04-08)
|
||||
|
||||
* Add find command
|
||||
|
||||
* Add '-wait' option to vm.ip to allow a non-waiting query
|
||||
|
||||
* Add datastore.disk.info command
|
||||
|
||||
* Add bash completion script
|
||||
|
||||
* Add metric commands: change, ls, info, sample, reset, interval.change, interval.info
|
||||
|
||||
### 0.13.0 (2017-03-02)
|
||||
|
||||
* Add vm.guest.tools command
|
||||
|
||||
* Add datastore.disk.create command
|
||||
|
||||
* Add datastore.vsan.dom.ls and datastore.vsan.dom.rm commands
|
||||
|
||||
* Add vm.disk.change command
|
||||
|
||||
* Add vm.rdm attach and ls commands
|
||||
|
||||
* Add '-n' option to vm.ip to wait for a specific NIC
|
||||
|
||||
* Add '-annotation' option to vm.create and vm.clone commands
|
||||
|
||||
* Add '-sync-time-with-host-' flag to vm.change command
|
||||
|
||||
* Add object.collect command (MOB for cli + Emacs)
|
||||
|
||||
### 0.12.1 (2016-12-19)
|
||||
|
||||
* Add '-f' flag to logs command
|
||||
|
||||
* Add storage support to vm.migrate
|
||||
|
||||
* Add support for file backed serialport devices
|
||||
|
||||
### 0.12.0 (2016-12-01)
|
||||
|
||||
* Add optional '-host' flag to datastore download/tail commands
|
||||
|
||||
* Support InjectOvfEnv without PowerOn when importing
|
||||
|
||||
* Support stdin as import options source
|
||||
|
||||
* Add basic NVME controller support
|
||||
|
||||
### 0.11.4 (2016-11-15)
|
||||
|
||||
* Add role create, remove, update, ls and usage commands
|
||||
|
||||
### 0.11.3 (2016-11-08)
|
||||
|
||||
* Add `-product-version` flag to dvs.create
|
||||
|
||||
* datastore.tail -f will exit without error if the file no longer exists
|
||||
|
||||
### 0.11.2 (2016-11-01)
|
||||
|
||||
* Add object.reload command
|
||||
|
||||
* Add ESX 5.5 support to host.account commands
|
||||
|
||||
### 0.11.1 (2016-10-27)
|
||||
|
||||
* Add support for VirtualApp in pool.change command
|
||||
|
||||
### 0.11.0 (2016-10-25)
|
||||
|
||||
* Add object.destroy and object.rename commands
|
||||
|
||||
* Remove datacenter.destroy command (use object.destroy instead)
|
||||
|
||||
* Remove folder.destroy command (use object.destroy instead)
|
||||
|
||||
* Rename folder.move_into -> object.mv
|
||||
|
||||
* Add dvs.portgroup.change command
|
||||
|
||||
* Add vlan flag to dvs.portgroup.add command
|
||||
|
||||
### 0.10.0 (2016-10-20)
|
||||
|
||||
* Add generated govc/USAGE.md
|
||||
|
||||
* Add host.date info and change commands
|
||||
|
||||
* Add session ls and rm commands
|
||||
|
||||
* Add `-tls-known-hosts` and `-tls-ca-certs` flags
|
||||
|
||||
* Add host.cert commands : info, csr, import
|
||||
|
||||
* Add about.cert command (similar to the Chrome Certificate Viewer)
|
||||
|
||||
* Add `-vspc-proxy` flag to device.serial.connect command
|
||||
|
||||
* Rename license.list -> license.ls, license.assigned.list -> license.assigned.ls
|
||||
|
||||
### 0.9.0 (2016-09-09)
|
||||
|
||||
* Add `-R` option to datastore.ls
|
||||
|
||||
* Add datastore.tail command
|
||||
|
||||
* Add vm.migrate command
|
||||
|
||||
* Add govc vm.register and vm.unregister commands
|
||||
|
||||
* Add govc vm snapshot commands: create, remove, revert, tree
|
||||
|
||||
* Add device.usb.add command
|
||||
|
||||
* Support stdin/stdout in datastore upload/download
|
||||
|
||||
* Add host.portgroup.change command
|
||||
|
||||
* Add host.portgroup.info command
|
||||
|
||||
* Add HostNetworkPolicy to host.vswitch.info
|
||||
|
||||
* Add `-json` support to host.vswitch.info command
|
||||
|
||||
* Support instance uuid in SearchFlag
|
||||
|
||||
* Add `-json` support to esxcli command
|
||||
|
||||
* Add `-unclaimed` flag to host.storage.info command
|
||||
|
||||
* Support Network mapping in import.{ova,ovf} commands
|
||||
|
||||
### 0.8.0 (2016-06-30)
|
||||
|
||||
* If username (`-u` / GOVC_USERNAME) is empty, attempt login via local ticket (Workstation)
|
||||
|
||||
* Add StoragePod support to govc folder.create
|
||||
|
||||
* Add `-folder` flag to datacenter.create command
|
||||
|
||||
* Logout when session persistence is disabled
|
||||
|
||||
* Add `-L` flag to ls command for resolving by managed object reference
|
||||
|
||||
* Add `-i` flag to ls command for listing the managed object reference
|
||||
|
||||
* Add vm.markasvm command
|
||||
|
||||
* Add vm.markastemplate command
|
||||
|
||||
### 0.7.1 (2016-06-03)
|
||||
|
||||
* Fix datastore.{upload,download} against VirtualCenter
|
||||
|
||||
### 0.7.0 (2016-06-02)
|
||||
|
||||
* Add `-require` flag to version command
|
||||
|
||||
* Add support for local type in the datastore.create command
|
||||
|
||||
* Add `-namespace` option to datastore.mkdir and datastore.rm to create/remove namespaces on VSANs
|
||||
|
||||
* Add host.service command
|
||||
|
||||
* Add host.storage.mark command
|
||||
|
||||
* Add `-rescan` option to host.storage.info command
|
||||
|
||||
### 0.6.0 (2016-04-29)
|
||||
|
||||
* Add folder commands: info, create, destroy, rename, moveinto
|
||||
|
||||
* Add datastore.info command
|
||||
|
||||
* Add `-a` and `-v4` flags to vm.ip command
|
||||
|
||||
* Add host.account.{create,update,remove} commands
|
||||
|
||||
* Add env command
|
||||
|
||||
* Add vm.clone command
|
||||
|
||||
### 0.5.0 (2016-03-30)
|
||||
|
||||
* Add dvs.portgroup.info command
|
||||
|
||||
* Add `-folder` flag to vm.create command
|
||||
|
||||
* Add `-dump` flag to OutputFlag
|
||||
|
||||
* Add `-f` flag to events command
|
||||
|
||||
* Add `-mode` flag to vm.disk.create command
|
||||
|
||||
* Add `-net` flag to device.info command
|
||||
|
||||
* Add `-eager` and `-thick` options to vm.create command
|
||||
|
||||
### 0.4.0 (2016-02-26)
|
||||
|
||||
* Add support for placement in datastore cluster to vm.create command
|
||||
|
||||
* Add support for creating new disks in vm.create command
|
||||
|
||||
* Add `-p` and `-a` options to govc datastore.ls command
|
||||
|
||||
### 0.3.0 (2016-01-16)
|
||||
|
||||
* Add permissions.{ls,set,remove} commands
|
||||
|
||||
* Add datastore.{create,remove} commands.
|
||||
The new create command supports both creating NAS and VMFS datastores.
|
||||
|
||||
* Add dvs.{create,add} and dvs.portgroup.add commands
|
||||
|
||||
* Add host.vnic.{service,info} commands
|
||||
|
||||
* Add cluster.{create,change,add} commands
|
||||
|
||||
* Add host.{disconnect,reconnect,remove,maintenance.enter,maintenance.exit} commands
|
||||
|
||||
* Add license.decode, license.assigned.list and license.assign commands
|
||||
|
||||
* Add firewall.ruleset.find command
|
||||
|
||||
* Add logs, logs.ls and logs.download commands
|
||||
|
||||
* Add support for LoginExtensionByCertificate with new `-cert` and `-key` flags
|
||||
|
||||
* Add govc extension.{info,register,unregister,setcert} commands
|
||||
|
||||
* Add govc vapp.{info,destroy,power} commands
|
||||
|
||||
### 0.2.0 (2015-09-15)
|
||||
|
||||
* The `vm.power` guest `-s` and `-r` options will fallback to hard `-off` / `-reset` if tools is unavailable and `-force` flag is given
|
||||
|
||||
* Add `PowerOn, InjectOvfEnv, WaitForIP` options to `import.ovf` and `import.ova` option spec file
|
||||
|
||||
* Add `import.spec` to produce an example json document
|
||||
|
||||
* Add `-options` to `import.ovf` and `import.ova`
|
||||
|
||||
* Add `-folder` to `import.ovf` and `import.ova`
|
||||
|
||||
* Add `fields` command to manage custom fields
|
||||
|
||||
* Add `datastore.info` command
|
||||
|
||||
* Add `events` command
|
||||
|
||||
* Add `-net.address` (Hardware Address) option to `vm.change` and `vm.create`
|
||||
|
||||
* Add `host.add` command to add host to datacenter.
|
||||
|
||||
* Add `GOVC_USERNAME` and `GOVC_PASSWORD` to allow overriding username and/or
|
||||
password (used when they contain special characters that prevent them from
|
||||
being embedded in the URL).
|
||||
|
||||
* Add `-e' (ExtraConfig) option to `vm.change` and `vm.info`
|
||||
|
||||
* Retry twice on temporary network errors.
|
||||
|
||||
* Add `host.autostart` commands to manage VM autostart.
|
||||
|
||||
* Add `-persist-session` flag to control whether or not the session is
|
||||
persisted to disk (defaults to true).
|
||||
|
||||
### 0.1.0 (2015-03-17)
|
||||
|
||||
Prior to this version the changes to govc's command set were not documented.
|
||||
211
vendor/github.com/vmware/govmomi/govc/README.md
generated
vendored
Normal file
211
vendor/github.com/vmware/govmomi/govc/README.md
generated
vendored
Normal file
@@ -0,0 +1,211 @@
|
||||
# govc
|
||||
|
||||
govc is a vSphere CLI built on top of govmomi.
|
||||
|
||||
The CLI is designed to be a user friendly CLI alternative to the GUI and well suited for automation tasks.
|
||||
It also acts as a [test harness](test) for the govmomi APIs and provides working examples of how to use the APIs.
|
||||
|
||||
## Installation
|
||||
|
||||
You can find prebuilt govc binaries on the [releases page](https://github.com/vmware/govmomi/releases).
|
||||
|
||||
Download and install a binary locally like this:
|
||||
|
||||
``` console
|
||||
% curl -L $URL_TO_BINARY | gunzip > /usr/local/bin/govc
|
||||
% chmod +x /usr/local/bin/govc
|
||||
```
|
||||
|
||||
### Source
|
||||
|
||||
To build govc from source, first install the [Go toolchain](https://golang.org/dl/).
|
||||
|
||||
Make sure to set the environment variable [GOPATH](https://github.com/golang/go/wiki/SettingGOPATH).
|
||||
|
||||
You can then install the latest govc from github using:
|
||||
|
||||
``` console
|
||||
% go get -u github.com/vmware/govmomi/govc
|
||||
```
|
||||
|
||||
Make sure `$GOPATH/bin` is in your `PATH` to use the version installed from source.
|
||||
|
||||
If you've made local modifications to the repository at `$GOPATH/src/github.com/vmware/govmomi`, you can install using:
|
||||
|
||||
``` console
|
||||
% go install github.com/vmware/govmomi/govc
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
For the complete list of commands and flags, refer to the [USAGE](USAGE.md) document.
|
||||
|
||||
Common flags include:
|
||||
|
||||
* `-u`: ESXi or vCenter URL (ex: `user:pass@host`)
|
||||
* `-debug`: Trace requests and responses (to `~/.govmomi/debug`)
|
||||
|
||||
Managed entities can be referred to by their absolute path or by their relative
|
||||
path. For example, when specifying a datastore to use for a subcommand, you can
|
||||
either specify it as `/mydatacenter/datastore/mydatastore`, or as
|
||||
`mydatastore`. If you're not sure about the name of the datastore, or even the
|
||||
full path to the datastore, you can specify a pattern to match. Both
|
||||
`/*center/*/my*` (absolute) and `my*store` (relative) will resolve to the same
|
||||
datastore, given there are no other datastores that match those globs.
|
||||
|
||||
The relative path in this example can only be used if the command can
|
||||
umambigously resolve a datacenter to use as origin for the query. If no
|
||||
datacenter is specified, govc defaults to the only datacenter, if there is only
|
||||
one. The datacenter itself can be specified as a pattern as well, enabling the
|
||||
following arguments: `-dc='my*' -ds='*store'`. The datastore pattern is looked
|
||||
up and matched relative to the datacenter which itself is specified as a
|
||||
pattern.
|
||||
|
||||
Besides specifying managed entities as arguments, they can also be specified
|
||||
using environment variables. The following environment variables are used by govc
|
||||
to set defaults:
|
||||
|
||||
* `GOVC_URL`: URL of ESXi or vCenter instance to connect to.
|
||||
|
||||
The URL scheme defaults to `https` and the URL path defaults to `/sdk`.
|
||||
This means that specifying `user:pass@host` is equivalent to
|
||||
`https://user:pass@host/sdk`.
|
||||
|
||||
If password include special characters like `#` or `:` you can use
|
||||
`GOVC_USERNAME` and `GOVC_PASSWORD` to have a simple `GOVC_URL`
|
||||
|
||||
When using govc against VMware Workstation, GOVC_URL can be set to "localhost"
|
||||
without a user or pass, in which case local ticket based authentication is used.
|
||||
|
||||
* `GOVC_USERNAME`: USERNAME to use if not specified in GOVC_URL.
|
||||
|
||||
* `GOVC_PASSWORD`: PASSWORD to use if not specified in GOVC_URL.
|
||||
|
||||
* `GOVC_TLS_CA_CERTS`: Override system root certificate authorities.
|
||||
|
||||
``` console
|
||||
$ export GOVC_TLS_CA_CERTS=~/.govc_ca.crt
|
||||
# Use path separator to specify multiple files:
|
||||
$ export GOVC_TLS_CA_CERTS=~/ca-certificates/bar.crt:~/ca-certificates/foo.crt
|
||||
```
|
||||
|
||||
* `GOVC_TLS_KNOWN_HOSTS`: File(s) for thumbprint based certificate verification.
|
||||
|
||||
Thumbprint based verification can be used in addition to or as an alternative to
|
||||
`GOVC_TLS_CA_CERTS` for self-signed certificates. Example:
|
||||
|
||||
``` console
|
||||
$ export GOVC_TLS_KNOWN_HOSTS=~/.govc_known_hosts
|
||||
$ govc about.cert -u host -k -thumbprint | tee -a $GOVC_TLS_KNOWN_HOSTS
|
||||
$ govc about -u user:pass@host
|
||||
```
|
||||
|
||||
* `GOVC_TLS_HANDSHAKE_TIMEOUT`: Limits the time spent performing the TLS handshake.
|
||||
|
||||
* `GOVC_INSECURE`: Disable certificate verification.
|
||||
|
||||
This option sets Go's `tls.Config.InsecureSkipVerify` flag and is false by default.
|
||||
Quoting https://golang.org/pkg/crypto/tls/#Config:
|
||||
> `InsecureSkipVerify` controls whether a client verifies the
|
||||
> server's certificate chain and host name.
|
||||
>
|
||||
> If `InsecureSkipVerify` is true, TLS accepts any certificate
|
||||
> presented by the server and any host name in that certificate.
|
||||
>
|
||||
> In this mode, TLS is susceptible to man-in-the-middle attacks.
|
||||
> This should be used only for testing.
|
||||
|
||||
* `GOVC_DATACENTER`
|
||||
|
||||
* `GOVC_DATASTORE`
|
||||
|
||||
* `GOVC_NETWORK`
|
||||
|
||||
* `GOVC_RESOURCE_POOL`
|
||||
|
||||
* `GOVC_HOST`
|
||||
|
||||
* `GOVC_GUEST_LOGIN`: Guest credentials for guest operations
|
||||
|
||||
* `GOVC_VIM_NAMESPACE`: Vim namespace defaults to `urn:vim25`
|
||||
|
||||
* `GOVC_VIM_VERSION`: Vim version defaults to `6.0`
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Environment variables
|
||||
|
||||
If you're using environment variables to set `GOVC_URL`, verify the values are set as expected:
|
||||
|
||||
``` console
|
||||
% govc env
|
||||
```
|
||||
|
||||
### Connection issues
|
||||
|
||||
Check your proxy settings:
|
||||
|
||||
``` console
|
||||
% env | grep -i https_proxy
|
||||
```
|
||||
|
||||
Test connection using curl:
|
||||
``` console
|
||||
% curl --verbose -k -X POST https://x.x.x.x/sdk
|
||||
```
|
||||
|
||||
### MSYS2 (Windows)
|
||||
|
||||
Inventory path arguments with a leading '/' are subject
|
||||
to [Posix path conversion](http://www.mingw.org/wiki/Posix_path_conversion).
|
||||
|
||||
## Examples
|
||||
|
||||
Several examples are embedded in the govc command [help](USAGE.md)
|
||||
|
||||
* [Upload ssh public key to a VM](examples/lib/ssh.sh)
|
||||
|
||||
* [Create a CoreOS VM](https://github.com/vmware/govmomi/blob/master/toolbox/toolbox-test.sh)
|
||||
|
||||
* [Create a Debian VM](https://github.com/kubernetes/kubernetes/tree/master/cluster/vsphere)
|
||||
|
||||
* [Create a Windows VM](https://github.com/dougm/govc-windows-box/blob/master/provision-esx.sh)
|
||||
|
||||
* [Create an ESX VM](../scripts/vcsa/create-esxi-vm.sh)
|
||||
|
||||
* [Create a vCenter VM](../scripts/vcsa/create-vcsa-vm.sh)
|
||||
|
||||
* [Create a Cluster](../scripts/vcsa/create-cluster.sh)
|
||||
|
||||
## Status
|
||||
|
||||
Changes to the cli are subject to [semantic versioning](http://semver.org).
|
||||
|
||||
Refer to the [CHANGELOG](CHANGELOG.md) for version to version changes.
|
||||
|
||||
When new govc commands or flags are added, the PATCH version will be incremented. This enables you to require a minimum
|
||||
version from within a script, for example:
|
||||
|
||||
``` console
|
||||
% govc version -require 0.14
|
||||
```
|
||||
|
||||
## Projects using govc
|
||||
|
||||
* [Emacs govc package](./emacs)
|
||||
|
||||
* [Kubernetes vSphere Provider](https://github.com/kubernetes/kubernetes/tree/master/cluster/vsphere)
|
||||
|
||||
* [VMware VIC Engine](https://github.com/vmware/vic)
|
||||
|
||||
* [vSphere Docker Volume Service](https://github.com/vmware/docker-volume-vsphere)
|
||||
|
||||
* [golang/build](https://github.com/golang/build)
|
||||
|
||||
## Related projects
|
||||
|
||||
* [rvc](https://github.com/vmware/rvc)
|
||||
|
||||
## License
|
||||
|
||||
govc is available under the [Apache 2 license](../LICENSE).
|
||||
3747
vendor/github.com/vmware/govmomi/govc/USAGE.md
generated
vendored
Normal file
3747
vendor/github.com/vmware/govmomi/govc/USAGE.md
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
120
vendor/github.com/vmware/govmomi/govc/about/cert.go
generated
vendored
Normal file
120
vendor/github.com/vmware/govmomi/govc/about/cert.go
generated
vendored
Normal file
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
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 about
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/pem"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
"github.com/vmware/govmomi/object"
|
||||
"github.com/vmware/govmomi/vim25/soap"
|
||||
)
|
||||
|
||||
type cert struct {
|
||||
*flags.ClientFlag
|
||||
*flags.OutputFlag
|
||||
|
||||
show bool
|
||||
thumbprint bool
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("about.cert", &cert{})
|
||||
}
|
||||
|
||||
func (cmd *cert) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.ClientFlag, ctx = flags.NewClientFlag(ctx)
|
||||
cmd.ClientFlag.Register(ctx, f)
|
||||
|
||||
cmd.OutputFlag, ctx = flags.NewOutputFlag(ctx)
|
||||
cmd.OutputFlag.Register(ctx, f)
|
||||
|
||||
f.BoolVar(&cmd.show, "show", false, "Show PEM encoded server certificate only")
|
||||
f.BoolVar(&cmd.thumbprint, "thumbprint", false, "Output host hash and thumbprint only")
|
||||
}
|
||||
|
||||
func (cmd *cert) Description() string {
|
||||
return `Display TLS certificate info for HOST.
|
||||
|
||||
If the HOST certificate cannot be verified, about.cert will return with exit code 60 (as curl does).
|
||||
If the '-k' flag is provided, about.cert will return with exit code 0 in this case.
|
||||
The SHA1 thumbprint can also be used as '-thumbprint' for the 'host.add' and 'cluster.add' commands.
|
||||
|
||||
Examples:
|
||||
govc about.cert -k -json | jq -r .ThumbprintSHA1
|
||||
govc about.cert -k -show | sudo tee /usr/local/share/ca-certificates/host.crt
|
||||
govc about.cert -k -thumbprint | tee -a ~/.govmomi/known_hosts`
|
||||
}
|
||||
|
||||
func (cmd *cert) Process(ctx context.Context) error {
|
||||
if err := cmd.ClientFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := cmd.OutputFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type certResult struct {
|
||||
cmd *cert
|
||||
info object.HostCertificateInfo
|
||||
}
|
||||
|
||||
func (r *certResult) Write(w io.Writer) error {
|
||||
if r.cmd.show {
|
||||
return pem.Encode(w, &pem.Block{Type: "CERTIFICATE", Bytes: r.info.Certificate.Raw})
|
||||
}
|
||||
|
||||
if r.cmd.thumbprint {
|
||||
u := r.cmd.URLWithoutPassword()
|
||||
_, err := fmt.Fprintf(w, "%s %s\n", u.Host, r.info.ThumbprintSHA1)
|
||||
return err
|
||||
}
|
||||
|
||||
return r.cmd.WriteResult(&r.info)
|
||||
}
|
||||
|
||||
func (cmd *cert) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
u := cmd.URLWithoutPassword()
|
||||
c := soap.NewClient(u, false)
|
||||
t := c.Client.Transport.(*http.Transport)
|
||||
r := certResult{cmd: cmd}
|
||||
|
||||
if err := cmd.SetRootCAs(c); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := r.info.FromURL(u, t.TLSClientConfig); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if r.info.Err != nil && r.cmd.IsSecure() {
|
||||
cmd.Out = os.Stderr
|
||||
// using same exit code as curl:
|
||||
defer os.Exit(60)
|
||||
}
|
||||
|
||||
return r.Write(cmd.Out)
|
||||
}
|
||||
116
vendor/github.com/vmware/govmomi/govc/about/command.go
generated
vendored
Normal file
116
vendor/github.com/vmware/govmomi/govc/about/command.go
generated
vendored
Normal file
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
Copyright (c) 2014-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 about
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"text/tabwriter"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
type about struct {
|
||||
*flags.ClientFlag
|
||||
*flags.OutputFlag
|
||||
|
||||
Long bool
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("about", &about{})
|
||||
}
|
||||
|
||||
func (cmd *about) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.ClientFlag, ctx = flags.NewClientFlag(ctx)
|
||||
cmd.ClientFlag.Register(ctx, f)
|
||||
|
||||
cmd.OutputFlag, ctx = flags.NewOutputFlag(ctx)
|
||||
cmd.OutputFlag.Register(ctx, f)
|
||||
|
||||
f.BoolVar(&cmd.Long, "l", false, "Include service content")
|
||||
}
|
||||
|
||||
func (cmd *about) Description() string {
|
||||
return `Display About info for HOST.
|
||||
|
||||
System information including the name, type, version, and build number.
|
||||
|
||||
Examples:
|
||||
govc about
|
||||
govc about -json | jq -r .About.ProductLineId`
|
||||
}
|
||||
|
||||
func (cmd *about) Process(ctx context.Context) error {
|
||||
if err := cmd.ClientFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := cmd.OutputFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *about) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
c, err := cmd.Client()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
res := infoResult{
|
||||
a: &c.ServiceContent.About,
|
||||
}
|
||||
|
||||
if cmd.Long {
|
||||
res.Content = &c.ServiceContent
|
||||
} else {
|
||||
res.About = res.a
|
||||
}
|
||||
|
||||
return cmd.WriteResult(&res)
|
||||
}
|
||||
|
||||
type infoResult struct {
|
||||
Content *types.ServiceContent `json:",omitempty"`
|
||||
About *types.AboutInfo `json:",omitempty"`
|
||||
a *types.AboutInfo
|
||||
}
|
||||
|
||||
func (r *infoResult) Write(w io.Writer) error {
|
||||
tw := tabwriter.NewWriter(w, 2, 0, 2, ' ', 0)
|
||||
fmt.Fprintf(tw, "Name:\t%s\n", r.a.Name)
|
||||
fmt.Fprintf(tw, "Vendor:\t%s\n", r.a.Vendor)
|
||||
fmt.Fprintf(tw, "Version:\t%s\n", r.a.Version)
|
||||
fmt.Fprintf(tw, "Build:\t%s\n", r.a.Build)
|
||||
fmt.Fprintf(tw, "OS type:\t%s\n", r.a.OsType)
|
||||
fmt.Fprintf(tw, "API type:\t%s\n", r.a.ApiType)
|
||||
fmt.Fprintf(tw, "API version:\t%s\n", r.a.ApiVersion)
|
||||
fmt.Fprintf(tw, "Product ID:\t%s\n", r.a.ProductLineId)
|
||||
fmt.Fprintf(tw, "UUID:\t%s\n", r.a.InstanceUuid)
|
||||
return tw.Flush()
|
||||
}
|
||||
|
||||
func (r *infoResult) Dump() interface{} {
|
||||
if r.Content != nil {
|
||||
return r.Content
|
||||
}
|
||||
return r.About
|
||||
}
|
||||
37
vendor/github.com/vmware/govmomi/govc/build.sh
generated
vendored
Executable file
37
vendor/github.com/vmware/govmomi/govc/build.sh
generated
vendored
Executable file
@@ -0,0 +1,37 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
git_version=$(git describe --dirty)
|
||||
if [[ $git_version == *-dirty ]] ; then
|
||||
echo 'Working tree is dirty.'
|
||||
echo 'NOTE: This script is meant for building govc releases via release.sh'
|
||||
echo 'To build govc from source see: https://github.com/vmware/govmomi/blob/master/govc/README.md#source'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
ldflags="-X github.com/vmware/govmomi/govc/version.gitVersion=${git_version}"
|
||||
|
||||
BUILD_OS=${BUILD_OS:-darwin linux windows freebsd}
|
||||
BUILD_ARCH=${BUILD_ARCH:-386 amd64}
|
||||
|
||||
for os in ${BUILD_OS}; do
|
||||
export GOOS="${os}"
|
||||
for arch in ${BUILD_ARCH}; do
|
||||
export GOARCH="${arch}"
|
||||
|
||||
out="govc_${os}_${arch}"
|
||||
if [ "${os}" == "windows" ]; then
|
||||
out="${out}.exe"
|
||||
fi
|
||||
|
||||
set -x
|
||||
go build \
|
||||
-o="${out}" \
|
||||
-pkgdir="./_pkg" \
|
||||
-compiler='gc' \
|
||||
-ldflags="${ldflags}" \
|
||||
github.com/vmware/govmomi/govc &
|
||||
set +x
|
||||
done
|
||||
done
|
||||
|
||||
wait
|
||||
179
vendor/github.com/vmware/govmomi/govc/cli/command.go
generated
vendored
Normal file
179
vendor/github.com/vmware/govmomi/govc/cli/command.go
generated
vendored
Normal file
@@ -0,0 +1,179 @@
|
||||
/*
|
||||
Copyright (c) 2014-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 cli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"sort"
|
||||
"text/tabwriter"
|
||||
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
type HasFlags interface {
|
||||
// Register may be called more than once and should be idempotent.
|
||||
Register(ctx context.Context, f *flag.FlagSet)
|
||||
|
||||
// Process may be called more than once and should be idempotent.
|
||||
Process(ctx context.Context) error
|
||||
}
|
||||
|
||||
type Command interface {
|
||||
HasFlags
|
||||
|
||||
Run(ctx context.Context, f *flag.FlagSet) error
|
||||
}
|
||||
|
||||
func generalHelp(w io.Writer) {
|
||||
fmt.Fprintf(w, "Usage of %s:\n", os.Args[0])
|
||||
|
||||
cmds := []string{}
|
||||
for name := range commands {
|
||||
cmds = append(cmds, name)
|
||||
}
|
||||
|
||||
sort.Strings(cmds)
|
||||
|
||||
for _, name := range cmds {
|
||||
fmt.Fprintf(w, " %s\n", name)
|
||||
}
|
||||
}
|
||||
|
||||
func commandHelp(w io.Writer, name string, cmd Command, f *flag.FlagSet) {
|
||||
type HasUsage interface {
|
||||
Usage() string
|
||||
}
|
||||
|
||||
fmt.Fprintf(w, "Usage: %s %s [OPTIONS]", os.Args[0], name)
|
||||
if u, ok := cmd.(HasUsage); ok {
|
||||
fmt.Fprintf(w, " %s", u.Usage())
|
||||
}
|
||||
fmt.Fprintf(w, "\n")
|
||||
|
||||
type HasDescription interface {
|
||||
Description() string
|
||||
}
|
||||
|
||||
if u, ok := cmd.(HasDescription); ok {
|
||||
fmt.Fprintf(w, "\n%s\n", u.Description())
|
||||
}
|
||||
|
||||
n := 0
|
||||
f.VisitAll(func(_ *flag.Flag) {
|
||||
n += 1
|
||||
})
|
||||
|
||||
if n > 0 {
|
||||
fmt.Fprintf(w, "\nOptions:\n")
|
||||
tw := tabwriter.NewWriter(w, 2, 0, 2, ' ', 0)
|
||||
f.VisitAll(func(f *flag.Flag) {
|
||||
fmt.Fprintf(tw, "\t-%s=%s\t%s\n", f.Name, f.DefValue, f.Usage)
|
||||
})
|
||||
tw.Flush()
|
||||
}
|
||||
}
|
||||
|
||||
func clientLogout(ctx context.Context, cmd Command) error {
|
||||
type logout interface {
|
||||
Logout(context.Context) error
|
||||
}
|
||||
|
||||
if l, ok := cmd.(logout); ok {
|
||||
return l.Logout(ctx)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func Run(args []string) int {
|
||||
hw := os.Stderr
|
||||
rc := 1
|
||||
hwrc := func(arg string) {
|
||||
if arg == "-h" {
|
||||
hw = os.Stdout
|
||||
rc = 0
|
||||
}
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
if len(args) == 0 {
|
||||
generalHelp(hw)
|
||||
return rc
|
||||
}
|
||||
|
||||
// Look up real command name in aliases table.
|
||||
name, ok := aliases[args[0]]
|
||||
if !ok {
|
||||
name = args[0]
|
||||
}
|
||||
|
||||
cmd, ok := commands[name]
|
||||
if !ok {
|
||||
hwrc(name)
|
||||
generalHelp(hw)
|
||||
return rc
|
||||
}
|
||||
|
||||
fs := flag.NewFlagSet("", flag.ContinueOnError)
|
||||
fs.SetOutput(ioutil.Discard)
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
if id := os.Getenv("GOVC_OPERATION_ID"); id != "" {
|
||||
ctx = context.WithValue(ctx, types.ID{}, id)
|
||||
}
|
||||
|
||||
cmd.Register(ctx, fs)
|
||||
|
||||
if err = fs.Parse(args[1:]); err != nil {
|
||||
goto error
|
||||
}
|
||||
|
||||
if err = cmd.Process(ctx); err != nil {
|
||||
goto error
|
||||
}
|
||||
|
||||
if err = cmd.Run(ctx, fs); err != nil {
|
||||
goto error
|
||||
}
|
||||
|
||||
if err = clientLogout(ctx, cmd); err != nil {
|
||||
goto error
|
||||
}
|
||||
|
||||
return 0
|
||||
|
||||
error:
|
||||
if err == flag.ErrHelp {
|
||||
if len(args) == 2 {
|
||||
hwrc(args[1])
|
||||
}
|
||||
commandHelp(hw, args[0], cmd, fs)
|
||||
} else {
|
||||
fmt.Fprintf(os.Stderr, "%s: %s\n", os.Args[0], err)
|
||||
}
|
||||
|
||||
_ = clientLogout(ctx, cmd)
|
||||
|
||||
return rc
|
||||
}
|
||||
33
vendor/github.com/vmware/govmomi/govc/cli/register.go
generated
vendored
Normal file
33
vendor/github.com/vmware/govmomi/govc/cli/register.go
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
Copyright (c) 2014-2015 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package cli
|
||||
|
||||
var commands = map[string]Command{}
|
||||
|
||||
var aliases = map[string]string{}
|
||||
|
||||
func Register(name string, c Command) {
|
||||
commands[name] = c
|
||||
}
|
||||
|
||||
func Alias(name string, alias string) {
|
||||
aliases[alias] = name
|
||||
}
|
||||
|
||||
func Commands() map[string]Command {
|
||||
return commands
|
||||
}
|
||||
114
vendor/github.com/vmware/govmomi/govc/cluster/add.go
generated
vendored
Normal file
114
vendor/github.com/vmware/govmomi/govc/cluster/add.go
generated
vendored
Normal file
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
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 cluster
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
"github.com/vmware/govmomi/object"
|
||||
)
|
||||
|
||||
type add struct {
|
||||
*flags.ClusterFlag
|
||||
*flags.HostConnectFlag
|
||||
|
||||
connect bool
|
||||
license string
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("cluster.add", &add{})
|
||||
}
|
||||
|
||||
func (cmd *add) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.ClusterFlag, ctx = flags.NewClusterFlag(ctx)
|
||||
cmd.ClusterFlag.Register(ctx, f)
|
||||
|
||||
cmd.HostConnectFlag, ctx = flags.NewHostConnectFlag(ctx)
|
||||
cmd.HostConnectFlag.Register(ctx, f)
|
||||
|
||||
f.StringVar(&cmd.license, "license", "", "Assign license key")
|
||||
|
||||
f.BoolVar(&cmd.connect, "connect", true, "Immediately connect to host")
|
||||
}
|
||||
|
||||
func (cmd *add) Process(ctx context.Context) error {
|
||||
if err := cmd.ClusterFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := cmd.HostConnectFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
if cmd.HostName == "" {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
if cmd.UserName == "" {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
if cmd.Password == "" {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *add) Description() string {
|
||||
return `Add HOST to CLUSTER.
|
||||
|
||||
The host is added to the cluster specified by the 'cluster' flag.
|
||||
|
||||
Examples:
|
||||
thumbprint=$(govc about.cert -k -u host.example.com -thumbprint | awk '{print $2}')
|
||||
govc cluster.add -cluster ClusterA -hostname host.example.com -username root -password pass -thumbprint $thumbprint
|
||||
govc cluster.add -cluster ClusterB -hostname 10.0.6.1 -username root -password pass -noverify`
|
||||
}
|
||||
|
||||
func (cmd *add) Add(ctx context.Context, cluster *object.ClusterComputeResource) error {
|
||||
spec := cmd.HostConnectSpec
|
||||
|
||||
var license *string
|
||||
if cmd.license != "" {
|
||||
license = &cmd.license
|
||||
}
|
||||
|
||||
task, err := cluster.AddHost(ctx, cmd.Spec(cluster.Client()), cmd.connect, license, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logger := cmd.ProgressLogger(fmt.Sprintf("adding %s to cluster %s... ", spec.HostName, cluster.InventoryPath))
|
||||
defer logger.Wait()
|
||||
|
||||
_, err = task.WaitForResult(ctx, logger)
|
||||
return err
|
||||
}
|
||||
|
||||
func (cmd *add) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
if f.NArg() != 0 {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
|
||||
cluster, err := cmd.Cluster()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return cmd.Fault(cmd.Add(ctx, cluster))
|
||||
}
|
||||
116
vendor/github.com/vmware/govmomi/govc/cluster/change.go
generated
vendored
Normal file
116
vendor/github.com/vmware/govmomi/govc/cluster/change.go
generated
vendored
Normal file
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
Copyright (c) 2015-2017 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package cluster
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"strings"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
func DrsBehaviorUsage() string {
|
||||
drsModes := []string{
|
||||
string(types.DrsBehaviorManual),
|
||||
string(types.DrsBehaviorPartiallyAutomated),
|
||||
string(types.DrsBehaviorFullyAutomated),
|
||||
}
|
||||
|
||||
return "DRS behavior for virtual machines: " + strings.Join(drsModes, ", ")
|
||||
}
|
||||
|
||||
type change struct {
|
||||
*flags.DatacenterFlag
|
||||
|
||||
types.ClusterConfigSpecEx
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("cluster.change", &change{})
|
||||
}
|
||||
|
||||
func (cmd *change) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.DatacenterFlag, ctx = flags.NewDatacenterFlag(ctx)
|
||||
cmd.DatacenterFlag.Register(ctx, f)
|
||||
|
||||
cmd.DrsConfig = new(types.ClusterDrsConfigInfo)
|
||||
cmd.DasConfig = new(types.ClusterDasConfigInfo)
|
||||
cmd.VsanConfig = new(types.VsanClusterConfigInfo)
|
||||
cmd.VsanConfig.DefaultConfig = new(types.VsanClusterConfigInfoHostDefaultInfo)
|
||||
|
||||
// DRS
|
||||
f.Var(flags.NewOptionalBool(&cmd.DrsConfig.Enabled), "drs-enabled", "Enable DRS")
|
||||
|
||||
f.StringVar((*string)(&cmd.DrsConfig.DefaultVmBehavior), "drs-mode", "", DrsBehaviorUsage())
|
||||
|
||||
// HA
|
||||
f.Var(flags.NewOptionalBool(&cmd.DasConfig.Enabled), "ha-enabled", "Enable HA")
|
||||
|
||||
// vSAN
|
||||
f.Var(flags.NewOptionalBool(&cmd.VsanConfig.Enabled), "vsan-enabled", "Enable vSAN")
|
||||
f.Var(flags.NewOptionalBool(&cmd.VsanConfig.DefaultConfig.AutoClaimStorage), "vsan-autoclaim", "Autoclaim storage on cluster hosts")
|
||||
}
|
||||
|
||||
func (cmd *change) Process(ctx context.Context) error {
|
||||
if err := cmd.DatacenterFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *change) Usage() string {
|
||||
return "CLUSTER..."
|
||||
}
|
||||
|
||||
func (cmd *change) Description() string {
|
||||
return `Change configuration of the given clusters.
|
||||
|
||||
Examples:
|
||||
govc cluster.change -drs-enabled -vsan-enabled -vsan-autoclaim ClusterA
|
||||
govc cluster.change -drs-enabled=false ClusterB`
|
||||
}
|
||||
|
||||
func (cmd *change) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
finder, err := cmd.Finder()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, path := range f.Args() {
|
||||
clusters, err := finder.ClusterComputeResourceList(ctx, path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, cluster := range clusters {
|
||||
task, err := cluster.Reconfigure(ctx, &cmd.ClusterConfigSpecEx, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = task.WaitForResult(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
78
vendor/github.com/vmware/govmomi/govc/cluster/create.go
generated
vendored
Normal file
78
vendor/github.com/vmware/govmomi/govc/cluster/create.go
generated
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
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 cluster
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
type create struct {
|
||||
*flags.FolderFlag
|
||||
|
||||
types.ClusterConfigSpecEx
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("cluster.create", &create{})
|
||||
}
|
||||
|
||||
func (cmd *create) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.FolderFlag, ctx = flags.NewFolderFlag(ctx)
|
||||
cmd.FolderFlag.Register(ctx, f)
|
||||
}
|
||||
|
||||
func (cmd *create) Usage() string {
|
||||
return "CLUSTER"
|
||||
}
|
||||
|
||||
func (cmd *create) Description() string {
|
||||
return `Create CLUSTER in datacenter.
|
||||
|
||||
The cluster is added to the folder specified by the 'folder' flag. If not given,
|
||||
this defaults to the host folder in the specified or default datacenter.
|
||||
|
||||
Examples:
|
||||
govc cluster.create ClusterA
|
||||
govc cluster.create -folder /dc2/test-folder ClusterB`
|
||||
}
|
||||
|
||||
func (cmd *create) Process(ctx context.Context) error {
|
||||
if err := cmd.FolderFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *create) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
if f.NArg() != 1 {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
|
||||
folder, err := cmd.FolderOrDefault("host")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = folder.CreateCluster(ctx, f.Arg(0), cmd.ClusterConfigSpecEx)
|
||||
|
||||
return err
|
||||
}
|
||||
75
vendor/github.com/vmware/govmomi/govc/cluster/group/change.go
generated
vendored
Normal file
75
vendor/github.com/vmware/govmomi/govc/cluster/group/change.go
generated
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
Copyright (c) 2017 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package group
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
type change struct {
|
||||
*InfoFlag
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("cluster.group.change", &change{})
|
||||
}
|
||||
|
||||
func (cmd *change) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.InfoFlag, ctx = NewInfoFlag(ctx)
|
||||
cmd.InfoFlag.Register(ctx, f)
|
||||
}
|
||||
|
||||
func (cmd *change) Process(ctx context.Context) error {
|
||||
if cmd.name == "" {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
return cmd.InfoFlag.Process(ctx)
|
||||
}
|
||||
|
||||
func (cmd *change) Usage() string {
|
||||
return `NAME...`
|
||||
}
|
||||
|
||||
func (cmd *change) Description() string {
|
||||
return `Set cluster group members.
|
||||
|
||||
Examples:
|
||||
govc cluster.group.change -name my_group vm_a vm_b vm_c # set
|
||||
govc cluster.group.change -name my_group vm_a vm_b vm_c $(govc cluster.group.ls -name my_group) vm_d # add
|
||||
govc cluster.group.ls -name my_group | grep -v vm_b | xargs govc cluster.group.change -name my_group vm_a vm_b vm_c # remove`
|
||||
}
|
||||
|
||||
func (cmd *change) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
update := types.ArrayUpdateSpec{Operation: types.ArrayUpdateOperationEdit}
|
||||
group, err := cmd.Group(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
refs, err := cmd.ObjectList(ctx, group.kind, f.Args())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*group.refs = refs
|
||||
|
||||
return cmd.Apply(ctx, update, group.info)
|
||||
}
|
||||
86
vendor/github.com/vmware/govmomi/govc/cluster/group/create.go
generated
vendored
Normal file
86
vendor/github.com/vmware/govmomi/govc/cluster/group/create.go
generated
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
Copyright (c) 2017 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package group
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
type create struct {
|
||||
*InfoFlag
|
||||
|
||||
vm bool
|
||||
host bool
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("cluster.group.create", &create{})
|
||||
}
|
||||
|
||||
func (cmd *create) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.InfoFlag, ctx = NewInfoFlag(ctx)
|
||||
cmd.InfoFlag.Register(ctx, f)
|
||||
|
||||
f.BoolVar(&cmd.vm, "vm", false, "Create cluster VM group")
|
||||
f.BoolVar(&cmd.host, "host", false, "Create cluster Host group")
|
||||
}
|
||||
|
||||
func (cmd *create) Process(ctx context.Context) error {
|
||||
if cmd.name == "" {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
return cmd.InfoFlag.Process(ctx)
|
||||
}
|
||||
|
||||
func (cmd *create) Description() string {
|
||||
return `Create cluster group.
|
||||
|
||||
One of '-vm' or '-host' must be provided to specify the group type.
|
||||
|
||||
Examples:
|
||||
govc cluster.group.create -name my_vm_group -vm vm_a vm_b vm_c
|
||||
govc cluster.group.create -name my_host_group -host host_a host_b host_c`
|
||||
}
|
||||
|
||||
func (cmd *create) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
update := types.ArrayUpdateSpec{Operation: types.ArrayUpdateOperationAdd}
|
||||
var info types.BaseClusterGroupInfo
|
||||
var err error
|
||||
|
||||
switch {
|
||||
case cmd.vm:
|
||||
info = new(types.ClusterVmGroup)
|
||||
case cmd.host:
|
||||
info = new(types.ClusterHostGroup)
|
||||
default:
|
||||
return flag.ErrHelp
|
||||
}
|
||||
|
||||
info.GetClusterGroupInfo().Name = cmd.name
|
||||
|
||||
group := newGroupInfo(info)
|
||||
*group.refs, err = cmd.ObjectList(ctx, group.kind, f.Args())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return cmd.Apply(ctx, update, info)
|
||||
}
|
||||
121
vendor/github.com/vmware/govmomi/govc/cluster/group/info_flag.go
generated
vendored
Normal file
121
vendor/github.com/vmware/govmomi/govc/cluster/group/info_flag.go
generated
vendored
Normal file
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
Copyright (c) 2017 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package group
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
type InfoFlag struct {
|
||||
*flags.ClusterFlag
|
||||
|
||||
groups []types.BaseClusterGroupInfo
|
||||
|
||||
name string
|
||||
}
|
||||
|
||||
func NewInfoFlag(ctx context.Context) (*InfoFlag, context.Context) {
|
||||
f := &InfoFlag{}
|
||||
f.ClusterFlag, ctx = flags.NewClusterFlag(ctx)
|
||||
return f, ctx
|
||||
}
|
||||
|
||||
func (f *InfoFlag) Register(ctx context.Context, fs *flag.FlagSet) {
|
||||
f.ClusterFlag.Register(ctx, fs)
|
||||
|
||||
fs.StringVar(&f.name, "name", "", "Cluster group name")
|
||||
}
|
||||
|
||||
func (f *InfoFlag) Process(ctx context.Context) error {
|
||||
return f.ClusterFlag.Process(ctx)
|
||||
}
|
||||
|
||||
func (f *InfoFlag) Groups(ctx context.Context) ([]types.BaseClusterGroupInfo, error) {
|
||||
if f.groups != nil {
|
||||
return f.groups, nil
|
||||
}
|
||||
|
||||
cluster, err := f.Cluster()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
config, err := cluster.Configuration(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
f.groups = config.Group
|
||||
|
||||
return f.groups, nil
|
||||
}
|
||||
|
||||
type ClusterGroupInfo struct {
|
||||
info types.BaseClusterGroupInfo
|
||||
|
||||
refs *[]types.ManagedObjectReference
|
||||
|
||||
kind string
|
||||
}
|
||||
|
||||
func newGroupInfo(info types.BaseClusterGroupInfo) *ClusterGroupInfo {
|
||||
group := &ClusterGroupInfo{info: info}
|
||||
|
||||
switch info := info.(type) {
|
||||
case *types.ClusterHostGroup:
|
||||
group.refs = &info.Host
|
||||
group.kind = "HostSystem"
|
||||
case *types.ClusterVmGroup:
|
||||
group.refs = &info.Vm
|
||||
group.kind = "VirtualMachine"
|
||||
}
|
||||
|
||||
return group
|
||||
}
|
||||
|
||||
func (f *InfoFlag) Group(ctx context.Context) (*ClusterGroupInfo, error) {
|
||||
groups, err := f.Groups(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, group := range groups {
|
||||
if group.GetClusterGroupInfo().Name == f.name {
|
||||
return newGroupInfo(group), nil
|
||||
}
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("group %q not found", f.name)
|
||||
}
|
||||
|
||||
func (f *InfoFlag) Apply(ctx context.Context, update types.ArrayUpdateSpec, info types.BaseClusterGroupInfo) error {
|
||||
spec := &types.ClusterConfigSpecEx{
|
||||
GroupSpec: []types.ClusterGroupSpec{
|
||||
{
|
||||
ArrayUpdateSpec: update,
|
||||
Info: info,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return f.Reconfigure(ctx, spec)
|
||||
}
|
||||
92
vendor/github.com/vmware/govmomi/govc/cluster/group/ls.go
generated
vendored
Normal file
92
vendor/github.com/vmware/govmomi/govc/cluster/group/ls.go
generated
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
Copyright (c) 2017 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package group
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
)
|
||||
|
||||
type ls struct {
|
||||
*InfoFlag
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("cluster.group.ls", &ls{})
|
||||
}
|
||||
|
||||
func (cmd *ls) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.InfoFlag, ctx = NewInfoFlag(ctx)
|
||||
cmd.InfoFlag.Register(ctx, f)
|
||||
}
|
||||
|
||||
func (cmd *ls) Process(ctx context.Context) error {
|
||||
return cmd.InfoFlag.Process(ctx)
|
||||
}
|
||||
|
||||
func (cmd *ls) Description() string {
|
||||
return `List cluster groups and group members.
|
||||
|
||||
Examples:
|
||||
govc cluster.group.ls -cluster my_cluster
|
||||
govc cluster.group.ls -cluster my_cluster -name my_group`
|
||||
}
|
||||
|
||||
type groupResult []string
|
||||
|
||||
func (r groupResult) Write(w io.Writer) error {
|
||||
for i := range r {
|
||||
fmt.Fprintln(w, r[i])
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *ls) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
var res groupResult
|
||||
|
||||
if cmd.name == "" {
|
||||
groups, err := cmd.Groups(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, g := range groups {
|
||||
res = append(res, g.GetClusterGroupInfo().Name)
|
||||
}
|
||||
} else {
|
||||
group, err := cmd.Group(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
names, err := cmd.Names(ctx, *group.refs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, ref := range *group.refs {
|
||||
res = append(res, names[ref])
|
||||
}
|
||||
}
|
||||
|
||||
return cmd.WriteResult(res)
|
||||
}
|
||||
61
vendor/github.com/vmware/govmomi/govc/cluster/group/remove.go
generated
vendored
Normal file
61
vendor/github.com/vmware/govmomi/govc/cluster/group/remove.go
generated
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
Copyright (c) 2017 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package group
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
type remove struct {
|
||||
*InfoFlag
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("cluster.group.remove", &remove{})
|
||||
}
|
||||
|
||||
func (cmd *remove) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.InfoFlag, ctx = NewInfoFlag(ctx)
|
||||
cmd.InfoFlag.Register(ctx, f)
|
||||
}
|
||||
|
||||
func (cmd *remove) Process(ctx context.Context) error {
|
||||
if cmd.name == "" {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
return cmd.InfoFlag.Process(ctx)
|
||||
}
|
||||
|
||||
func (cmd *remove) Description() string {
|
||||
return `Remove cluster group.
|
||||
|
||||
Examples:
|
||||
govc cluster.group.remove -cluster my_cluster -name my_group`
|
||||
}
|
||||
|
||||
func (cmd *remove) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
update := types.ArrayUpdateSpec{
|
||||
Operation: types.ArrayUpdateOperationRemove,
|
||||
RemoveKey: cmd.name,
|
||||
}
|
||||
|
||||
return cmd.Apply(ctx, update, nil)
|
||||
}
|
||||
148
vendor/github.com/vmware/govmomi/govc/cluster/override/change.go
generated
vendored
Normal file
148
vendor/github.com/vmware/govmomi/govc/cluster/override/change.go
generated
vendored
Normal file
@@ -0,0 +1,148 @@
|
||||
/*
|
||||
Copyright (c) 2017 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package override
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"strings"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/cluster"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
type change struct {
|
||||
*flags.ClusterFlag
|
||||
*flags.VirtualMachineFlag
|
||||
|
||||
drs types.ClusterDrsVmConfigInfo
|
||||
das types.ClusterDasVmConfigInfo
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("cluster.override.change", &change{})
|
||||
}
|
||||
|
||||
func (cmd *change) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.ClusterFlag, ctx = flags.NewClusterFlag(ctx)
|
||||
cmd.ClusterFlag.Register(ctx, f)
|
||||
cmd.VirtualMachineFlag, ctx = flags.NewVirtualMachineFlag(ctx)
|
||||
cmd.VirtualMachineFlag.Register(ctx, f)
|
||||
|
||||
// DRS
|
||||
f.Var(flags.NewOptionalBool(&cmd.drs.Enabled), "drs-enabled", "Enable DRS")
|
||||
|
||||
f.StringVar((*string)(&cmd.drs.Behavior), "drs-mode", "", cluster.DrsBehaviorUsage())
|
||||
|
||||
// HA
|
||||
rp := []string{
|
||||
string(types.DasVmPriorityDisabled),
|
||||
string(types.DasVmPriorityLow),
|
||||
string(types.DasVmPriorityMedium),
|
||||
string(types.DasVmPriorityHigh),
|
||||
}
|
||||
cmd.das.DasSettings = new(types.ClusterDasVmSettings)
|
||||
|
||||
f.StringVar((*string)(&cmd.das.DasSettings.RestartPriority), "ha-restart-priority", "", "HA restart priority: "+strings.Join(rp, ", "))
|
||||
}
|
||||
|
||||
func (cmd *change) Description() string {
|
||||
return `Change cluster VM overrides.
|
||||
|
||||
Examples:
|
||||
govc cluster.override.change -cluster cluster_1 -vm vm_1 -ha-restart-priority high
|
||||
govc cluster.override.change -cluster cluster_1 -vm vm_2 -drs-enabled=false
|
||||
govc cluster.override.change -cluster cluster_1 -vm vm_3 -drs-enabled -drs-mode fullyAutomated`
|
||||
}
|
||||
|
||||
func (cmd *change) Process(ctx context.Context) error {
|
||||
if err := cmd.ClusterFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return cmd.VirtualMachineFlag.Process(ctx)
|
||||
}
|
||||
|
||||
func (cmd *change) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
vm, err := cmd.VirtualMachine()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if vm == nil {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
|
||||
cluster, err := cmd.Cluster()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
config, err := cluster.Configuration(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
spec := &types.ClusterConfigSpecEx{}
|
||||
cmd.drs.Key = vm.Reference()
|
||||
cmd.das.Key = vm.Reference()
|
||||
|
||||
if cmd.drs.Behavior != "" || cmd.drs.Enabled != nil {
|
||||
op := types.ArrayUpdateOperationAdd
|
||||
for _, c := range config.DrsVmConfig {
|
||||
if c.Key == cmd.drs.Key {
|
||||
op = types.ArrayUpdateOperationEdit
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
spec.DrsVmConfigSpec = []types.ClusterDrsVmConfigSpec{
|
||||
{
|
||||
ArrayUpdateSpec: types.ArrayUpdateSpec{
|
||||
Operation: op,
|
||||
},
|
||||
Info: &cmd.drs,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
if cmd.das.DasSettings.RestartPriority != "" {
|
||||
op := types.ArrayUpdateOperationAdd
|
||||
for _, c := range config.DasVmConfig {
|
||||
if c.Key == cmd.das.Key {
|
||||
op = types.ArrayUpdateOperationEdit
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
spec.DasVmConfigSpec = []types.ClusterDasVmConfigSpec{
|
||||
{
|
||||
ArrayUpdateSpec: types.ArrayUpdateSpec{
|
||||
Operation: op,
|
||||
},
|
||||
Info: &cmd.das,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
if spec.DrsVmConfigSpec == nil && spec.DasVmConfigSpec == nil {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
|
||||
return cmd.Reconfigure(ctx, spec)
|
||||
}
|
||||
142
vendor/github.com/vmware/govmomi/govc/cluster/override/info.go
generated
vendored
Normal file
142
vendor/github.com/vmware/govmomi/govc/cluster/override/info.go
generated
vendored
Normal file
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
Copyright (c) 2017 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package override
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
"text/tabwriter"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
"github.com/vmware/govmomi/object"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
type info struct {
|
||||
*flags.ClusterFlag
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("cluster.override.info", &info{})
|
||||
}
|
||||
|
||||
func (cmd *info) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.ClusterFlag, ctx = flags.NewClusterFlag(ctx)
|
||||
cmd.ClusterFlag.Register(ctx, f)
|
||||
}
|
||||
|
||||
func (cmd *info) Description() string {
|
||||
return `Cluster VM overrides info.
|
||||
|
||||
Examples:
|
||||
govc cluster.override.info
|
||||
govc cluster.override.info -json`
|
||||
}
|
||||
|
||||
func (cmd *info) Process(ctx context.Context) error {
|
||||
return cmd.ClusterFlag.Process(ctx)
|
||||
}
|
||||
|
||||
type Override struct {
|
||||
id types.ManagedObjectReference
|
||||
Name string
|
||||
Host string `json:",omitempty"`
|
||||
DRS *types.ClusterDrsVmConfigInfo `json:",omitempty"`
|
||||
DAS *types.ClusterDasVmConfigInfo `json:",omitempty"`
|
||||
}
|
||||
|
||||
type infoResult struct {
|
||||
Overrides map[string]*Override
|
||||
}
|
||||
|
||||
func (r *infoResult) Write(w io.Writer) error {
|
||||
tw := tabwriter.NewWriter(w, 2, 0, 2, ' ', 0)
|
||||
|
||||
for _, entry := range r.Overrides {
|
||||
behavior := fmt.Sprintf("Default (%s)", types.DrsBehaviorFullyAutomated)
|
||||
if entry.DRS != nil {
|
||||
if *entry.DRS.Enabled {
|
||||
behavior = string(entry.DRS.Behavior)
|
||||
}
|
||||
}
|
||||
|
||||
priority := fmt.Sprintf("Default (%s)", types.DasVmPriorityMedium)
|
||||
if entry.DAS != nil {
|
||||
priority = entry.DAS.DasSettings.RestartPriority
|
||||
}
|
||||
|
||||
fmt.Fprintf(tw, "Name:\t%s\n", entry.Name)
|
||||
fmt.Fprintf(tw, " DRS Automation Level:\t%s\n", strings.Title(behavior))
|
||||
fmt.Fprintf(tw, " HA Restart Priority:\t%s\n", strings.Title(priority))
|
||||
fmt.Fprintf(tw, " Host:\t%s\n", entry.Host)
|
||||
}
|
||||
|
||||
return tw.Flush()
|
||||
}
|
||||
|
||||
func (r *infoResult) entry(id types.ManagedObjectReference) *Override {
|
||||
key := id.String()
|
||||
vm, ok := r.Overrides[key]
|
||||
if !ok {
|
||||
r.Overrides[key] = &Override{id: id}
|
||||
vm = r.Overrides[key]
|
||||
}
|
||||
return vm
|
||||
}
|
||||
|
||||
func (cmd *info) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
cluster, err := cmd.Cluster()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
config, err := cluster.Configuration(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
res := &infoResult{
|
||||
Overrides: make(map[string]*Override),
|
||||
}
|
||||
|
||||
for i := range config.DasVmConfig {
|
||||
vm := res.entry(config.DasVmConfig[i].Key)
|
||||
|
||||
vm.DAS = &config.DasVmConfig[i]
|
||||
}
|
||||
|
||||
for i := range config.DrsVmConfig {
|
||||
vm := res.entry(config.DrsVmConfig[i].Key)
|
||||
|
||||
vm.DRS = &config.DrsVmConfig[i]
|
||||
}
|
||||
|
||||
for _, o := range res.Overrides {
|
||||
// TODO: can optimize to reduce round trips
|
||||
vm := object.NewVirtualMachine(cluster.Client(), o.id)
|
||||
o.Name, _ = vm.ObjectName(ctx)
|
||||
if h, herr := vm.HostSystem(ctx); herr == nil {
|
||||
o.Host, _ = h.ObjectName(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
return cmd.WriteResult(res)
|
||||
}
|
||||
110
vendor/github.com/vmware/govmomi/govc/cluster/override/remove.go
generated
vendored
Normal file
110
vendor/github.com/vmware/govmomi/govc/cluster/override/remove.go
generated
vendored
Normal file
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
Copyright (c) 2017 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package override
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
type remove struct {
|
||||
*flags.ClusterFlag
|
||||
*flags.VirtualMachineFlag
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("cluster.override.remove", &remove{})
|
||||
}
|
||||
|
||||
func (cmd *remove) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.ClusterFlag, ctx = flags.NewClusterFlag(ctx)
|
||||
cmd.ClusterFlag.Register(ctx, f)
|
||||
cmd.VirtualMachineFlag, ctx = flags.NewVirtualMachineFlag(ctx)
|
||||
cmd.VirtualMachineFlag.Register(ctx, f)
|
||||
}
|
||||
|
||||
func (cmd *remove) Description() string {
|
||||
return `Remove cluster VM overrides.
|
||||
|
||||
Examples:
|
||||
govc cluster.override.remove -cluster cluster_1 -vm vm_1`
|
||||
}
|
||||
|
||||
func (cmd *remove) Process(ctx context.Context) error {
|
||||
if err := cmd.ClusterFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return cmd.VirtualMachineFlag.Process(ctx)
|
||||
}
|
||||
|
||||
func (cmd *remove) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
vm, err := cmd.VirtualMachine()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if vm == nil {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
|
||||
cluster, err := cmd.Cluster()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
config, err := cluster.Configuration(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
spec := &types.ClusterConfigSpecEx{}
|
||||
ref := vm.Reference()
|
||||
|
||||
for _, c := range config.DrsVmConfig {
|
||||
if c.Key == ref {
|
||||
spec.DrsVmConfigSpec = []types.ClusterDrsVmConfigSpec{
|
||||
{
|
||||
ArrayUpdateSpec: types.ArrayUpdateSpec{
|
||||
Operation: types.ArrayUpdateOperationRemove,
|
||||
RemoveKey: ref,
|
||||
},
|
||||
},
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
for _, c := range config.DasVmConfig {
|
||||
if c.Key == ref {
|
||||
spec.DasVmConfigSpec = []types.ClusterDasVmConfigSpec{
|
||||
{
|
||||
ArrayUpdateSpec: types.ArrayUpdateSpec{
|
||||
Operation: types.ArrayUpdateOperationRemove,
|
||||
RemoveKey: ref,
|
||||
},
|
||||
},
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return cmd.Reconfigure(ctx, spec)
|
||||
}
|
||||
93
vendor/github.com/vmware/govmomi/govc/cluster/rule/change.go
generated
vendored
Normal file
93
vendor/github.com/vmware/govmomi/govc/cluster/rule/change.go
generated
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
Copyright (c) 2017 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package rule
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
type change struct {
|
||||
*SpecFlag
|
||||
*InfoFlag
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("cluster.rule.change", &change{})
|
||||
}
|
||||
|
||||
func (cmd *change) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.SpecFlag = new(SpecFlag)
|
||||
cmd.SpecFlag.Register(ctx, f)
|
||||
|
||||
cmd.InfoFlag, ctx = NewInfoFlag(ctx)
|
||||
cmd.InfoFlag.Register(ctx, f)
|
||||
}
|
||||
|
||||
func (cmd *change) Process(ctx context.Context) error {
|
||||
if cmd.name == "" {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
return cmd.InfoFlag.Process(ctx)
|
||||
}
|
||||
|
||||
func (cmd *change) Usage() string {
|
||||
return `NAME...`
|
||||
}
|
||||
|
||||
func (cmd *change) Description() string {
|
||||
return `Change cluster rule.
|
||||
|
||||
Examples:
|
||||
govc cluster.rule.change -cluster my_cluster -name my_rule -enable=false`
|
||||
}
|
||||
|
||||
func (cmd *change) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
update := types.ArrayUpdateSpec{Operation: types.ArrayUpdateOperationEdit}
|
||||
rule, err := cmd.Rule(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var vms *[]types.ManagedObjectReference
|
||||
|
||||
switch r := rule.info.(type) {
|
||||
case *types.ClusterAffinityRuleSpec:
|
||||
vms = &r.Vm
|
||||
case *types.ClusterAntiAffinityRuleSpec:
|
||||
vms = &r.Vm
|
||||
}
|
||||
|
||||
if vms != nil && f.NArg() != 0 {
|
||||
refs, err := cmd.ObjectList(ctx, rule.kind, f.Args())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*vms = refs
|
||||
}
|
||||
|
||||
info := rule.info.GetClusterRuleInfo()
|
||||
info.Name = cmd.name
|
||||
info.Enabled = cmd.Enabled
|
||||
info.Mandatory = cmd.Mandatory
|
||||
|
||||
return cmd.Apply(ctx, update, rule.info)
|
||||
}
|
||||
136
vendor/github.com/vmware/govmomi/govc/cluster/rule/create.go
generated
vendored
Normal file
136
vendor/github.com/vmware/govmomi/govc/cluster/rule/create.go
generated
vendored
Normal file
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
Copyright (c) 2017 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package rule
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
type create struct {
|
||||
*SpecFlag
|
||||
*InfoFlag
|
||||
|
||||
vmhost bool
|
||||
affinity bool
|
||||
antiaffinity bool
|
||||
depends bool
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("cluster.rule.create", &create{})
|
||||
}
|
||||
|
||||
func (cmd *create) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.SpecFlag = new(SpecFlag)
|
||||
cmd.SpecFlag.Register(ctx, f)
|
||||
|
||||
cmd.InfoFlag, ctx = NewInfoFlag(ctx)
|
||||
cmd.InfoFlag.Register(ctx, f)
|
||||
|
||||
f.BoolVar(&cmd.vmhost, "vm-host", false, "Virtual Machines to Hosts")
|
||||
f.BoolVar(&cmd.affinity, "affinity", false, "Keep Virtual Machines Together")
|
||||
f.BoolVar(&cmd.antiaffinity, "anti-affinity", false, "Separate Virtual Machines")
|
||||
f.BoolVar(&cmd.depends, "depends", false, "Virtual Machines to Virtual Machines")
|
||||
}
|
||||
|
||||
func (cmd *create) Process(ctx context.Context) error {
|
||||
if cmd.name == "" {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
return cmd.InfoFlag.Process(ctx)
|
||||
}
|
||||
|
||||
func (cmd *create) Usage() string {
|
||||
return "NAME..."
|
||||
}
|
||||
|
||||
func (cmd *create) Description() string {
|
||||
return `Create cluster rule.
|
||||
|
||||
Rules are not enabled by default, use the 'enable' flag to enable upon creation or cluster.rule.change after creation.
|
||||
|
||||
One of '-affinity', '-anti-affinity', '-depends' or '-vm-host' must be provided to specify the rule type.
|
||||
|
||||
With '-affinity' or '-anti-affinity', at least 2 vm NAME arguments must be specified.
|
||||
|
||||
With '-depends', vm group NAME and vm group dependency NAME arguments must be specified.
|
||||
|
||||
With '-vm-host', use the '-vm-group' flag combined with the '-host-affine-group' and/or '-host-anti-affine-group' flags.
|
||||
|
||||
Examples:
|
||||
govc cluster.rule.create -name pod1 -enable -affinity vm_a vm_b vm_c
|
||||
govc cluster.rule.create -name pod2 -enable -anti-affinity vm_d vm_e vm_f
|
||||
govc cluster.rule.create -name pod3 -enable -mandatory -vm-host -vm-group my_vms -host-affine-group my_hosts
|
||||
govc cluster.rule.create -name pod4 -depends vm_group_app vm_group_db`
|
||||
}
|
||||
|
||||
func (cmd *create) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
args := f.Args()
|
||||
update := types.ArrayUpdateSpec{Operation: types.ArrayUpdateOperationAdd}
|
||||
var rule types.BaseClusterRuleInfo
|
||||
var err error
|
||||
|
||||
switch {
|
||||
case cmd.vmhost:
|
||||
rule = &cmd.ClusterVmHostRuleInfo
|
||||
case cmd.affinity:
|
||||
rule = &cmd.ClusterAffinityRuleSpec
|
||||
if len(args) < 2 {
|
||||
return flag.ErrHelp // can't create this rule without 2 or more hosts
|
||||
}
|
||||
cmd.ClusterAffinityRuleSpec.Vm, err = cmd.ObjectList(ctx, "VirtualMachine", args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
case cmd.antiaffinity:
|
||||
rule = &cmd.ClusterAntiAffinityRuleSpec
|
||||
if len(args) < 2 {
|
||||
return flag.ErrHelp // can't create this rule without 2 or more hosts
|
||||
}
|
||||
cmd.ClusterAntiAffinityRuleSpec.Vm, err = cmd.ObjectList(ctx, "VirtualMachine", args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
case cmd.depends:
|
||||
if len(args) != 2 {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
rule = &types.ClusterDependencyRuleInfo{
|
||||
VmGroup: args[0],
|
||||
DependsOnVmGroup: args[1],
|
||||
}
|
||||
default:
|
||||
return flag.ErrHelp
|
||||
}
|
||||
|
||||
if cmd.Enabled == nil {
|
||||
// ClusterDependencyRuleInfo throws InvalidArgument if Enabled == nil
|
||||
cmd.Enabled = types.NewBool(false)
|
||||
}
|
||||
|
||||
info := rule.GetClusterRuleInfo()
|
||||
info.Name = cmd.name
|
||||
info.Enabled = cmd.Enabled
|
||||
info.Mandatory = cmd.Mandatory
|
||||
info.UserCreated = types.NewBool(true)
|
||||
|
||||
return cmd.Apply(ctx, update, rule)
|
||||
}
|
||||
135
vendor/github.com/vmware/govmomi/govc/cluster/rule/info_flag.go
generated
vendored
Normal file
135
vendor/github.com/vmware/govmomi/govc/cluster/rule/info_flag.go
generated
vendored
Normal file
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
Copyright (c) 2017 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package rule
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
type InfoFlag struct {
|
||||
*flags.ClusterFlag
|
||||
|
||||
rules []types.BaseClusterRuleInfo
|
||||
|
||||
name string
|
||||
}
|
||||
|
||||
func NewInfoFlag(ctx context.Context) (*InfoFlag, context.Context) {
|
||||
f := &InfoFlag{}
|
||||
f.ClusterFlag, ctx = flags.NewClusterFlag(ctx)
|
||||
return f, ctx
|
||||
}
|
||||
|
||||
func (f *InfoFlag) Register(ctx context.Context, fs *flag.FlagSet) {
|
||||
f.ClusterFlag.Register(ctx, fs)
|
||||
|
||||
fs.StringVar(&f.name, "name", "", "Cluster rule name")
|
||||
}
|
||||
|
||||
func (f *InfoFlag) Process(ctx context.Context) error {
|
||||
return f.ClusterFlag.Process(ctx)
|
||||
}
|
||||
|
||||
func (f *InfoFlag) Rules(ctx context.Context) ([]types.BaseClusterRuleInfo, error) {
|
||||
if f.rules != nil {
|
||||
return f.rules, nil
|
||||
}
|
||||
|
||||
cluster, err := f.Cluster()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
config, err := cluster.Configuration(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
f.rules = config.Rule
|
||||
|
||||
return f.rules, nil
|
||||
}
|
||||
|
||||
type ClusterRuleInfo struct {
|
||||
info types.BaseClusterRuleInfo
|
||||
|
||||
refs *[]types.ManagedObjectReference
|
||||
|
||||
kind string
|
||||
}
|
||||
|
||||
func (f *InfoFlag) Rule(ctx context.Context) (*ClusterRuleInfo, error) {
|
||||
rules, err := f.Rules(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, rule := range rules {
|
||||
if rule.GetClusterRuleInfo().Name != f.name {
|
||||
continue
|
||||
}
|
||||
|
||||
r := &ClusterRuleInfo{info: rule}
|
||||
|
||||
switch info := rule.(type) {
|
||||
case *types.ClusterAffinityRuleSpec:
|
||||
r.refs = &info.Vm
|
||||
r.kind = "VirtualMachine"
|
||||
case *types.ClusterAntiAffinityRuleSpec:
|
||||
r.refs = &info.Vm
|
||||
r.kind = "VirtualMachine"
|
||||
}
|
||||
|
||||
return r, nil
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("rule %q not found", f.name)
|
||||
}
|
||||
|
||||
func (f *InfoFlag) Apply(ctx context.Context, update types.ArrayUpdateSpec, info types.BaseClusterRuleInfo) error {
|
||||
spec := &types.ClusterConfigSpecEx{
|
||||
RulesSpec: []types.ClusterRuleSpec{
|
||||
{
|
||||
ArrayUpdateSpec: update,
|
||||
Info: info,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return f.Reconfigure(ctx, spec)
|
||||
}
|
||||
|
||||
type SpecFlag struct {
|
||||
types.ClusterRuleInfo
|
||||
types.ClusterVmHostRuleInfo
|
||||
types.ClusterAffinityRuleSpec
|
||||
types.ClusterAntiAffinityRuleSpec
|
||||
}
|
||||
|
||||
func (s *SpecFlag) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
f.Var(flags.NewOptionalBool(&s.Enabled), "enable", "Enable rule")
|
||||
f.Var(flags.NewOptionalBool(&s.Mandatory), "mandatory", "Enforce rule compliance")
|
||||
|
||||
f.StringVar(&s.VmGroupName, "vm-group", "", "VM group name")
|
||||
f.StringVar(&s.AffineHostGroupName, "host-affine-group", "", "Host affine group name")
|
||||
f.StringVar(&s.AntiAffineHostGroupName, "host-anti-affine-group", "", "Host anti-affine group name")
|
||||
}
|
||||
96
vendor/github.com/vmware/govmomi/govc/cluster/rule/ls.go
generated
vendored
Normal file
96
vendor/github.com/vmware/govmomi/govc/cluster/rule/ls.go
generated
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
Copyright (c) 2017 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package rule
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
)
|
||||
|
||||
type ls struct {
|
||||
*InfoFlag
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("cluster.rule.ls", &ls{})
|
||||
}
|
||||
|
||||
func (cmd *ls) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.InfoFlag, ctx = NewInfoFlag(ctx)
|
||||
cmd.InfoFlag.Register(ctx, f)
|
||||
}
|
||||
|
||||
func (cmd *ls) Process(ctx context.Context) error {
|
||||
return cmd.InfoFlag.Process(ctx)
|
||||
}
|
||||
|
||||
func (cmd *ls) Description() string {
|
||||
return `List cluster rules and rule members.
|
||||
|
||||
Examples:
|
||||
govc cluster.rule.ls -cluster my_cluster
|
||||
govc cluster.rule.ls -cluster my_cluster -name my_rule`
|
||||
}
|
||||
|
||||
type ruleResult []string
|
||||
|
||||
func (r ruleResult) Write(w io.Writer) error {
|
||||
for i := range r {
|
||||
fmt.Fprintln(w, r[i])
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *ls) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
var res ruleResult
|
||||
|
||||
if cmd.name == "" {
|
||||
rules, err := cmd.Rules(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, g := range rules {
|
||||
res = append(res, g.GetClusterRuleInfo().Name)
|
||||
}
|
||||
} else {
|
||||
rule, err := cmd.Rule(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if rule.refs == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
names, err := cmd.Names(ctx, *rule.refs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, ref := range *rule.refs {
|
||||
res = append(res, names[ref])
|
||||
}
|
||||
}
|
||||
|
||||
return cmd.WriteResult(res)
|
||||
}
|
||||
66
vendor/github.com/vmware/govmomi/govc/cluster/rule/remove.go
generated
vendored
Normal file
66
vendor/github.com/vmware/govmomi/govc/cluster/rule/remove.go
generated
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
Copyright (c) 2017 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package rule
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
type remove struct {
|
||||
*InfoFlag
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("cluster.rule.remove", &remove{})
|
||||
}
|
||||
|
||||
func (cmd *remove) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.InfoFlag, ctx = NewInfoFlag(ctx)
|
||||
cmd.InfoFlag.Register(ctx, f)
|
||||
}
|
||||
|
||||
func (cmd *remove) Process(ctx context.Context) error {
|
||||
if cmd.name == "" {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
return cmd.InfoFlag.Process(ctx)
|
||||
}
|
||||
|
||||
func (cmd *remove) Description() string {
|
||||
return `Remove cluster rule.
|
||||
|
||||
Examples:
|
||||
govc cluster.group.remove -cluster my_cluster -name my_rule`
|
||||
}
|
||||
|
||||
func (cmd *remove) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
rule, err := cmd.Rule(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
update := types.ArrayUpdateSpec{
|
||||
Operation: types.ArrayUpdateOperationRemove,
|
||||
RemoveKey: rule.info.GetClusterRuleInfo().Key,
|
||||
}
|
||||
|
||||
return cmd.Apply(ctx, update, nil)
|
||||
}
|
||||
69
vendor/github.com/vmware/govmomi/govc/datacenter/create.go
generated
vendored
Normal file
69
vendor/github.com/vmware/govmomi/govc/datacenter/create.go
generated
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
Copyright (c) 2014-2015 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package datacenter
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
)
|
||||
|
||||
type create struct {
|
||||
*flags.FolderFlag
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("datacenter.create", &create{})
|
||||
}
|
||||
|
||||
func (cmd *create) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.FolderFlag, ctx = flags.NewFolderFlag(ctx)
|
||||
cmd.FolderFlag.Register(ctx, f)
|
||||
}
|
||||
|
||||
func (cmd *create) Usage() string {
|
||||
return "NAME..."
|
||||
}
|
||||
|
||||
func (cmd *create) Process(ctx context.Context) error {
|
||||
if err := cmd.FolderFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *create) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
folder, err := cmd.FolderOrDefault("/")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if f.NArg() == 0 {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
|
||||
for _, name := range f.Args() {
|
||||
_, err := folder.CreateDatacenter(ctx, name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
174
vendor/github.com/vmware/govmomi/govc/datacenter/info.go
generated
vendored
Normal file
174
vendor/github.com/vmware/govmomi/govc/datacenter/info.go
generated
vendored
Normal file
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
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 datacenter
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"path"
|
||||
"text/tabwriter"
|
||||
|
||||
"github.com/vmware/govmomi/find"
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
"github.com/vmware/govmomi/object"
|
||||
"github.com/vmware/govmomi/property"
|
||||
"github.com/vmware/govmomi/vim25/mo"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
type info struct {
|
||||
*flags.ClientFlag
|
||||
*flags.OutputFlag
|
||||
*flags.DatacenterFlag
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("datacenter.info", &info{})
|
||||
}
|
||||
|
||||
func (cmd *info) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.ClientFlag, ctx = flags.NewClientFlag(ctx)
|
||||
cmd.ClientFlag.Register(ctx, f)
|
||||
|
||||
cmd.OutputFlag, ctx = flags.NewOutputFlag(ctx)
|
||||
cmd.OutputFlag.Register(ctx, f)
|
||||
|
||||
cmd.DatacenterFlag, ctx = flags.NewDatacenterFlag(ctx)
|
||||
cmd.DatacenterFlag.Register(ctx, f)
|
||||
}
|
||||
|
||||
func (cmd *info) Process(ctx context.Context) error {
|
||||
if err := cmd.ClientFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := cmd.OutputFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := cmd.DatacenterFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *info) Usage() string {
|
||||
return "[PATH]..."
|
||||
}
|
||||
|
||||
func (cmd *info) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
c, err := cmd.Client()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
finder, err := cmd.Finder()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
args := f.Args()
|
||||
if len(args) == 0 {
|
||||
args = []string{"*"}
|
||||
}
|
||||
|
||||
var props []string
|
||||
res := infoResult{
|
||||
finder: finder,
|
||||
ctx: ctx,
|
||||
}
|
||||
|
||||
if !cmd.OutputFlag.All() {
|
||||
props = []string{
|
||||
"name",
|
||||
"vmFolder",
|
||||
"hostFolder",
|
||||
"datastoreFolder",
|
||||
"networkFolder",
|
||||
"datastore",
|
||||
"network",
|
||||
}
|
||||
}
|
||||
|
||||
for _, arg := range args {
|
||||
objects, err := finder.DatacenterList(ctx, arg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
res.objects = append(res.objects, objects...)
|
||||
}
|
||||
|
||||
if len(res.objects) != 0 {
|
||||
refs := make([]types.ManagedObjectReference, 0, len(res.objects))
|
||||
for _, o := range res.objects {
|
||||
refs = append(refs, o.Reference())
|
||||
}
|
||||
|
||||
pc := property.DefaultCollector(c)
|
||||
err = pc.Retrieve(ctx, refs, props, &res.Datacenters)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return cmd.WriteResult(&res)
|
||||
}
|
||||
|
||||
type infoResult struct {
|
||||
Datacenters []mo.Datacenter
|
||||
objects []*object.Datacenter
|
||||
finder *find.Finder
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
func (r *infoResult) Write(w io.Writer) error {
|
||||
// Maintain order via r.objects as Property collector does not always return results in order.
|
||||
objects := make(map[types.ManagedObjectReference]mo.Datacenter, len(r.Datacenters))
|
||||
for _, o := range r.Datacenters {
|
||||
objects[o.Reference()] = o
|
||||
}
|
||||
|
||||
tw := tabwriter.NewWriter(w, 2, 0, 2, ' ', 0)
|
||||
|
||||
for _, o := range r.objects {
|
||||
dc := objects[o.Reference()]
|
||||
fmt.Fprintf(tw, "Name:\t%s\n", dc.Name)
|
||||
fmt.Fprintf(tw, " Path:\t%s\n", o.InventoryPath)
|
||||
|
||||
folders, err := o.Folders(r.ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
r.finder.SetDatacenter(o)
|
||||
|
||||
hosts, _ := r.finder.HostSystemList(r.ctx, path.Join(folders.HostFolder.InventoryPath, "*"))
|
||||
fmt.Fprintf(tw, " Hosts:\t%d\n", len(hosts))
|
||||
|
||||
clusters, _ := r.finder.ClusterComputeResourceList(r.ctx, path.Join(folders.HostFolder.InventoryPath, "*"))
|
||||
fmt.Fprintf(tw, " Clusters:\t%d\n", len(clusters))
|
||||
|
||||
vms, _ := r.finder.VirtualMachineList(r.ctx, path.Join(folders.VmFolder.InventoryPath, "*"))
|
||||
fmt.Fprintf(tw, " Virtual Machines:\t%d\n", len(vms))
|
||||
|
||||
fmt.Fprintf(tw, " Networks:\t%d\n", len(dc.Network))
|
||||
fmt.Fprintf(tw, " Datastores:\t%d\n", len(dc.Datastore))
|
||||
}
|
||||
|
||||
return tw.Flush()
|
||||
}
|
||||
152
vendor/github.com/vmware/govmomi/govc/datastore/cp.go
generated
vendored
Normal file
152
vendor/github.com/vmware/govmomi/govc/datastore/cp.go
generated
vendored
Normal file
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
Copyright (c) 2014-2018 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 datastore
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
"github.com/vmware/govmomi/object"
|
||||
)
|
||||
|
||||
type cp struct {
|
||||
target
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("datastore.cp", &cp{})
|
||||
}
|
||||
|
||||
type target struct {
|
||||
*flags.DatastoreFlag // The source Datastore and the default target Datastore
|
||||
|
||||
dc *flags.DatacenterFlag // Optionally target a different Datacenter
|
||||
ds *flags.DatastoreFlag // Optionally target a different Datastore
|
||||
|
||||
kind bool
|
||||
force bool
|
||||
}
|
||||
|
||||
func (cmd *target) FileManager() (*object.DatastoreFileManager, error) {
|
||||
dc, err := cmd.Datacenter()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ds, err := cmd.Datastore()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
m := ds.NewFileManager(dc, cmd.force)
|
||||
|
||||
dc, err = cmd.dc.Datacenter()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
m.DatacenterTarget = dc
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (cmd *target) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.DatastoreFlag, ctx = flags.NewDatastoreFlag(ctx)
|
||||
cmd.DatastoreFlag.Register(ctx, f)
|
||||
|
||||
cmd.dc = &flags.DatacenterFlag{
|
||||
OutputFlag: cmd.OutputFlag,
|
||||
ClientFlag: cmd.ClientFlag,
|
||||
}
|
||||
f.StringVar(&cmd.dc.Name, "dc-target", "", "Datacenter destination (defaults to -dc)")
|
||||
|
||||
cmd.ds = &flags.DatastoreFlag{
|
||||
DatacenterFlag: cmd.dc,
|
||||
}
|
||||
f.StringVar(&cmd.ds.Name, "ds-target", "", "Datastore destination (defaults to -ds)")
|
||||
|
||||
f.BoolVar(&cmd.kind, "t", true, "Use file type to choose disk or file manager")
|
||||
f.BoolVar(&cmd.force, "f", false, "If true, overwrite any identically named file at the destination")
|
||||
}
|
||||
|
||||
func (cmd *target) Process(ctx context.Context) error {
|
||||
if err := cmd.DatastoreFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if cmd.dc.Name == "" {
|
||||
// Use source DC as target DC
|
||||
cmd.dc = cmd.DatacenterFlag
|
||||
cmd.ds.DatacenterFlag = cmd.dc
|
||||
}
|
||||
|
||||
if cmd.ds.Name == "" {
|
||||
// Use source DS as target DS
|
||||
cmd.ds.Name = cmd.DatastoreFlag.Name
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *cp) Usage() string {
|
||||
return "SRC DST"
|
||||
}
|
||||
|
||||
func (cmd *cp) Description() string {
|
||||
return `Copy SRC to DST on DATASTORE.
|
||||
|
||||
Examples:
|
||||
govc datastore.cp foo/foo.vmx foo/foo.vmx.old
|
||||
govc datastore.cp -f my.vmx foo/foo.vmx
|
||||
govc datastore.cp disks/disk1.vmdk disks/disk2.vmdk
|
||||
govc datastore.cp disks/disk1.vmdk -dc-target DC2 disks/disk2.vmdk
|
||||
govc datastore.cp disks/disk1.vmdk -ds-target NFS-2 disks/disk2.vmdk`
|
||||
}
|
||||
|
||||
func (cmd *cp) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
args := f.Args()
|
||||
if len(args) != 2 {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
|
||||
m, err := cmd.FileManager()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
src, err := cmd.DatastorePath(args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dst, err := cmd.target.ds.DatastorePath(args[1])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cp := m.CopyFile
|
||||
if cmd.kind {
|
||||
cp = m.Copy
|
||||
}
|
||||
|
||||
logger := cmd.ProgressLogger(fmt.Sprintf("Copying %s to %s...", src, dst))
|
||||
defer logger.Wait()
|
||||
|
||||
return cp(m.WithProgress(ctx, logger), src, dst)
|
||||
}
|
||||
321
vendor/github.com/vmware/govmomi/govc/datastore/create.go
generated
vendored
Normal file
321
vendor/github.com/vmware/govmomi/govc/datastore/create.go
generated
vendored
Normal file
@@ -0,0 +1,321 @@
|
||||
/*
|
||||
Copyright (c) 2015-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 datastore
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
"github.com/vmware/govmomi/object"
|
||||
"github.com/vmware/govmomi/vim25/soap"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
type create struct {
|
||||
*flags.HostSystemFlag
|
||||
|
||||
// Generic options
|
||||
Type typeFlag
|
||||
Name string
|
||||
Force bool
|
||||
|
||||
// Options for NAS
|
||||
RemoteHost string
|
||||
RemotePath string
|
||||
AccessMode string
|
||||
UserName string
|
||||
Password string
|
||||
|
||||
// Options for VMFS
|
||||
DiskCanonicalName string
|
||||
|
||||
// Options for local
|
||||
Path string
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("datastore.create", &create{})
|
||||
}
|
||||
|
||||
var nasTypes = []string{
|
||||
string(types.HostFileSystemVolumeFileSystemTypeNFS),
|
||||
string(types.HostFileSystemVolumeFileSystemTypeNFS41),
|
||||
string(types.HostFileSystemVolumeFileSystemTypeCIFS),
|
||||
}
|
||||
|
||||
var vmfsTypes = []string{
|
||||
string(types.HostFileSystemVolumeFileSystemTypeVMFS),
|
||||
}
|
||||
|
||||
var localTypes = []string{
|
||||
"local",
|
||||
}
|
||||
|
||||
var allTypes = []string{}
|
||||
|
||||
func init() {
|
||||
allTypes = append(allTypes, nasTypes...)
|
||||
allTypes = append(allTypes, vmfsTypes...)
|
||||
allTypes = append(allTypes, localTypes...)
|
||||
}
|
||||
|
||||
type typeFlag string
|
||||
|
||||
func (t *typeFlag) Set(s string) error {
|
||||
s = strings.ToLower(s)
|
||||
for _, e := range allTypes {
|
||||
if s == strings.ToLower(e) {
|
||||
*t = typeFlag(e)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Errorf("unknown type")
|
||||
}
|
||||
|
||||
func (t *typeFlag) String() string {
|
||||
return string(*t)
|
||||
}
|
||||
|
||||
func (t *typeFlag) partOf(m []string) bool {
|
||||
for _, e := range m {
|
||||
if t.String() == e {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (t *typeFlag) IsNasType() bool {
|
||||
return t.partOf(nasTypes)
|
||||
}
|
||||
|
||||
func (t *typeFlag) IsVmfsType() bool {
|
||||
return t.partOf(vmfsTypes)
|
||||
}
|
||||
|
||||
func (t *typeFlag) IsLocalType() bool {
|
||||
return t.partOf(localTypes)
|
||||
}
|
||||
|
||||
func (cmd *create) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.HostSystemFlag, ctx = flags.NewHostSystemFlag(ctx)
|
||||
cmd.HostSystemFlag.Register(ctx, f)
|
||||
|
||||
modes := []string{
|
||||
string(types.HostMountModeReadOnly),
|
||||
string(types.HostMountModeReadWrite),
|
||||
}
|
||||
|
||||
f.StringVar(&cmd.Name, "name", "", "Datastore name")
|
||||
f.Var(&cmd.Type, "type", fmt.Sprintf("Datastore type (%s)", strings.Join(allTypes, "|")))
|
||||
f.BoolVar(&cmd.Force, "force", false, "Ignore DuplicateName error if datastore is already mounted on a host")
|
||||
|
||||
// Options for NAS
|
||||
f.StringVar(&cmd.RemoteHost, "remote-host", "", "Remote hostname of the NAS datastore")
|
||||
f.StringVar(&cmd.RemotePath, "remote-path", "", "Remote path of the NFS mount point")
|
||||
f.StringVar(&cmd.AccessMode, "mode", modes[0],
|
||||
fmt.Sprintf("Access mode for the mount point (%s)", strings.Join(modes, "|")))
|
||||
f.StringVar(&cmd.UserName, "username", "", "Username to use when connecting (CIFS only)")
|
||||
f.StringVar(&cmd.Password, "password", "", "Password to use when connecting (CIFS only)")
|
||||
|
||||
// Options for VMFS
|
||||
f.StringVar(&cmd.DiskCanonicalName, "disk", "", "Canonical name of disk (VMFS only)")
|
||||
|
||||
// Options for Local
|
||||
f.StringVar(&cmd.Path, "path", "", "Local directory path for the datastore (local only)")
|
||||
}
|
||||
|
||||
func (cmd *create) Process(ctx context.Context) error {
|
||||
if err := cmd.HostSystemFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *create) Usage() string {
|
||||
return "HOST..."
|
||||
}
|
||||
|
||||
func (cmd *create) Description() string {
|
||||
return `Create datastore on HOST.
|
||||
|
||||
Examples:
|
||||
govc datastore.create -type nfs -name nfsDatastore -remote-host 10.143.2.232 -remote-path /share cluster1
|
||||
govc datastore.create -type vmfs -name vmfsDatastore -disk=mpx.vmhba0:C0:T0:L0 cluster1
|
||||
govc datastore.create -type local -name localDatastore -path /var/datastore host1`
|
||||
}
|
||||
|
||||
func (cmd *create) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
hosts, err := cmd.HostSystems(f.Args())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
switch {
|
||||
case cmd.Type.IsNasType():
|
||||
return cmd.CreateNasDatastore(ctx, hosts)
|
||||
case cmd.Type.IsVmfsType():
|
||||
return cmd.CreateVmfsDatastore(ctx, hosts)
|
||||
case cmd.Type.IsLocalType():
|
||||
return cmd.CreateLocalDatastore(ctx, hosts)
|
||||
default:
|
||||
return fmt.Errorf("unhandled type %#v", cmd.Type)
|
||||
}
|
||||
}
|
||||
|
||||
func (cmd *create) GetHostNasVolumeSpec() types.HostNasVolumeSpec {
|
||||
localPath := cmd.Path
|
||||
if localPath == "" {
|
||||
localPath = cmd.Name
|
||||
}
|
||||
|
||||
s := types.HostNasVolumeSpec{
|
||||
LocalPath: localPath,
|
||||
Type: cmd.Type.String(),
|
||||
RemoteHost: cmd.RemoteHost,
|
||||
RemotePath: cmd.RemotePath,
|
||||
AccessMode: cmd.AccessMode,
|
||||
UserName: cmd.UserName,
|
||||
Password: cmd.Password,
|
||||
}
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
func (cmd *create) CreateNasDatastore(ctx context.Context, hosts []*object.HostSystem) error {
|
||||
object := types.ManagedObjectReference{
|
||||
Type: "Datastore",
|
||||
Value: fmt.Sprintf("%s:%s", cmd.RemoteHost, cmd.RemotePath),
|
||||
}
|
||||
|
||||
spec := cmd.GetHostNasVolumeSpec()
|
||||
|
||||
for _, host := range hosts {
|
||||
ds, err := host.ConfigManager().DatastoreSystem(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = ds.CreateNasDatastore(ctx, spec)
|
||||
if err != nil {
|
||||
if soap.IsSoapFault(err) {
|
||||
switch fault := soap.ToSoapFault(err).VimFault().(type) {
|
||||
case types.PlatformConfigFault:
|
||||
if len(fault.FaultMessage) != 0 {
|
||||
return errors.New(fault.FaultMessage[0].Message)
|
||||
}
|
||||
case types.DuplicateName:
|
||||
if cmd.Force && fault.Object == object {
|
||||
fmt.Fprintf(os.Stderr, "%s: '%s' already mounted\n",
|
||||
host.InventoryPath, cmd.Name)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Errorf("%s: %s", host.InventoryPath, err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *create) CreateVmfsDatastore(ctx context.Context, hosts []*object.HostSystem) error {
|
||||
for _, host := range hosts {
|
||||
ds, err := host.ConfigManager().DatastoreSystem(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Find the specified disk
|
||||
disks, err := ds.QueryAvailableDisksForVmfs(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var disk *types.HostScsiDisk
|
||||
for _, e := range disks {
|
||||
if e.CanonicalName == cmd.DiskCanonicalName {
|
||||
disk = &e
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if disk == nil {
|
||||
return fmt.Errorf("no eligible disk found for name %#v", cmd.DiskCanonicalName)
|
||||
}
|
||||
|
||||
// Query for creation options and pick the right one
|
||||
options, err := ds.QueryVmfsDatastoreCreateOptions(ctx, disk.DevicePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var option *types.VmfsDatastoreOption
|
||||
for _, e := range options {
|
||||
if _, ok := e.Info.(*types.VmfsDatastoreAllExtentOption); ok {
|
||||
option = &e
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if option == nil {
|
||||
return fmt.Errorf("cannot use entire disk for datastore for name %#v", cmd.DiskCanonicalName)
|
||||
}
|
||||
|
||||
spec := *option.Spec.(*types.VmfsDatastoreCreateSpec)
|
||||
spec.Vmfs.VolumeName = cmd.Name
|
||||
_, err = ds.CreateVmfsDatastore(ctx, spec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *create) CreateLocalDatastore(ctx context.Context, hosts []*object.HostSystem) error {
|
||||
for _, host := range hosts {
|
||||
ds, err := host.ConfigManager().DatastoreSystem(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if cmd.Path == "" {
|
||||
cmd.Path = cmd.Name
|
||||
}
|
||||
|
||||
if cmd.Name == "" {
|
||||
cmd.Name = filepath.Base(cmd.Path)
|
||||
}
|
||||
|
||||
_, err = ds.CreateLocalDatastore(ctx, cmd.Name, cmd.Path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
114
vendor/github.com/vmware/govmomi/govc/datastore/disk/create.go
generated
vendored
Normal file
114
vendor/github.com/vmware/govmomi/govc/datastore/disk/create.go
generated
vendored
Normal file
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
Copyright (c) 2017-2018 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 disk
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
"github.com/vmware/govmomi/object"
|
||||
"github.com/vmware/govmomi/units"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
type spec struct {
|
||||
types.FileBackedVirtualDiskSpec
|
||||
force bool
|
||||
}
|
||||
|
||||
func (s *spec) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
f.StringVar(&s.AdapterType, "a", string(types.VirtualDiskAdapterTypeLsiLogic), "Disk adapter")
|
||||
f.StringVar(&s.DiskType, "d", string(types.VirtualDiskTypeThin), "Disk format")
|
||||
f.BoolVar(&s.force, "f", false, "Force")
|
||||
}
|
||||
|
||||
type create struct {
|
||||
*flags.DatastoreFlag
|
||||
|
||||
Bytes units.ByteSize
|
||||
spec
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("datastore.disk.create", &create{})
|
||||
}
|
||||
|
||||
func (cmd *create) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.DatastoreFlag, ctx = flags.NewDatastoreFlag(ctx)
|
||||
cmd.DatastoreFlag.Register(ctx, f)
|
||||
|
||||
_ = cmd.Bytes.Set("10G")
|
||||
f.Var(&cmd.Bytes, "size", "Size of new disk")
|
||||
|
||||
cmd.spec.Register(ctx, f)
|
||||
}
|
||||
|
||||
func (cmd *create) Usage() string {
|
||||
return "VMDK"
|
||||
}
|
||||
|
||||
func (cmd *create) Description() string {
|
||||
return `Create VMDK on DS.
|
||||
|
||||
Examples:
|
||||
govc datastore.mkdir disks
|
||||
govc datastore.disk.create -size 24G disks/disk1.vmdk
|
||||
govc datastore.disk.create disks/parent.vmdk disk/child.vmdk`
|
||||
}
|
||||
|
||||
func (cmd *create) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
if f.NArg() == 0 {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
|
||||
dc, err := cmd.Datacenter()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ds, err := cmd.Datastore()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
m := object.NewVirtualDiskManager(ds.Client())
|
||||
|
||||
var task *object.Task
|
||||
var dst string
|
||||
|
||||
if f.NArg() == 1 {
|
||||
cmd.spec.CapacityKb = int64(cmd.Bytes) / 1024
|
||||
dst = ds.Path(f.Arg(0))
|
||||
task, err = m.CreateVirtualDisk(ctx, dst, dc, &cmd.spec.FileBackedVirtualDiskSpec)
|
||||
} else {
|
||||
dst = ds.Path(f.Arg(0))
|
||||
task, err = m.CreateChildDisk(ctx, ds.Path(f.Arg(0)), dc, dst, dc, cmd.force)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logger := cmd.ProgressLogger(fmt.Sprintf("Creating %s...", dst))
|
||||
defer logger.Wait()
|
||||
|
||||
_, err = task.WaitForResult(ctx, logger)
|
||||
return err
|
||||
}
|
||||
80
vendor/github.com/vmware/govmomi/govc/datastore/disk/inflate.go
generated
vendored
Normal file
80
vendor/github.com/vmware/govmomi/govc/datastore/disk/inflate.go
generated
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
Copyright (c) 2017 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package disk
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
"github.com/vmware/govmomi/object"
|
||||
)
|
||||
|
||||
type inflate struct {
|
||||
*flags.DatastoreFlag
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("datastore.disk.inflate", &inflate{})
|
||||
}
|
||||
|
||||
func (cmd *inflate) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.DatastoreFlag, ctx = flags.NewDatastoreFlag(ctx)
|
||||
cmd.DatastoreFlag.Register(ctx, f)
|
||||
}
|
||||
|
||||
func (cmd *inflate) Process(ctx context.Context) error {
|
||||
return cmd.DatastoreFlag.Process(ctx)
|
||||
}
|
||||
|
||||
func (cmd *inflate) Usage() string {
|
||||
return "VMDK"
|
||||
}
|
||||
|
||||
func (cmd *inflate) Description() string {
|
||||
return `Inflate VMDK on DS.
|
||||
|
||||
Examples:
|
||||
govc datastore.disk.inflate disks/disk1.vmdk`
|
||||
}
|
||||
|
||||
func (cmd *inflate) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
dc, err := cmd.Datacenter()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ds, err := cmd.Datastore()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
m := object.NewVirtualDiskManager(ds.Client())
|
||||
path := ds.Path(f.Arg(0))
|
||||
task, err := m.InflateVirtualDisk(ctx, path, dc)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logger := cmd.ProgressLogger(fmt.Sprintf("Inflating %s...", path))
|
||||
defer logger.Wait()
|
||||
|
||||
_, err = task.WaitForResult(ctx, logger)
|
||||
return err
|
||||
}
|
||||
145
vendor/github.com/vmware/govmomi/govc/datastore/disk/info.go
generated
vendored
Normal file
145
vendor/github.com/vmware/govmomi/govc/datastore/disk/info.go
generated
vendored
Normal file
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
Copyright (c) 2017 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package disk
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
"text/tabwriter"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
"github.com/vmware/govmomi/object"
|
||||
)
|
||||
|
||||
type info struct {
|
||||
*flags.DatastoreFlag
|
||||
|
||||
c bool
|
||||
d bool
|
||||
p bool
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("datastore.disk.info", &info{})
|
||||
}
|
||||
|
||||
func (cmd *info) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.DatastoreFlag, ctx = flags.NewDatastoreFlag(ctx)
|
||||
cmd.DatastoreFlag.Register(ctx, f)
|
||||
|
||||
f.BoolVar(&cmd.c, "c", false, "Chain format")
|
||||
f.BoolVar(&cmd.d, "d", false, "Include datastore in output")
|
||||
f.BoolVar(&cmd.p, "p", true, "Include parents")
|
||||
}
|
||||
|
||||
func (cmd *info) Process(ctx context.Context) error {
|
||||
if err := cmd.DatastoreFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *info) Usage() string {
|
||||
return "VMDK"
|
||||
}
|
||||
|
||||
func (cmd *info) Description() string {
|
||||
return `Query VMDK info on DS.
|
||||
|
||||
Examples:
|
||||
govc datastore.disk.info disks/disk1.vmdk`
|
||||
}
|
||||
|
||||
func fullPath(s string) string {
|
||||
return s
|
||||
}
|
||||
|
||||
func dsPath(s string) string {
|
||||
var p object.DatastorePath
|
||||
|
||||
if p.FromString(s) {
|
||||
return p.Path
|
||||
}
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
var infoPath = dsPath
|
||||
|
||||
type infoResult []object.VirtualDiskInfo
|
||||
|
||||
func (r infoResult) Write(w io.Writer) error {
|
||||
tw := tabwriter.NewWriter(w, 2, 0, 2, ' ', 0)
|
||||
|
||||
for _, info := range r {
|
||||
fmt.Fprintf(tw, "Name:\t%s\n", infoPath(info.Name))
|
||||
fmt.Fprintf(tw, " Type:\t%s\n", info.DiskType)
|
||||
fmt.Fprintf(tw, " Parent:\t%s\n", infoPath(info.Parent))
|
||||
}
|
||||
|
||||
return tw.Flush()
|
||||
}
|
||||
|
||||
type chainResult []object.VirtualDiskInfo
|
||||
|
||||
func (r chainResult) Write(w io.Writer) error {
|
||||
for i, info := range r {
|
||||
fmt.Fprint(w, strings.Repeat(" ", i*2))
|
||||
fmt.Fprintln(w, infoPath(info.Name))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *info) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
if f.NArg() != 1 {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
|
||||
dc, err := cmd.Datacenter()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ds, err := cmd.Datastore()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
m := object.NewVirtualDiskManager(ds.Client())
|
||||
|
||||
info, err := m.QueryVirtualDiskInfo(ctx, ds.Path(f.Arg(0)), dc, cmd.p)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if cmd.d {
|
||||
infoPath = fullPath
|
||||
}
|
||||
|
||||
var r flags.OutputWriter = infoResult(info)
|
||||
|
||||
if cmd.c {
|
||||
r = chainResult(info)
|
||||
}
|
||||
|
||||
return cmd.WriteResult(r)
|
||||
}
|
||||
84
vendor/github.com/vmware/govmomi/govc/datastore/disk/shrink.go
generated
vendored
Normal file
84
vendor/github.com/vmware/govmomi/govc/datastore/disk/shrink.go
generated
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
Copyright (c) 2017 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package disk
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
"github.com/vmware/govmomi/object"
|
||||
)
|
||||
|
||||
type shrink struct {
|
||||
*flags.DatastoreFlag
|
||||
|
||||
copy *bool
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("datastore.disk.shrink", &shrink{})
|
||||
}
|
||||
|
||||
func (cmd *shrink) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.DatastoreFlag, ctx = flags.NewDatastoreFlag(ctx)
|
||||
cmd.DatastoreFlag.Register(ctx, f)
|
||||
|
||||
f.Var(flags.NewOptionalBool(&cmd.copy), "copy", "Perform shrink in-place mode if false, copy-shrink mode otherwise")
|
||||
}
|
||||
|
||||
func (cmd *shrink) Process(ctx context.Context) error {
|
||||
return cmd.DatastoreFlag.Process(ctx)
|
||||
}
|
||||
|
||||
func (cmd *shrink) Usage() string {
|
||||
return "VMDK"
|
||||
}
|
||||
|
||||
func (cmd *shrink) Description() string {
|
||||
return `Shrink VMDK on DS.
|
||||
|
||||
Examples:
|
||||
govc datastore.disk.shrink disks/disk1.vmdk`
|
||||
}
|
||||
|
||||
func (cmd *shrink) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
dc, err := cmd.Datacenter()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ds, err := cmd.Datastore()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
m := object.NewVirtualDiskManager(ds.Client())
|
||||
path := ds.Path(f.Arg(0))
|
||||
task, err := m.ShrinkVirtualDisk(ctx, path, dc, cmd.copy)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logger := cmd.ProgressLogger(fmt.Sprintf("Shrinking %s...", path))
|
||||
defer logger.Wait()
|
||||
|
||||
_, err = task.WaitForResult(ctx, logger)
|
||||
return err
|
||||
}
|
||||
117
vendor/github.com/vmware/govmomi/govc/datastore/download.go
generated
vendored
Normal file
117
vendor/github.com/vmware/govmomi/govc/datastore/download.go
generated
vendored
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
Copyright (c) 2014-2015 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package datastore
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
"github.com/vmware/govmomi/vim25/soap"
|
||||
)
|
||||
|
||||
type download struct {
|
||||
*flags.DatastoreFlag
|
||||
*flags.HostSystemFlag
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("datastore.download", &download{})
|
||||
}
|
||||
|
||||
func (cmd *download) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.DatastoreFlag, ctx = flags.NewDatastoreFlag(ctx)
|
||||
cmd.DatastoreFlag.Register(ctx, f)
|
||||
|
||||
cmd.HostSystemFlag, ctx = flags.NewHostSystemFlag(ctx)
|
||||
cmd.HostSystemFlag.Register(ctx, f)
|
||||
}
|
||||
|
||||
func (cmd *download) Process(ctx context.Context) error {
|
||||
if err := cmd.DatastoreFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := cmd.HostSystemFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *download) Usage() string {
|
||||
return "SOURCE DEST"
|
||||
}
|
||||
|
||||
func (cmd *download) Description() string {
|
||||
return `Copy SOURCE from DS to DEST on the local system.
|
||||
|
||||
If DEST name is "-", source is written to stdout.
|
||||
|
||||
Examples:
|
||||
govc datastore.download vm-name/vmware.log ./local.log
|
||||
govc datastore.download vm-name/vmware.log - | grep -i error`
|
||||
}
|
||||
|
||||
func (cmd *download) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
args := f.Args()
|
||||
if len(args) != 2 {
|
||||
return errors.New("invalid arguments")
|
||||
}
|
||||
|
||||
ds, err := cmd.Datastore()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
h, err := cmd.HostSystemIfSpecified()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var via string
|
||||
|
||||
if h != nil {
|
||||
via = fmt.Sprintf(" via %s", h.InventoryPath)
|
||||
ctx = ds.HostContext(ctx, h)
|
||||
}
|
||||
|
||||
p := soap.DefaultDownload
|
||||
|
||||
src := args[0]
|
||||
dst := args[1]
|
||||
|
||||
if dst == "-" {
|
||||
f, _, err := ds.Download(ctx, src, &p)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = io.Copy(os.Stdout, f)
|
||||
return err
|
||||
}
|
||||
|
||||
if cmd.DatastoreFlag.OutputFlag.TTY {
|
||||
logger := cmd.DatastoreFlag.ProgressLogger(fmt.Sprintf("Downloading%s... ", via))
|
||||
p.Progress = logger
|
||||
defer logger.Wait()
|
||||
}
|
||||
|
||||
return ds.DownloadFile(ctx, src, dst, &p)
|
||||
}
|
||||
153
vendor/github.com/vmware/govmomi/govc/datastore/info.go
generated
vendored
Normal file
153
vendor/github.com/vmware/govmomi/govc/datastore/info.go
generated
vendored
Normal file
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
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 datastore
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"text/tabwriter"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
"github.com/vmware/govmomi/object"
|
||||
"github.com/vmware/govmomi/property"
|
||||
"github.com/vmware/govmomi/vim25/mo"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
type info struct {
|
||||
*flags.ClientFlag
|
||||
*flags.OutputFlag
|
||||
*flags.DatacenterFlag
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("datastore.info", &info{})
|
||||
}
|
||||
|
||||
func (cmd *info) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.ClientFlag, ctx = flags.NewClientFlag(ctx)
|
||||
cmd.ClientFlag.Register(ctx, f)
|
||||
|
||||
cmd.OutputFlag, ctx = flags.NewOutputFlag(ctx)
|
||||
cmd.OutputFlag.Register(ctx, f)
|
||||
|
||||
cmd.DatacenterFlag, ctx = flags.NewDatacenterFlag(ctx)
|
||||
cmd.DatacenterFlag.Register(ctx, f)
|
||||
}
|
||||
|
||||
func (cmd *info) Process(ctx context.Context) error {
|
||||
if err := cmd.ClientFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := cmd.OutputFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := cmd.DatacenterFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *info) Usage() string {
|
||||
return "[PATH]..."
|
||||
}
|
||||
|
||||
func (cmd *info) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
c, err := cmd.Client()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
finder, err := cmd.Finder()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
args := f.Args()
|
||||
if len(args) == 0 {
|
||||
args = []string{"*"}
|
||||
}
|
||||
|
||||
var res infoResult
|
||||
var props []string
|
||||
|
||||
if cmd.OutputFlag.All() {
|
||||
props = nil // Load everything
|
||||
} else {
|
||||
props = []string{"info", "summary"} // Load summary
|
||||
}
|
||||
|
||||
for _, arg := range args {
|
||||
objects, err := finder.DatastoreList(ctx, arg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
res.objects = append(res.objects, objects...)
|
||||
}
|
||||
|
||||
if len(res.objects) != 0 {
|
||||
refs := make([]types.ManagedObjectReference, 0, len(res.objects))
|
||||
for _, o := range res.objects {
|
||||
refs = append(refs, o.Reference())
|
||||
}
|
||||
|
||||
pc := property.DefaultCollector(c)
|
||||
err = pc.Retrieve(ctx, refs, props, &res.Datastores)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return cmd.WriteResult(&res)
|
||||
}
|
||||
|
||||
type infoResult struct {
|
||||
Datastores []mo.Datastore
|
||||
objects []*object.Datastore
|
||||
}
|
||||
|
||||
func (r *infoResult) Write(w io.Writer) error {
|
||||
// Maintain order via r.objects as Property collector does not always return results in order.
|
||||
objects := make(map[types.ManagedObjectReference]mo.Datastore, len(r.Datastores))
|
||||
for _, o := range r.Datastores {
|
||||
objects[o.Reference()] = o
|
||||
}
|
||||
|
||||
tw := tabwriter.NewWriter(os.Stdout, 2, 0, 2, ' ', 0)
|
||||
|
||||
for _, o := range r.objects {
|
||||
ds := objects[o.Reference()]
|
||||
s := ds.Summary
|
||||
fmt.Fprintf(tw, "Name:\t%s\n", s.Name)
|
||||
fmt.Fprintf(tw, " Path:\t%s\n", o.InventoryPath)
|
||||
fmt.Fprintf(tw, " Type:\t%s\n", s.Type)
|
||||
fmt.Fprintf(tw, " URL:\t%s\n", s.Url)
|
||||
fmt.Fprintf(tw, " Capacity:\t%.1f GB\n", float64(s.Capacity)/(1<<30))
|
||||
fmt.Fprintf(tw, " Free:\t%.1f GB\n", float64(s.FreeSpace)/(1<<30))
|
||||
|
||||
switch info := ds.Info.(type) {
|
||||
case *types.NasDatastoreInfo:
|
||||
fmt.Fprintf(tw, " Remote:\t%s:%s\n", info.Nas.RemoteHost, info.Nas.RemotePath)
|
||||
}
|
||||
}
|
||||
|
||||
return tw.Flush()
|
||||
}
|
||||
280
vendor/github.com/vmware/govmomi/govc/datastore/ls.go
generated
vendored
Normal file
280
vendor/github.com/vmware/govmomi/govc/datastore/ls.go
generated
vendored
Normal file
@@ -0,0 +1,280 @@
|
||||
/*
|
||||
Copyright (c) 2014-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 datastore
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"path"
|
||||
"strings"
|
||||
"text/tabwriter"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
"github.com/vmware/govmomi/object"
|
||||
"github.com/vmware/govmomi/units"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
type ls struct {
|
||||
*flags.DatastoreFlag
|
||||
*flags.OutputFlag
|
||||
|
||||
long bool
|
||||
slash bool
|
||||
all bool
|
||||
recurse bool
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("datastore.ls", &ls{})
|
||||
}
|
||||
|
||||
func (cmd *ls) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.DatastoreFlag, ctx = flags.NewDatastoreFlag(ctx)
|
||||
cmd.DatastoreFlag.Register(ctx, f)
|
||||
|
||||
cmd.OutputFlag, ctx = flags.NewOutputFlag(ctx)
|
||||
cmd.OutputFlag.Register(ctx, f)
|
||||
|
||||
f.BoolVar(&cmd.long, "l", false, "Long listing format")
|
||||
f.BoolVar(&cmd.slash, "p", false, "Append / indicator to directories")
|
||||
f.BoolVar(&cmd.all, "a", false, "Do not ignore entries starting with .")
|
||||
f.BoolVar(&cmd.recurse, "R", false, "List subdirectories recursively")
|
||||
}
|
||||
|
||||
func (cmd *ls) Process(ctx context.Context) error {
|
||||
if err := cmd.DatastoreFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := cmd.OutputFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *ls) Usage() string {
|
||||
return "[FILE]..."
|
||||
}
|
||||
|
||||
func isInvalid(err error) bool {
|
||||
if f, ok := err.(types.HasFault); ok {
|
||||
switch f.Fault().(type) {
|
||||
case *types.InvalidArgument:
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (cmd *ls) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
args := cmd.Args(f.Args())
|
||||
|
||||
ds, err := cmd.Datastore()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
b, err := ds.Browser(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(args) == 0 {
|
||||
args = append(args, object.DatastorePath{})
|
||||
}
|
||||
|
||||
result := &listOutput{
|
||||
rs: make([]types.HostDatastoreBrowserSearchResults, 0),
|
||||
cmd: cmd,
|
||||
}
|
||||
|
||||
for _, p := range args {
|
||||
arg := p.Path
|
||||
|
||||
spec := types.HostDatastoreBrowserSearchSpec{
|
||||
MatchPattern: []string{"*"},
|
||||
}
|
||||
|
||||
if cmd.long {
|
||||
spec.Details = &types.FileQueryFlags{
|
||||
FileType: true,
|
||||
FileSize: true,
|
||||
FileOwner: types.NewBool(true), // TODO: omitempty is generated, but seems to be required
|
||||
Modification: true,
|
||||
}
|
||||
}
|
||||
|
||||
for i := 0; ; i++ {
|
||||
r, err := cmd.ListPath(b, arg, spec)
|
||||
if err != nil {
|
||||
// Treat the argument as a match pattern if not found as directory
|
||||
if i == 0 && types.IsFileNotFound(err) || isInvalid(err) {
|
||||
spec.MatchPattern[0] = path.Base(arg)
|
||||
arg = path.Dir(arg)
|
||||
continue
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// Treat an empty result against match pattern as file not found
|
||||
if i == 1 && len(r) == 1 && len(r[0].File) == 0 {
|
||||
return fmt.Errorf("File %s/%s was not found", r[0].FolderPath, spec.MatchPattern[0])
|
||||
}
|
||||
|
||||
for n := range r {
|
||||
result.add(r[n])
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return cmd.WriteResult(result)
|
||||
}
|
||||
|
||||
func (cmd *ls) ListPath(b *object.HostDatastoreBrowser, path string, spec types.HostDatastoreBrowserSearchSpec) ([]types.HostDatastoreBrowserSearchResults, error) {
|
||||
ctx := context.TODO()
|
||||
|
||||
path, err := cmd.DatastorePath(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
search := b.SearchDatastore
|
||||
if cmd.recurse {
|
||||
search = b.SearchDatastoreSubFolders
|
||||
}
|
||||
|
||||
task, err := search(ctx, path, &spec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info, err := task.WaitForResult(ctx, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
switch r := info.Result.(type) {
|
||||
case types.HostDatastoreBrowserSearchResults:
|
||||
return []types.HostDatastoreBrowserSearchResults{r}, nil
|
||||
case types.ArrayOfHostDatastoreBrowserSearchResults:
|
||||
return r.HostDatastoreBrowserSearchResults, nil
|
||||
default:
|
||||
panic(fmt.Sprintf("unknown result type: %T", r))
|
||||
}
|
||||
}
|
||||
|
||||
type listOutput struct {
|
||||
rs []types.HostDatastoreBrowserSearchResults
|
||||
cmd *ls
|
||||
}
|
||||
|
||||
func (o *listOutput) add(r types.HostDatastoreBrowserSearchResults) {
|
||||
if o.cmd.recurse && !o.cmd.all {
|
||||
// filter out ".hidden" directories
|
||||
path := strings.SplitN(r.FolderPath, " ", 2)
|
||||
if len(path) == 2 {
|
||||
path = strings.Split(path[1], "/")
|
||||
if path[0] == "." {
|
||||
path = path[1:]
|
||||
}
|
||||
|
||||
for _, p := range path {
|
||||
if len(p) != 0 && p[0] == '.' {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
res := r
|
||||
res.File = nil
|
||||
|
||||
for _, f := range r.File {
|
||||
if f.GetFileInfo().Path[0] == '.' && !o.cmd.all {
|
||||
continue
|
||||
}
|
||||
|
||||
if o.cmd.slash {
|
||||
if d, ok := f.(*types.FolderFileInfo); ok {
|
||||
d.Path += "/"
|
||||
}
|
||||
}
|
||||
|
||||
res.File = append(res.File, f)
|
||||
}
|
||||
|
||||
o.rs = append(o.rs, res)
|
||||
}
|
||||
|
||||
// hasMultiplePaths returns whether or not the slice of search results contains
|
||||
// results from more than one folder path.
|
||||
func (o *listOutput) hasMultiplePaths() bool {
|
||||
if len(o.rs) == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
p := o.rs[0].FolderPath
|
||||
|
||||
// Multiple paths if any entry is not equal to the first one.
|
||||
for _, e := range o.rs {
|
||||
if e.FolderPath != p {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (o *listOutput) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(o.rs)
|
||||
}
|
||||
|
||||
func (o *listOutput) Write(w io.Writer) error {
|
||||
// Only include path header if we're dealing with more than one path.
|
||||
includeHeader := false
|
||||
if o.hasMultiplePaths() {
|
||||
includeHeader = true
|
||||
}
|
||||
|
||||
tw := tabwriter.NewWriter(w, 3, 0, 2, ' ', 0)
|
||||
for i, r := range o.rs {
|
||||
if includeHeader {
|
||||
if i > 0 {
|
||||
fmt.Fprintf(tw, "\n")
|
||||
}
|
||||
fmt.Fprintf(tw, "%s:\n", r.FolderPath)
|
||||
}
|
||||
for _, file := range r.File {
|
||||
info := file.GetFileInfo()
|
||||
if o.cmd.long {
|
||||
fmt.Fprintf(tw, "%s\t%s\t%s\n", units.ByteSize(info.FileSize), info.Modification.Format("Mon Jan 2 15:04:05 2006"), info.Path)
|
||||
} else {
|
||||
fmt.Fprintf(tw, "%s\n", info.Path)
|
||||
}
|
||||
}
|
||||
}
|
||||
tw.Flush()
|
||||
return nil
|
||||
}
|
||||
118
vendor/github.com/vmware/govmomi/govc/datastore/mkdir.go
generated
vendored
Normal file
118
vendor/github.com/vmware/govmomi/govc/datastore/mkdir.go
generated
vendored
Normal file
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
Copyright (c) 2014-2015 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package datastore
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
"github.com/vmware/govmomi/object"
|
||||
"github.com/vmware/govmomi/vim25/soap"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
type mkdir struct {
|
||||
*flags.DatastoreFlag
|
||||
|
||||
createParents bool
|
||||
isNamespace bool
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("datastore.mkdir", &mkdir{})
|
||||
}
|
||||
|
||||
func (cmd *mkdir) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.DatastoreFlag, ctx = flags.NewDatastoreFlag(ctx)
|
||||
cmd.DatastoreFlag.Register(ctx, f)
|
||||
|
||||
f.BoolVar(&cmd.createParents, "p", false, "Create intermediate directories as needed")
|
||||
f.BoolVar(&cmd.isNamespace, "namespace", false, "Return uuid of namespace created on vsan datastore")
|
||||
}
|
||||
|
||||
func (cmd *mkdir) Process(ctx context.Context) error {
|
||||
if err := cmd.DatastoreFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *mkdir) Usage() string {
|
||||
return "DIRECTORY"
|
||||
}
|
||||
|
||||
func (cmd *mkdir) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
args := f.Args()
|
||||
if len(args) == 0 {
|
||||
return errors.New("missing operand")
|
||||
}
|
||||
|
||||
c, err := cmd.Client()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if cmd.isNamespace {
|
||||
var uuid string
|
||||
var ds *object.Datastore
|
||||
|
||||
if ds, err = cmd.Datastore(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
path := args[0]
|
||||
|
||||
nm := object.NewDatastoreNamespaceManager(c)
|
||||
if uuid, err = nm.CreateDirectory(ctx, ds, path, ""); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Println(uuid)
|
||||
} else {
|
||||
var dc *object.Datacenter
|
||||
var path string
|
||||
|
||||
dc, err = cmd.Datacenter()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
path, err = cmd.DatastorePath(args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
m := object.NewFileManager(c)
|
||||
err = m.MakeDirectory(ctx, path, dc, cmd.createParents)
|
||||
|
||||
// ignore EEXIST if -p flag is given
|
||||
if err != nil && cmd.createParents {
|
||||
if soap.IsSoapFault(err) {
|
||||
soapFault := soap.ToSoapFault(err)
|
||||
if _, ok := soapFault.VimFault().(types.FileAlreadyExists); ok {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
77
vendor/github.com/vmware/govmomi/govc/datastore/mv.go
generated
vendored
Normal file
77
vendor/github.com/vmware/govmomi/govc/datastore/mv.go
generated
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
Copyright (c) 2014-2018 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 datastore
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
)
|
||||
|
||||
type mv struct {
|
||||
target
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("datastore.mv", &mv{})
|
||||
}
|
||||
|
||||
func (cmd *mv) Usage() string {
|
||||
return "SRC DST"
|
||||
}
|
||||
|
||||
func (cmd *mv) Description() string {
|
||||
return `Move SRC to DST on DATASTORE.
|
||||
|
||||
Examples:
|
||||
govc datastore.mv foo/foo.vmx foo/foo.vmx.old
|
||||
govc datastore.mv -f my.vmx foo/foo.vmx`
|
||||
}
|
||||
|
||||
func (cmd *mv) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
args := f.Args()
|
||||
if len(args) != 2 {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
|
||||
m, err := cmd.FileManager()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
src, err := cmd.DatastorePath(args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dst, err := cmd.target.ds.DatastorePath(args[1])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
mv := m.MoveFile
|
||||
if cmd.kind {
|
||||
mv = m.Move
|
||||
}
|
||||
|
||||
logger := cmd.ProgressLogger(fmt.Sprintf("Moving %s to %s...", src, dst))
|
||||
defer logger.Wait()
|
||||
|
||||
return mv(m.WithProgress(ctx, logger), src, dst)
|
||||
}
|
||||
90
vendor/github.com/vmware/govmomi/govc/datastore/remove.go
generated
vendored
Normal file
90
vendor/github.com/vmware/govmomi/govc/datastore/remove.go
generated
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
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 datastore
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
)
|
||||
|
||||
type remove struct {
|
||||
*flags.HostSystemFlag
|
||||
*flags.DatastoreFlag
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("datastore.remove", &remove{})
|
||||
}
|
||||
|
||||
func (cmd *remove) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.HostSystemFlag, ctx = flags.NewHostSystemFlag(ctx)
|
||||
cmd.HostSystemFlag.Register(ctx, f)
|
||||
|
||||
cmd.DatastoreFlag, ctx = flags.NewDatastoreFlag(ctx)
|
||||
cmd.DatastoreFlag.Register(ctx, f)
|
||||
}
|
||||
|
||||
func (cmd *remove) Process(ctx context.Context) error {
|
||||
if err := cmd.HostSystemFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := cmd.DatastoreFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *remove) Usage() string {
|
||||
return "HOST..."
|
||||
}
|
||||
|
||||
func (cmd *remove) Description() string {
|
||||
return `Remove datastore from HOST.
|
||||
|
||||
Examples:
|
||||
govc datastore.remove -ds nfsDatastore cluster1
|
||||
govc datastore.remove -ds nasDatastore host1 host2 host3`
|
||||
}
|
||||
|
||||
func (cmd *remove) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
ds, err := cmd.Datastore()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
hosts, err := cmd.HostSystems(f.Args())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, host := range hosts {
|
||||
hds, err := host.ConfigManager().DatastoreSystem(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = hds.Remove(ctx, ds)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
117
vendor/github.com/vmware/govmomi/govc/datastore/rm.go
generated
vendored
Normal file
117
vendor/github.com/vmware/govmomi/govc/datastore/rm.go
generated
vendored
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
Copyright (c) 2014-2015 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package datastore
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
"github.com/vmware/govmomi/object"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
type rm struct {
|
||||
*flags.DatastoreFlag
|
||||
|
||||
kind bool
|
||||
force bool
|
||||
isNamespace bool
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("datastore.rm", &rm{})
|
||||
cli.Alias("datastore.rm", "datastore.delete")
|
||||
}
|
||||
|
||||
func (cmd *rm) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.DatastoreFlag, ctx = flags.NewDatastoreFlag(ctx)
|
||||
cmd.DatastoreFlag.Register(ctx, f)
|
||||
|
||||
f.BoolVar(&cmd.kind, "t", true, "Use file type to choose disk or file manager")
|
||||
f.BoolVar(&cmd.force, "f", false, "Force; ignore nonexistent files and arguments")
|
||||
f.BoolVar(&cmd.isNamespace, "namespace", false, "Path is uuid of namespace on vsan datastore")
|
||||
}
|
||||
|
||||
func (cmd *rm) Process(ctx context.Context) error {
|
||||
if err := cmd.DatastoreFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *rm) Usage() string {
|
||||
return "FILE"
|
||||
}
|
||||
|
||||
func (cmd *rm) Description() string {
|
||||
return `Remove FILE from DATASTORE.
|
||||
|
||||
Examples:
|
||||
govc datastore.rm vm/vmware.log
|
||||
govc datastore.rm vm
|
||||
govc datastore.rm -f images/base.vmdk`
|
||||
}
|
||||
|
||||
func (cmd *rm) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
args := f.Args()
|
||||
if len(args) == 0 {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
|
||||
c, err := cmd.Client()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var dc *object.Datacenter
|
||||
dc, err = cmd.Datacenter()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ds, err := cmd.Datastore()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if cmd.isNamespace {
|
||||
path := args[0]
|
||||
|
||||
nm := object.NewDatastoreNamespaceManager(c)
|
||||
err = nm.DeleteDirectory(ctx, dc, path)
|
||||
} else {
|
||||
fm := ds.NewFileManager(dc, cmd.force)
|
||||
|
||||
remove := fm.DeleteFile // File delete
|
||||
if cmd.kind {
|
||||
remove = fm.Delete // VirtualDisk or File delete
|
||||
}
|
||||
|
||||
err = remove(ctx, args[0])
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
if types.IsFileNotFound(err) && cmd.force {
|
||||
// Ignore error
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
137
vendor/github.com/vmware/govmomi/govc/datastore/tail.go
generated
vendored
Normal file
137
vendor/github.com/vmware/govmomi/govc/datastore/tail.go
generated
vendored
Normal file
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
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 datastore
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"io"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
)
|
||||
|
||||
type tail struct {
|
||||
*flags.DatastoreFlag
|
||||
*flags.HostSystemFlag
|
||||
|
||||
count int64
|
||||
lines int
|
||||
follow bool
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("datastore.tail", &tail{})
|
||||
}
|
||||
|
||||
func (cmd *tail) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.DatastoreFlag, ctx = flags.NewDatastoreFlag(ctx)
|
||||
cmd.DatastoreFlag.Register(ctx, f)
|
||||
|
||||
cmd.HostSystemFlag, ctx = flags.NewHostSystemFlag(ctx)
|
||||
cmd.HostSystemFlag.Register(ctx, f)
|
||||
|
||||
f.Int64Var(&cmd.count, "c", -1, "Output the last NUM bytes")
|
||||
f.IntVar(&cmd.lines, "n", 10, "Output the last NUM lines")
|
||||
f.BoolVar(&cmd.follow, "f", false, "Output appended data as the file grows")
|
||||
}
|
||||
|
||||
func (cmd *tail) Description() string {
|
||||
return `Output the last part of datastore files.
|
||||
|
||||
Examples:
|
||||
govc datastore.tail -n 100 vm-name/vmware.log
|
||||
govc datastore.tail -n 0 -f vm-name/vmware.log`
|
||||
}
|
||||
|
||||
func (cmd *tail) Process(ctx context.Context) error {
|
||||
if err := cmd.DatastoreFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := cmd.HostSystemFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *tail) Usage() string {
|
||||
return "PATH"
|
||||
}
|
||||
|
||||
func (cmd *tail) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
if f.NArg() != 1 {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
|
||||
p := cmd.Args(f.Args())[0]
|
||||
|
||||
ds, err := cmd.Datastore()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
h, err := cmd.HostSystemIfSpecified()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if h != nil {
|
||||
ctx = ds.HostContext(ctx, h)
|
||||
}
|
||||
|
||||
file, err := ds.Open(ctx, p.Path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var reader io.ReadCloser = file
|
||||
|
||||
var offset int64
|
||||
|
||||
if cmd.count >= 0 {
|
||||
info, serr := file.Stat()
|
||||
if serr != nil {
|
||||
return serr
|
||||
}
|
||||
|
||||
if info.Size() > cmd.count {
|
||||
offset = info.Size() - cmd.count
|
||||
|
||||
_, err = file.Seek(offset, io.SeekStart)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else if cmd.lines >= 0 {
|
||||
err = file.Tail(cmd.lines)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if cmd.follow {
|
||||
reader = file.Follow(time.Second)
|
||||
}
|
||||
|
||||
_, err = io.Copy(os.Stdout, reader)
|
||||
|
||||
_ = reader.Close()
|
||||
|
||||
return err
|
||||
}
|
||||
98
vendor/github.com/vmware/govmomi/govc/datastore/upload.go
generated
vendored
Normal file
98
vendor/github.com/vmware/govmomi/govc/datastore/upload.go
generated
vendored
Normal file
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
Copyright (c) 2014-2015 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package datastore
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"flag"
|
||||
"os"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
"github.com/vmware/govmomi/vim25/soap"
|
||||
)
|
||||
|
||||
type upload struct {
|
||||
*flags.OutputFlag
|
||||
*flags.DatastoreFlag
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("datastore.upload", &upload{})
|
||||
}
|
||||
|
||||
func (cmd *upload) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.OutputFlag, ctx = flags.NewOutputFlag(ctx)
|
||||
cmd.OutputFlag.Register(ctx, f)
|
||||
|
||||
cmd.DatastoreFlag, ctx = flags.NewDatastoreFlag(ctx)
|
||||
cmd.DatastoreFlag.Register(ctx, f)
|
||||
}
|
||||
|
||||
func (cmd *upload) Process(ctx context.Context) error {
|
||||
if err := cmd.OutputFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := cmd.DatastoreFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *upload) Usage() string {
|
||||
return "SOURCE DEST"
|
||||
}
|
||||
|
||||
func (cmd *upload) Description() string {
|
||||
return `Copy SOURCE from the local system to DEST on DS.
|
||||
|
||||
If SOURCE name is "-", read source from stdin.
|
||||
|
||||
Examples:
|
||||
govc datastore.upload -ds datastore1 ./config.iso vm-name/config.iso
|
||||
genisoimage ... | govc datastore.upload -ds datastore1 - vm-name/config.iso`
|
||||
}
|
||||
|
||||
func (cmd *upload) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
args := f.Args()
|
||||
if len(args) != 2 {
|
||||
return errors.New("invalid arguments")
|
||||
}
|
||||
|
||||
ds, err := cmd.Datastore()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
p := soap.DefaultUpload
|
||||
|
||||
src := args[0]
|
||||
dst := args[1]
|
||||
|
||||
if src == "-" {
|
||||
return ds.Upload(ctx, os.Stdin, dst, &p)
|
||||
}
|
||||
|
||||
if cmd.OutputFlag.TTY {
|
||||
logger := cmd.ProgressLogger("Uploading... ")
|
||||
p.Progress = logger
|
||||
defer logger.Wait()
|
||||
}
|
||||
|
||||
return ds.UploadFile(ctx, src, dst, &p)
|
||||
}
|
||||
156
vendor/github.com/vmware/govmomi/govc/datastore/vsan/ls.go
generated
vendored
Normal file
156
vendor/github.com/vmware/govmomi/govc/datastore/vsan/ls.go
generated
vendored
Normal file
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
Copyright (c) 2017 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package vsan
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"text/tabwriter"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
"github.com/vmware/govmomi/object"
|
||||
"github.com/vmware/govmomi/vim25/mo"
|
||||
)
|
||||
|
||||
type ls struct {
|
||||
*flags.DatastoreFlag
|
||||
|
||||
long bool
|
||||
orphan bool
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("datastore.vsan.dom.ls", &ls{})
|
||||
}
|
||||
|
||||
func (cmd *ls) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.DatastoreFlag, ctx = flags.NewDatastoreFlag(ctx)
|
||||
cmd.DatastoreFlag.Register(ctx, f)
|
||||
|
||||
f.BoolVar(&cmd.long, "l", false, "Long listing")
|
||||
f.BoolVar(&cmd.orphan, "o", false, "List orphan objects")
|
||||
}
|
||||
|
||||
func (cmd *ls) Process(ctx context.Context) error {
|
||||
if err := cmd.DatastoreFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *ls) Usage() string {
|
||||
return "[UUID]..."
|
||||
}
|
||||
|
||||
func (cmd *ls) Description() string {
|
||||
return `List vSAN DOM objects in DS.
|
||||
|
||||
Examples:
|
||||
govc datastore.vsan.dom.ls
|
||||
govc datastore.vsan.dom.ls -ds vsanDatastore -l
|
||||
govc datastore.vsan.dom.ls -l d85aa758-63f5-500a-3150-0200308e589c`
|
||||
}
|
||||
|
||||
func (cmd *ls) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
ds, err := cmd.Datastore()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var mds mo.Datastore
|
||||
err = ds.Properties(ctx, ds.Reference(), []string{"summary"}, &mds)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if mds.Summary.Type != "vsan" {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
|
||||
hosts, err := ds.AttachedHosts(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(hosts) == 0 {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
|
||||
m, err := hosts[0].ConfigManager().VsanInternalSystem(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ids, err := m.QueryVsanObjectUuidsByFilter(ctx, f.Args(), 0, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
if !cmd.long && !cmd.orphan {
|
||||
for _, id := range ids {
|
||||
fmt.Fprintln(cmd.Out, id)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
objs, err := m.GetVsanObjExtAttrs(ctx, ids)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
u, err := url.Parse(mds.Summary.Url)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
tw := tabwriter.NewWriter(cmd.Out, 2, 0, 2, ' ', 0)
|
||||
cmd.Out = tw
|
||||
|
||||
for id, obj := range objs {
|
||||
path := obj.DatastorePath(u.Path)
|
||||
|
||||
if cmd.orphan {
|
||||
_, err = ds.Stat(ctx, path)
|
||||
if err == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
switch err.(type) {
|
||||
case object.DatastoreNoSuchDirectoryError, object.DatastoreNoSuchFileError:
|
||||
default:
|
||||
return err
|
||||
}
|
||||
|
||||
if !cmd.long {
|
||||
fmt.Fprintln(cmd.Out, id)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Fprintf(cmd.Out, "%s\t%s\t%s\n", id, obj.Class, path)
|
||||
}
|
||||
|
||||
return tw.Flush()
|
||||
}
|
||||
108
vendor/github.com/vmware/govmomi/govc/datastore/vsan/rm.go
generated
vendored
Normal file
108
vendor/github.com/vmware/govmomi/govc/datastore/vsan/rm.go
generated
vendored
Normal file
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
Copyright (c) 2017 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package vsan
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
)
|
||||
|
||||
type rm struct {
|
||||
*flags.DatastoreFlag
|
||||
|
||||
force bool
|
||||
verbose bool
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("datastore.vsan.dom.rm", &rm{})
|
||||
}
|
||||
|
||||
func (cmd *rm) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.DatastoreFlag, ctx = flags.NewDatastoreFlag(ctx)
|
||||
cmd.DatastoreFlag.Register(ctx, f)
|
||||
|
||||
f.BoolVar(&cmd.force, "f", false, "Force delete")
|
||||
f.BoolVar(&cmd.verbose, "v", false, "Print deleted UUIDs to stdout, failed to stderr")
|
||||
}
|
||||
|
||||
func (cmd *rm) Process(ctx context.Context) error {
|
||||
if err := cmd.DatastoreFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *rm) Usage() string {
|
||||
return "UUID..."
|
||||
}
|
||||
|
||||
func (cmd *rm) Description() string {
|
||||
return `Remove vSAN DOM objects in DS.
|
||||
|
||||
Examples:
|
||||
govc datastore.vsan.dom.rm d85aa758-63f5-500a-3150-0200308e589c
|
||||
govc datastore.vsan.dom.rm -f d85aa758-63f5-500a-3150-0200308e589c
|
||||
govc datastore.vsan.dom.ls -o | xargs govc datastore.vsan.dom.rm`
|
||||
}
|
||||
|
||||
func (cmd *rm) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
if f.NArg() == 0 {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
|
||||
ds, err := cmd.Datastore()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
hosts, err := ds.AttachedHosts(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(hosts) == 0 {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
|
||||
m, err := hosts[0].ConfigManager().VsanInternalSystem(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
res, err := m.DeleteVsanObjects(ctx, f.Args(), &cmd.force)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if cmd.verbose {
|
||||
for _, r := range res {
|
||||
if r.Success {
|
||||
fmt.Fprintln(cmd.Out, r.Uuid)
|
||||
} else {
|
||||
fmt.Fprintf(os.Stderr, "%s %s\n", r.Uuid, r.FailureReason[0].Message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
91
vendor/github.com/vmware/govmomi/govc/device/boot.go
generated
vendored
Normal file
91
vendor/github.com/vmware/govmomi/govc/device/boot.go
generated
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
Copyright (c) 2014-2017 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
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 device
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"strings"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
type boot struct {
|
||||
*flags.VirtualMachineFlag
|
||||
|
||||
order string
|
||||
types.VirtualMachineBootOptions
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("device.boot", &boot{})
|
||||
}
|
||||
|
||||
func (cmd *boot) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.VirtualMachineFlag, ctx = flags.NewVirtualMachineFlag(ctx)
|
||||
cmd.VirtualMachineFlag.Register(ctx, f)
|
||||
|
||||
f.Int64Var(&cmd.BootDelay, "delay", 0, "Delay in ms before starting the boot sequence")
|
||||
f.StringVar(&cmd.order, "order", "", "Boot device order [-,floppy,cdrom,ethernet,disk]")
|
||||
f.Int64Var(&cmd.BootRetryDelay, "retry-delay", 0, "Delay in ms before a boot retry")
|
||||
|
||||
cmd.BootRetryEnabled = types.NewBool(false)
|
||||
f.BoolVar(cmd.BootRetryEnabled, "retry", false, "If true, retry boot after retry-delay")
|
||||
|
||||
cmd.EnterBIOSSetup = types.NewBool(false)
|
||||
f.BoolVar(cmd.EnterBIOSSetup, "setup", false, "If true, enter BIOS setup on next boot")
|
||||
}
|
||||
|
||||
func (cmd *boot) Description() string {
|
||||
return `Configure VM boot settings.
|
||||
|
||||
Examples:
|
||||
govc device.boot -vm $vm -delay 1000 -order floppy,cdrom,ethernet,disk
|
||||
govc device.boot -vm $vm -order - # reset boot order`
|
||||
}
|
||||
|
||||
func (cmd *boot) Process(ctx context.Context) error {
|
||||
if err := cmd.VirtualMachineFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *boot) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
vm, err := cmd.VirtualMachine()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if vm == nil {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
|
||||
devices, err := vm.Device(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if cmd.order != "" {
|
||||
o := strings.Split(cmd.order, ",")
|
||||
cmd.BootOrder = devices.BootOrder(o)
|
||||
}
|
||||
|
||||
return vm.SetBootOptions(ctx, &cmd.VirtualMachineBootOptions)
|
||||
}
|
||||
105
vendor/github.com/vmware/govmomi/govc/device/cdrom/add.go
generated
vendored
Normal file
105
vendor/github.com/vmware/govmomi/govc/device/cdrom/add.go
generated
vendored
Normal file
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
Copyright (c) 2014-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 cdrom
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
)
|
||||
|
||||
type add struct {
|
||||
*flags.VirtualMachineFlag
|
||||
|
||||
controller string
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("device.cdrom.add", &add{})
|
||||
}
|
||||
|
||||
func (cmd *add) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.VirtualMachineFlag, ctx = flags.NewVirtualMachineFlag(ctx)
|
||||
cmd.VirtualMachineFlag.Register(ctx, f)
|
||||
|
||||
f.StringVar(&cmd.controller, "controller", "", "IDE controller name")
|
||||
}
|
||||
|
||||
func (cmd *add) Description() string {
|
||||
return `Add CD-ROM device to VM.
|
||||
|
||||
Examples:
|
||||
govc device.cdrom.add -vm $vm
|
||||
govc device.ls -vm $vm | grep ide-
|
||||
govc device.cdrom.add -vm $vm -controller ide-200
|
||||
govc device.info cdrom-*`
|
||||
}
|
||||
|
||||
func (cmd *add) Process(ctx context.Context) error {
|
||||
if err := cmd.VirtualMachineFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *add) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
vm, err := cmd.VirtualMachine()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if vm == nil {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
|
||||
devices, err := vm.Device(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c, err := devices.FindIDEController(cmd.controller)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
d, err := devices.CreateCdrom(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = vm.AddDevice(ctx, d)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// output name of device we just created
|
||||
devices, err = vm.Device(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
devices = devices.SelectByType(d)
|
||||
|
||||
name := devices.Name(devices[len(devices)-1])
|
||||
|
||||
fmt.Println(name)
|
||||
|
||||
return nil
|
||||
}
|
||||
82
vendor/github.com/vmware/govmomi/govc/device/cdrom/eject.go
generated
vendored
Normal file
82
vendor/github.com/vmware/govmomi/govc/device/cdrom/eject.go
generated
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
Copyright (c) 2014-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 cdrom
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
)
|
||||
|
||||
type eject struct {
|
||||
*flags.VirtualMachineFlag
|
||||
|
||||
device string
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("device.cdrom.eject", &eject{})
|
||||
}
|
||||
|
||||
func (cmd *eject) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.VirtualMachineFlag, ctx = flags.NewVirtualMachineFlag(ctx)
|
||||
cmd.VirtualMachineFlag.Register(ctx, f)
|
||||
|
||||
f.StringVar(&cmd.device, "device", "", "CD-ROM device name")
|
||||
}
|
||||
|
||||
func (cmd *eject) Process(ctx context.Context) error {
|
||||
if err := cmd.VirtualMachineFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *eject) Description() string {
|
||||
return `Eject media from CD-ROM device.
|
||||
|
||||
If device is not specified, the first CD-ROM device is used.
|
||||
|
||||
Examples:
|
||||
govc device.cdrom.eject -vm vm-1
|
||||
govc device.cdrom.eject -vm vm-1 -device floppy-1`
|
||||
}
|
||||
|
||||
func (cmd *eject) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
vm, err := cmd.VirtualMachine()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if vm == nil {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
|
||||
devices, err := vm.Device(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c, err := devices.FindCdrom(cmd.device)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return vm.EditDevice(ctx, devices.EjectIso(c))
|
||||
}
|
||||
96
vendor/github.com/vmware/govmomi/govc/device/cdrom/insert.go
generated
vendored
Normal file
96
vendor/github.com/vmware/govmomi/govc/device/cdrom/insert.go
generated
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
Copyright (c) 2014-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 cdrom
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
)
|
||||
|
||||
type insert struct {
|
||||
*flags.DatastoreFlag
|
||||
*flags.VirtualMachineFlag
|
||||
|
||||
device string
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("device.cdrom.insert", &insert{})
|
||||
}
|
||||
|
||||
func (cmd *insert) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.DatastoreFlag, ctx = flags.NewDatastoreFlag(ctx)
|
||||
cmd.DatastoreFlag.Register(ctx, f)
|
||||
cmd.VirtualMachineFlag, ctx = flags.NewVirtualMachineFlag(ctx)
|
||||
cmd.VirtualMachineFlag.Register(ctx, f)
|
||||
|
||||
f.StringVar(&cmd.device, "device", "", "CD-ROM device name")
|
||||
}
|
||||
|
||||
func (cmd *insert) Process(ctx context.Context) error {
|
||||
if err := cmd.DatastoreFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := cmd.VirtualMachineFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *insert) Usage() string {
|
||||
return "ISO"
|
||||
}
|
||||
|
||||
func (cmd *insert) Description() string {
|
||||
return `Insert media on datastore into CD-ROM device.
|
||||
|
||||
If device is not specified, the first CD-ROM device is used.
|
||||
|
||||
Examples:
|
||||
govc device.cdrom.insert -vm vm-1 -device cdrom-3000 images/boot.iso`
|
||||
}
|
||||
|
||||
func (cmd *insert) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
vm, err := cmd.VirtualMachine()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if vm == nil || f.NArg() != 1 {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
|
||||
devices, err := vm.Device(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c, err := devices.FindCdrom(cmd.device)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
iso, err := cmd.DatastorePath(f.Arg(0))
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return vm.EditDevice(ctx, devices.InsertIso(c, iso))
|
||||
}
|
||||
90
vendor/github.com/vmware/govmomi/govc/device/connect.go
generated
vendored
Normal file
90
vendor/github.com/vmware/govmomi/govc/device/connect.go
generated
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
Copyright (c) 2014-2017 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
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 device
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
)
|
||||
|
||||
type connect struct {
|
||||
*flags.VirtualMachineFlag
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("device.connect", &connect{})
|
||||
}
|
||||
|
||||
func (cmd *connect) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.VirtualMachineFlag, ctx = flags.NewVirtualMachineFlag(ctx)
|
||||
cmd.VirtualMachineFlag.Register(ctx, f)
|
||||
}
|
||||
|
||||
func (cmd *connect) Process(ctx context.Context) error {
|
||||
if err := cmd.VirtualMachineFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *connect) Usage() string {
|
||||
return "DEVICE..."
|
||||
}
|
||||
|
||||
func (cmd *connect) Description() string {
|
||||
return `Connect DEVICE on VM.
|
||||
|
||||
Examples:
|
||||
govc device.connect -vm $name cdrom-3000`
|
||||
}
|
||||
|
||||
func (cmd *connect) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
vm, err := cmd.VirtualMachine()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if vm == nil {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
|
||||
devices, err := vm.Device(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, name := range f.Args() {
|
||||
device := devices.Find(name)
|
||||
if device == nil {
|
||||
return fmt.Errorf("device '%s' not found", name)
|
||||
}
|
||||
|
||||
if err = devices.Connect(device); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = vm.EditDevice(ctx, device); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
90
vendor/github.com/vmware/govmomi/govc/device/disconnect.go
generated
vendored
Normal file
90
vendor/github.com/vmware/govmomi/govc/device/disconnect.go
generated
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
Copyright (c) 2014-2017 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
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 device
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
)
|
||||
|
||||
type disconnect struct {
|
||||
*flags.VirtualMachineFlag
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("device.disconnect", &disconnect{})
|
||||
}
|
||||
|
||||
func (cmd *disconnect) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.VirtualMachineFlag, ctx = flags.NewVirtualMachineFlag(ctx)
|
||||
cmd.VirtualMachineFlag.Register(ctx, f)
|
||||
}
|
||||
|
||||
func (cmd *disconnect) Process(ctx context.Context) error {
|
||||
if err := cmd.VirtualMachineFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *disconnect) Usage() string {
|
||||
return "DEVICE..."
|
||||
}
|
||||
|
||||
func (cmd *disconnect) Description() string {
|
||||
return `Disconnect DEVICE on VM.
|
||||
|
||||
Examples:
|
||||
govc device.disconnect -vm $name cdrom-3000`
|
||||
}
|
||||
|
||||
func (cmd *disconnect) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
vm, err := cmd.VirtualMachine()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if vm == nil {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
|
||||
devices, err := vm.Device(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, name := range f.Args() {
|
||||
device := devices.Find(name)
|
||||
if device == nil {
|
||||
return fmt.Errorf("device '%s' not found", name)
|
||||
}
|
||||
|
||||
if err = devices.Disconnect(device); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = vm.EditDevice(ctx, device); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
94
vendor/github.com/vmware/govmomi/govc/device/floppy/add.go
generated
vendored
Normal file
94
vendor/github.com/vmware/govmomi/govc/device/floppy/add.go
generated
vendored
Normal file
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
Copyright (c) 2014-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 floppy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
)
|
||||
|
||||
type add struct {
|
||||
*flags.VirtualMachineFlag
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("device.floppy.add", &add{})
|
||||
}
|
||||
|
||||
func (cmd *add) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.VirtualMachineFlag, ctx = flags.NewVirtualMachineFlag(ctx)
|
||||
cmd.VirtualMachineFlag.Register(ctx, f)
|
||||
}
|
||||
|
||||
func (cmd *add) Description() string {
|
||||
return `Add floppy device to VM.
|
||||
|
||||
Examples:
|
||||
govc device.floppy.add -vm $vm
|
||||
govc device.info floppy-*`
|
||||
}
|
||||
|
||||
func (cmd *add) Process(ctx context.Context) error {
|
||||
if err := cmd.VirtualMachineFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *add) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
vm, err := cmd.VirtualMachine()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if vm == nil {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
|
||||
devices, err := vm.Device(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
d, err := devices.CreateFloppy()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = vm.AddDevice(ctx, d)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// output name of device we just created
|
||||
devices, err = vm.Device(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
devices = devices.SelectByType(d)
|
||||
|
||||
name := devices.Name(devices[len(devices)-1])
|
||||
|
||||
fmt.Println(name)
|
||||
|
||||
return nil
|
||||
}
|
||||
81
vendor/github.com/vmware/govmomi/govc/device/floppy/eject.go
generated
vendored
Normal file
81
vendor/github.com/vmware/govmomi/govc/device/floppy/eject.go
generated
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
Copyright (c) 2014-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 floppy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
)
|
||||
|
||||
type eject struct {
|
||||
*flags.VirtualMachineFlag
|
||||
|
||||
device string
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("device.floppy.eject", &eject{})
|
||||
}
|
||||
|
||||
func (cmd *eject) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.VirtualMachineFlag, ctx = flags.NewVirtualMachineFlag(ctx)
|
||||
cmd.VirtualMachineFlag.Register(ctx, f)
|
||||
|
||||
f.StringVar(&cmd.device, "device", "", "Floppy device name")
|
||||
}
|
||||
|
||||
func (cmd *eject) Process(ctx context.Context) error {
|
||||
if err := cmd.VirtualMachineFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *eject) Description() string {
|
||||
return `Eject image from floppy device.
|
||||
|
||||
If device is not specified, the first floppy device is used.
|
||||
|
||||
Examples:
|
||||
govc device.floppy.eject -vm vm-1`
|
||||
}
|
||||
|
||||
func (cmd *eject) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
vm, err := cmd.VirtualMachine()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if vm == nil {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
|
||||
devices, err := vm.Device(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c, err := devices.FindFloppy(cmd.device)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return vm.EditDevice(ctx, devices.EjectImg(c))
|
||||
}
|
||||
96
vendor/github.com/vmware/govmomi/govc/device/floppy/insert.go
generated
vendored
Normal file
96
vendor/github.com/vmware/govmomi/govc/device/floppy/insert.go
generated
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
Copyright (c) 2014-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 floppy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
)
|
||||
|
||||
type insert struct {
|
||||
*flags.DatastoreFlag
|
||||
*flags.VirtualMachineFlag
|
||||
|
||||
device string
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("device.floppy.insert", &insert{})
|
||||
}
|
||||
|
||||
func (cmd *insert) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.DatastoreFlag, ctx = flags.NewDatastoreFlag(ctx)
|
||||
cmd.DatastoreFlag.Register(ctx, f)
|
||||
cmd.VirtualMachineFlag, ctx = flags.NewVirtualMachineFlag(ctx)
|
||||
cmd.VirtualMachineFlag.Register(ctx, f)
|
||||
|
||||
f.StringVar(&cmd.device, "device", "", "Floppy device name")
|
||||
}
|
||||
|
||||
func (cmd *insert) Process(ctx context.Context) error {
|
||||
if err := cmd.DatastoreFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := cmd.VirtualMachineFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *insert) Usage() string {
|
||||
return "IMG"
|
||||
}
|
||||
|
||||
func (cmd *insert) Description() string {
|
||||
return `Insert IMG on datastore into floppy device.
|
||||
|
||||
If device is not specified, the first floppy device is used.
|
||||
|
||||
Examples:
|
||||
govc device.floppy.insert -vm vm-1 vm-1/config.img`
|
||||
}
|
||||
|
||||
func (cmd *insert) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
vm, err := cmd.VirtualMachine()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if vm == nil || f.NArg() != 1 {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
|
||||
devices, err := vm.Device(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c, err := devices.FindFloppy(cmd.device)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
img, err := cmd.DatastorePath(f.Arg(0))
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return vm.EditDevice(ctx, devices.InsertImg(c, img))
|
||||
}
|
||||
249
vendor/github.com/vmware/govmomi/govc/device/info.go
generated
vendored
Normal file
249
vendor/github.com/vmware/govmomi/govc/device/info.go
generated
vendored
Normal file
@@ -0,0 +1,249 @@
|
||||
/*
|
||||
Copyright (c) 2014-2017 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
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 device
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
"text/tabwriter"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
"github.com/vmware/govmomi/object"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
type info struct {
|
||||
*flags.VirtualMachineFlag
|
||||
*flags.OutputFlag
|
||||
*flags.NetworkFlag
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("device.info", &info{})
|
||||
}
|
||||
|
||||
func (cmd *info) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.VirtualMachineFlag, ctx = flags.NewVirtualMachineFlag(ctx)
|
||||
cmd.VirtualMachineFlag.Register(ctx, f)
|
||||
|
||||
cmd.OutputFlag, ctx = flags.NewOutputFlag(ctx)
|
||||
cmd.OutputFlag.Register(ctx, f)
|
||||
|
||||
cmd.NetworkFlag, ctx = flags.NewNetworkFlag(ctx)
|
||||
cmd.NetworkFlag.Register(ctx, f)
|
||||
}
|
||||
|
||||
func (cmd *info) Process(ctx context.Context) error {
|
||||
if err := cmd.VirtualMachineFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := cmd.OutputFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := cmd.NetworkFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *info) Usage() string {
|
||||
return "[DEVICE]..."
|
||||
}
|
||||
|
||||
func (cmd *info) Description() string {
|
||||
return `Device info for VM.
|
||||
|
||||
Examples:
|
||||
govc device.info -vm $name
|
||||
govc device.info -vm $name disk-*
|
||||
govc device.info -vm $name -json ethernet-0 | jq -r .Devices[].MacAddress`
|
||||
}
|
||||
|
||||
func (cmd *info) match(p string, devices object.VirtualDeviceList) object.VirtualDeviceList {
|
||||
var matches object.VirtualDeviceList
|
||||
match := func(name string) bool {
|
||||
matched, _ := path.Match(p, name)
|
||||
return matched
|
||||
}
|
||||
|
||||
for _, device := range devices {
|
||||
name := devices.Name(device)
|
||||
eq := name == p
|
||||
if eq || match(name) {
|
||||
matches = append(matches, device)
|
||||
}
|
||||
if eq {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return matches
|
||||
}
|
||||
|
||||
func (cmd *info) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
vm, err := cmd.VirtualMachine()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if vm == nil {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
|
||||
devices, err := vm.Device(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
res := infoResult{
|
||||
list: devices,
|
||||
}
|
||||
|
||||
if cmd.NetworkFlag.IsSet() {
|
||||
net, err := cmd.Network()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
backing, err := net.EthernetCardBackingInfo(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
devices = devices.SelectByBackingInfo(backing)
|
||||
}
|
||||
|
||||
if f.NArg() == 0 {
|
||||
res.Devices = toInfoList(devices)
|
||||
} else {
|
||||
for _, name := range f.Args() {
|
||||
matches := cmd.match(name, devices)
|
||||
if len(matches) == 0 {
|
||||
return fmt.Errorf("device '%s' not found", name)
|
||||
}
|
||||
|
||||
res.Devices = append(res.Devices, toInfoList(matches)...)
|
||||
}
|
||||
}
|
||||
|
||||
return cmd.WriteResult(&res)
|
||||
}
|
||||
|
||||
func toInfoList(devices object.VirtualDeviceList) []infoDevice {
|
||||
var res []infoDevice
|
||||
|
||||
for _, device := range devices {
|
||||
res = append(res, infoDevice{
|
||||
Name: devices.Name(device),
|
||||
Type: devices.TypeName(device),
|
||||
BaseVirtualDevice: device,
|
||||
})
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
type infoDevice struct {
|
||||
Name string
|
||||
Type string
|
||||
types.BaseVirtualDevice
|
||||
}
|
||||
|
||||
func (d *infoDevice) MarshalJSON() ([]byte, error) {
|
||||
b, err := json.Marshal(d.BaseVirtualDevice)
|
||||
if err != nil {
|
||||
return b, err
|
||||
}
|
||||
|
||||
// TODO: make use of "inline" tag if it comes to be: https://github.com/golang/go/issues/6213
|
||||
|
||||
return append([]byte(fmt.Sprintf(`{"Name":"%s","Type":"%s",`, d.Name, d.Type)), b[1:]...), err
|
||||
}
|
||||
|
||||
type infoResult struct {
|
||||
Devices []infoDevice
|
||||
// need the full list of devices to lookup attached devices and controllers
|
||||
list object.VirtualDeviceList
|
||||
}
|
||||
|
||||
func (r *infoResult) Write(w io.Writer) error {
|
||||
tw := tabwriter.NewWriter(os.Stdout, 2, 0, 2, ' ', 0)
|
||||
|
||||
for i := range r.Devices {
|
||||
device := r.Devices[i].BaseVirtualDevice
|
||||
d := device.GetVirtualDevice()
|
||||
info := d.DeviceInfo.GetDescription()
|
||||
|
||||
fmt.Fprintf(tw, "Name:\t%s\n", r.Devices[i].Name)
|
||||
fmt.Fprintf(tw, " Type:\t%s\n", r.list.TypeName(device))
|
||||
fmt.Fprintf(tw, " Label:\t%s\n", info.Label)
|
||||
fmt.Fprintf(tw, " Summary:\t%s\n", info.Summary)
|
||||
fmt.Fprintf(tw, " Key:\t%d\n", d.Key)
|
||||
|
||||
if c, ok := device.(types.BaseVirtualController); ok {
|
||||
var attached []string
|
||||
for _, key := range c.GetVirtualController().Device {
|
||||
attached = append(attached, r.list.Name(r.list.FindByKey(key)))
|
||||
}
|
||||
fmt.Fprintf(tw, " Devices:\t%s\n", strings.Join(attached, ", "))
|
||||
} else {
|
||||
if c := r.list.FindByKey(d.ControllerKey); c != nil {
|
||||
fmt.Fprintf(tw, " Controller:\t%s\n", r.list.Name(c))
|
||||
if d.UnitNumber != nil {
|
||||
fmt.Fprintf(tw, " Unit number:\t%d\n", *d.UnitNumber)
|
||||
} else {
|
||||
fmt.Fprintf(tw, " Unit number:\t<nil>\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ca := d.Connectable; ca != nil {
|
||||
fmt.Fprintf(tw, " Connected:\t%t\n", ca.Connected)
|
||||
fmt.Fprintf(tw, " Start connected:\t%t\n", ca.StartConnected)
|
||||
fmt.Fprintf(tw, " Guest control:\t%t\n", ca.AllowGuestControl)
|
||||
fmt.Fprintf(tw, " Status:\t%s\n", ca.Status)
|
||||
}
|
||||
|
||||
switch md := device.(type) {
|
||||
case types.BaseVirtualEthernetCard:
|
||||
fmt.Fprintf(tw, " MAC Address:\t%s\n", md.GetVirtualEthernetCard().MacAddress)
|
||||
fmt.Fprintf(tw, " Address type:\t%s\n", md.GetVirtualEthernetCard().AddressType)
|
||||
case *types.VirtualDisk:
|
||||
if b, ok := md.Backing.(types.BaseVirtualDeviceFileBackingInfo); ok {
|
||||
fmt.Fprintf(tw, " File:\t%s\n", b.GetVirtualDeviceFileBackingInfo().FileName)
|
||||
}
|
||||
if b, ok := md.Backing.(*types.VirtualDiskFlatVer2BackingInfo); ok && b.Parent != nil {
|
||||
fmt.Fprintf(tw, " Parent:\t%s\n", b.Parent.GetVirtualDeviceFileBackingInfo().FileName)
|
||||
}
|
||||
case *types.VirtualSerialPort:
|
||||
if b, ok := md.Backing.(*types.VirtualSerialPortURIBackingInfo); ok {
|
||||
fmt.Fprintf(tw, " Direction:\t%s\n", b.Direction)
|
||||
fmt.Fprintf(tw, " Service URI:\t%s\n", b.ServiceURI)
|
||||
fmt.Fprintf(tw, " Proxy URI:\t%s\n", b.ProxyURI)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return tw.Flush()
|
||||
}
|
||||
93
vendor/github.com/vmware/govmomi/govc/device/ls.go
generated
vendored
Normal file
93
vendor/github.com/vmware/govmomi/govc/device/ls.go
generated
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
Copyright (c) 2014-2017 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
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 device
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"text/tabwriter"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
)
|
||||
|
||||
type ls struct {
|
||||
*flags.VirtualMachineFlag
|
||||
|
||||
boot bool
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("device.ls", &ls{})
|
||||
}
|
||||
|
||||
func (cmd *ls) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.VirtualMachineFlag, ctx = flags.NewVirtualMachineFlag(ctx)
|
||||
cmd.VirtualMachineFlag.Register(ctx, f)
|
||||
|
||||
f.BoolVar(&cmd.boot, "boot", false, "List devices configured in the VM's boot options")
|
||||
}
|
||||
|
||||
func (cmd *ls) Process(ctx context.Context) error {
|
||||
if err := cmd.VirtualMachineFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *ls) Description() string {
|
||||
return `List devices for VM.
|
||||
|
||||
Examples:
|
||||
govc device.ls -vm $name`
|
||||
}
|
||||
|
||||
func (cmd *ls) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
vm, err := cmd.VirtualMachine()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if vm == nil {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
|
||||
devices, err := vm.Device(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if cmd.boot {
|
||||
options, err := vm.BootOptions(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
devices = devices.SelectBootOrder(options.BootOrder)
|
||||
}
|
||||
|
||||
tw := tabwriter.NewWriter(os.Stdout, 3, 0, 2, ' ', 0)
|
||||
|
||||
for _, device := range devices {
|
||||
fmt.Fprintf(tw, "%s\t%s\t%s\n", devices.Name(device), devices.TypeName(device),
|
||||
device.GetVirtualDevice().DeviceInfo.GetDescription().Summary)
|
||||
}
|
||||
|
||||
return tw.Flush()
|
||||
}
|
||||
89
vendor/github.com/vmware/govmomi/govc/device/remove.go
generated
vendored
Normal file
89
vendor/github.com/vmware/govmomi/govc/device/remove.go
generated
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
Copyright (c) 2014-2017 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
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 device
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
)
|
||||
|
||||
type remove struct {
|
||||
*flags.VirtualMachineFlag
|
||||
keepFiles bool
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("device.remove", &remove{})
|
||||
}
|
||||
|
||||
func (cmd *remove) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.VirtualMachineFlag, ctx = flags.NewVirtualMachineFlag(ctx)
|
||||
cmd.VirtualMachineFlag.Register(ctx, f)
|
||||
f.BoolVar(&cmd.keepFiles, "keep", false, "Keep files in datastore")
|
||||
}
|
||||
|
||||
func (cmd *remove) Process(ctx context.Context) error {
|
||||
if err := cmd.VirtualMachineFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *remove) Usage() string {
|
||||
return "DEVICE..."
|
||||
}
|
||||
|
||||
func (cmd *remove) Description() string {
|
||||
return `Remove DEVICE from VM.
|
||||
|
||||
Examples:
|
||||
govc device.remove -vm $name cdrom-3000
|
||||
govc device.remove -vm $name -keep disk-1000`
|
||||
}
|
||||
|
||||
func (cmd *remove) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
vm, err := cmd.VirtualMachine()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if vm == nil {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
|
||||
devices, err := vm.Device(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, name := range f.Args() {
|
||||
device := devices.Find(name)
|
||||
if device == nil {
|
||||
return fmt.Errorf("device '%s' not found", name)
|
||||
}
|
||||
|
||||
if err = vm.RemoveDevice(ctx, cmd.keepFiles, device); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
116
vendor/github.com/vmware/govmomi/govc/device/scsi/add.go
generated
vendored
Normal file
116
vendor/github.com/vmware/govmomi/govc/device/scsi/add.go
generated
vendored
Normal file
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
Copyright (c) 2014-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 scsi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
"github.com/vmware/govmomi/object"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
type add struct {
|
||||
*flags.VirtualMachineFlag
|
||||
|
||||
controller string
|
||||
sharedBus string
|
||||
hotAddRemove bool
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("device.scsi.add", &add{})
|
||||
}
|
||||
|
||||
func (cmd *add) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.VirtualMachineFlag, ctx = flags.NewVirtualMachineFlag(ctx)
|
||||
cmd.VirtualMachineFlag.Register(ctx, f)
|
||||
|
||||
var ctypes []string
|
||||
ct := object.SCSIControllerTypes()
|
||||
for _, t := range ct {
|
||||
ctypes = append(ctypes, ct.Type(t))
|
||||
}
|
||||
f.StringVar(&cmd.controller, "type", ct.Type(ct[0]),
|
||||
fmt.Sprintf("SCSI controller type (%s)", strings.Join(ctypes, "|")))
|
||||
f.StringVar(&cmd.sharedBus, "sharing", string(types.VirtualSCSISharingNoSharing), "SCSI sharing")
|
||||
f.BoolVar(&cmd.hotAddRemove, "hot", false, "Enable hot-add/remove")
|
||||
}
|
||||
|
||||
func (cmd *add) Description() string {
|
||||
return `Add SCSI controller to VM.
|
||||
|
||||
Examples:
|
||||
govc device.scsi.add -vm $vm
|
||||
govc device.scsi.add -vm $vm -type pvscsi
|
||||
govc device.info -vm $vm {lsi,pv}*`
|
||||
}
|
||||
|
||||
func (cmd *add) Process(ctx context.Context) error {
|
||||
if err := cmd.VirtualMachineFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *add) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
vm, err := cmd.VirtualMachine()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if vm == nil {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
|
||||
devices, err := vm.Device(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
d, err := devices.CreateSCSIController(cmd.controller)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c := d.(types.BaseVirtualSCSIController).GetVirtualSCSIController()
|
||||
c.HotAddRemove = &cmd.hotAddRemove
|
||||
c.SharedBus = types.VirtualSCSISharing(cmd.sharedBus)
|
||||
|
||||
err = vm.AddDevice(ctx, d)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// output name of device we just created
|
||||
devices, err = vm.Device(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
devices = devices.SelectByType(d)
|
||||
|
||||
name := devices.Name(devices[len(devices)-1])
|
||||
|
||||
fmt.Println(name)
|
||||
|
||||
return nil
|
||||
}
|
||||
94
vendor/github.com/vmware/govmomi/govc/device/serial/add.go
generated
vendored
Normal file
94
vendor/github.com/vmware/govmomi/govc/device/serial/add.go
generated
vendored
Normal file
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
Copyright (c) 2014-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 serial
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
)
|
||||
|
||||
type add struct {
|
||||
*flags.VirtualMachineFlag
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("device.serial.add", &add{})
|
||||
}
|
||||
|
||||
func (cmd *add) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.VirtualMachineFlag, ctx = flags.NewVirtualMachineFlag(ctx)
|
||||
cmd.VirtualMachineFlag.Register(ctx, f)
|
||||
}
|
||||
|
||||
func (cmd *add) Description() string {
|
||||
return `Add serial port to VM.
|
||||
|
||||
Examples:
|
||||
govc device.serial.add -vm $vm
|
||||
govc device.info -vm $vm serialport-*`
|
||||
}
|
||||
|
||||
func (cmd *add) Process(ctx context.Context) error {
|
||||
if err := cmd.VirtualMachineFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *add) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
vm, err := cmd.VirtualMachine()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if vm == nil {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
|
||||
devices, err := vm.Device(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
d, err := devices.CreateSerialPort()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = vm.AddDevice(ctx, d)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// output name of device we just created
|
||||
devices, err = vm.Device(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
devices = devices.SelectByType(d)
|
||||
|
||||
name := devices.Name(devices[len(devices)-1])
|
||||
|
||||
fmt.Println(name)
|
||||
|
||||
return nil
|
||||
}
|
||||
116
vendor/github.com/vmware/govmomi/govc/device/serial/connect.go
generated
vendored
Normal file
116
vendor/github.com/vmware/govmomi/govc/device/serial/connect.go
generated
vendored
Normal file
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
Copyright (c) 2014-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 serial
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"path"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
"github.com/vmware/govmomi/vim25/mo"
|
||||
)
|
||||
|
||||
type connect struct {
|
||||
*flags.VirtualMachineFlag
|
||||
|
||||
proxy string
|
||||
device string
|
||||
client bool
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("device.serial.connect", &connect{})
|
||||
}
|
||||
|
||||
func (cmd *connect) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.VirtualMachineFlag, ctx = flags.NewVirtualMachineFlag(ctx)
|
||||
cmd.VirtualMachineFlag.Register(ctx, f)
|
||||
|
||||
f.StringVar(&cmd.proxy, "vspc-proxy", "", "vSPC proxy URI")
|
||||
f.StringVar(&cmd.device, "device", "", "serial port device name")
|
||||
f.BoolVar(&cmd.client, "client", false, "Use client direction")
|
||||
}
|
||||
|
||||
func (cmd *connect) Usage() string {
|
||||
return "URI"
|
||||
}
|
||||
|
||||
func (cmd *connect) Description() string {
|
||||
return `Connect service URI to serial port.
|
||||
|
||||
If "-" is given as URI, connects file backed device with file name of
|
||||
device name + .log suffix in the VM Config.Files.LogDirectory.
|
||||
|
||||
Defaults to the first serial port if no DEVICE is given.
|
||||
|
||||
Examples:
|
||||
govc device.ls | grep serialport-
|
||||
govc device.serial.connect -vm $vm -device serialport-8000 telnet://:33233
|
||||
govc device.info -vm $vm serialport-*
|
||||
govc device.serial.connect -vm $vm "[datastore1] $vm/console.log"
|
||||
govc device.serial.connect -vm $vm -
|
||||
govc datastore.tail -f $vm/serialport-8000.log`
|
||||
}
|
||||
|
||||
func (cmd *connect) Process(ctx context.Context) error {
|
||||
if err := cmd.VirtualMachineFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *connect) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
if f.NArg() != 1 {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
|
||||
vm, err := cmd.VirtualMachine()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if vm == nil {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
|
||||
devices, err := vm.Device(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
d, err := devices.FindSerialPort(cmd.device)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
uri := f.Arg(0)
|
||||
|
||||
if uri == "-" {
|
||||
var mvm mo.VirtualMachine
|
||||
err = vm.Properties(ctx, vm.Reference(), []string{"config.files.logDirectory"}, &mvm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
uri = path.Join(mvm.Config.Files.LogDirectory, fmt.Sprintf("%s.log", devices.Name(d)))
|
||||
}
|
||||
|
||||
return vm.EditDevice(ctx, devices.ConnectSerialPort(d, uri, cmd.client, cmd.proxy))
|
||||
}
|
||||
81
vendor/github.com/vmware/govmomi/govc/device/serial/disconnect.go
generated
vendored
Normal file
81
vendor/github.com/vmware/govmomi/govc/device/serial/disconnect.go
generated
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
Copyright (c) 2014-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 serial
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
)
|
||||
|
||||
type disconnect struct {
|
||||
*flags.VirtualMachineFlag
|
||||
|
||||
device string
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("device.serial.disconnect", &disconnect{})
|
||||
}
|
||||
|
||||
func (cmd *disconnect) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.VirtualMachineFlag, ctx = flags.NewVirtualMachineFlag(ctx)
|
||||
cmd.VirtualMachineFlag.Register(ctx, f)
|
||||
|
||||
f.StringVar(&cmd.device, "device", "", "serial port device name")
|
||||
}
|
||||
|
||||
func (cmd *disconnect) Description() string {
|
||||
return `Disconnect service URI from serial port.
|
||||
|
||||
Examples:
|
||||
govc device.ls | grep serialport-
|
||||
govc device.serial.disconnect -vm $vm -device serialport-8000
|
||||
govc device.info -vm $vm serialport-*`
|
||||
}
|
||||
|
||||
func (cmd *disconnect) Process(ctx context.Context) error {
|
||||
if err := cmd.VirtualMachineFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *disconnect) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
vm, err := cmd.VirtualMachine()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if vm == nil {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
|
||||
devices, err := vm.Device(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
d, err := devices.FindSerialPort(cmd.device)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return vm.EditDevice(ctx, devices.DisconnectSerialPort(d))
|
||||
}
|
||||
114
vendor/github.com/vmware/govmomi/govc/device/usb/add.go
generated
vendored
Normal file
114
vendor/github.com/vmware/govmomi/govc/device/usb/add.go
generated
vendored
Normal file
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
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 usb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
type add struct {
|
||||
*flags.VirtualMachineFlag
|
||||
|
||||
controller string
|
||||
autoConnect bool
|
||||
ehciEnabled bool
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("device.usb.add", &add{})
|
||||
}
|
||||
|
||||
func (cmd *add) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.VirtualMachineFlag, ctx = flags.NewVirtualMachineFlag(ctx)
|
||||
cmd.VirtualMachineFlag.Register(ctx, f)
|
||||
|
||||
ctypes := []string{"usb", "xhci"}
|
||||
f.StringVar(&cmd.controller, "type", ctypes[0],
|
||||
fmt.Sprintf("USB controller type (%s)", strings.Join(ctypes, "|")))
|
||||
|
||||
f.BoolVar(&cmd.autoConnect, "auto", true, "Enable ability to hot plug devices")
|
||||
f.BoolVar(&cmd.ehciEnabled, "ehci", true, "Enable enhanced host controller interface (USB 2.0)")
|
||||
}
|
||||
|
||||
func (cmd *add) Description() string {
|
||||
return `Add USB device to VM.
|
||||
|
||||
Examples:
|
||||
govc device.usb.add -vm $vm
|
||||
govc device.usb.add -type xhci -vm $vm
|
||||
govc device.info usb*`
|
||||
}
|
||||
|
||||
func (cmd *add) Process(ctx context.Context) error {
|
||||
if err := cmd.VirtualMachineFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *add) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
vm, err := cmd.VirtualMachine()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if vm == nil {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
|
||||
var d types.BaseVirtualDevice
|
||||
|
||||
switch cmd.controller {
|
||||
case "usb":
|
||||
c := new(types.VirtualUSBController)
|
||||
c.AutoConnectDevices = &cmd.autoConnect
|
||||
c.EhciEnabled = &cmd.ehciEnabled
|
||||
d = c
|
||||
case "xhci":
|
||||
c := new(types.VirtualUSBXHCIController)
|
||||
c.AutoConnectDevices = &cmd.autoConnect
|
||||
d = c
|
||||
default:
|
||||
return flag.ErrHelp
|
||||
}
|
||||
|
||||
err = vm.AddDevice(ctx, d)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// output name of device we just created
|
||||
devices, err := vm.Device(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
devices = devices.SelectByType(d)
|
||||
|
||||
name := devices.Name(devices[len(devices)-1])
|
||||
|
||||
fmt.Println(name)
|
||||
|
||||
return nil
|
||||
}
|
||||
147
vendor/github.com/vmware/govmomi/govc/dvs/add.go
generated
vendored
Normal file
147
vendor/github.com/vmware/govmomi/govc/dvs/add.go
generated
vendored
Normal file
@@ -0,0 +1,147 @@
|
||||
/*
|
||||
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 dvs
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
"github.com/vmware/govmomi/object"
|
||||
"github.com/vmware/govmomi/vim25/mo"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
type add struct {
|
||||
*flags.HostSystemFlag
|
||||
|
||||
path string
|
||||
pnic string
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("dvs.add", &add{})
|
||||
}
|
||||
|
||||
func (cmd *add) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.HostSystemFlag, ctx = flags.NewHostSystemFlag(ctx)
|
||||
cmd.HostSystemFlag.Register(ctx, f)
|
||||
|
||||
f.StringVar(&cmd.path, "dvs", "", "DVS path")
|
||||
f.StringVar(&cmd.pnic, "pnic", "vmnic0", "Name of the host physical NIC")
|
||||
}
|
||||
|
||||
func (cmd *add) Process(ctx context.Context) error {
|
||||
if err := cmd.HostSystemFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *add) Usage() string {
|
||||
return "HOST..."
|
||||
}
|
||||
|
||||
func (cmd *add) Description() string {
|
||||
return `Add hosts to DVS.
|
||||
|
||||
Examples:
|
||||
govc dvs.add -dvs dvsName -pnic vmnic1 hostA hostB hostC`
|
||||
}
|
||||
|
||||
func (cmd *add) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
if f.NArg() == 0 {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
|
||||
finder, err := cmd.Finder()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
net, err := finder.Network(ctx, cmd.path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dvs, ok := net.(*object.DistributedVirtualSwitch)
|
||||
if !ok {
|
||||
return fmt.Errorf("%s (%T) is not of type %T", cmd.path, net, dvs)
|
||||
}
|
||||
|
||||
var s mo.DistributedVirtualSwitch
|
||||
err = dvs.Properties(ctx, dvs.Reference(), []string{"config"}, &s)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
backing := new(types.DistributedVirtualSwitchHostMemberPnicBacking)
|
||||
|
||||
for _, vmnic := range strings.Split(cmd.pnic, ",") {
|
||||
backing.PnicSpec = append(backing.PnicSpec, types.DistributedVirtualSwitchHostMemberPnicSpec{
|
||||
PnicDevice: strings.TrimSpace(vmnic),
|
||||
})
|
||||
}
|
||||
|
||||
config := &types.DVSConfigSpec{
|
||||
ConfigVersion: s.Config.GetDVSConfigInfo().ConfigVersion,
|
||||
}
|
||||
|
||||
hosts, err := cmd.HostSystems(f.Args())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
existing := make(map[string]bool)
|
||||
// TODO: host.pnic.info command
|
||||
for _, member := range s.Config.GetDVSConfigInfo().Host {
|
||||
existing[member.Config.Host.Value] = true
|
||||
}
|
||||
|
||||
for _, host := range hosts {
|
||||
ref := host.Reference()
|
||||
if existing[ref.Value] {
|
||||
fmt.Fprintf(os.Stderr, "%s is already a member of %s\n", host.InventoryPath, dvs.InventoryPath)
|
||||
continue
|
||||
}
|
||||
|
||||
config.Host = append(config.Host, types.DistributedVirtualSwitchHostMemberConfigSpec{
|
||||
Operation: "add",
|
||||
Host: ref,
|
||||
Backing: backing,
|
||||
})
|
||||
}
|
||||
|
||||
if len(config.Host) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
task, err := dvs.Reconfigure(ctx, config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logger := cmd.ProgressLogger(fmt.Sprintf("adding %d hosts to dvs %s... ", len(config.Host), dvs.InventoryPath))
|
||||
defer logger.Wait()
|
||||
|
||||
_, err = task.WaitForResult(ctx, logger)
|
||||
return err
|
||||
}
|
||||
99
vendor/github.com/vmware/govmomi/govc/dvs/create.go
generated
vendored
Normal file
99
vendor/github.com/vmware/govmomi/govc/dvs/create.go
generated
vendored
Normal file
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
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 dvs
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
type create struct {
|
||||
*flags.FolderFlag
|
||||
|
||||
types.DVSCreateSpec
|
||||
|
||||
configSpec *types.VMwareDVSConfigSpec
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("dvs.create", &create{})
|
||||
}
|
||||
|
||||
func (cmd *create) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.FolderFlag, ctx = flags.NewFolderFlag(ctx)
|
||||
cmd.FolderFlag.Register(ctx, f)
|
||||
|
||||
cmd.configSpec = new(types.VMwareDVSConfigSpec)
|
||||
|
||||
cmd.DVSCreateSpec.ConfigSpec = cmd.configSpec
|
||||
cmd.DVSCreateSpec.ProductInfo = new(types.DistributedVirtualSwitchProductSpec)
|
||||
|
||||
f.StringVar(&cmd.ProductInfo.Version, "product-version", "", "DVS product version")
|
||||
}
|
||||
|
||||
func (cmd *create) Usage() string {
|
||||
return "DVS"
|
||||
}
|
||||
|
||||
func (cmd *create) Description() string {
|
||||
return `Create DVS (DistributedVirtualSwitch) in datacenter.
|
||||
|
||||
The dvs is added to the folder specified by the 'folder' flag. If not given,
|
||||
this defaults to the network folder in the specified or default datacenter.
|
||||
|
||||
Examples:
|
||||
govc dvs.create DSwitch
|
||||
govc dvs.create -product-version 5.5.0 DSwitch`
|
||||
}
|
||||
|
||||
func (cmd *create) Process(ctx context.Context) error {
|
||||
if err := cmd.FolderFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *create) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
if f.NArg() != 1 {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
|
||||
name := f.Arg(0)
|
||||
|
||||
cmd.configSpec.Name = name
|
||||
|
||||
folder, err := cmd.FolderOrDefault("network")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
task, err := folder.CreateDVS(ctx, cmd.DVSCreateSpec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logger := cmd.ProgressLogger(fmt.Sprintf("adding %s to folder %s... ", name, folder.InventoryPath))
|
||||
defer logger.Wait()
|
||||
|
||||
_, err = task.WaitForResult(ctx, logger)
|
||||
return err
|
||||
}
|
||||
107
vendor/github.com/vmware/govmomi/govc/dvs/portgroup/add.go
generated
vendored
Normal file
107
vendor/github.com/vmware/govmomi/govc/dvs/portgroup/add.go
generated
vendored
Normal file
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
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 portgroup
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
"github.com/vmware/govmomi/object"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
type add struct {
|
||||
*flags.DatacenterFlag
|
||||
|
||||
DVPortgroupConfigSpec
|
||||
|
||||
path string
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("dvs.portgroup.add", &add{})
|
||||
}
|
||||
|
||||
func (cmd *add) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.DatacenterFlag, ctx = flags.NewDatacenterFlag(ctx)
|
||||
cmd.DatacenterFlag.Register(ctx, f)
|
||||
|
||||
f.StringVar(&cmd.path, "dvs", "", "DVS path")
|
||||
|
||||
cmd.DVPortgroupConfigSpec.NumPorts = 128 // default
|
||||
|
||||
cmd.DVPortgroupConfigSpec.Register(ctx, f)
|
||||
}
|
||||
|
||||
func (cmd *add) Description() string {
|
||||
return `Add portgroup to DVS.
|
||||
|
||||
Examples:
|
||||
govc dvs.create DSwitch
|
||||
govc dvs.portgroup.add -dvs DSwitch -type earlyBinding -nports 16 ExternalNetwork
|
||||
govc dvs.portgroup.add -dvs DSwitch -type ephemeral InternalNetwork`
|
||||
}
|
||||
|
||||
func (cmd *add) Process(ctx context.Context) error {
|
||||
if err := cmd.DatacenterFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *add) Usage() string {
|
||||
return "NAME"
|
||||
}
|
||||
|
||||
func (cmd *add) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
if f.NArg() == 0 {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
|
||||
name := f.Arg(0)
|
||||
|
||||
finder, err := cmd.Finder()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
net, err := finder.Network(ctx, cmd.path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dvs, ok := net.(*object.DistributedVirtualSwitch)
|
||||
if !ok {
|
||||
return fmt.Errorf("%s (%T) is not of type %T", cmd.path, net, dvs)
|
||||
}
|
||||
|
||||
cmd.DVPortgroupConfigSpec.Name = name
|
||||
|
||||
task, err := dvs.AddPortgroup(ctx, []types.DVPortgroupConfigSpec{cmd.Spec()})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logger := cmd.ProgressLogger(fmt.Sprintf("adding %s portgroup to dvs %s... ", name, dvs.InventoryPath))
|
||||
defer logger.Wait()
|
||||
|
||||
_, err = task.WaitForResult(ctx, logger)
|
||||
return err
|
||||
}
|
||||
107
vendor/github.com/vmware/govmomi/govc/dvs/portgroup/change.go
generated
vendored
Normal file
107
vendor/github.com/vmware/govmomi/govc/dvs/portgroup/change.go
generated
vendored
Normal file
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
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 portgroup
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
"github.com/vmware/govmomi/object"
|
||||
"github.com/vmware/govmomi/vim25/mo"
|
||||
)
|
||||
|
||||
type change struct {
|
||||
*flags.DatacenterFlag
|
||||
|
||||
DVPortgroupConfigSpec
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("dvs.portgroup.change", &change{})
|
||||
}
|
||||
|
||||
func (cmd *change) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.DatacenterFlag, ctx = flags.NewDatacenterFlag(ctx)
|
||||
cmd.DatacenterFlag.Register(ctx, f)
|
||||
|
||||
cmd.DVPortgroupConfigSpec.Register(ctx, f)
|
||||
}
|
||||
|
||||
func (cmd *change) Description() string {
|
||||
return `Change DVS portgroup configuration.
|
||||
|
||||
Examples:
|
||||
govc dvs.portgroup.change -nports 26 ExternalNetwork
|
||||
govc dvs.portgroup.change -vlan 3214 ExternalNetwork`
|
||||
}
|
||||
|
||||
func (cmd *change) Process(ctx context.Context) error {
|
||||
if err := cmd.DatacenterFlag.Process(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *change) Usage() string {
|
||||
return "PATH"
|
||||
}
|
||||
|
||||
func (cmd *change) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
if f.NArg() != 1 {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
|
||||
path := f.Arg(0)
|
||||
|
||||
finder, err := cmd.Finder()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
net, err := finder.Network(ctx, path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pg, ok := net.(*object.DistributedVirtualPortgroup)
|
||||
if !ok {
|
||||
return fmt.Errorf("%s (%T) is not of type %T", path, net, pg)
|
||||
}
|
||||
|
||||
var s mo.DistributedVirtualPortgroup
|
||||
err = pg.Properties(ctx, pg.Reference(), []string{"config.configVersion"}, &s)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
spec := cmd.Spec()
|
||||
spec.ConfigVersion = s.Config.ConfigVersion
|
||||
|
||||
task, err := pg.Reconfigure(ctx, spec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logger := cmd.ProgressLogger(fmt.Sprintf("changing %s portgroup configuration %s... ", pg.Name(), pg.InventoryPath))
|
||||
defer logger.Wait()
|
||||
|
||||
_, err = task.WaitForResult(ctx, logger)
|
||||
return err
|
||||
}
|
||||
173
vendor/github.com/vmware/govmomi/govc/dvs/portgroup/info.go
generated
vendored
Normal file
173
vendor/github.com/vmware/govmomi/govc/dvs/portgroup/info.go
generated
vendored
Normal file
@@ -0,0 +1,173 @@
|
||||
/*
|
||||
Copyright (c) 2015-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 portgroup
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/vmware/govmomi/govc/cli"
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
"github.com/vmware/govmomi/object"
|
||||
"github.com/vmware/govmomi/vim25/mo"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
type info struct {
|
||||
*flags.DatacenterFlag
|
||||
|
||||
pg string
|
||||
active bool
|
||||
connected bool
|
||||
inside bool
|
||||
uplinkPort bool
|
||||
vlanID int
|
||||
count int
|
||||
}
|
||||
|
||||
func init() {
|
||||
cli.Register("dvs.portgroup.info", &info{})
|
||||
}
|
||||
|
||||
func (cmd *info) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
cmd.DatacenterFlag, ctx = flags.NewDatacenterFlag(ctx)
|
||||
cmd.DatacenterFlag.Register(ctx, f)
|
||||
|
||||
f.StringVar(&cmd.pg, "pg", "", "Distributed Virtual Portgroup")
|
||||
f.BoolVar(&cmd.active, "active", false, "Filter by port active or inactive status")
|
||||
f.BoolVar(&cmd.connected, "connected", false, "Filter by port connected or disconnected status")
|
||||
f.BoolVar(&cmd.inside, "inside", true, "Filter by port inside or outside status")
|
||||
f.BoolVar(&cmd.uplinkPort, "uplinkPort", false, "Filter for uplink ports")
|
||||
f.IntVar(&cmd.vlanID, "vlan", 0, "Filter by VLAN ID (0 = unfiltered)")
|
||||
f.IntVar(&cmd.count, "count", 0, "Number of matches to return (0 = unlimited)")
|
||||
}
|
||||
|
||||
func (cmd *info) Usage() string {
|
||||
return "DVS"
|
||||
}
|
||||
|
||||
func (cmd *info) Description() string {
|
||||
return `Portgroup info for DVS.
|
||||
|
||||
Examples:
|
||||
govc dvs.portgroup.info DSwitch
|
||||
govc dvs.portgroup.info -pg InternalNetwork DSwitch
|
||||
govc find / -type DistributedVirtualSwitch | xargs -n1 govc dvs.portgroup.info`
|
||||
}
|
||||
|
||||
type infoResult struct {
|
||||
Port []types.DistributedVirtualPort
|
||||
cmd *info
|
||||
}
|
||||
|
||||
func (r *infoResult) Write(w io.Writer) error {
|
||||
for _, port := range r.Port {
|
||||
var vlanID int32
|
||||
setting := port.Config.Setting.(*types.VMwareDVSPortSetting)
|
||||
|
||||
switch vlan := setting.Vlan.(type) {
|
||||
case *types.VmwareDistributedVirtualSwitchVlanIdSpec:
|
||||
vlanID = vlan.VlanId
|
||||
case *types.VmwareDistributedVirtualSwitchTrunkVlanSpec:
|
||||
case *types.VmwareDistributedVirtualSwitchPvlanSpec:
|
||||
vlanID = vlan.PvlanId
|
||||
}
|
||||
|
||||
// Show port info if: VLAN ID is not defined, or VLAN ID matches requested VLAN
|
||||
if r.cmd.vlanID == 0 || vlanID == int32(r.cmd.vlanID) {
|
||||
fmt.Printf("PortgroupKey: %s\n", port.PortgroupKey)
|
||||
fmt.Printf("DvsUuid: %s\n", port.DvsUuid)
|
||||
fmt.Printf("VlanId: %d\n", vlanID)
|
||||
fmt.Printf("PortKey: %s\n\n", port.Key)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *info) Run(ctx context.Context, f *flag.FlagSet) error {
|
||||
if f.NArg() != 1 {
|
||||
return flag.ErrHelp
|
||||
}
|
||||
|
||||
finder, err := cmd.Finder()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Retrieve DVS reference
|
||||
net, err := finder.Network(ctx, f.Arg(0))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Convert to DVS object type
|
||||
dvs, ok := net.(*object.DistributedVirtualSwitch)
|
||||
if !ok {
|
||||
return fmt.Errorf("%s (%s) is not a DVS", f.Arg(0), net.Reference().Type)
|
||||
}
|
||||
|
||||
// Set base search criteria
|
||||
criteria := types.DistributedVirtualSwitchPortCriteria{
|
||||
Connected: types.NewBool(cmd.connected),
|
||||
Active: types.NewBool(cmd.active),
|
||||
UplinkPort: types.NewBool(cmd.uplinkPort),
|
||||
Inside: types.NewBool(cmd.inside),
|
||||
}
|
||||
|
||||
// If a distributed virtual portgroup path is set, then add its portgroup key to the base criteria
|
||||
if len(cmd.pg) > 0 {
|
||||
// Retrieve distributed virtual portgroup reference
|
||||
net, err = finder.Network(ctx, cmd.pg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Convert distributed virtual portgroup object type
|
||||
dvpg, ok := net.(*object.DistributedVirtualPortgroup)
|
||||
if !ok {
|
||||
return fmt.Errorf("%s (%s) is not a DVPG", cmd.pg, net.Reference().Type)
|
||||
}
|
||||
|
||||
// Obtain portgroup key property
|
||||
var dvp mo.DistributedVirtualPortgroup
|
||||
if err := dvpg.Properties(ctx, dvpg.Reference(), []string{"key"}, &dvp); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Add portgroup key to port search criteria
|
||||
criteria.PortgroupKey = []string{dvp.Key}
|
||||
}
|
||||
|
||||
res, err := dvs.FetchDVPorts(ctx, &criteria)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Truncate output to -count if specified
|
||||
if cmd.count > 0 && cmd.count < len(res) {
|
||||
res = res[:cmd.count]
|
||||
}
|
||||
|
||||
info := infoResult{
|
||||
cmd: cmd,
|
||||
Port: res,
|
||||
}
|
||||
|
||||
return cmd.WriteResult(&info)
|
||||
}
|
||||
55
vendor/github.com/vmware/govmomi/govc/dvs/portgroup/spec.go
generated
vendored
Normal file
55
vendor/github.com/vmware/govmomi/govc/dvs/portgroup/spec.go
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
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 portgroup
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/vmware/govmomi/govc/flags"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
type DVPortgroupConfigSpec struct {
|
||||
types.DVPortgroupConfigSpec
|
||||
}
|
||||
|
||||
func (spec *DVPortgroupConfigSpec) Register(ctx context.Context, f *flag.FlagSet) {
|
||||
ptypes := []string{
|
||||
string(types.DistributedVirtualPortgroupPortgroupTypeEarlyBinding),
|
||||
string(types.DistributedVirtualPortgroupPortgroupTypeLateBinding),
|
||||
string(types.DistributedVirtualPortgroupPortgroupTypeEphemeral),
|
||||
}
|
||||
|
||||
f.StringVar(&spec.Type, "type", ptypes[0],
|
||||
fmt.Sprintf("Portgroup type (%s)", strings.Join(ptypes, "|")))
|
||||
|
||||
f.Var(flags.NewInt32(&spec.NumPorts), "nports", "Number of ports")
|
||||
|
||||
config := new(types.VMwareDVSPortSetting)
|
||||
vlan := new(types.VmwareDistributedVirtualSwitchVlanIdSpec)
|
||||
spec.DefaultPortConfig = config
|
||||
config.Vlan = vlan
|
||||
|
||||
f.Var(flags.NewInt32(&vlan.VlanId), "vlan", "VLAN ID")
|
||||
}
|
||||
|
||||
func (spec *DVPortgroupConfigSpec) Spec() types.DVPortgroupConfigSpec {
|
||||
return spec.DVPortgroupConfigSpec
|
||||
}
|
||||
3
vendor/github.com/vmware/govmomi/govc/emacs/.gitignore
generated
vendored
Normal file
3
vendor/github.com/vmware/govmomi/govc/emacs/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
.cask
|
||||
elpa
|
||||
*.elc
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user