# ResetInstances

## 1. API Description

This API (ResetInstances) is used to reinstall the operating system on multiple instances.

#### Preparation

* Query images: Call [DescribeImages](https://docs.console.zenlayer.com/api-reference/compute/zec/image/describeimages) to obtain the operating system image information required for reinstallation.

{% hint style="info" %}
**Note**

* If the `imageId` parameter is specified, the instance will be reinstalled using the specified image; otherwise, it will be reinstalled using the current image of the instance.
* Reinstallation across operating system types (`osType`) is not supported. For example, reinstalling from `linux` to `windows`.
* The boot disk size of the instance must be greater than or equal to the size of the target image. Otherwise, the operation will be rejected.
* The boot disk will be formatted and reset; ensure there are no important files on the boot disk.
* You can set either a password or a keyId, but not both.
* System reinstallation can only be performed when the instance is in a powered-off state.
* `Windows` and `Generic` do not support SSH login using `key_id`.
* After reinstallation, the instance enters the `DEPLOYING` state. If the instance's latest state changes to `RUNNING`, the operation is successful. If it changes to `REINSTALL_FAILED`, the operation is failed; please contact the administrator. The instance state can be queried via the [`DescribeInstancesStatus`](https://docs.console.zenlayer.com/api-reference/compute/zec/instance/describeinstancesstatus) API.
  {% endhint %}

## 2. Input Parameters

The following request parameter list only provides API request parameters.

| Parameter Name | Required | Type            | Description                                                                                                                                                                                                                                                                                                                                                            |
| -------------- | -------- | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| instanceIds    | Yes      | Array of String | The instance IDs to be reinstalled.                                                                                                                                                                                                                                                                                                                                    |
| password       | No       | String          | <p>The new password for the instance.</p><p>You can set either a password or a keyId, but not both; Windows and Generic images support neither option.</p><p>The password must contain the following three character types: uppercase and lowercase letters: \[a-zA-Z], digits: 0-9, and special characters: \~!@$^\*-\_=+</p>                                         |
| keyId          | No       | String          | <p>SSH key pair ID.</p><p>You can set either a password or a keyId, but not both; Windows and Generic images support neither option.</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>Example: key-YWD2QFOl.</p> |
| imageId        | No       | String          | <p>Specify a valid image ID.</p><p>To obtain valid image ID, you can call <a href="https://github.com/zenlayer/zenlayercloud-api-doc-en/blob/main/zec/instance/describeimages.md">DescribeImages</a> and look for imageId in the response.</p><p>If not specified, the instance will be reinstalled using the current image.</p>                                       |
| timezone       | No       | String          | Time zone configuration for the operating system.                                                                                                                                                                                                                                                                                                                      |
| 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> |
| instanceIds    | Array of String | List of instance IDs for which the reinstallation operation failed.                                                   |

## 4. Code Example

{% tabs %}
{% tab title="Example" %}
**Batch reinstall instances.**

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

Request：
{
  "instanceIds": ["<instanceId1>" , "<instanceId2>"],
  "imageId": "ubuntu2022",
  "password": "Example+123",
  "enableAgent": true
}

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

{% endtab %}
{% endtabs %}

## 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 |
| ---------------- | ---------- | ----------- |
