Change Operating System and set to build via API/Python

Hello,

I have a number of hosts I would like to rebuild to a certain OS so I want
to do this client side via the API with a Python script.

I have this function:-

def change_os(buildhost):
msg = "Changing host OS"
log_message(msg, 'INFO')
data = {
"name": buildhost,
"build": "true",
"medium_id": '25',
"operatingsystem_id": '40'
}
oschange = put_json(FMN_API + "hosts/" + buildhost,json.dumps(data))

Where buildhost is passed in as an argument (I have hard-coded medium_id,
and operatingsystem_id for now although they will
be arguments also.

I get a "Record Not Found" from the logs. Where this get function works fine

def host_info(buildhost):
host_info = get_json(FMN_API + "hosts/" + buildhost)
return host_info

Any ideas on where I am going wrong ?

Thanks
Paul

Hello,
check the server logs. It should give you more information about what
resource wasn't found. Most likely one of the associated resources
couldn't be found. This is quite common in create and update actions.

BTW if you're using python check out Nailgun bindings, it could save
you some work:
https://nailgun.readthedocs.io/en/stable/index.html

Tomas

ยทยทยท On Wed, Jan 11, 2017 at 12:13 PM, Paul Seymour wrote: > Hello, > > I have a number of hosts I would like to rebuild to a certain OS so I want > to do this client side via the API with a Python script. > > I have this function:- > > def change_os(buildhost): > msg = "Changing host OS" > log_message(msg, 'INFO') > data = { > "name": buildhost, > "build": "true", > "medium_id": '25', > "operatingsystem_id": '40' > } > oschange = put_json(FMN_API + "hosts/" + buildhost,json.dumps(data)) > > Where buildhost is passed in as an argument (I have hard-coded medium_id, > and operatingsystem_id for now although they will > be arguments also. > > I get a "Record Not Found" from the logs. Where this get function works fine > > def host_info(buildhost): > host_info = get_json(FMN_API + "hosts/" + buildhost) > return host_info > > Any ideas on where I am going wrong ? > > Thanks > Paul > > -- > 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 https://groups.google.com/group/foreman-users. > For more options, visit https://groups.google.com/d/optout.