github.com/vmware/govmomi@v0.37.1/govc/README.md (about)

     1  # govc
     2  
     3  `govc` is a vSphere CLI built on top of `govmomi`.
     4  
     5  The CLI is designed to be a user friendly CLI alternative to the GUI and well suited for automation tasks.
     6  It also acts as a [test harness](test) for the `govmomi` APIs and provides working examples of how to use the APIs.
     7  
     8  ## Installation
     9  
    10  ### Docker
    11  
    12  The official `govc` [Docker images](https://hub.docker.com/r/vmware/govc) are built from this [Dockerfile](../Dockerfile.govc).
    13  
    14  ### Binaries
    15  You can find prebuilt `govc` binaries on the [releases page](https://github.com/vmware/govmomi/releases).
    16  
    17  You can download and install a binary locally like this:
    18  
    19  ```bash
    20  # extract govc binary to /usr/local/bin
    21  # note: the "tar" command must run with root permissions
    22  curl -L -o - "https://github.com/vmware/govmomi/releases/latest/download/govc_$(uname -s)_$(uname -m).tar.gz" | tar -C /usr/local/bin -xvzf - govc
    23  ```
    24  
    25  ### Source
    26  
    27  #### Install via `go install`
    28  
    29  To build `govc` from source, first install the [Go
    30  toolchain](https://golang.org/dl/). You can then install the latest `govc` from
    31  Github using:
    32  
    33  ```bash
    34  go install github.com/vmware/govmomi/govc@latest
    35  ```
    36  
    37  **Note:** `govmomi` and its binaries use [Go
    38  modules](https://golang.org/ref/mod), i.e. explicitly setting `GOPATH` is not
    39  required anymore. To inject build variables (see details
    40  [below](#install-via-goreleaser)) used by `govc version [-l]`, `GOFLAGS` can be
    41  defined and are honored by `go get`.
    42  
    43  ⚠️ Make sure `$GOPATH/bin` is in your `PATH` to use the version installed from
    44  source.
    45  
    46  If you've made local modifications to the repository at
    47  `$GOPATH/src/github.com/vmware/govmomi`, you can install using:
    48  
    49  ```bash
    50  go install github.com/vmware/govmomi/govc
    51  ```
    52  
    53  #### Install via `goreleaser`
    54  
    55  You can also build `govc` following our release process using `goreleaser`
    56  (requires [Go toolchain](https://golang.org/dl/)). This will ensure that build
    57  time variables are correctly injected. Build (linker) flags and injection are
    58  defined in [.goreleaser.yaml](./../.goreleaser.yml) and automatically set as
    59  `GOFLAGS` when building with `goreleaser`.
    60  
    61  Install `goreleaser` as per the installation
    62  [instructions](https://goreleaser.com/install/), then:
    63  
    64  ```bash
    65  git clone https://github.com/vmware/govmomi.git
    66  cd govmomi
    67  
    68  # pick a tag (>=v0.25.0)
    69  RELEASE=v0.25.0
    70  
    71  git checkout ${RELEASE}
    72  
    73  # build for the host OS/ARCH, otherwise omit --single-target
    74  # binaries are placed in respective subdirectories in ./dist/
    75  goreleaser build --clean --single-target
    76  ```
    77  
    78  ## Usage
    79  
    80  For the complete list of commands and flags, refer to the [USAGE](USAGE.md) document.
    81  
    82  Common flags include:
    83  
    84  * `-u`: ESXi or vCenter URL (ex: `user:pass@host`)
    85  * `-debug`: Trace requests and responses (to `~/.govmomi/debug`)
    86  
    87  Managed entities can be referred to by their absolute path or by their relative
    88  path. For example, when specifying a datastore to use for a subcommand, you can
    89  either specify it as `/mydatacenter/datastore/mydatastore`, or as
    90  `mydatastore`. If you're not sure about the name of the datastore, or even the
    91  full path to the datastore, you can specify a pattern to match. Both
    92  `/*center/*/my*` (absolute) and `my*store` (relative) will resolve to the same
    93  datastore, given there are no other datastores that match those globs.
    94  
    95  The relative path in this example can only be used if the command can
    96  umambigously resolve a datacenter to use as origin for the query. If no
    97  datacenter is specified, `govc` defaults to the only datacenter, if there is
    98  only one. The datacenter itself can be specified as a pattern as well, enabling
    99  the following arguments: `-dc='my*' -ds='*store'`. The datastore pattern is
   100  looked up and matched relative to the datacenter which itself is specified as a
   101  pattern.
   102  
   103  Besides specifying managed entities as arguments, they can also be specified
   104  using environment variables. The following environment variables are used by
   105  `govc` to set defaults:
   106  
   107  * `GOVC_URL`: URL of ESXi or vCenter instance to connect to.
   108  
   109      The URL scheme defaults to `https` and the URL path defaults to `/sdk`.
   110      This means that specifying `user:pass@host` is equivalent to
   111      `https://user:pass@host/sdk`.
   112  
   113      If username or password includes special characters like `\`, `#` or `:` you can use
   114      `GOVC_USERNAME` and `GOVC_PASSWORD` to have a simple `GOVC_URL`
   115  
   116      When using govc against VMware Workstation, GOVC_URL can be set to "localhost"
   117      without a user or pass, in which case local ticket based authentication is used.
   118  
   119  * `GOVC_USERNAME`: USERNAME to use if not specified in GOVC_URL.
   120  
   121  * `GOVC_PASSWORD`: PASSWORD to use if not specified in GOVC_URL.
   122  
   123  * `GOVC_TLS_CA_CERTS`: Override system root certificate authorities.
   124  
   125      ```bash
   126      export GOVC_TLS_CA_CERTS=~/.govc_ca.crt
   127      # Use path separator to specify multiple files:
   128      export GOVC_TLS_CA_CERTS=~/ca-certificates/bar.crt:~/ca-certificates/foo.crt
   129      ```
   130  
   131  * `GOVC_TLS_KNOWN_HOSTS`: File(s) for thumbprint based certificate verification.
   132  
   133      Thumbprint based verification can be used in addition to or as an alternative to
   134      `GOVC_TLS_CA_CERTS` for self-signed certificates.  Example:
   135  
   136      ```bash
   137      export GOVC_TLS_KNOWN_HOSTS=~/.govc_known_hosts
   138      govc about.cert -u host -k -thumbprint | tee -a $GOVC_TLS_KNOWN_HOSTS
   139      govc about -u user:pass@host
   140      ```
   141  
   142  * `GOVC_TLS_HANDSHAKE_TIMEOUT`: Limits the time spent performing the TLS handshake.
   143  
   144  * `GOVC_INSECURE`: Disable certificate verification.
   145  
   146      This option sets Go's `tls.Config.InsecureSkipVerify` flag and is false by default.
   147      Quoting https://golang.org/pkg/crypto/tls/#Config:
   148      > `InsecureSkipVerify` controls whether a client verifies the
   149      > server's certificate chain and host name.
   150      >
   151      > If `InsecureSkipVerify` is true, TLS accepts any certificate
   152      > presented by the server and any host name in that certificate.
   153      >
   154      > In this mode, TLS is susceptible to man-in-the-middle attacks.
   155      > This should be used only for testing.
   156  
   157  * `GOVC_DATACENTER`
   158  
   159  * `GOVC_DATASTORE`
   160  
   161  * `GOVC_NETWORK`
   162  
   163  * `GOVC_RESOURCE_POOL`
   164  
   165  * `GOVC_HOST`
   166  
   167  * `GOVC_GUEST_LOGIN`: Guest credentials for guest operations
   168  
   169  * `GOVC_VIM_NAMESPACE`: Vim namespace defaults to `urn:vim25`
   170  
   171  * `GOVC_VIM_VERSION`: Vim version defaults to `6.0`
   172  
   173  * `GOVC_VI_JSON`: Uses JSON transport instead of SOAP (Experimental; Usable only
   174  for vim25 APIs in vCenter 8.0u1)
   175  
   176  ## Troubleshooting
   177  
   178  ### Verbose Flag
   179  
   180  The `-verbose` flag writes request and response data to stderr, in a format more compact than the `-trace` or `-debug` flags.
   181  The output includes the request method name with abbreviated input parameters. The response data is more detailed and may include
   182  structures formatted as Go code, such as Task property updates.  The value of some properties will the `govc` `object.collect`
   183  command that can be used to view the actual value.
   184  
   185  ### Trace flag
   186  
   187  The `-trace` flag writes HTTP request and response data to stderr.
   188  XML bodies are formatted using `xmlstarlet` if installed and JSON bodies using `jq` if installed.
   189  Formatting can be disabled via `export GOVC_DEBUG_FORMAT=false`.
   190  
   191  If both `-trace` and `-verbose` flags are specified, request and response data is formatted as Go code.
   192  
   193  ### Debug Flag
   194  
   195  The`-debug` flag traces vSphere API calls similar to the `-trace` flag, but saves to files rather than stderr.
   196  When the `-debug` flag is specified, the default behavior is to put the output in `~/.govmomi/debug/<run timestamp>`.
   197  In that directory will be four (4) files per API call.
   198  
   199  ```bash
   200  1-0001.req.headers #headers from the request sent to the API
   201  1-0001.req.xml #body content from request sent to the API
   202  1-0001.res.headers #headers from the response from the API
   203  1-0001.res.xml #body from the respnse from the API
   204  ```
   205  
   206  In that filename the `0001` represents the an incremented call order and will increment for each time the SOAP client
   207  makes an API call.
   208  
   209  To configure the debug output you can use two environment variables.
   210  * `GOVC_DEBUG_PATH`: defaults to ~/.govmomi/debug
   211  * `GOVC_DEBUG_PATH_RUN`: defaults to timestamp of the run
   212  
   213  The [debug-format](../scripts/debug-format.sh) script can be used to format the debug output similar to the `-trace` flag.
   214  
   215  ### Print Version Information
   216  
   217  For troubleshooting and when filing issues, get build related details with:
   218  
   219  ```console
   220  $ govc version -l
   221  Build Version: v0.25.0-next
   222  Build Commit: e86da96e
   223  Build Date: 2021-04-19T10:29:57Z
   224  ```
   225  
   226  #### stderr debug
   227  
   228  If you prefer debug output to be sent to stderr and seen while the command is running you can override the file behavior
   229  by setting the debug path to a dash: `export GOVC_DEBUG_PATH=-`
   230  
   231  ### Environment variables
   232  
   233  If you're using environment variables to set `GOVC_URL`, verify the values are set as expected:
   234  
   235  ```bash
   236  govc env
   237  ```
   238  
   239  ### Connection issues
   240  
   241  Check your proxy settings:
   242  
   243  ```bash
   244  env | grep -i https_proxy
   245  ```
   246  
   247  Test connection using `curl`:
   248  
   249  ```bash
   250  curl --verbose -k -X POST https://x.x.x.x/sdk
   251  ```
   252  
   253  ### MSYS2 (Windows)
   254  
   255  Inventory path arguments with a leading '/' are subject
   256  to [Posix path conversion](http://www.mingw.org/wiki/Posix_path_conversion).
   257  
   258  ### NotAuthenticated
   259  
   260  When connecting to a non-TLS endpoint, Go's http.Client will not send Secure
   261  cookies, resulting in a `NotAuthenticated` error. For example, running `govc`
   262  directly against the vCenter vpxd endpoint at `http://127.0.0.1:8085`. Set the
   263  environment variable `GOVMOMI_INSECURE_COOKIES=true` to workaround this:
   264  
   265  ```bash
   266  GOVMOMI_INSECURE_COOKIES=true govc ls -u http://user:pass@127.0.0.1:8085
   267  ```
   268  
   269  ## Examples
   270  
   271  Several examples are embedded in the govc command [help](USAGE.md)
   272  
   273  * [Upload ssh public key to a VM](examples/lib/ssh.sh)
   274  
   275  * [Create a CoreOS VM](https://github.com/vmware/govmomi/blob/main/toolbox/toolbox-test.sh)
   276  
   277  * [Create a Debian VM](https://github.com/kubernetes/kubernetes/tree/master/cluster/vsphere)
   278  
   279  * [Create a Windows VM](https://github.com/dougm/govc-windows-box/blob/master/provision-esx.sh)
   280  
   281  * [Create an ESX VM](../scripts/vcsa/create-esxi-vm.sh)
   282  
   283  * [Create a vCenter VM](../scripts/vcsa/create-vcsa-vm.sh)
   284  
   285  * [Create a Cluster](../scripts/vcsa/create-cluster.sh)
   286  
   287  ## Status
   288  
   289  Changes to the CLI are subject to [semantic versioning](http://semver.org).
   290  
   291  Refer to the [CHANGELOG](../CHANGELOG.md) for version to version changes.
   292  
   293  When new `govc` commands or flags are added, the PATCH version will be
   294  incremented.  This enables you to require a minimum version from within a
   295  script, for example:
   296  
   297  ```bash
   298  govc version -require 0.24
   299  ```
   300  
   301  ## Projects using `govc`
   302  
   303  * [Emacs govc package](./emacs)
   304  
   305  * [Kubernetes vSphere Cloud Provider](https://github.com/kubernetes/cloud-provider-vsphere)
   306  
   307  * [VMware VIC Engine](https://github.com/vmware/vic)
   308  
   309  * [vSphere Docker Volume Service](https://github.com/vmware/docker-volume-vsphere)
   310  
   311  * [golang/build](https://github.com/golang/build)
   312  
   313  ## Related projects
   314  
   315  * [rvc](https://github.com/vmware/rvc)
   316  
   317  ## License
   318  
   319  `govc` is available under the [Apache 2 license](../LICENSE).
   320  
   321  ## Name
   322  
   323  Pronounced "go-v-c", short for "Go(lang) vCenter CLI".