Foreman REST Interface and Curl

> Hi all,
>
> I'm using the following version of foreman:
> foreman-console-0.5.1-1.el6.noarch
> foreman-proxy-0.5.1-1.el6.noarch
> foreman-sqlite-0.5.1-1.el6.noarch
> foreman-0.5.1-1.el6.noarch
>
> I'm trying to figure out what is the minimum information that I need to
> put into a curl post to add a host, I've tried the curl example but I get
> an error. I've also tried the following but I still get an error:
>
> curl -u admin:password -H "Accept:application/json" -d
> "host[name]=test08.uncommonsense.local" -d "host[environment_id]=3" -d
> "host[mac]=00:00:00:00:01" -d "host[ip]=10.0.2.26" -d
> "host[architecture_id]=2" -d "host[operatingsystem_id]=2" -d
> "host[ptable_id]=10" -d "host[build]=0" -d "host[subnet_id]=255.255.255.0"
> -d "host[puppetmaster_name=localhost"
>
subnet is an id, not a value,
also I'm not sure exactly when we changed it ( i think after 0.5.x), but
you should not use puppetmaster_name, rather puppetmaster_id or similar).

check your logs when creating a host via the ui, you could see the exact
names.

also, its recommended to update to 1.0 :slight_smile:

Ohad

··· On Tue, Jun 26, 2012 at 4:33 PM, Action Jack wrote:

http://localhost:8080/hosts

Am I doing something wrong or has the example changed?

Cheers

Action Jack


You received this message because you are subscribed to the Google Groups
"Foreman users" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/foreman-users/-/KhsR2eAAY50J.
To post to this group, send email to foreman-users@googlegroups.com.
To unsubscribe from this group, send email to
foreman-users+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/foreman-users?hl=en.

>
>
>>
>>
>>
>>
>> Hi all,
>>>
>>> I'm using the following version of foreman:
>>> foreman-console-0.5.1-1.el6.**noarch
>>> foreman-proxy-0.5.1-1.el6.**noarch
>>> foreman-sqlite-0.5.1-1.el6.**noarch
>>> foreman-0.5.1-1.el6.noarch
>>>
>>> I'm trying to figure out what is the minimum information that I need to
>>> put into a curl post to add a host, I've tried the curl example but I get
>>> an error. I've also tried the following but I still get an error:
>>>
>>> curl -u admin:password -H "Accept:application/json" -d
>>> "host[name]=test08.**uncommonsense.local" -d "host[environment_id]=3"
>>> -d "host[mac]=00:00:00:00:01" -d "host[ip]=10.0.2.26" -d
>>> "host[architecture_id]=2" -d "host[operatingsystem_id]=2" -d
>>> "host[ptable_id]=10" -d "host[build]=0" -d "host[subnet_id]=255.255.255.
>>> **0" -d "host[puppetmaster_name=**localhost"
>>>
>> subnet is an id, not a value,
>> also I'm not sure exactly when we changed it ( i think after 0.5.x), but
>> you should not use puppetmaster_name, rather puppetmaster_id or similar).
>>
>> check your logs when creating a host via the ui, you could see the exact
>> names.
>>
>> also, its recommended to update to 1.0 :slight_smile:
>>
>> Ohad
>>
>>> http://localhost:8080/hosts
>>>
>>> Am I doing something wrong or has the example changed?
>>>
>>> Cheers
>>>
>>> Action Jack
>>>
>>> Hi Ohad,
>>
>
> I've updated to 1.0 and it does tell you what is missing from the input so
> now I put in:
>
> curl -u admin:password -H "Accept:application/json" -d
> "host[name]=test09.uncommonsense.local" -d "host[environment_id]=3" -d
> "host[mac]=46:25:a5:51:b5:db" -d "host[ip]=10.0.2.27" -d
> "host[architecture_id]=2" -d "host[operatingsystem_id]=2" -d
> "host[ptable_id]=10" -d "host[puppet_proxy_id]=1" http://localhost:8080
> /hosts
>
> Unfortunately I get the following error:
>
> Started POST "/hosts" for 10.0.2.2 at Sat Jun 23 09:43:37 +0000 2012
> Processing by HostsController#create as JSON
> Parameters: {"host"=>{"architecture_id"=>"2", "puppet_proxy_id"=>"1",
> "mac"=>"46:25:a5:51:b5:db", "ip"=>"10.0.2.27",
> "name"=>"test09.uncommonsense.local", "operatingsystem_id"=>"2",
> "ptable_id"=>"10"}}
> Authorized user admin(Admin User)
> Failed to save: Environment can't be blank
> Completed 422 Unprocessable Entity in 145ms (Views: 0.3ms | ActiveRecord:
> 3.6ms)
>
>
> Started POST "/hosts" for 10.0.2.2 at Sat Jun 23 09:43:52 +0000 2012
> Processing by HostsController#create as JSON
> Parameters: {"host"=>{"architecture_id"=>"2", "puppet_proxy_id"=>"1",
> "mac"=>"46:25:a5:51:b5:db", "ip"=>"10.0.2.27", "environment_id"=>"3",
> "name"=>"test09.uncommonsense.local", "operatingsystem_id"=>"2",
> "ptable_id"=>"10"}}
> Authorized user admin(Admin User)
> Add DNS A record for test09.uncommonsense.local/10.0.2.27
> Operation FAILED: undefined method `associated_type' for
> #<Audited::Adapters::ActiveRecord::Audit:0x7f846e475b90>
>

sadly this seems like the rake db:migrate didn't happen via rpm update,
please run it manually and try again :slight_smile:

Ohad

··· On Tue, Jun 26, 2012 at 6:47 PM, Action Jack wrote: > On Tuesday, 26 June 2012 15:30:39 UTC+1, ohad wrote: >> On Tue, Jun 26, 2012 at 4:33 PM, Action Jack wrote:

Completed 500 Internal Server Error in 305ms

ArgumentError (There was no default layout for HostsController in
[#<ActionView::FileSystemResolver:0x7f846ffa2b20 @caching=true,
@path="/usr/share/foreman/app/views",
@cached={#<ActionView::LookupContext::DetailsKey:0x7f846e05bf00
@hash=70103379140480>=>{“audits”=>{“index”=>{false=>[app/views/audits/index.html.erb]},
“row”=>{true=>[app/views/audits/_row.erb]}},
“layouts”=>{“audits”=>{false=>[]}, “statistics”=>{false=>[]},
“users”=>{false=>[]}, “dashboard”=>{false=>[]},
“application”=>{false=>[app/views/layouts/application.html.erb]},
“hosts”=>{false=>[]}},
“statistics”=>{“index”=>{false=>[app/views/statistics/index.html.erb]}},
“common”=>{“searchbar”=>{true=>[app/views/common/_searchbar.erb]}},
“bookmarks”=>{“list”=>{true=>[app/views/bookmarks/_list.html.erb]}},
“users”=>{“login”=>{false=>[app/views/users/login.html.erb]}},
“dashboard”=>{“index”=>{false=>[app/views/dashboard/index.html.erb]}},
“hosts”=>{“index”=>{false=>[app/views/hosts/index.html.erb]},
“list”=>{true=>[app/views/hosts/_list.html.erb]}},
“home”=>{“topbar”=>{true=>[app/views/home/_topbar.rhtml]},
“user_dropdown”=>{true=>[app/views/home/_user_dropdown.rhtml]},
“settings”=>{true=>[app/views/home/_settings.html.erb]}}},
#<ActionView::LookupContext::DetailsKey:0x7f846e4d9668
@hash=70103381494580>=>{“layouts/action_controller”=>{“base”=>{false=>[]}},
“layouts”=>{“application”=>{false=>[]}, “hosts”=>{false=>[]}}},
#<ActionView::LookupContext::DetailsKey:0x7f846e07d088
@hash=70103379208260>=>{“layouts”=>{“fact_values”=>{false=>[]},
“application”=>{false=>[app/views/layouts/application.html.erb]},
“reports”=>{false=>[]}},
“fact_values”=>{“welcome”=>{false=>[app/views/fact_values/welcome.html.erb]}},
“reports”=>{“welcome”=>{false=>[app/views/reports/welcome.html.erb]}}}}>]):
app/controllers/application_controller.rb:278:in `generic_exception’

BTW: I’m using a Foreman DNS smart proxy

Cheers

-Martin


You received this message because you are subscribed to the Google Groups
"Foreman users" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/foreman-users/-/3W4dVb9UZEQJ.

To post to this group, send email to foreman-users@googlegroups.com.
To unsubscribe from this group, send email to
foreman-users+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/foreman-users?hl=en.

Yes that has fixed it, Thanks Ohad!

-Martin

··· On Tuesday, 26 June 2012 18:14:23 UTC+1, ohad wrote: > > > > On Tue, Jun 26, 2012 at 6:47 PM, Action Jack <> wrote: > >> >> >> On Tuesday, 26 June 2012 15:30:39 UTC+1, ohad wrote: >>> >>> >>> >>> On Tue, Jun 26, 2012 at 4:33 PM, Action Jack wrote: >>> >>> Hi all, >>>> >>>> I'm using the following version of foreman: >>>> foreman-console-0.5.1-1.el6.**noarch >>>> foreman-proxy-0.5.1-1.el6.**noarch >>>> foreman-sqlite-0.5.1-1.el6.**noarch >>>> foreman-0.5.1-1.el6.noarch >>>> >>>> I'm trying to figure out what is the minimum information that I need to >>>> put into a curl post to add a host, I've tried the curl example but I get >>>> an error. I've also tried the following but I still get an error: >>>> >>>> curl -u admin:password -H "Accept:application/json" -d >>>> "host[name]=test08.**uncommonsense.local" -d "host[environment_id]=3" >>>> -d "host[mac]=00:00:00:00:01" -d "host[ip]=10.0.2.26" -d >>>> "host[architecture_id]=2" -d "host[operatingsystem_id]=2" -d >>>> "host[ptable_id]=10" -d "host[build]=0" -d "host[subnet_id]=255.255.255. >>>> **0" -d "host[puppetmaster_name=**localhost" >>>> >>> subnet is an id, not a value, >>> also I'm not sure exactly when we changed it ( i think after 0.5.x), but >>> you should not use puppetmaster_name, rather puppetmaster_id or similar). >>> >>> check your logs when creating a host via the ui, you could see the exact >>> names. >>> >>> also, its recommended to update to 1.0 :) >>> >>> Ohad >>> >>>> http://localhost:8080/hosts >>>> >>>> Am I doing something wrong or has the example changed? >>>> >>>> Cheers >>>> >>>> Action Jack >>>> >>>> Hi Ohad, >>> >> >> I've updated to 1.0 and it does tell you what is missing from the input >> so now I put in: >> >> curl -u admin:password -H "Accept:application/json" -d >> "host[name]=test09.uncommonsense.local" -d "host[environment_id]=3" -d >> "host[mac]=46:25:a5:51:b5:db" -d "host[ip]=10.0.2.27" -d >> "host[architecture_id]=2" -d "host[operatingsystem_id]=2" -d >> "host[ptable_id]=10" -d "host[puppet_proxy_id]=1" http://localhost:8080 >> /hosts >> >> Unfortunately I get the following error: >> >> Started POST "/hosts" for 10.0.2.2 at Sat Jun 23 09:43:37 +0000 2012 >> Processing by HostsController#create as JSON >> Parameters: {"host"=>{"architecture_id"=>"2", "puppet_proxy_id"=>"1", >> "mac"=>"46:25:a5:51:b5:db", "ip"=>"10.0.2.27", >> "name"=>"test09.uncommonsense.local", "operatingsystem_id"=>"2", >> "ptable_id"=>"10"}} >> Authorized user admin(Admin User) >> Failed to save: Environment can't be blank >> Completed 422 Unprocessable Entity in 145ms (Views: 0.3ms | ActiveRecord: >> 3.6ms) >> >> >> Started POST "/hosts" for 10.0.2.2 at Sat Jun 23 09:43:52 +0000 2012 >> Processing by HostsController#create as JSON >> Parameters: {"host"=>{"architecture_id"=>"2", "puppet_proxy_id"=>"1", >> "mac"=>"46:25:a5:51:b5:db", "ip"=>"10.0.2.27", "environment_id"=>"3", >> "name"=>"test09.uncommonsense.local", "operatingsystem_id"=>"2", >> "ptable_id"=>"10"}} >> Authorized user admin(Admin User) >> Add DNS A record for test09.uncommonsense.local/10.0.2.27 >> Operation FAILED: undefined method `associated_type' for >> # >> > > sadly this seems like the rake db:migrate didn't happen via rpm update, > please run it manually and try again :) > > Ohad > >> Completed 500 Internal Server Error in 305ms >> >> ArgumentError (There was no default layout for HostsController in >> [#> @path="/usr/share/foreman/app/views", >> @cached={#> @hash=70103379140480>=>{"audits"=>{"index"=>{false=>[app/views/audits/index.html.erb]}, >> "row"=>{true=>[app/views/audits/_row.erb]}}, >> "layouts"=>{"audits"=>{false=>[]}, "statistics"=>{false=>[]}, >> "users"=>{false=>[]}, "dashboard"=>{false=>[]}, >> "application"=>{false=>[app/views/layouts/application.html.erb]}, >> "hosts"=>{false=>[]}}, >> "statistics"=>{"index"=>{false=>[app/views/statistics/index.html.erb]}}, >> "common"=>{"searchbar"=>{true=>[app/views/common/_searchbar.erb]}}, >> "bookmarks"=>{"list"=>{true=>[app/views/bookmarks/_list.html.erb]}}, >> "users"=>{"login"=>{false=>[app/views/users/login.html.erb]}}, >> "dashboard"=>{"index"=>{false=>[app/views/dashboard/index.html.erb]}}, >> "hosts"=>{"index"=>{false=>[app/views/hosts/index.html.erb]}, >> "list"=>{true=>[app/views/hosts/_list.html.erb]}}, >> "home"=>{"topbar"=>{true=>[app/views/home/_topbar.rhtml]}, >> "user_dropdown"=>{true=>[app/views/home/_user_dropdown.rhtml]}, >> "settings"=>{true=>[app/views/home/_settings.html.erb]}}}, >> #> @hash=70103381494580>=>{"layouts/action_controller"=>{"base"=>{false=>[]}}, >> "layouts"=>{"application"=>{false=>[]}, "hosts"=>{false=>[]}}}, >> #> @hash=70103379208260>=>{"layouts"=>{"fact_values"=>{false=>[]}, >> "application"=>{false=>[app/views/layouts/application.html.erb]}, >> "reports"=>{false=>[]}}, >> "fact_values"=>{"welcome"=>{false=>[app/views/fact_values/welcome.html.erb]}}, >> "reports"=>{"welcome"=>{false=>[app/views/reports/welcome.html.erb]}}}}>]): >> app/controllers/application_controller.rb:278:in `generic_exception' >> >> BTW: I'm using a Foreman DNS smart proxy >> >> Cheers >> >> -Martin >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Foreman users" group. >> To view this discussion on the web visit >> https://groups.google.com/d/msg/foreman-users/-/3W4dVb9UZEQJ. >> >> To post to this group, send email to foreman-users@googlegroups.com. >> To unsubscribe from this group, send email to >> foreman-users+unsubscribe@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/foreman-users?hl=en. >> >