# ResetInstance

## 1. API Description

This API (ResetInstance) is used to reinstall the operating system on an elastic compute instance.

#### Prerequisites

* Query images: call [DescribeImages](https://docs.console.zenlayer.com/api-reference/compute/zec/image/describeimages) to check information on images.

{% hint style="info" %} <mark style="color:blue;">**Note**</mark>

* <mark style="color:blue;">If the</mark> <mark style="color:blue;">`imageId`</mark> <mark style="color:blue;">parameter is specified, the instance will be reinstalled using the specified image; otherwise, it will be reinstalled with its current image.</mark>
* <mark style="color:blue;">The boot disk size of the instance must be greater than or equal to the size of the reinstalled image. Otherwise, the operation will fail.</mark>
* <mark style="color:blue;">The boot disk will be formatted and reset. Make sure there are no important files in the boot disk.</mark>
* <mark style="color:blue;">Specify either a password or a key pair, not both.</mark>
* <mark style="color:blue;">Only operations on instances that are in powered-off state are supported.</mark>
* <mark style="color:blue;">After reinstallation, the instance enters the</mark> <mark style="color:blue;">`DEPLOYING`</mark> <mark style="color:blue;">state. If the latest status of the instance changes to</mark> <mark style="color:blue;">`RUNNING`</mark><mark style="color:blue;">, it means that the operation is successful. If it changes to</mark> <mark style="color:blue;">`REINSTALL_FAILED`</mark><mark style="color:blue;">, it means that the operation has failed. Please contact the administrator. You can call</mark> <mark style="color:blue;">`DescribeInstancesStatus`</mark> <mark style="color:blue;">to query the instance status.</mark>
  {% endhint %}

## 2. Input Parameters

The following request parameter list only provides API request parameters.

| Parameter Name | Required | Type    | Description                                                                                                                                                                                                                                                                                                                                                            |
| -------------- | -------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| instanceId     | Yes      | String  | <p>Instance ID(s).</p><p>To obtain the instance ID, you can call DescribeInstances and look for instanceId in the response.</p>                                                                                                                                                                                                                                        |
| password       | No       | String  | <p>Instance password.</p><p>The parameter must be 8-16 characters, including:</p><p>lowercase letters: \[a-z] uppercase letters: \[A-Z] digits: 0-9 special characters: \`\~!@$^\*-\_=+</p>                                                                                                                                                                            |
| keyId          | No       | String  | <p>SSH key pair ID. For example: key-YWD2QFOl .</p><p>Your SSH key pair contains several public keys that can be placed on your server. You can access your instance with the private key. Call DescribeKeyPairs to obtain key pair information.</p><p>You can set either a password or a keyId , but not both; Windows and Generic images support neither option.</p> |
| imageId        | No       | String  | <p>Specify a valid image ID.</p><p>To obtain valid image ID, you can call DescribeImages and look for imageId in the response. You can also reinstall it according to the original image.</p>                                                                                                                                                                          |
| timezone       | No       | String  | If not specified, the instance will be reinstalled using its original time zone.                                                                                                                                                                                                                                                                                       |
| enableAgent    | No       | Boolean | <p>Whether QGA is enabled or not.</p><p>Default value: false</p>                                                                                                                                                                                                                                                                                                       |
| instanceName   | No       | String  | <p>The modified instance name.</p><p>2–63 characters in length.</p><p>Only letters, numbers, hyphens (-), and periods (.) are allowed.</p>                                                                                                                                                                                                                             |
| userData       | No       | String  | Initialization command.                                                                                                                                                                                                                                                                                                                                                |

## 3. Output Parameters

| Parameter Name | Type   | Description                                                                                                           |
| -------------- | ------ | --------------------------------------------------------------------------------------------------------------------- |
| requestId      | String | <p>The unique request ID, which is returned for each request.</p><p>RequestId is required for locating a problem.</p> |

## 4. Code Example

{% tabs %} {% tab title="Example" %}

**Reinstall operating system.**

```json
POST /api/v2/zec HTTP/1.1
Host: console.zenlayer.com
Content-Type: application/json
X-ZC-Action: ResetInstance
<Common Request Params>

Request：
{
  "instanceId": "<instanceId>",
  "imageId": "ubuntu2022",
  "password": "Example+123",
  "enableAgent": true
}

Response：
{
  "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
  "response": {
    "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3"
  }
}
```

## 5. Developer Resources

Zenlayer Cloud API 2.0 integrates [SDKs](https://docs.console.zenlayer.com/api-reference/api-introduction/toolkit/api-sdk)，to make it easier for you to call APIs. More programming languages will be supported.

## 6. Error Codes

The following only lists the error codes related to the API business logic. For other error codes, see [Common Error Codes](https://docs.console.zenlayer.com/api-reference/api-introduction/instruction/commonerrorcode).

| HTTP Status Code | Error Code                               | Description                                                        |
| ---------------- | ---------------------------------------- | ------------------------------------------------------------------ |
| 400              | INVALID\_IMAGE\_AGENT\_NOT\_SUPPORT      | QGA is not supported for the selected image.                       |
| 400              | INVALID\_IMAGE\_KEY\_PAIR\_NOT\_SUPPORT  | The image does not support SSH key pairs.                          |
| 404              | INVALID\_IMAGE\_NOT\_FOUND               | Image not found.                                                   |
| 400              | INVALID\_IMAGE\_PASSWORD\_NOT\_SUPPORT   | The operating system does not support the specified password.      |
| 400              | INVALID\_IMAGE\_SIZE\_EXCEED             | Boot disk size should be larger than the image size.               |
| 400              | INVALID\_IMAGE\_STATUS                   | The image's state does not support this operation.                 |
| 400              | INVALID\_OS\_TYPE\_NOT\_SAME             | Operating system types are inconsistent, operation not allowed.    |
| 400              | INVALID\_PARAMETER\_USER\_DATA\_EXCEED   | Initialization command exceeds length limit.                       |
| 404              | INVALID\_INSTANCE\_NOT\_FOUND            | Instance not found.                                                |
| 404              | INVALID\_KEY\_PAIR\_NOT\_FOUND           | SSH key pair does not exist.                                       |
| 400              | INVALID\_KEY\_PAIR\_NOT\_SUPPORT         | Unsupported SSH key pair exists.                                   |
| 400              | INVALID\_LOGIN\_SETTING\_CONFLICT        | You must and can only pass the value of either password or keyId . |
| 400              | INVALID\_PASSWORD\_MALFORMED             | Password format error.                                             |
| 400              | UNSUPPORTED\_OPERATION\_INSTANCE\_STATUS | Operations on instances in current state are not supported.        |
