创建

描述

对象 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地址设置到主机资产清单里 请求:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "host.create",
  4. "params": {
  5. "host": "Linux server",
  6. "interfaces": [
  7. {
  8. "type": 1,
  9. "main": 1,
  10. "useip": 1,
  11. "ip": "192.168.3.1",
  12. "dns": "",
  13. "port": "10050"
  14. }
  15. ],
  16. "groups": [
  17. {
  18. "groupid": "50"
  19. }
  20. ],
  21. "templates": [
  22. {
  23. "templateid": "20045"
  24. }
  25. ],
  26. "inventory_mode": 0,
  27. "inventory": {
  28. "macaddress_a": "01234",
  29. "macaddress_b": "56768"
  30. }
  31. },
  32. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  33. "id": 1
  34. }

响应:

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

参考

来源

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