> For the complete documentation index, see [llms.txt](https://docs.enclaive.cloud/enclaive-multi-cloud-platform/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.enclaive.cloud/enclaive-multi-cloud-platform/developers/api/client-api/manage/virtual-machine.md).

# Virtual Machine

Endpoints for virtual machine management across different cloud providers like Azure, AWS, and Kraud.Cloud. This includes creating, deleting, updating, and retrieving VM details

It is important to note that the password and shh keys for remote access are stored in Vault.

## Create virtual machine

<mark style="color:green;">`POST`</mark> `{{BASE_URL}}/api/virtual-machines`

Virtual Machine Creation. Currently, only ( Kraud.Cloud, Azure, AWS ) can be created.

#### Headers

| Name                                            | Type   | Description  |
| ----------------------------------------------- | ------ | ------------ |
| Authorization<mark style="color:red;">\*</mark> | String | Bearer Token |

#### Request Body

| Name                                   | Type   | Description |
| -------------------------------------- | ------ | ----------- |
| data<mark style="color:red;">\*</mark> | Object |             |

{% tabs %}
{% tab title="201: Created " %}

```json
[
    {
        "region": {
            "datacenter": {
                "name": "berlin",
                "displayName": "Berlin"
            },
            "physicalLocation": "Germany"
        },
        "image": {
            "version": {
                "name": "20_04-lts",
                "displayName": "20.04 LTS"
            },
            "distribution": "Ubuntu"
        },
        "attestationId": "5cb168ab-25de-4b20-9949-a07a2cf23e65",
        "access": null,
        "authMethod": 1,
        "status": 0,
        "isBlocked": false,
        "tags": [],
        "subscription": null,
        "_id": "654a11e60b23ef1b0f36d44e",
        "name": "kraud-cloud-ubuntu-1vcpu-4gb-berlin-01",
        "provider": "6548a383e2442d14b6bf968b",
        "size": "6548a383e2442d14b6bf9745",
        "price": "6548a383e2442d14b6bf970b",
        "owner": "6548a41138406c14db33b606",
        "project": "6548a41f38406c14db33b62c",
        "team": "6548a41f38406c14db33b61e",
        "ipConfigurations": [],
        "createdAt": "2023-11-07T10:31:02.692Z",
        "updatedAt": "2023-11-07T10:31:02.692Z"
    }
]
```

{% endtab %}
{% endtabs %}

<details>

<summary>Request payload</summary>

```json
{
    "cloudProvider": "6548a383e2442d14b6bf9685",
    "team": "6548a41f38406c14db33b61e",
    "project": "6548a41f38406c14db33b62c",
    "hostNames": [
        "kraud-cloud-ubuntu-1vcpu-4gb-berlin-01"
    ],
    "provider": "6548a383e2442d14b6bf968b",
    "size": "6548a383e2442d14b6bf9745",
    "price": "6548a383e2442d14b6bf970b",
    "subscription": "",
    "tags": [],
    "access": null,
    "region": {
        "physicalLocation": "Germany",
        "datacenter": {
            "name": "berlin",
            "displayName": "Berlin"
        }
    },
    "image": {
        "distribution": "Ubuntu",
        "version": {
            "name": "20_04-lts",
            "displayName": "20.04 LTS"
        }
    },
    "authMethod": 1,
    "quantity": 1
}
```

</details>

***

Below is a screenshot of the [Vault](https://vault.dev.m4rgdmtr.1d.pt/ui/vault/auth?with=token) UI. This shows the path to the keys. From this path you can get the keys to remotely connect to the VM.

Below is an example of how to make this request.\
\
{{VAULT\_URL}}/v1/enclaive-static/data/{teamId}/user/root?version=0

<figure><img src="https://github.com/enclaive/documentation/blob/emcp/developers/.gitbook/assets/Screenshot%202023-11-09%20at%2009.34.45.png" alt=""><figcaption></figcaption></figure>

## Get virtual machines

<mark style="color:blue;">`GET`</mark> `{{BASE_URL}}/api/teams/{team}/projects/{project}/virtual-machines`

Get all active virtual machines for a specific project.

#### Path Parameters

| Name                                      | Type   | Description |
| ----------------------------------------- | ------ | ----------- |
| team<mark style="color:red;">\*</mark>    | String | Team ID     |
| project<mark style="color:red;">\*</mark> | String | Project ID  |

#### Headers

| Name                                            | Type   | Description  |
| ----------------------------------------------- | ------ | ------------ |
| Authorization<mark style="color:red;">\*</mark> | String | Bearer Token |

{% tabs %}
{% tab title="200: OK " %}

```json
[
    {
        "_id": "654a11e60b23ef1b0f36d44e",
        "region": {
            "datacenter": {
                "name": "berlin",
                "displayName": "Berlin"
            },
            "physicalLocation": "Germany"
        },
        "image": {
            "version": {
                "name": "20_04-lts",
                "displayName": "20.04 LTS"
            },
            "distribution": "Ubuntu"
        },
        "attestationId": "5cb168ab-25de-4b20-9949-a07a2cf23e65",
        "access": null,
        "authMethod": 1,
        "status": 3,
        "isBlocked": false,
        "tags": [],
        "subscription": null,
        "name": "kraud-cloud-ubuntu-1vcpu-4gb-berlin-01",
        "provider": {
            "_id": "6548a383e2442d14b6bf968b",
            "type": "vm",
            "isDisabled": false,
            "cloudProvider": {
                "_id": "6548a383e2442d14b6bf9685",
                "name": "Kraud.Cloud",
                "isDisabled": false
            }
        },
        "size": {
            "_id": "6548a383e2442d14b6bf9745",
            "provider": "6548a383e2442d14b6bf968b",
            "location": "berlin",
            "name": "Standart_berlin_1_4_50",
            "vCPUs": 1,
            "memoryGB": 4,
            "spaceGB": 50,
            "group": 0
        },
        "price": {
            "_id": "6548a383e2442d14b6bf970b",
            "provider": "6548a383e2442d14b6bf968b",
            "locationName": "berlin",
            "sizeName": "Standart_berlin_1_4_50",
            "imageName": "Ubuntu",
            "pricePerHour": 0.04,
            "pricePerMonth": 30,
            "currencyCode": "EUR",
            "createdAt": "2023-11-06T08:27:47.134Z",
            "updatedAt": "2023-11-06T08:27:47.134Z"
        },
        "owner": "6548a41138406c14db33b606",
        "project": "6548a41f38406c14db33b62c",
        "team": "6548a41f38406c14db33b61e",
        "ipConfigurations": [
            {
                "_id": "654a11f60b23ef1b0f36d46c",
                "type": "public",
                "method": "Dynamic",
                "version": "IPv4",
                "address": "185.112.181.100"
            }
        ],
        "createdAt": "2023-11-07T10:31:02.692Z",
        "updatedAt": "2023-11-07T10:31:18.020Z",
        "attestation": null
    }
]
```

{% endtab %}
{% endtabs %}

## Get virtual machine

<mark style="color:blue;">`GET`</mark> `{{BASE_URL}}/api/virtual-machines/{id}`

Get a specific virtual machine by unique id.

#### Path Parameters

| Name                                 | Type   | Description        |
| ------------------------------------ | ------ | ------------------ |
| id<mark style="color:red;">\*</mark> | String | Virtual machine ID |

#### Headers

| Name                                            | Type   | Description  |
| ----------------------------------------------- | ------ | ------------ |
| Authorization<mark style="color:red;">\*</mark> | String | Bearer Token |

{% tabs %}
{% tab title="200: OK " %}

```json
{
    "_id": "654a11e60b23ef1b0f36d44e",
    "region": {
        "datacenter": {
            "name": "berlin",
            "displayName": "Berlin"
        },
        "physicalLocation": "Germany"
    },
    "image": {
        "version": {
            "name": "20_04-lts",
            "displayName": "20.04 LTS"
        },
        "distribution": "Ubuntu"
    },
    "attestationId": "5cb168ab-25de-4b20-9949-a07a2cf23e65",
    "access": null,
    "authMethod": 1,
    "status": 3,
    "isBlocked": false,
    "tags": [],
    "subscription": null,
    "name": "kraud-cloud-ubuntu-1vcpu-4gb-berlin-01",
    "provider": {
        "_id": "6548a383e2442d14b6bf968b",
        "type": "vm",
        "isDisabled": false,
        "cloudProvider": {
            "_id": "6548a383e2442d14b6bf9685",
            "name": "Kraud.Cloud",
            "isDisabled": false
        }
    },
    "size": {
        "_id": "6548a383e2442d14b6bf9745",
        "provider": "6548a383e2442d14b6bf968b",
        "location": "berlin",
        "name": "Standart_berlin_1_4_50",
        "vCPUs": 1,
        "memoryGB": 4,
        "spaceGB": 50,
        "group": 0
    },
    "price": {
        "_id": "6548a383e2442d14b6bf970b",
        "provider": "6548a383e2442d14b6bf968b",
        "locationName": "berlin",
        "sizeName": "Standart_berlin_1_4_50",
        "imageName": "Ubuntu",
        "pricePerHour": 0.04,
        "pricePerMonth": 30,
        "currencyCode": "EUR",
        "createdAt": "2023-11-06T08:27:47.134Z",
        "updatedAt": "2023-11-06T08:27:47.134Z"
    },
    "owner": "6548a41138406c14db33b606",
    "project": {
        "_id": "6548a41f38406c14db33b62c",
        "name": "first-project",
        "description": "Update your project information under Settings",
        "environment": "Development",
        "purpose": "Just trying out Enclaive",
        "isDefault": false,
        "icon": 1,
        "owner": "6548a41138406c14db33b606",
        "team": "6548a41f38406c14db33b61e",
        "createdAt": "2023-11-06T08:30:23.552Z",
        "updatedAt": "2023-11-07T08:52:28.154Z"
    },
    "team": {
        "_id": "6548a41f38406c14db33b61e",
        "name": "My Team",
        "email": "john.doe@mail.com",
        "members": [
            {
                "user": "6548a41138406c14db33b606",
                "role": 0
            }
        ],
        "createdAt": "2023-11-06T08:30:23.529Z",
        "updatedAt": "2023-11-06T12:56:06.337Z",
        "billingSettings": "6548e2660919dc0442dc2ec7"
    },
    "ipConfigurations": [
        {
            "_id": "654a11f60b23ef1b0f36d46c",
            "type": "public",
            "method": "Dynamic",
            "version": "IPv4",
            "address": "185.112.181.100"
        }
    ],
    "createdAt": "2023-11-07T10:31:02.692Z",
    "updatedAt": "2023-11-07T10:31:18.020Z",
    "attestation": null
}
```

{% endtab %}
{% endtabs %}

## Stop virtual machine

<mark style="color:orange;">`PUT`</mark> `{{BASE_URL}}/api/virtual-machines/{id}/stop`

Stop virtual machine by unique id.

#### Path Parameters

| Name                                 | Type   | Description        |
| ------------------------------------ | ------ | ------------------ |
| id<mark style="color:red;">\*</mark> | String | Virtual machine ID |

#### Headers

| Name                                            | Type   | Description  |
| ----------------------------------------------- | ------ | ------------ |
| Authorization<mark style="color:red;">\*</mark> | String | Bearer Token |

{% tabs %}
{% tab title="200: OK " %}

```json
{"message":"Virtual machine is stopped","vmId":"654a11e60b23ef1b0f36d44e"}
```

{% endtab %}
{% endtabs %}

## Start virtual machine

<mark style="color:orange;">`PUT`</mark> `{{BASE_URL}}/api/virtual-machines/{id}/start`

Start virtual machine by unique id.

#### Path Parameters

| Name                                 | Type   | Description        |
| ------------------------------------ | ------ | ------------------ |
| id<mark style="color:red;">\*</mark> | String | Virtual machine ID |

#### Headers

| Name                                            | Type   | Description  |
| ----------------------------------------------- | ------ | ------------ |
| Authorization<mark style="color:red;">\*</mark> | String | Bearer Token |

{% tabs %}
{% tab title="200: OK " %}

```json
{"message":"Virtual machine is running","vmId":"654a11e60b23ef1b0f36d44e"}
```

{% endtab %}
{% endtabs %}

## Delete virtual machine

<mark style="color:red;">`DELETE`</mark> `{{BASE_URL}}/api/virtual-machines/{id}`

Delete a specific virtual machine by unique id.

#### Path Parameters

| Name                                 | Type   | Description        |
| ------------------------------------ | ------ | ------------------ |
| id<mark style="color:red;">\*</mark> | String | Virtual machine ID |

#### Headers

| Name                                            | Type   | Description  |
| ----------------------------------------------- | ------ | ------------ |
| Authorization<mark style="color:red;">\*</mark> | String | Bearer Token |

{% tabs %}
{% tab title="200: OK " %}

```json
{"message":"Virtual machine is deleted","vmId":"654a10fd619e4f1a657135bd"}
```

{% endtab %}
{% endtabs %}
