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参数 T pe类型 Des ription说明
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请求:

{
           "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
       }

Source来源

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