> For the complete documentation index, see [llms.txt](https://docs.console.zenlayer.com/api-reference/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.console.zenlayer.com/api-reference/zec/instance/resetinstances.md).

# ResetInstances

## 1. API Description

This API (ResetInstances) is used to reinstalls the operating system on one or more elastic compute instances. You can specify a new image, login method (password or key pair), time zone, and instance name.

#### Preparations

* Query images: you can call [DescribeImages](/api-reference/zec/image/describeimages.md) to query the information of the operating system image to be reinstalled.

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

* Batch reinstallation processes each instance independently, so a partial failure does not affect the remaining ones. The failed items are returned through the `instanceIds` in the response.
* If the `imageId` parameter is specified, the specified image is used for the reinstallation. Otherwise, the reinstallation is performed with the image currently used by the instance.
* Reinstallation across operating system types (`osType`) is not supported. For example, `linux` cannot be reinstalled as `windows`.
* The system disk size of the instance must be greater than or equal to the size of the image to be reinstalled. Otherwise, the operation is rejected.
* The system disk is formatted and reset. Make sure that there is no important file on the system disk.
* Either a password or a keyPair must be specified, and only one of them can be specified.
* The operating system can be reinstalled only when the instance is shut down.
* `Windows` and `Generic` do not support specifying `key_id` for SSH login.
* After the reinstallation, the instance enters the `DEPLOYING` status. If the latest status of the instance changes to `RUNNING`, the operation succeeded. If it changes to `REINSTALL_FAILED`, the operation failed and you need to contact the administrator. The instance status can be queried by calling the [DescribeInstancesStatus](/api-reference/zec/instance/describeinstancesstatus.md) interface.
  {% endhint %}

## 2. Input Parameters

The following request parameter list only provides API request parameters.

| Parameter Name | Required | Type            | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| -------------- | -------- | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| instanceIds    | Yes      | Array of String | <p>ID of the instance to be reinstalled.</p><p>It can be obtained by calling <a href="/api-reference/zec/instance/describeinstances.md">DescribeInstances</a>.</p>                                                                                                                                                                                                                                                                                                                                                                                                 |
| password       | No       | String          | <p>New password of the instance.</p><p>Specify either this parameter or keyId (a password and a key cannot be specified for Windows and Generic images).</p><p>It must contain all of the following three types of characters: uppercase and lowercase letters (a-z, A-Z), digits (0-9), and special characters (\~!@$^\*-\_=+).</p>                                                                                                                                                                                                                               |
| keyId          | No       | String          | <p>Key ID.</p><p>Specify either this parameter or password (a password and a key cannot be specified for Windows and Generic images).</p><p>You can call <a href="/api-reference/security/ccs/key-pair/describekeypairs.md">DescribeKeyPairs</a> to obtain the latest key pair information.</p><p>After a key is associated, you can access the instance with the corresponding private key. A key and a password cannot be specified at the same time, and the Windows operating system does not support specifying a key.</p><p>Example value: key-YWD2QFOl.</p> |
| imageId        | No       | String          | <p>Specify the image ID for the reinstallation.</p><p>It can be obtained from the imageId field returned by calling <a href="/api-reference/zec/image/describeimages.md">DescribeImages</a>.</p><p>If it is not specified, the reinstallation is performed based on the current image.</p>                                                                                                                                                                                                                                                                         |
| timezone       | No       | String          | Time zone configuration for the operating system.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| enableAgent    | No       | Boolean         | <p>Whether to enable the QEMU Guest Agent (QGA).</p><p>Default value: false</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| instanceName   | No       | String          | <p>The modified instance name.</p><p>2 to 63 characters in length.</p><p>Only letters, digits, periods (.), underscores (\_), slashes (/) and hyphens (-) are supported, and it must start and end with a letter or a digit.</p>                                                                                                                                                                                                                                                                                                                                   |
| userData       | No       | String          | Custom initialization script for the instance. The value must be Base64-encoded, and the decoded size must be less than 64 KiB.                                                                                                                                                                                                                                                                                                                                                                                                                                    |

## 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" %}
**1. Reinstall the OS on multiple instances in a batch.**

```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"
  }
}
```

**2. Reinstall the OS on multiple instances in a batch and specify an initialization script through `userData`. The `userData` in this example is the Base64-encoded value of the script `#!/bin/bash\necho "hello zenlayer" > /tmp/init.log`.**

```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,
  "userData": "IyEvYmluL2Jhc2gKZWNobyAiaGVsbG8gemVubGF5ZXIiID4gL3RtcC9pbml0LmxvZwo="
}

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](/api-reference/api-introduction/toolkit/api-sdk.md)，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](/api-reference/api-introduction/instruction/commonerrorcode.md).

| HTTP Status Code | Error Code | Description |
| ---------------- | ---------- | ----------- |
