Bulk host creation: Use API or Hammer, are multiple nics fully supported? - Foreman 1.7

Hey Guys

I'm looking into automating a lot of the setup of foreman/satellite using
the HAMMER CLI and API. The main thing i am interested in is using these
tools to bulk load approx 200 hosts to be built.

If i look at the hammer cli, i am not sure how to create muliple NICs as
the OPTIONS for host create only seem to cater for 1 IP/MAC combo - have i
mis-understood?

With the API - this looks more promising as
Foreman mentions "interfaces": [], but it does
not mention this in the parameters section.

As a l test, i was trying to create a very basic host with the below simple
curl statemnet but getting an internal 500. Any ideas?
curl -v -k -u admin:changeme -H "Accept: version=2, application/json" -H
"Content-Type: application/json" -X POST -d '{"name":"newhost1",
"hostgroup_id":4, "mac":"A0:48:1C:90:3E:5E", "organization_id":1,
"location_id":1}' https://server.fqdn/api/v2/hosts

My question is, do either of these in 1.7 fully support the creation of a
host with multiple interfaces? Also, if anyone has any experience of doing
this, it would be good to hear from you.

The overall plan would be to use Python to create and fire off the request
to the foreman API.

many thanks for any input

thanks for the tip Ohad, i'll check that out!

-Should i not bother with hammer as i am not certain the functionality is
there?
-Is the functionality there for the API?
-Does my test curl look correct?

Cheers

> Hey Guys
>
> I'm looking into automating a lot of the setup of foreman/satellite using
> the HAMMER CLI and API. The main thing i am interested in is using these
> tools to bulk load approx 200 hosts to be built.
>
> If i look at the hammer cli, i am not sure how to create muliple NICs as
> the OPTIONS for host create only seem to cater for 1 IP/MAC combo - have i
> mis-understood?
>
> With the API - this looks more promising as
> Foreman mentions "interfaces": [], but it does
> not mention this in the parameters section.
>
> As a l test, i was trying to create a very basic host with the below
> simple curl statemnet but getting an internal 500. Any ideas?
> curl -v -k -u admin:changeme -H "Accept: version=2, application/json"
> -H "Content-Type: application/json" -X POST -d '{"name":"newhost1",
> "hostgroup_id":4, "mac":"A0:48:1C:90:3E:5E", "organization_id":1,
> "location_id":1}' https://server.fqdn/api/v2/hosts
>
> My question is, do either of these in 1.7 fully support the creation of a
> host with multiple interfaces? Also, if anyone has any experience of doing
> this, it would be good to hear from you.
>
> The overall plan would be to use Python to create and fire off the request
> to the foreman API.
>

if you are using python, you could consider using the native python
bindings for foreman [1]

Ohad

[1] https://pypi.python.org/pypi/python-foreman

··· On Tue, Aug 4, 2015 at 10:24 AM, Matzuba wrote:

many thanks for any input


You received this message because you are subscribed to the Google Groups
"Foreman users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to foreman-users+unsubscribe@googlegroups.com.
To post to this group, send email to foreman-users@googlegroups.com.
Visit this group at http://groups.google.com/group/foreman-users.
For more options, visit https://groups.google.com/d/optout.

cheers for that Tomas

it looks like interface is supported but i am seeing strange results, this
is my .json file i am POSTing to the API. The host is create but it seems
to "steal" the NIC from another host. What is the NIC id and how to
reference? Also, i include name but this does not get specified for the
2nd NIC. Have i got the syntax right for interface?

{
"host": {
"name": "testhost11",
"environment_id": "1",
"domain_id": "1",
"ip": "10.0.0.20",
"mac": "52:53:00:1e:85:93",
"ptable_id": "7",
"medium_id": "7",
"architecture_id": "1",
"operatingsystem_id": "1",
"root_pass": "xybxa6JUkz63w",
"location_id": "1",
"organization_id": "1",
"interfaces": [
{
"id": "1",
"name": "eth2",
"type": "interface",
"ip": "10.0.0.1",
"mac": "AA:AA:AA:AA:AA:AA"
}
]
}
}

> thanks for the tip Ohad, i'll check that out!
>
> -Should i not bother with hammer as i am not certain the functionality
> is there?
> -Is the functionality there for the API?
> -Does my test curl look correct?
>
> Cheers
>

Multiple nics are supported in 1.7's API but not in hammer if I recall
correctly. Check the resource "interfaces" in the API docs.

BTW the online documentation at theforeman.org is probably generated for
some other version of the Foreman. It doesn't mention the version
anywhere. I'm fixing it in
https://github.com/theforeman/theforeman.org/pull/406

Tomas

··· On 08/04/2015 02:59 PM, Matzuba wrote:


You received this message because you are subscribed to the Google
Groups “Foreman users” group.
To unsubscribe from this group and stop receiving emails from it, send
an email to foreman-users+unsubscribe@googlegroups.com
mailto:foreman-users+unsubscribe@googlegroups.com.
To post to this group, send email to foreman-users@googlegroups.com
mailto:foreman-users@googlegroups.com.
Visit this group at http://groups.google.com/group/foreman-users.
For more options, visit https://groups.google.com/d/optout.

Interface ID is an automatically incremented integer value. Skip it for
new interfaces. Passing some value may lead to "stealing" interfaces as
you described it.

Interface's name is a DNS name. You probably wanted to use "identifier":
"eth2".

I also think that you should use "interfaces_attributes" instead of
"interfaces".

Regards
Tomas

··· On 08/05/2015 01:54 PM, Matzuba wrote: > cheers for that Tomas > > it looks like interface is supported but i am seeing strange results, > this is my .json file i am POSTing to the API. The host is create but > it seems to "steal" the NIC from another host. What is the NIC id and > how to reference? Also, i include name but this does not get specified > for the 2nd NIC. Have i got the syntax right for interface? > > { > "host": { > "name": "testhost11", > "environment_id": "1", > "domain_id": "1", > "ip": "10.0.0.20", > "mac": "52:53:00:1e:85:93", > "ptable_id": "7", > "medium_id": "7", > "architecture_id": "1", > "operatingsystem_id": "1", > "root_pass": "xybxa6JUkz63w", > "location_id": "1", > "organization_id": "1", > "interfaces": [ > { > "id": "1", > "name": "eth2", > "type": "interface", > "ip": "10.0.0.1", > "mac": "AA:AA:AA:AA:AA:AA" > } > ] > } > } > >

Thanks again for the pointed. I was looking at the Foreman API v2 1.7 as
Katello.org seemed to be down for a few days.

So i am trying this now with the host[interface_attributes] and it is still
not right.

This is the code request:

{
"host": {
"name": "testhost1",
"environment_id": "1",
"domain_id": "1",
"ip": "10.0.0.20",
"mac": "52:53:00:1e:85:93",
"ptable_id": "7",
"medium_id": "7",
"architecture_id": "1",
"operatingsystem_id": "1",
"root_pass": "xybxa6JUkz63w",
"location_id": "1",
"organization_id": "1",
"interfaces_attributes": [
{
"identifier": "eth2",
"ip": "10.0.0.1",
"mac": "AA:AA:AA:AA:AA:AA",
"type": "interface",
"managed": true
}
]
}
}

  1. If try to use type: interface, the error complains - "error":
    {"message":"wrong constant name interface"}
  2. The API does not mention if this is a string or not, if i take away the
    quote, there appears to be an issue with the JSON code.
  3. If i remove "type" as it is option, the request works but teh host does
    not not appear to get created properly as the IP is null, what is type
    "base"?
    The response is:
    interfaces":[{"id":11,"name":null,"ip":null,"mac":"aa:aa:aa:aa:aa:aa","type":"base"}],
    When i try to look at the host in the GUI and select EDIT, I get a
    something went wrong error page with the error relating to NICs

15-08-06 11:26:25 [I] Rendered hosts/_unattended.html.erb (76.6ms)
2015-08-06 11:26:25 [I] Rendered hosts/_form.html.erb (419.6ms)
2015-08-06 11:26:25 [I] Rendered hosts/edit.html.erb within
layouts/application (423.1ms)
2015-08-06 11:26:25 [I] Completed 500 Internal Server Error in 466ms
2015-08-06 11:26:25 [F]
ActionView::MissingTemplate (Missing partial nic/bases/base with
{:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :haml,
:rabl]}. Searched in:

  • "/usr/share/foreman/app/views"
··· * "/opt/rh/ruby193/root/usr/share/gems/gems/foreman_discovery-2.0.0.15/app/views" * "/opt/rh/ruby193/root/usr/share/gems/gems/redhat_access-0.2.0/app/views" * "/opt/rh/ruby193/root/usr/share/gems/gems/katello-2.2.0.51/app/views" * "/opt/rh/ruby193/root/usr/share/gems/gems/foreman_docker-1.2.0.14/app/views" * "/opt/rh/ruby193/root/usr/share/gems/gems/foreman_bootdisk-4.0.2.13/app/views" * "/opt/rh/ruby193/root/usr/share/gems/gems/bastion-0.3.0.10/app/views" * "/opt/rh/ruby193/root/usr/share/gems/gems/foreman-tasks-0.6.12.8/app/views" * "/opt/rh/ruby193/root/usr/share/gems/gems/apipie-rails-0.2.5/app/views" ): app/views/hosts/_interfaces.html.erb:60:in `block in _app_views_hosts__interfaces_html_erb___1478265227518780051_82507020' app/views/hosts/_interfaces.html.erb:59:in `_app_views_hosts__interfaces_html_erb___1478265227518780051_82507020' app/views/hosts/_unattended.html.erb:31:in `block in _app_views_hosts__unattended_html_erb___1148042227097334928_118222560' app/views/hosts/_unattended.html.erb:15:in `_app_views_hosts__unattended_html_erb___1148042227097334928_118222560' app/views/hosts/_form.html.erb:122:in `block (2 levels) in _app_views_hosts__form_html_erb___4520343611190404768_81386340' app/helpers/layout_helper.rb:268:in `form_for' app/views/hosts/_form.html.erb:8:in `block in _app_views_hosts__form_html_erb___4520343611190404768_81386340' app/models/taxonomy.rb:61:in `block (2 levels) in as_taxonomy' app/models/concerns/foreman/thread_session.rb:148:in `as_location' app/models/taxonomy.rb:60:in `block in as_taxonomy' app/models/concerns/foreman/thread_session.rb:113:in `as_org' app/models/taxonomy.rb:59:in `as_taxonomy' app/views/hosts/_form.html.erb:6:in `_app_views_hosts__form_html_erb___4520343611190404768_81386340' app/views/hosts/edit.html.erb:9:in `_app_views_hosts_edit_html_erb___417381282997809442_116896780' app/models/concerns/foreman/thread_session.rb:33:in `clear_thread' lib/middleware/catch_json_parse_errors.rb:9:in `call'

~

You might want to create what you want in the GUI as you tail -f the log.
You can often get good insights into how Foreman handles it without delving
deep into the code.