# Copy a VM

> A new VM whose disk starts as a copy of the source VM's disk.

`POST /v1/tenants/{tenant}/vms/{source}/copy`

```bash curl
curl -X POST "https://api.shako.dev/v1/tenants/acme/vms/web1/copy" \
  -H "Authorization: Bearer $SHAKO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name":"web1-test"}'
```

```python Python
import os

import requests

response = requests.post(
    "https://api.shako.dev/v1/tenants/acme/vms/web1/copy",
    headers={"Authorization": f"Bearer {os.environ['SHAKO_API_KEY']}"},
    json={
        "name": "web1-test",
    },
)
response.raise_for_status()
print(response.json())
```

```javascript JavaScript
const response = await fetch("https://api.shako.dev/v1/tenants/acme/vms/web1/copy", {
  method: "POST",
  headers: { Authorization: `Bearer ${process.env.SHAKO_API_KEY}`, "Content-Type": "application/json" },
  body: JSON.stringify({
    "name": "web1-test"
  }),
});
if (!response.ok) throw new Error(await response.text());
console.log(await response.json());
```

```json 201 (excerpt)
{
  "name": "web1",
  "tenant": "acme",
  "state": "awake",
  "ssh": "web1.acme.shako.dev",
  "vcpus": 1,
  "mem_mib": 2048,
  "disk_gb": 10
}
```

Authenticate with `Authorization: Bearer <API key>` on `https://api.shako.dev`. Role: contributor or owner.

## Path parameters

**tenant** `string` *required*

The tenant's name, from GET /v1/tenants.

**source** `string` *required*

The VM to copy.

## Request body

**name** `string` *required*

The new VM's name: a-z, 0-9 and single hyphens, starting with a letter, at most 31 characters. It is in the VM's SSH name and in the URLs of its public ports.

**sleep** `string (auto, never)` (default: the sleep policy of the source VM)

When the VM sleeps. auto: when it is quiet. never: it stays on, and it restarts after a reboot or a crash. With both, the sleep and wake endpoints work at once.

**idle** `string` (default: the quiet time of the source VM)

The quiet time before the VM sleeps, for example "15m" or "2h".

## Response

201 with [the VM object](https://shako.dev/api/objects/vm-view.md).

## Behavior

The copy gets the size, the image, the agents and the role of the source VM, and it boots with new SSH host keys. The answer comes at once, with the copy creating, as for a create.

The errors: https://shako.dev/api/errors.md. All the endpoints of VMs: https://shako.dev/api/vms.md.
