template.create

Description说明

object template.create(object/array templates)

This method allows to create new templates此方法允许创建新模板.

Parameters参数

(object/array) Templates to create创建模板.

Additionally to the standard template properties, the method accepts the following parameters.除standard template properties之外,该方法接受以下参数.

Parameter参数 Type类型 Description说明
groups(required) object/array Host groups to add the template to将模板添加到主机组. The host groups must have the groupid property defined主机组必须定义groupid属性。.
templates object/array Templates to be linked to the template要链接到模板的模板. The templates must have the templateid property defined模板必须定义templateid属性.
macros object/array User macros to be created for the template为模板创建的用户宏.
hosts object/array Hosts to link the template to链接模板的主机.

Return values返回值

(object) Returns an object containing the IDs of the created templates under the templateids property. The order of the returned IDs matches the order of the passed templates.(object)返回一个对象,它包含templateids属性下创建的模板的ID,返回的ID的顺序与传递的模板的顺序相匹配。

Examples范例

Creating a template创建模板

Create a template and link it to two hosts创建一个模板并将其链接到两个主机.

Request请求:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "template.create",
  4. "params": {
  5. "host": "Linux template",
  6. "groups": {
  7. "groupid": 1
  8. },
  9. "hosts": [
  10. {
  11. "hostid": "10084"
  12. },
  13. {
  14. "hostid": "10090"
  15. }
  16. ]
  17. },
  18. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  19. "id": 1
  20. }

Response响应:

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

Source来源

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