创建

描述

对象 host.create(对象/数组 hosts)

这个方法可以用来创建主机.

参数

(对象/数组) 要创建的主机.

另外,对于标准的主机属性,该方法接受下列参数

属性 类 描述
groups
(必选)
对象/数组 添加主
的主机组.
主机组必须已定义groupid属性.
interfaces
(必选)
对象/数组 为主机 建的接口.
templates 对象/数组 链接到 机的模板.

模板必须已定义过templateid属性.
macros 对象/数组 为主机 建的用户宏.
inventory 对象 主 资产清单属性.

返回值

(对象) 返回包含已创建主机ID的属性hostid ,返回ID的顺序与传入主机的顺序一致

示例

创建主机

Create a host called "Linux server" with an IP interface, add it to a group, link a template to it and set the MAC addresses in the host inventory.

创建一个具有IP接口的“Linux Server”主机,将其添加到主机组中,链接一个模板并且把MAC地址设置到主机资产清单里 请求:

{  "jsonrpc": "2.0",  "method": "host.create",  "params": {  "host": "Linux server",  "interfaces": [  {  "type": 1,  "main": 1,  "useip": 1,  "ip": "192.168.3.1",  "dns": "",  "port": "10050"  }  ],  "groups": [  {  "groupid": "50"  }  ],  "templates": [  {  "templateid": "20045"  }  ],  "inventory_mode": 0,  "inventory": {  "macaddress_a": "01234",  "macaddress_b": "56768"  }  },  "auth": "038e1d7b1735c6a5436ee9eae095879e",  "id": 1 }

响应:

{  "jsonrpc": "2.0",  "result": {  "hostids": [  "107819"  ]  },  "id": 1 }

参考

来源

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

Source

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