# VSphere

OPS works perfectly fine with VSphere ESX 6.7 and 7.0.

It uses the pvsci driver for storage and vmnetx3 for networking.

For most operations you'll want to use the following config and you'll need access to your API key and the access key and secret access key found in your portal:

```javascript
{
  "CloudConfig" :{
    "BucketName":"nanos-test"
  }
}
```

```bash
package main

import (
  "fmt"
  "net/http"
)

func main() {
  fmt.Println("hello world!")

  http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "Welcome to my website!")
  })

  fs := http.FileServer(http.Dir("static/"))
  http.Handle("/static/", http.StripPrefix("/static/", fs))

  http.ListenAndServe("0.0.0.0:8080", nil)
}
```

## Image Operations

### Create Image

This creates a monolithicFlat image (2 files) and uploads it to vsphere's datastorage.

```bash
export GOVC_INSECURE=1
export GOVC_URL="login:pass@host:port"

GOOS=linux go build -o gtest

ops image create gtest -c config.json -t vsphere
```

### List Images

```bash
export GOVC_INSECURE=1
export GOVC_URL="login:pass@host:port"

ops image list -t vsphere
```

### Delete Image

## Instance Operations

### Create Instance

The domain part of the Resource Pool is in this example, 'localhost.localdomain'. You can find that in your portal.

![domain](/files/-MByl2XwOYDoAv8rNXIX)

```bash
export GOVC_INSECURE=1
export GOVC_URL="login:pass@host:port"
export GOVC_RESOURCE_POOL="/ha-datacenter/host/localhost.localdomain/Resources"

ops instance create gtest -t vsphere
```

### Start an Instance

```bash
export GOVC_INSECURE=1
export GOVC_URL="login:pass@host:port"

ops instance start mytest -t vsphere
```

### List Instances

```bash
export GOVC_INSECURE=1
export GOVC_URL="login:pass@host:port"

ops instance list -t vsphere
```

Note: The first time you run this command you might need to have the Guest IP Hack set. OPS will try to set that automatically for you but all existing vms won't report their ips until it is set *and* will require a new ARP request to be sent. If you already know the ip in question you can simply connect to it or you can reboot the vm and that will generate traffic.

### Get Logs for Instance

You can obtain the logs via:

```
export GOVC_INSECURE=1
export GOVC_URL="login:pass@host:port"

ops instance logs -t vsphere gtest
```

### Delete Instance

Right now the delete instance deletes both the instance and the image. We will probably change this in the future to do just the instance.

```bash
export GOVC_INSECURE=1
export GOVC_URL="login:pass@host:port"
export GOVC_RESOURCE_POOL="/ha-datacenter/host/localhost.localdomain/Resources"

ops instance delete -t vsphere named
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.ops.city/ops/hypervisors/vsphere.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
