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.
-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?
> 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]
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?
> 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.
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"
> }
> ]
> }
> }
>
>
If try to use type: interface, the error complains - "error":
{"message":"wrong constant name interface"}
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.
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
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.