无法使用JSON POST请求在foreman 1.16.2中创建主机

时间:2019-06-04 13:54:59

标签: curl crud foreman

我想使用curl使用工头API创建新主机。就像它是手动编写的一样:https://www.theforeman.org/manuals/1.21/index.html#5.1API

我正在使用工头1.16.2,并且成功创建了这样的对象:

$ curl -k -u admin:changeme -H "Accept: version=2,application/json" -H "Content-Type: application/json" \
-X POST -d '{ "name":"foo.bar.com","fullname":"foo.bar.com description" }' \
https://foreman.example.com/api/domains

但是我想创建新主机,所以我去了here

并创建了这样的内容:createhost.json

{
  "host": {
    "name": "testhost11",
    "environment_id": 334344675,
    "domain_id": 22495316,
    "ptable_id": 1007981705,
    "medium_id": 980190962,
    "architecture_id": 501905019,
    "operatingsystem_id": 1073012828,
    "puppet_proxy_id": 182953976,
    "compute_resource_id": 980190962,
    "root_pass": "xybxa6JUkz63w",
    "location_id": 255093256,
    "organization_id": 447626438,
    "ip": "10.0.0.20",
    "mac": "52:53:00:1e:85:93",
    "compute_attributes": {
      "cpus": 4,
      "memory": 1024
    }
  }
}

myscript.sh

#! /bin/sh
#   
curl -k -u Name:Pass -H "Accept: version=2,application/json" -H "Content-Type: application/json" \
        -X POST -d "@createhost.json" https://myserver.com/api/hosts

我得到了这个错误:

{
  "error": {"message":"Internal Server Error: the server was unable to finish the request. This may be caused by unavailability of some required service, incorrect API call or a server-side bug. There may be more information in the server's logs."}
}

这在服务器上:

Processing by Api::V2::HostsController#create as JSON
2019-06-04 14:05:36 46c25a42 [app] [I]   Parameters: {"host"=>{"name"=>"testhost11", "environment_id"=>334344675, "domain_id"=>22495316, "ptable_id"=>1007981705, "medium_id"=>980190962, "architecture_id"=>501
905019, "operatingsystem_id"=>1073012828, "puppet_proxy_id"=>182953976, "compute_resource_id"=>980190962, "root_pass"=>"[FILTERED]", "location_id"=>255093256, "organization_id"=>447626438, "ip"=>"10.0.0.2
0", "mac"=>"52:53:00:1e:85:93", "compute_attributes"=>{"cpus"=>4, "memory"=>1024}}, "apiv"=>"v2"}
2019-06-04 14:05:37 46c25a42 [app] [I] Current user: foreman_admin (administrator)
2019-06-04 14:05:37 46c25a42 [app] [I] Expire fragment views/tabs_and_title_records-9 (0.2ms)
2019-06-04 14:05:37 46c25a42 [app] [I] Current user: foreman_admin (administrator)
2019-06-04 14:05:37 46c25a42 [app] [I] Current user: Me (administrator)
2019-06-04 14:05:37 46c25a42 [app] [I] Authorized user Me(Its Me)
2019-06-04 14:05:37 46c25a42 [app] [I] Current user: Me (administrator)
2019-06-04 14:05:37 46c25a42 [app] [W] Action failed
 | NoMethodError: undefined method `provided_attributes' for nil:NilClass

任何人都知道为什么它不起作用?谢谢。

0 个答案:

没有答案