创建

Description 描述

object script.create(object/array scripts)

This method allows to create new scripts. 此方法允许创建一个新的脚本

Parameters 参数

(object/array) Scripts to create.

The method accepts scripts with the standard script properties.

Return values

(object) Returns an object containing the IDs of the created scripts under the scriptids property. The order of the returned IDs matches the order of the passed scripts. (object)返回一个对象,该对象包含在scriptids属性下创建的脚本的id。返回的id的顺序与通过的脚本的顺序相匹配。

Examples 示例如下

Create a script 创建一个脚本

Create a script that will reboot a server. The script will require write access to the host and will display a configuration message before running in the frontend. 创建一个重启一个server的脚本,这个脚本需要对该主机有写的权限,并且在脚本运行在界面之前会提示一个确认信息。

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "script.create",
  4. "params": {
  5. "name": "Reboot server",
  6. "command": "reboot server 1",
  7. "host_access": 3,
  8. "confirmation": "Are you sure you would like to reboot the server?"
  9. },
  10. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  11. "id": 1
  12. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": {
  4. "scriptids": [
  5. "3"
  6. ]
  7. },
  8. "id": 1
  9. }

Source

CScript::create() in frontends/php/include/classes/api/services/CScript.php.

Create a custom script

Create a custom script that will reboot a server. The script will require write access to the host and will display a configuration message before running in the frontend.

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "script.create",
  4. "params": {
  5. "name": "Reboot server",
  6. "command": "reboot server 1",
  7. "host_access": 3,
  8. "confirmation": "Are you sure you would like to reboot the server?",
  9. "type": 0
  10. },
  11. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  12. "id": 1
  13. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": {
  4. "scriptids": [
  5. "4"
  6. ]
  7. },
  8. "id": 1
  9. }

Source

CScript::create() in ui/include/classes/api/services/CScript.php.