Adding subnet details to Interface hash sent via orchestration 'create' event

I'm using foreman hooks to update an external IPAM system. The interface
hash that is sent does not include the subnet name or id that the interface
has been designated in foreman.
There is subnet information sent through in the host hash but only one
subnet per host is sent - not useful is there are multiple network
interfaces on different subnets.

I've tired making an API call in the create hook but the data isn't
committed to the database at this stage so can't retrieve the subnet
information for each network interface.

This is what currently gets sent through with the create hook for the
interface hash:

interfaces":[{"id":null,"name":"interface1name","ip":null,"mac":"00:11:22:33:44:55","identifier":"","primary":true,"provision":true,"type":"interface"},{"id":null,"name":"interface2name","ip":null,"mac":"00:11:22:33:44:56","identifier":"","primary":false,"provision":false,"type":"interface"}]

The ideal data that I need would look like:

interfaces":[{"id":null,"name":"interface1name","ip":null,"mac":"00:11:22:33:44:55","identifier":"","primary":true,"provision":true,"type":"interface","subnet_id":2,"subnet_name":"Frontend","sp_subnet_id":null},{"id":null,"name":"interface2name","ip":null,"mac":"00:11:22:33:44:56","identifier":"","primary":false,"provision":false,"type":"interface","subnet_id":3,"subnet_name":"Backend","sp_subnet_id":null}]

Has anyone got any idea what code I need to modify (or if it's possible) to
add the subnet name and subnet id through with the create hook event data
in the interfaces hash?

It's from the API responses defined in
app/views/api/v2/hosts/show.json.rabl, which uses the "base" interface
view rather than the "main" one which usually includes the subnet ID.

··· On 21/03/16 20:57, Francois Herbert wrote: > I'm using foreman hooks to update an external IPAM system. The interface > hash that is sent does not include the subnet name or id that the > interface has been designated in foreman. > There is subnet information sent through in the host hash but only one > subnet per host is sent - not useful is there are multiple network > interfaces on different subnets. > > I've tired making an API call in the create hook but the data isn't > committed to the database at this stage so can't retrieve the subnet > information for each network interface. > > This is what currently gets sent through with the create hook for the > interface hash: > > interfaces":[{"id":null,"name":"interface1name","ip":null,"mac":"00:11:22:33:44:55","identifier":"","primary":true,"provision":true,"type":"interface"},{"id":null,"name":"interface2name","ip":null,"mac":"00:11:22:33:44:56","identifier":"","primary":false,"provision":false,"type":"interface"}] > > > The ideal data that I need would look like: > > interfaces":[{"id":null,"name":"interface1name","ip":null,"mac":"00:11:22:33:44:55","identifier":"","primary":true,"provision":true,"type":"interface","subnet_id":2,"subnet_name":"Frontend","sp_subnet_id":null},{"id":null,"name":"interface2name","ip":null,"mac":"00:11:22:33:44:56","identifier":"","primary":false,"provision":false,"type":"interface","subnet_id":3,"subnet_name":"Backend","sp_subnet_id":null}] > > > Has anyone got any idea what code I need to modify (or if it's possible) > to add the subnet name and subnet id through with the create hook event > data in the interfaces hash?


Dominic Cleal
dominic@cleal.org

Has this behaviour changed in version 1.11.4?

in app/views/api/v2/hosts.show.json.rabl I have:

extends "api/v2/interfaces/main”

but I don’t get the subnet_name or subnet_id passed to the hook on the
create event. I've checked main.json.rabl and it is adding the subnet_id
and subnet_name attributes.

What I do get is:

"interfaces":[{"id":null,"name":"test52.domain.com","ip":null,"mac":"00:50:56:9a:43:f7","identifier":"","primary":true,"provision":true,"type":"interface"}]

Thanks

Francois

··· On Tuesday, March 22, 2016 at 9:15:28 PM UTC+13, Dominic Cleal wrote: > > On 21/03/16 20:57, Francois Herbert wrote: > > I'm using foreman hooks to update an external IPAM system. The interface > > hash that is sent does not include the subnet name or id that the > > interface has been designated in foreman. > > There is subnet information sent through in the host hash but only one > > subnet per host is sent - not useful is there are multiple network > > interfaces on different subnets. > > > > I've tired making an API call in the create hook but the data isn't > > committed to the database at this stage so can't retrieve the subnet > > information for each network interface. > > > > This is what currently gets sent through with the create hook for the > > interface hash: > > > > > interfaces":[{"id":null,"name":"interface1name","ip":null,"mac":"00:11:22:33:44:55","identifier":"","primary":true,"provision":true,"type":"interface"},{"id":null,"name":"interface2name","ip":null,"mac":"00:11:22:33:44:56","identifier":"","primary":false,"provision":false,"type":"interface"}] > > > > > > > The ideal data that I need would look like: > > > > > interfaces":[{"id":null,"name":"interface1name","ip":null,"mac":"00:11:22:33:44:55","identifier":"","primary":true,"provision":true,"type":"interface","subnet_id":2,"subnet_name":"Frontend","sp_subnet_id":null},{"id":null,"name":"interface2name","ip":null,"mac":"00:11:22:33:44:56","identifier":"","primary":false,"provision":false,"type":"interface","subnet_id":3,"subnet_name":"Backend","sp_subnet_id":null}] > > > > > > > Has anyone got any idea what code I need to modify (or if it's possible) > > to add the subnet name and subnet id through with the create hook event > > data in the interfaces hash? > > It's from the API responses defined in > app/views/api/v2/hosts/show.json.rabl, which uses the "base" interface > view rather than the "main" one which usually includes the subnet ID. > > -- > Dominic Cleal > dom...@cleal.org >

OK, Just in case anyone else needs to know, I figured this out, in the same
file (app/views/api-v2/hosts/show.json.rabl) I needed to apply the
following patch:

14c14

< extends "api/v2/interfaces/main"

··· ---

extends “api/v2/interfaces/base”

This makes the following change:

child :interfaces => :interfaces do

extends “api/v2/interfaces/main”

end

On Thursday, August 11, 2016 at 11:27:52 AM UTC+12, Francois Herbert wrote:

Has this behaviour changed in version 1.11.4?

in app/views/api/v2/hosts.show.json.rabl I have:

extends "api/v2/interfaces/main”

but I don’t get the subnet_name or subnet_id passed to the hook on the
create event. I’ve checked main.json.rabl and it is adding the subnet_id
and subnet_name attributes.

What I do get is:

“interfaces”:[{“id”:null,“name”:“test52.domain.com
”,“ip”:null,“mac”:“00:50:56:9a:43:f7”,“identifier”:"",“primary”:true,“provision”:true,“type”:“interface”}]

Thanks

Francois

On Tuesday, March 22, 2016 at 9:15:28 PM UTC+13, Dominic Cleal wrote:

On 21/03/16 20:57, Francois Herbert wrote:

I’m using foreman hooks to update an external IPAM system. The
interface
hash that is sent does not include the subnet name or id that the
interface has been designated in foreman.
There is subnet information sent through in the host hash but only one
subnet per host is sent - not useful is there are multiple network
interfaces on different subnets.

I’ve tired making an API call in the create hook but the data isn’t
committed to the database at this stage so can’t retrieve the subnet
information for each network interface.

This is what currently gets sent through with the create hook for the
interface hash:

interfaces":[{“id”:null,“name”:“interface1name”,“ip”:null,“mac”:“00:11:22:33:44:55”,“identifier”:"",“primary”:true,“provision”:true,“type”:“interface”},{“id”:null,“name”:“interface2name”,“ip”:null,“mac”:“00:11:22:33:44:56”,“identifier”:"",“primary”:false,“provision”:false,“type”:“interface”}]

The ideal data that I need would look like:

interfaces":[{“id”:null,“name”:“interface1name”,“ip”:null,“mac”:“00:11:22:33:44:55”,“identifier”:"",“primary”:true,“provision”:true,“type”:“interface”,“subnet_id”:2,“subnet_name”:“Frontend”,“sp_subnet_id”:null},{“id”:null,“name”:“interface2name”,“ip”:null,“mac”:“00:11:22:33:44:56”,“identifier”:"",“primary”:false,“provision”:false,“type”:“interface”,“subnet_id”:3,“subnet_name”:“Backend”,“sp_subnet_id”:null}]

Has anyone got any idea what code I need to modify (or if it’s
possible)
to add the subnet name and subnet id through with the create hook event
data in the interfaces hash?

It’s from the API responses defined in
app/views/api/v2/hosts/show.json.rabl, which uses the “base” interface
view rather than the “main” one which usually includes the subnet ID.


Dominic Cleal
dom...@cleal.org

Hello

Sorry I'm not aware of that change. Since this sounds like something useful
for everybody and you already got a patch, could you please create a redmine
issue and send a pull request so we incorporate it? You can find information
about the process at [1]. One potential benefit for you - you wouldn't lose the
custom patch after next Foreman upgrade :slight_smile:

[1] Foreman :: Contribute

··· -- Marek

On Tuesday 16 of August 2016 17:20:09 Francois Herbert wrote:

OK, Just in case anyone else needs to know, I figured this out, in the same
file (app/views/api-v2/hosts/show.json.rabl) I needed to apply the
following patch:

14c14

< extends “api/v2/interfaces/main”


extends “api/v2/interfaces/base”

This makes the following change:

child :interfaces => :interfaces do

extends “api/v2/interfaces/main”

end

On Thursday, August 11, 2016 at 11:27:52 AM UTC+12, Francois Herbert wrote:

Has this behaviour changed in version 1.11.4?

in app/views/api/v2/hosts.show.json.rabl I have:

extends "api/v2/interfaces/main”

but I don’t get the subnet_name or subnet_id passed to the hook on the
create event. I’ve checked main.json.rabl and it is adding the subnet_id
and subnet_name attributes.

What I do get is:

“interfaces”:[{“id”:null,“name”:“test52.domain.com
”,“ip”:null,“mac”:“00:50:56:9a:43:f7”,“identifier”:"",“primary”:true,“prov
ision”:true,“type”:“interface”}]

Thanks

Francois

On Tuesday, March 22, 2016 at 9:15:28 PM UTC+13, Dominic Cleal wrote:

On 21/03/16 20:57, Francois Herbert wrote:

I’m using foreman hooks to update an external IPAM system. The

interface

hash that is sent does not include the subnet name or id that the
interface has been designated in foreman.
There is subnet information sent through in the host hash but only one
subnet per host is sent - not useful is there are multiple network
interfaces on different subnets.

I’ve tired making an API call in the create hook but the data isn’t
committed to the database at this stage so can’t retrieve the subnet
information for each network interface.

This is what currently gets sent through with the create hook for the

interface hash:
interfaces":[{“id”:null,“name”:“interface1name”,“ip”:null,“mac”:“00:11:22
:33:44:55”,“identifier”:"",“primary”:true,“provision”:true,“type”:“interf
ace”},{“id”:null,“name”:“interface2name”,“ip”:null,“mac”:“00:11:22:33:44:
56”,“identifier”:"",“primary”:false,“provision”:false,“type”:“interface”}
]>>
The ideal data that I need would look like:
interfaces":[{“id”:null,“name”:“interface1name”,“ip”:null,“mac”:“00:11:22
:33:44:55”,“identifier”:"",“primary”:true,“provision”:true,“type”:“interf
ace”,“subnet_id”:2,“subnet_name”:“Frontend”,“sp_subnet_id”:null},{“id”:nu
ll,“name”:“interface2name”,“ip”:null,“mac”:“00:11:22:33:44:56”,“identifie
r”:"",“primary”:false,“provision”:false,“type”:“interface”,“subnet_id”:3,
“subnet_name”:“Backend”,“sp_subnet_id”:null}]>>
Has anyone got any idea what code I need to modify (or if it’s

possible)

to add the subnet name and subnet id through with the create hook event
data in the interfaces hash?

It’s from the API responses defined in
app/views/api/v2/hosts/show.json.rabl, which uses the “base” interface
view rather than the “main” one which usually includes the subnet ID.