> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/dsx-air/llms.txt.

# Create an instruction on a device

POST https://api.dsx-air.nvidia.com/api/v3/simulations/devices/instructions/
Content-Type: application/json

Create a new instruction for a device which boots an operating system of its own (e.g. a DPU), naming the `device` rather than the node it runs. This operation is only permitted when the simulation is in the `ACTIVE` or `INACTIVE` state.

**Required scope:** Simulation Edit (roles: Air Org Administrator, Air User)

Reference: https://docs.nvidia.com/dsx-air/api-reference/instructions/api-v-3-simulations-devices-instructions-create

## Authentication

- `Authorization` header (bearer token, required) — Bearer authentication of the form `Bearer <token>`, where token is your auth token.

## Request

### Body (application/json)

This endpoint expects a DeviceInstructionCreateSerializerTypesRequest.

- `DeviceInstructionCreateSerializerTypesRequest`
  - DeviceInitInstructionCreateSchemaRequest: DeviceInitInstructionCreateSchemaRequest
  - DeviceFileInstructionCreateSchemaRequest: DeviceFileInstructionCreateSchemaRequest
  - DeviceShellInstructionCreateSchemaRequest: DeviceShellInstructionCreateSchemaRequest

## Response

### 201

- `InstructionReadSerializerTypes`
  - InitInstructionRead: InitInstructionRead
  - FileInstructionRead: FileInstructionRead
  - ShellInstructionRead: ShellInstructionRead

## Errors

### 400 Bad Request Error

- `detail` (string, required) — Description of an error.
- `request_id` (string, required, nullable) — ID assigned to the request which encountered the error. Should be provided when opening a support case.
- `type` (enum, required) — Specific type of a 400 error. * `PROTECTED` - Instance may not be deleted as it is being referenced by other instances. * `VALIDATION` - Validation errors encountered during payload processing.
  - Allowed values: `PROTECTED`, `VALIDATION`
- `protected_instances` (list of ProtectedErrorInstance, optional) — Instances which bar the current instance from being deleted. Only defined when `type` is set to `PROTECTED`.
- `validation_errors` (BadRequestValidationErrors, optional) — Validation errors encountered during payload processing. Only defined when `type` is set to `VALIDATION`.

### 403 Forbidden Error

- `detail` (string, required) — Description of an error.
- `request_id` (string, required, nullable) — ID assigned to the request which encountered the error. Should be provided when opening a support case.

### 500 Internal Server Error

- `request_id` (string, required, nullable) — ID assigned to the request which encountered the error. Should be provided when opening a support case.
- `code` (string, required) — Error code which identifies the error. Should be provided when opening a support case.
- `detail` (string, optional, default: An unexpected error has occurred. Please contact NVIDIA Air support for further assistance.) — Description of an error.

## Types

### DeviceInitInstructionCreateSchemaRequest

Schema for the `init` executor on the device route.

- `device` (string, required) — The `id` of the device to instruct. It must boot an operating system of its own.
- `executor` (enum, required) — Must be `init` to select this instruction type. * `init` - init
  - Allowed values: `init`
- `data` (InitDataRequest, required) — Data on what hostname should be assigned to the node when it initializes.
- `name` (string, optional) — The name of the instruction.
- `run_again_on_rebuild` (boolean, optional) — If the instruction should be run again if the simulation is rebuilt.
- `wait_for_network` (boolean, optional, default: true) — Whether to wait for network connectivity before executing the instruction.
- `reachability_check` (ReachabilityCheckRequest, optional, nullable) — Configuration for network reachability check.

### DeviceFileInstructionCreateSchemaRequest

Schema for the `file` executor on the device route.

- `device` (string, required) — The `id` of the device to instruct. It must boot an operating system of its own.
- `executor` (enum, required) — Must be `file` to select this instruction type. * `file` - file
  - Allowed values: `file`
- `data` (FileDataRequest, required) — Information needed to write files to the node.
- `name` (string, optional) — The name of the instruction.
- `run_again_on_rebuild` (boolean, optional) — If the instruction should be run again if the simulation is rebuilt.
- `wait_for_network` (boolean, optional, default: true) — Whether to wait for network connectivity before executing the instruction.
- `reachability_check` (ReachabilityCheckRequest, optional, nullable) — Configuration for network reachability check.

### DeviceShellInstructionCreateSchemaRequest

Schema for the `shell` executor on the device route.

- `device` (string, required) — The `id` of the device to instruct. It must boot an operating system of its own.
- `executor` (enum, required) — Must be `shell` to select this instruction type. * `shell` - shell
  - Allowed values: `shell`
- `data` (ShellDataRequest, required) — Information on shell commands to be run on the node.
- `name` (string, optional) — The name of the instruction.
- `run_again_on_rebuild` (boolean, optional) — If the instruction should be run again if the simulation is rebuilt.
- `wait_for_network` (boolean, optional, default: true) — Whether to wait for network connectivity before executing the instruction.
- `reachability_check` (ReachabilityCheckRequest, optional, nullable) — Configuration for network reachability check.

### InitInstructionRead

Representation of a hostname assignment instruction.

- `id` (string, required)
- `created` (datetime, required)
- `modified` (datetime, required)
- `node` (string, required) — The node which will execute the instruction.
- `device` (string, required, nullable) — The `id` of the device this instruction runs on, when its node is one a device runs (e.g. a DPU). `null` for a standalone node.
- `data` (InitDataRead, required) — Data on what hostname should be assigned to the node when it initializes.
- `state` (enum, required) — The current lifecycle state of this instruction. Defaults to NOT_READY; transitions to READY once the target VM is running. * `NOT_READY` - The instruction exists but is not yet ready for worker pickup. * `READY` - The instruction is ready to be picked up and executed. * `IN_PROGRESS` - The instruction has been picked up by the worker. * `COMPLETE` - The instruction was successfully executed. * `FAILED` - The instruction failed to finish execution. * `CANCELLED` - The instruction was cancelled before execution.
  - Allowed values: `NOT_READY`, `READY`, `IN_PROGRESS`, `COMPLETE`, `FAILED`, `CANCELLED`
- `created_by_client` (boolean, required) — Whether the instruction was created by a client.
- `wait_for_network` (boolean, required) — Whether to wait for network connectivity before executing the instruction.
- `reachability_check` (any, required, nullable) — Configuration for network reachability check. None when wait_for_network is False or not set.
- `name` (string, optional) — The name of the instruction.
- `run_again_on_rebuild` (boolean, optional) — If the instruction should be run again if the simulation is rebuilt.

### FileInstructionRead

Representation of an instruction that writes files to a node.

- `id` (string, required)
- `created` (datetime, required)
- `modified` (datetime, required)
- `node` (string, required) — The node which will execute the instruction.
- `device` (string, required, nullable) — The `id` of the device this instruction runs on, when its node is one a device runs (e.g. a DPU). `null` for a standalone node.
- `data` (FileDataRead, required) — Information needed to write files to the node.
- `state` (enum, required) — The current lifecycle state of this instruction. Defaults to NOT_READY; transitions to READY once the target VM is running. * `NOT_READY` - The instruction exists but is not yet ready for worker pickup. * `READY` - The instruction is ready to be picked up and executed. * `IN_PROGRESS` - The instruction has been picked up by the worker. * `COMPLETE` - The instruction was successfully executed. * `FAILED` - The instruction failed to finish execution. * `CANCELLED` - The instruction was cancelled before execution.
  - Allowed values: `NOT_READY`, `READY`, `IN_PROGRESS`, `COMPLETE`, `FAILED`, `CANCELLED`
- `created_by_client` (boolean, required) — Whether the instruction was created by a client.
- `wait_for_network` (boolean, required) — Whether to wait for network connectivity before executing the instruction.
- `reachability_check` (any, required, nullable) — Configuration for network reachability check. None when wait_for_network is False or not set.
- `name` (string, optional) — The name of the instruction.
- `run_again_on_rebuild` (boolean, optional) — If the instruction should be run again if the simulation is rebuilt.

### ShellInstructionRead

Representation of an arbitrary shell execution instruction.

- `id` (string, required)
- `created` (datetime, required)
- `modified` (datetime, required)
- `node` (string, required) — The node which will execute the instruction.
- `device` (string, required, nullable) — The `id` of the device this instruction runs on, when its node is one a device runs (e.g. a DPU). `null` for a standalone node.
- `data` (ShellDataRead, required) — Information on shell commands to be run on the node.
- `state` (enum, required) — The current lifecycle state of this instruction. Defaults to NOT_READY; transitions to READY once the target VM is running. * `NOT_READY` - The instruction exists but is not yet ready for worker pickup. * `READY` - The instruction is ready to be picked up and executed. * `IN_PROGRESS` - The instruction has been picked up by the worker. * `COMPLETE` - The instruction was successfully executed. * `FAILED` - The instruction failed to finish execution. * `CANCELLED` - The instruction was cancelled before execution.
  - Allowed values: `NOT_READY`, `READY`, `IN_PROGRESS`, `COMPLETE`, `FAILED`, `CANCELLED`
- `created_by_client` (boolean, required) — Whether the instruction was created by a client.
- `wait_for_network` (boolean, required) — Whether to wait for network connectivity before executing the instruction.
- `reachability_check` (any, required, nullable) — Configuration for network reachability check. None when wait_for_network is False or not set.
- `name` (string, optional) — The name of the instruction.
- `run_again_on_rebuild` (boolean, optional) — If the instruction should be run again if the simulation is rebuilt.

### ProtectedErrorInstance

Identifier of a protected instance.

- `id` (string, required) — ID of the instance.
- `type` (string, required) — Type of the instance.

### BadRequestValidationErrors

Validation errors encountered during payload processing. Only defined when `type` is set to `VALIDATION`.

- map from string to BadRequestValidationErrorsOneOf0
- list of BadRequestValidationErrorsOneOf1Items

### InitDataRequest

Data on what hostname should be assigned to the node when it initializes.

- `hostname` (string, required) — Hostname to assign to the node when it initializes.

### ReachabilityCheckRequest

Serializer for network reachability check configuration.

- `reachability_ip` (string, optional, nullable) — IPv4 address to check for reachability. If automatic OOB is enabled and no address is given, the `oob-mgmt-server` address is used instead.
- `timeout` (integer, optional, default: 480) — How long to wait for the reachability check, in seconds.
- `vrf` (string, optional, nullable) — Name of the VRF to check reachability in. Optional.

### FileDataRequest

Information needed to write files to the node.

- `files` (list of NestedFileInfoRequest, required) — List of files to write to the node.
- `post_commands` (list of string, optional) — List of shell commands to run, in order, after the files are written.

### ShellDataRequest

Information on shell commands to be run on the node.

- `commands` (list of string, required) — List of shell commands to run on the node, in order.

### InitDataRead

Data on what hostname should be assigned to the node when it initializes.

- `executor` (enum, required) — The `init` executor option. * `init` - init
  - Allowed values: `init`
- `hostname` (string, required) — Hostname to assign to the node when it initializes.

### FileDataRead

Information needed to write files to the node.

- `executor` (enum, required) — The `file` executor option. * `file` - file
  - Allowed values: `file`
- `files` (list of NestedFileInfo, required) — List of files to write to the node.
- `post_commands` (list of string, optional) — List of shell commands to run, in order, after the files are written.

### ShellDataRead

Information on shell commands to be run on the node.

- `executor` (enum, required) — The `shell` executor option. * `shell` - shell
  - Allowed values: `shell`
- `commands` (list of string, required) — List of shell commands to run on the node, in order.

### BadRequestValidationErrorsOneOf0

- list of BadRequestValidationErrorsOneOf0OneOf0Items
- BadRequestValidationErrorsOneOf01
- map from string to any

### BadRequestValidationErrorsOneOf1Items

A single validation error.

- `message` (string, required) — Human-readable description of the error.
- `code` (string, required) — Machine-readable identifier for the error, for branching in client code. DRF supplies the default (e.g. `invalid`, `required`, `unique`); Air sets its own where a generic code would hide the cause, such as `protected` when a delete is refused because another instance still references this one.

### NestedFileInfoRequest

Information about an individual file to be written to the node.

- `path` (string, required) — Path on the node where the file will be written.
- `content` (string, required) — Text content to write into the file.

### NestedFileInfo

Information about an individual file to be written to the node.

- `path` (string, required) — Path on the node where the file will be written.
- `content` (string, required) — Text content to write into the file.

### BadRequestValidationErrorsOneOf0OneOf0Items

A single validation error.

- `message` (string, required) — Human-readable description of the error.
- `code` (string, required) — Machine-readable identifier for the error, for branching in client code. DRF supplies the default (e.g. `invalid`, `required`, `unique`); Air sets its own where a generic code would hide the cause, such as `protected` when a delete is refused because another instance still references this one.

### BadRequestValidationErrorsOneOf01

A single validation error.

- `message` (string, required) — Human-readable description of the error.
- `code` (string, required) — Machine-readable identifier for the error, for branching in client code. DRF supplies the default (e.g. `invalid`, `required`, `unique`); Air sets its own where a generic code would hide the cause, such as `protected` when a delete is refused because another instance still references this one.

## Examples

**Request**

```json
{
  "data": {
    "hostname": "string"
  },
  "device": "string",
  "executor": "init"
}
```

**Response**

```json
{
  "created": "2024-01-15T09:30:00Z",
  "created_by_client": true,
  "data": {
    "executor": "init",
    "hostname": "string"
  },
  "device": "string",
  "id": "string",
  "modified": "2024-01-15T09:30:00Z",
  "name": "string",
  "node": "string",
  "reachability_check": null,
  "run_again_on_rebuild": true,
  "state": "NOT_READY",
  "wait_for_network": true
}
```

**SDK Code**

```python
import requests

url = "https://api.dsx-air.nvidia.com/api/v3/simulations/devices/instructions/"

payload = {
    "data": { "hostname": "string" },
    "device": "string",
    "executor": "init"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://api.dsx-air.nvidia.com/api/v3/simulations/devices/instructions/';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"data":{"hostname":"string"},"device":"string","executor":"init"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.dsx-air.nvidia.com/api/v3/simulations/devices/instructions/"

	payload := strings.NewReader("{\n  \"data\": {\n    \"hostname\": \"string\"\n  },\n  \"device\": \"string\",\n  \"executor\": \"init\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.dsx-air.nvidia.com/api/v3/simulations/devices/instructions/")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"data\": {\n    \"hostname\": \"string\"\n  },\n  \"device\": \"string\",\n  \"executor\": \"init\"\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.dsx-air.nvidia.com/api/v3/simulations/devices/instructions/")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"data\": {\n    \"hostname\": \"string\"\n  },\n  \"device\": \"string\",\n  \"executor\": \"init\"\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.dsx-air.nvidia.com/api/v3/simulations/devices/instructions/', [
  'body' => '{
  "data": {
    "hostname": "string"
  },
  "device": "string",
  "executor": "init"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.dsx-air.nvidia.com/api/v3/simulations/devices/instructions/");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"data\": {\n    \"hostname\": \"string\"\n  },\n  \"device\": \"string\",\n  \"executor\": \"init\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "data": ["hostname": "string"],
  "device": "string",
  "executor": "init"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.dsx-air.nvidia.com/api/v3/simulations/devices/instructions/")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```