创建

说明

object template.create(object/array templates)

此方法允许创建新模板。

参数

(object/array) 创建模板。

除了标准模板属性之外,该方法接受以下属性。

参数 类 说明
groups
(必须)
object/array主 模板添加到主机组。
组必须定义groupid属性。
tags object/array 模板标签。
templates object/array 被链接到模板的模板。
模板必须定义templateid属性。
macros object/array 为模板创建的用户宏。
hosts object/array 链接到模板的主机。
主机必须定义hostid属性。

返回值

(object)返回一个对象,包含templateids属性中创建的模板ID,返回ID的顺序与传递模板的顺序一致。

范例

创建模板

创建一个模板并将其链接到两台主机上。

Request 请求:

{  "jsonrpc": "2.0",  "method": "template.create",  "params": {  "host": "Linux template",  "groups": {  "groupid": 1  },  "hosts": [  {  "hostid": "10084"  },  {  "hostid": "10090"  }  ]  },  "auth": "038e1d7b1735c6a5436ee9eae095879e",  "id": 1 }

Response 响应:

{  "jsonrpc": "2.0",  "result": {  "templateids": [  "10086"  ]  },  "id": 1 }

源码

CTemplate::create()方法可在ui/include/classes/api/services/CTemplate.php中参考。