# ReinstallInstance

## 1. API Description

This API (ReinstallInstance) is used to reinstall the operating system of the specified instance.

#### Prerequisites

* Query image: call [`DescribeImages`](/api-reference/compute/bmc/bare-metal-instance/describeimages.md) to check information on image.
* Query key pairs: call [`DescribeKeyPairs`](https://github.com/zenlayer/zenlayercloud-api-doc-en/blob/main/security/key-service/key-pair/describekeypairs.md) to check information on key pair ID.

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

* <mark style="color:blue;">If you specify an</mark> <mark style="color:blue;">`imageId`</mark><mark style="color:blue;">, the specified image is used. Otherwise, the image used by the current instance is used.</mark>
* <mark style="color:blue;">Operations on instances in recycle bin or in stalling status are not supported.</mark>
* <mark style="color:blue;">The system disk will be formatted and reset. Therefore, make sure that no important files are stored on the system disk.</mark>
* <mark style="color:blue;">If no password is specified, you will get a random password via mailbox.</mark>
* <mark style="color:blue;">The status of the instance will be</mark> <mark style="color:blue;">`INSTALLING`</mark> <mark style="color:blue;">during reinstallation. You can use</mark> [<mark style="color:purple;">DescribeInstances</mark>](/api-reference/compute/bmc/bare-metal-instance/describeinstances.md) <mark style="color:blue;">to query the status of the instance. If the status changes to</mark> <mark style="color:blue;">`Running`</mark><mark style="color:blue;">, it means that the instance has been reinstalled successfully;</mark> <mark style="color:blue;">`INSTALL_FAILED`</mark> <mark style="color:blue;">means the instance has been reinstalled failed. Any operations on the instances are not allowed while creating. Please contact Zenlayer Support if you have failed.</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.</p><p>To obtain the instance ID,you can call DescribeInstances and look for instanceId in the response.</p>                                                                                                                                                                                                                                                                                                                                    |
| imageId        | No       | String                                                                      | <p>Valid image ID.</p><p>To obtain valid image ID,you can call DescribeImages ,pass in instanceTypeId to retrieve the list of images supported by the current model,and then find the imageId in the response.</p><p>You can also not specify an image and install it later through IPMI.</p><p>When using iPXE to install OS,pass the value of ipxeUrl ,and leave imageId empty.</p>                                                                          |
| hostname       | No       | String                                                                      | <p>Instance hostname.</p><p>Default value:hostname.</p><p>This parameter can contain up to 64 . characters.Only letters,numbers,-and periods(.)are supported.</p>                                                                                                                                                                                                                                                                                              |
| password       | No       | String                                                                      | <p>Instance password.</p><p>The parameter must be 8-16 characters,including uppercase letters,lowercase letters,numbers and special characters like 1\~!@$^\*-\_=+ .This password is also used as the password for IPMI login.Please keep it safe.</p><p>You must and can only pass the value of either password or keyId .</p>                                                                                                                                |
| keyId          | No       | String                                                                      | <p>SSH key pair ID.</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>SSH key pairs and passwords cannot to set at the same time.SSH key pairs are not supported for Windows operating system.</p><p>For example: key-YWD2QFOl</p><p>You must and can only pass the value of either password or keyId .</p> |
| raidConfig     | No       | [RaidConfig](/api-reference/compute/bmc/datastructure.md#raidconfig)        | Disk array configuration.                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| partitions     | No       | Array of [Partition](/api-reference/compute/bmc/datastructure.md#partition) | <p>Disk partition configuration.</p><p>If the operating system is not installed,the partition cannot be set.</p>                                                                                                                                                                                                                                                                                                                                               |
| nic            | No       | [Nic](/api-reference/compute/bmc/datastructure.md#nic)                      | NIC configuration.                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| ipxeUrl        | No       | String                                                                      | <p>iPXE URL.</p><p>Pass in the value and install your OS via IPMI.</p><p>You can choose to install OS using Netboot.See Deploy a Custom Image Using iPXE for more details.</p>                                                                                                                                                                                                                                                                                 |
| userData       | No       | String                                                                      | <p>User Data.</p><p>You can specify user data during instance installation. When the instance is launched for the first time, the user data is passed to the server as text and executed. The maximum supported data size is 32 KB.</p>                                                                                                                                                                                                                        |

## 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" %}
**Default reinstallation**

Reinstall the operating system of the instance of the `instanceId` ID with default value.

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

Request：
{
    "instanceId": "instanceId"
}

Response:
{
  "requestId": "TC1748D3E-452D-4F74-8485-7AA73718E453",
  "response": {
    "requestId": "TC1748D3E-452D-4F74-8485-7AA73718E453"
  }

```

{% 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 |
| ---------------- | ---------- | ----------- |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.console.zenlayer.com/api-reference/compute/bmc/bare-metal-instance/reinstallinstance.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
