Foreman API: Associating operating system with template

Hi all,

I'm using Foreman API to script the automatic installation of it. I can't
find documentation to associate an operating system with the 3 types of
provisioning templates needed. Has anybody pointers or know of the correct
request I should send?

Thanks, Oleksii

Hi Oleksii,

For API v2 we are working on nested routes for all routes, but we aren't there yet. In your case, the goal is to see the provisioning templates for any OS by going to
api/operatingsystems/:id/config_templates

Since you can't do this at this stage, try to update (PUT) to api/operatingsystems/:id and in the -d data hash pass an array of ids -d {'config_template_ids': [1,2,3,4,5]}

Hope this helps,

Joseph

··· ----- Original Message ----- > From: "Serhiienko Oleksii" > To: foreman-users@googlegroups.com > Sent: Monday, November 11, 2013 1:25:52 PM > Subject: [foreman-users] Foreman API: Associating operating system with template > > Hi all, > > I'm using Foreman API to script the automatic installation of it. I can't > find documentation to associate an operating system with the 3 types of > provisioning templates needed. Has anybody pointers or know of the correct > request I should send? > > Thanks, Oleksii > > -- > 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/groups/opt_out. >

Yes, that what I'm doing:

os = {"operatingsystem": {'name': os_name, 'major': os_major, 'minor':
os_minor, 'family': os_family,

  •                      'release_name': os_release, 'architecture_ids': 
    

[id_arch], 'ptable_ids': [2],*

  •                      'medium_ids': [id_media],*
    
  •                      'config_template_ids': [2, 6, 7]}}*
    

r = requests.post(get_address('operatingsystems'),data=json.dumps(os),
headers=headers)

But in this case I'm just associate operating system with template. I need
associate template with operating system too. In 'Operating Systems' ->
'Templates' three empty fields: 'provision', 'finish', 'PXELinux' and I'm
can't choose templates.

··· On Monday, 11 November 2013 12:55:22 UTC+1, Joseph Magen wrote: > > Hi Oleksii, > > For API v2 we are working on nested routes for all routes, but we aren't > there yet. In your case, the goal is to see the provisioning templates for > any OS by going to > api/operatingsystems/:id/config_templates > > Since you can't do this at this stage, try to update (PUT) to > api/operatingsystems/:id and in the -d data hash pass an array of ids -d > {'config_template_ids': [1,2,3,4,5]} > > Hope this helps, > > Joseph > > > ----- Original Message ----- > > From: "Serhiienko Oleksii" <aleksey...@gmail.com > > > To: forema...@googlegroups.com > > Sent: Monday, November 11, 2013 1:25:52 PM > > Subject: [foreman-users] Foreman API: Associating operating system with > template > > > > Hi all, > > > > I'm using Foreman API to script the automatic installation of it. I > can't > > find documentation to associate an operating system with the 3 types of > > provisioning templates needed. Has anybody pointers or know of the > correct > > request I should send? > > > > Thanks, Oleksii > > > > -- > > 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-user...@googlegroups.com . > > To post to this group, send email to forema...@googlegroups.com. > > > Visit this group at http://groups.google.com/group/foreman-users. > > For more options, visit https://groups.google.com/groups/opt_out. > > >

I found solution:
If you want associate template once:
(PUT) to api/operatingsystems/:id and in the -d data hash pass os={'operatingsystem':
{'os_default_templates_attributes': {int(line_number): {'template_kind_id':
int(id) , 'config_template_id': int(id)}}}}

os={'operatingsystem': {'os_default_templates_attributes': {0:
{'template_kind_id': 2 , 'config_template_id':2 }}}}

Once you have associated the template with the operating system - each
'line' is assigned to id. If you want change it you should do it in other
way:
os={'operatingsystem': {'os_default_templates_attributes':
{int(line_number): {'id': int(id) , 'config_template_id': int(id)}}}}

os={'operatingsystem': {'os_default_templates_attributes': {0: {'id':
392 , 'config_template_id':2 }}}}

··· On Monday, 11 November 2013 13:55:02 UTC+1, Serhiienko Oleksii wrote: > > Yes, that what I'm doing: > > *os = {"operatingsystem": {'name': os_name, 'major': os_major, 'minor': > os_minor, 'family': os_family,* > * 'release_name': os_release, 'architecture_ids': > [id_arch], 'ptable_ids': [2],* > * 'medium_ids': [id_media],* > * 'config_template_ids': [2, 6, 7]}}* > > > *r = requests.post(get_address('operatingsystems'),data=json.dumps(os), > headers=headers)* > But in this case I'm just associate operating system with template. I need > associate template with operating system too. In 'Operating Systems' -> > 'Templates' three empty fields: 'provision', 'finish', 'PXELinux' and I'm > can't choose templates. > > On Monday, 11 November 2013 12:55:22 UTC+1, Joseph Magen wrote: >> >> Hi Oleksii, >> >> For API v2 we are working on nested routes for all routes, but we aren't >> there yet. In your case, the goal is to see the provisioning templates for >> any OS by going to >> api/operatingsystems/:id/config_templates >> >> Since you can't do this at this stage, try to update (PUT) to >> api/operatingsystems/:id and in the -d data hash pass an array of ids -d >> {'config_template_ids': [1,2,3,4,5]} >> >> Hope this helps, >> >> Joseph >> >> >> ----- Original Message ----- >> > From: "Serhiienko Oleksii" >> > To: forema...@googlegroups.com >> > Sent: Monday, November 11, 2013 1:25:52 PM >> > Subject: [foreman-users] Foreman API: Associating operating system with >> template >> > >> > Hi all, >> > >> > I'm using Foreman API to script the automatic installation of it. I >> can't >> > find documentation to associate an operating system with the 3 types of >> > provisioning templates needed. Has anybody pointers or know of the >> correct >> > request I should send? >> > >> > Thanks, Oleksii >> > >> > -- >> > 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-user...@googlegroups.com. >> > To post to this group, send email to forema...@googlegroups.com. >> > Visit this group at http://groups.google.com/group/foreman-users. >> > For more options, visit https://groups.google.com/groups/opt_out. >> > >> >

If you interesting about this script you can find it here:
https://github.com/lexxito/foreman_script

··· On Friday, 15 November 2013 11:12:53 UTC+1, Serhiienko Oleksii wrote: > > I found solution: > If you want associate template once: > (PUT) to api/operatingsystems/:id and in the -d data hash pass *os={'operatingsystem': > {'os_default_templates_attributes': {int(line_number): {'template_kind_id': > int(id) , 'config_template_id': int(id)}}}}* > > *os={'operatingsystem': {'os_default_templates_attributes': {0: > {'template_kind_id': 2 , 'config_template_id':2 }}}}* > Once you have associated the template with the operating system - each > 'line' is assigned to id. If you want change it you should do it in other > way: > *os={'operatingsystem': {'os_default_templates_attributes': > {int(line_number): {'id': int(id) , 'config_template_id': int(id)}}}}* > *os={'operatingsystem': {'os_default_templates_attributes': {0: {'id': > 392 , 'config_template_id':2 }}}}* > > > On Monday, 11 November 2013 13:55:02 UTC+1, Serhiienko Oleksii wrote: >> >> Yes, that what I'm doing: >> >> *os = {"operatingsystem": {'name': os_name, 'major': os_major, 'minor': >> os_minor, 'family': os_family,* >> * 'release_name': os_release, >> 'architecture_ids': [id_arch], 'ptable_ids': [2],* >> * 'medium_ids': [id_media],* >> * 'config_template_ids': [2, 6, 7]}}* >> >> >> *r = requests.post(get_address('operatingsystems'),data=json.dumps(os), >> headers=headers)* >> But in this case I'm just associate operating system with template. I >> need associate template with operating system too. In 'Operating Systems' >> -> 'Templates' three empty fields: 'provision', 'finish', 'PXELinux' and >> I'm can't choose templates. >> >> On Monday, 11 November 2013 12:55:22 UTC+1, Joseph Magen wrote: >>> >>> Hi Oleksii, >>> >>> For API v2 we are working on nested routes for all routes, but we aren't >>> there yet. In your case, the goal is to see the provisioning templates for >>> any OS by going to >>> api/operatingsystems/:id/config_templates >>> >>> Since you can't do this at this stage, try to update (PUT) to >>> api/operatingsystems/:id and in the -d data hash pass an array of ids -d >>> {'config_template_ids': [1,2,3,4,5]} >>> >>> Hope this helps, >>> >>> Joseph >>> >>> >>> ----- Original Message ----- >>> > From: "Serhiienko Oleksii" >>> > To: forema...@googlegroups.com >>> > Sent: Monday, November 11, 2013 1:25:52 PM >>> > Subject: [foreman-users] Foreman API: Associating operating system >>> with template >>> > >>> > Hi all, >>> > >>> > I'm using Foreman API to script the automatic installation of it. I >>> can't >>> > find documentation to associate an operating system with the 3 types >>> of >>> > provisioning templates needed. Has anybody pointers or know of the >>> correct >>> > request I should send? >>> > >>> > Thanks, Oleksii >>> > >>> > -- >>> > 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-user...@googlegroups.com. >>> > To post to this group, send email to forema...@googlegroups.com. >>> > Visit this group at http://groups.google.com/group/foreman-users. >>> > For more options, visit https://groups.google.com/groups/opt_out. >>> > >>> >>