Project

General

Profile

Actions

Support #2973

closed

REST API for editing a node's classes directly?

Added by Adan Saenz almost 11 years ago. Updated over 10 years ago.

Status:
Resolved
Priority:
Normal
Assignee:
-
Category:
API
Target version:
-
Triaged:
Fixed in Releases:
Found in Releases:

Description

I recently installed Foreman, but noticed I don't see any direct way to edit the classes under a host/node.

I remember seeing something about making a host group for the individual classes and assigning that group to a host, but that seems like a "non-direct solution" to me.

Looking through the API docs, I see a PUT request to update a host, but I see nothing about the classes in its response.

Is it possible to update the classes for a host like that through the REST API? Am I just missing something?

Actions #1

Updated by Joseph Magen almost 11 years ago

I assume that you meaning adding/removing classes from a host. This is undocumented in v1, but you can pass and array of puppetclass ids to the parameter puppetclass_ids in the json data on your PUT call.

"{\"puppetclass_ids\":[12,30,45,77]}

I am working on a more RESTful and documented way in v2.

Actions #2

Updated by Joseph Magen almost 11 years ago

Actually, the code is already in v2 that you can use but since API v2 is still in development, the docs haven't been released you.

To use API v2, just pass version=2 in the header

curl -u admin:secret -H 'Accept:application/json,version=2'

and POST to hosts/:id/puppetclass_ids with parameter :puppetclass_id as the id to be added

Here is the code at
https://github.com/theforeman/foreman/blob/develop/app/controllers/api/v2/host_classes_controller.rb

api :POST, "/hosts/:host_id/puppetclass_ids", "Add a puppetclass to host" 
param :host_id, String, :required => true, :desc => "id of host"
param :puppetclass_id, String, :required => true, :desc => "id of puppetclass"
def create
@host_class = HostClass.create!(:host_id => host_id, :puppetclass_id => params[:puppetclass_id].to_i)
render :json => {:host_id => @host_class.host_id, :puppetclass_id => @host_class.puppetclass_id}
end
Actions #3

Updated by Dominic Cleal over 10 years ago

  • Status changed from New to Resolved
Actions

Also available in: Atom PDF