Add multiple hosts at a time

2023-08-22 02:46:05  Updated

Description

You can call this operation to add multiple hosts at a time.

Call description

Prerequisite

You have the HOST_MANAGER permissions.

Request path

POST /api/v2/compute/hosts/batchCreate

Request parameters

Parameter Type Required Example value Description
hostBasicDataList ObjectArray Yes -- The HostBasicData array, which contains basic information of the host.
sshPort Integer Yes 22 The SSH port number of the host.
kind String Yes DEDICATED_PHYSICAL_MACHINE The type of the host. Valid values: * DEDICATED_PHYSICAL_MACHINE * DEDICATED_CONTAINER
publishPorts StringArray No 8080:8080,8090,8090 The port mapping. When kind is set to DEDICATED_CONTAINER, the port mapping between the container and the physical machine must be specified.
idcId Long Yes 100 The ID of the IDC.
typeId Long Yes 1001 The ID of the host type.
credentialId Long Yes 1001 The ID of the credential, which is used to access the host over SSH.
alias String No Server 1 The alias of the host. You can set an alias only when you add a single host.
description String No Test server The description of the host.

Data structure of HostBasicData

Parameter Type Required Example value Description
innerIpAddress String Yes xxx.xxx.xxx.xxx The IP address of the host.
serialNumber String No 6CU4120W67 The serial number of the host.

Response parameters

Parameter Type Description
data Object The requested data.
├─ contents Array The TaskInstance array. For more information about the data structure, see the following table.
successful Boolean Indicates whether the request was successful.
timestamp Datetime The timestamp when the server completed the request.
duration Integer The time taken by the server to process the request, in milliseconds.
status Integer An HTTP status code.
traceId String The trace ID of the request. This trace ID is used for troubleshooting.
server String The address of the application server that responded to the request.

Data structure of TaskInstance

Parameter Type Description
id Long The ID of the software package.
name String The name of the software package.
clusterId Long The ID of the cluster.
tenantId Long The ID of the tenant.
hostId Long The ID of the host.
type String The type of the task. Valid values: * MANUAL: indicates a manually initiated task. * SYS_ONECE: indicates a one-time task executed by the system. * SCHEDULED: indicates a non-built-in scheduled task. * SYS_SCHEDULED: indicates a built-in scheduled task.
status Integer The status of the task. Valid values: * RUNNING * FAILED * SUCCESSFUL
creator String The username of the task creator.
operation String The operation performed by the task. Valid values: * EXECUTE * RETRY * ROLLBACK * SKIP * CANCEL
executor String The IP address of the node that executed the task.
createTime String The time when the task was created.
startTime String The start time of the task.
finishTime String The end time of the task.
prohibitRollback Boolean Indicates whether rollback was supported by the task.
subtasks ObjectArray The SubtaskInstance array, which contains the information of all subtasks.

Data structure of SubtaskInstance

Parameter Type Description
id Long The ID of the subtask instance.
name String The name of the subtask.
seriesId Long The serial number of the subtask.
description String The description of the subtask.
timeout Integer The timeout period of the subtask, in seconds.
status String The status of the subtask. Valid values: * PENDING * READY * RUNNING * CANCELING * FAILED * SUCCESSFUL
operation String The operation performed by the subtask. Valid values: * EXECUTE * RETRY * ROLLBACK * SKIP * CANCEL
executor String The node that executed the subtask.
runTime Integer The number of executions of the subtask.
createTime String The time when the subtask was created.
startTime String The start time of the subtask.
finishTime String The end time of the subtask.
nodeType String The node type, for example, JAVA_TASK.
paralleIdx Integer The index of a parallel subtask. -1 indicates that the subtask is not a parallel subtask.
upstreams LongArray The IDs of upstream subtasks.
downstream LongArray The IDs of downstream subtasks.
prohibitRollback Boolean Indicates whether rollback was supported by the subtask.

Examples

Sample request

POST /api/v2/compute/hosts/batchCreate

curl --user <username>:<password> -X POST 'http://<IP>:<PORT>/api/v2/compute/hosts/batchCreate' \
-H 'Content-Type: application/json' \
--data-raw '{"hostBasicDataList":[{"innerIpAddress":"xxx.xxx.xxx.xxx"}],"sshPort":22,"typeId":1,"idcId":1000002,"kind":"DEDICATED_PHYSICAL_MACHINE","credentialId":2000001}' \

Sample response

{
  "data": {
    "contents": [
      {
        "creator": "admin",
        "executor": "xx.xx.xx.xx",
        "hostId": 4000002,
        "id": 35006655,
        "name": "Prepare host",
        "operation": "EXECUTE",
        "startTime": "2021-08-25T19:48:49.604+08:00",
        "status": "RUNNING",
        "subtasks": [
          {
            "description": "Update host status",
            "downstreams": [],
            "id": 13006993,
            "name": "Update host status",
            "nodeType": "JAVA_TASK",
            "operation": "EXECUTE",
            "parallelIdx": -1,
            "prohibitRollback": false,
            "runTime": 1,
            "seriesId": 4,
            "status": "PENDING",
            "timeout": 1800,
            "upstreams": [
              13006994
            ]
          },
          {
            "description": "Uninstall legacy ocp agent",
            "downstreams": [
              13006994
            ],
            "id": 13006990,
            "name": "Uninstall legacy ocp agent",
            "nodeType": "JAVA_TASK",
            "operation": "EXECUTE",
            "parallelIdx": -1,
            "prohibitRollback": false,
            "runTime": 1,
            "seriesId": 2,
            "status": "PENDING",
            "timeout": 600,
            "upstreams": [
              13006991
            ]
          },
          {
            "description": "Pre check for create host",
            "downstreams": [
              13006991
            ],
            "id": 13006992,
            "name": "Pre check for create host",
            "nodeType": "JAVA_TASK",
            "operation": "EXECUTE",
            "parallelIdx": -1,
            "prohibitRollback": false,
            "runTime": 1,
            "seriesId": 1,
            "status": "READY",
            "timeout": 1800,
            "upstreams": []
          },
          {
            "description": "Install ocp agent",
            "downstreams": [
              13006993
            ],
            "id": 13006994,
            "name": "Install ocp agent",
            "nodeType": "JAVA_TASK",
            "operation": "EXECUTE",
            "parallelIdx": -1,
            "prohibitRollback": false,
            "runTime": 1,
            "seriesId": 0,
            "status": "PENDING",
            "timeout": 5400,
            "upstreams": [
              13006990
            ]
          },
          {
            "description": "Uninstall legacy obagent",
            "downstreams": [
              13006990
            ],
            "id": 13006991,
            "name": "Uninstall legacy obagent",
            "nodeType": "JAVA_TASK",
            "operation": "EXECUTE",
            "parallelIdx": -1,
            "prohibitRollback": false,
            "runTime": 1,
            "seriesId": 3,
            "status": "PENDING",
            "timeout": 2100,
            "upstreams": [
              13006992
            ]
          }
        ],
        "type": "MANUAL"
      }
    ]
  },
  "duration": 1118,
  "server": "xxx.xxx.xxx.xxx",
  "status": 200,
  "successful": true,
  "timestamp": "2021-08-25T19:48:49.639+08:00",
  "traceId": "93c00223847c4e0a"
}

Contact Us