Using where or search in foreman 1.2 api GET request

Can someone tell me how I can get the following result using the foreman
1.2 api to find a specific id for (for example) an osversion so I can
update a hosts osversion with the found id from a shell script.
Preferably using only curl so I don't have to install additional rpms or
gems.

Wat i would like to do is:

  1. for example: specify family (redhat or centos), major version (6) and
    minor version (4).
  2. find the id of the osversion that has the params values or name.
  3. use the id to update an hosts osversion before i will rekickstart it.
  4. do this inside one command or script

I know that the following command will find osversion details but I haven't
been to use param values like an sql where clause or the search
functionality of the gui or foremancli.

curl -H "Content-Type:application/json" -s -H "Accept:application/json" -k
-u admin:changeme https://foreman/operatingsystems | prettify_json.rb

I would like to use (for example) the result values "name": "CentOS 6.3" to
get the id that belongs to this osversion and use this id in a PUT request
to update the hosts osversion within a script that i use for rekickstarting
a host and set it into build mode using the api.

In sql this would look soming like:
select id from osversion where name = "CentOS 6.3" # (result: 1)
update hosts set operatingsystem_id=1 where host="name of host"

This is only one example that I'm trying to solve. In general I encountered
many situations where it was easy to update a value of an resource if i
knew the needed value of values,
but where it was difficult to find the needed value in the result of an api
call. The more returned values and similar name fields the harder it gets.

In an curl PUT command I can specify the fields (with -d) that I would
like to update. But it appears to me there is no way to specify a field or
fields from which i want there values returned in a GET request so I can
use the in an next api call.

Ronny,

In the current API v1, there is no feature to limit or specify the fields that you want returned in the response. I am working on this for API v2 but there is no open pull request yet.

Joseph

··· ----- Original Message ----- From: "Ronny M" To: foreman-users@googlegroups.com Sent: Monday, July 29, 2013 10:53:40 PM Subject: [foreman-users] Using where or search in foreman 1.2 api GET request

Can someone tell me how I can get the following result using the foreman
1.2 api to find a specific id for (for example) an osversion so I can
update a hosts osversion with the found id from a shell script.
Preferably using only curl so I don’t have to install additional rpms or
gems.

Wat i would like to do is:

  1. for example: specify family (redhat or centos), major version (6) and
    minor version (4).
  2. find the id of the osversion that has the params values or name.
  3. use the id to update an hosts osversion before i will rekickstart it.
  4. do this inside one command or script

I know that the following command will find osversion details but I haven’t
been to use param values like an sql where clause or the search
functionality of the gui or foremancli.

curl -H “Content-Type:application/json” -s -H “Accept:application/json” -k
-u admin:changeme https://foreman/operatingsystems | prettify_json.rb

I would like to use (for example) the result values “name”: “CentOS 6.3” to
get the id that belongs to this osversion and use this id in a PUT request
to update the hosts osversion within a script that i use for rekickstarting
a host and set it into build mode using the api.

In sql this would look soming like:
select id from osversion where name = “CentOS 6.3” # (result: 1)
update hosts set operatingsystem_id=1 where host=“name of host”

This is only one example that I’m trying to solve. In general I encountered
many situations where it was easy to update a value of an resource if i
knew the needed value of values,
but where it was difficult to find the needed value in the result of an api
call. The more returned values and similar name fields the harder it gets.

In an curl PUT command I can specify the fields (with -d) that I would
like to update. But it appears to me there is no way to specify a field or
fields from which i want there values returned in a GET request so I can
use the in an next api call.


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.

I think you want to do this

curl -H "Content-Type:application/json" -s -H "Accept:application/json" -k -u
admin:changeme
'https://localhost/foreman/operatingsystems?search=name=CentOS+AND+major=6+AND+minor=3'
> ruby -r json -e 'p JSON.parse(STDIN.read).first["operatingsystem"]["id"]'

this command will print id of a first OS that it finds which should be CentOS
6.3

··· -- Marek

On Monday 29 of July 2013 12:53:40 Ronny M wrote:

Can someone tell me how I can get the following result using the foreman
1.2 api to find a specific id for (for example) an osversion so I can
update a hosts osversion with the found id from a shell script.
Preferably using only curl so I don’t have to install additional rpms or
gems.

Wat i would like to do is:

  1. for example: specify family (redhat or centos), major version (6) and
    minor version (4).
  2. find the id of the osversion that has the params values or name.
  3. use the id to update an hosts osversion before i will rekickstart it.
  4. do this inside one command or script

I know that the following command will find osversion details but I haven’t
been to use param values like an sql where clause or the search
functionality of the gui or foremancli.

curl -H “Content-Type:application/json” -s -H “Accept:application/json” -k
-u admin:changeme https://foreman/operatingsystems | prettify_json.rb

I would like to use (for example) the result values “name”: “CentOS 6.3” to
get the id that belongs to this osversion and use this id in a PUT request
to update the hosts osversion within a script that i use for rekickstarting
a host and set it into build mode using the api.

In sql this would look soming like:
select id from osversion where name = “CentOS 6.3” # (result: 1)
update hosts set operatingsystem_id=1 where host=“name of host”

This is only one example that I’m trying to solve. In general I encountered
many situations where it was easy to update a value of an resource if i
knew the needed value of values,
but where it was difficult to find the needed value in the result of an api
call. The more returned values and similar name fields the harder it gets.

In an curl PUT command I can specify the fields (with -d) that I would
like to update. But it appears to me there is no way to specify a field or
fields from which i want there values returned in a GET request so I can
use the in an next api call.

@Marek,

Thanks I will try that. My first tests gave me some errors (about json) but
if I get it to work or not I will post my results good or bad in this post.

··· 2013/7/30 Marek Hulan

I think you want to do this

curl -H “Content-Type:application/json” -s -H “Accept:application/json”
-k -u
admin:changeme

https://localhost/foreman/operatingsystems?search=name=CentOS+AND+major=6+AND+minor=3

ruby -r json -e ‘p JSON.parse(STDIN.read).first[“operatingsystem”][“id”]’

this command will print id of a first OS that it finds which should be
CentOS
6.3


Marek

On Monday 29 of July 2013 12:53:40 Ronny M wrote:

Can someone tell me how I can get the following result using the foreman
1.2 api to find a specific id for (for example) an osversion so I can
update a hosts osversion with the found id from a shell script.
Preferably using only curl so I don’t have to install additional rpms or
gems.

Wat i would like to do is:

  1. for example: specify family (redhat or centos), major version (6) and
    minor version (4).
  2. find the id of the osversion that has the params values or name.
  3. use the id to update an hosts osversion before i will rekickstart it.
  4. do this inside one command or script

I know that the following command will find osversion details but I
haven’t
been to use param values like an sql where clause or the search
functionality of the gui or foremancli.

curl -H “Content-Type:application/json” -s -H “Accept:application/json”
-k
-u admin:changeme https://foreman/operatingsystems | prettify_json.rb

I would like to use (for example) the result values “name”: "CentOS 6.3"
to
get the id that belongs to this osversion and use this id in a PUT
request
to update the hosts osversion within a script that i use for
rekickstarting
a host and set it into build mode using the api.

In sql this would look soming like:
select id from osversion where name = “CentOS 6.3” # (result: 1)
update hosts set operatingsystem_id=1 where host=“name of host”

This is only one example that I’m trying to solve. In general I
encountered
many situations where it was easy to update a value of an resource if i
knew the needed value of values,
but where it was difficult to find the needed value in the result of an
api
call. The more returned values and similar name fields the harder it
gets.

In an curl PUT command I can specify the fields (with -d) that I would
like to update. But it appears to me there is no way to specify a field
or
fields from which i want there values returned in a GET request so I can
use the in an next api call.


You received this message because you are subscribed to a topic in the
Google Groups “Foreman users” group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/foreman-users/3767vNhuHpY/unsubscribe.
To unsubscribe from this group and all its topics, 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.

@Joseph,

Ok thanks for the information. Would be nice if that would be (become)
possible in the v2 api.

··· 2013/7/30 Joseph Magen

Ronny,

In the current API v1, there is no feature to limit or specify the fields
that you want returned in the response. I am working on this for API v2
but there is no open pull request yet.

Joseph

----- Original Message -----
From: “Ronny M” maas.ronny@gmail.com
To: foreman-users@googlegroups.com
Sent: Monday, July 29, 2013 10:53:40 PM
Subject: [foreman-users] Using where or search in foreman 1.2 api GET
request

Can someone tell me how I can get the following result using the foreman
1.2 api to find a specific id for (for example) an osversion so I can
update a hosts osversion with the found id from a shell script.
Preferably using only curl so I don’t have to install additional rpms or
gems.

Wat i would like to do is:

  1. for example: specify family (redhat or centos), major version (6) and
    minor version (4).
  2. find the id of the osversion that has the params values or name.
  3. use the id to update an hosts osversion before i will rekickstart it.
  4. do this inside one command or script

I know that the following command will find osversion details but I haven’t
been to use param values like an sql where clause or the search
functionality of the gui or foremancli.

curl -H “Content-Type:application/json” -s -H “Accept:application/json” -k
-u admin:changeme https://foreman/operatingsystems | prettify_json.rb

I would like to use (for example) the result values “name”: “CentOS 6.3” to
get the id that belongs to this osversion and use this id in a PUT request
to update the hosts osversion within a script that i use for rekickstarting
a host and set it into build mode using the api.

In sql this would look soming like:
select id from osversion where name = “CentOS 6.3” # (result: 1)
update hosts set operatingsystem_id=1 where host=“name of host”

This is only one example that I’m trying to solve. In general I encountered
many situations where it was easy to update a value of an resource if i
knew the needed value of values,
but where it was difficult to find the needed value in the result of an api
call. The more returned values and similar name fields the harder it gets.

In an curl PUT command I can specify the fields (with -d) that I would
like to update. But it appears to me there is no way to specify a field or
fields from which i want there values returned in a GET request so I can
use the in an next api call.


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.


You received this message because you are subscribed to a topic in the
Google Groups “Foreman users” group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/foreman-users/3767vNhuHpY/unsubscribe.
To unsubscribe from this group and all its topics, 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.

@Marek,

Thanks. your search suggestion for finding the osversion id works fine :slight_smile:

··· 2013/7/31 Ronny M

@Joseph,

Ok thanks for the information. Would be nice if that would be (become)
possible in the v2 api.

2013/7/30 Joseph Magen jmagen@redhat.com

Ronny,

In the current API v1, there is no feature to limit or specify the fields
that you want returned in the response. I am working on this for API v2
but there is no open pull request yet.

Joseph

----- Original Message -----
From: “Ronny M” maas.ronny@gmail.com
To: foreman-users@googlegroups.com
Sent: Monday, July 29, 2013 10:53:40 PM
Subject: [foreman-users] Using where or search in foreman 1.2 api GET
request

Can someone tell me how I can get the following result using the foreman
1.2 api to find a specific id for (for example) an osversion so I can
update a hosts osversion with the found id from a shell script.
Preferably using only curl so I don’t have to install additional rpms or
gems.

Wat i would like to do is:

  1. for example: specify family (redhat or centos), major version (6) and
    minor version (4).
  2. find the id of the osversion that has the params values or name.
  3. use the id to update an hosts osversion before i will rekickstart it.
  4. do this inside one command or script

I know that the following command will find osversion details but I
haven’t
been to use param values like an sql where clause or the search
functionality of the gui or foremancli.

curl -H “Content-Type:application/json” -s -H “Accept:application/json”
-k
-u admin:changeme https://foreman/operatingsystems | prettify_json.rb

I would like to use (for example) the result values “name”: "CentOS 6.3"
to
get the id that belongs to this osversion and use this id in a PUT request
to update the hosts osversion within a script that i use for
rekickstarting
a host and set it into build mode using the api.

In sql this would look soming like:
select id from osversion where name = “CentOS 6.3” # (result: 1)
update hosts set operatingsystem_id=1 where host=“name of host”

This is only one example that I’m trying to solve. In general I
encountered
many situations where it was easy to update a value of an resource if i
knew the needed value of values,
but where it was difficult to find the needed value in the result of an
api
call. The more returned values and similar name fields the harder it gets.

In an curl PUT command I can specify the fields (with -d) that I would
like to update. But it appears to me there is no way to specify a field or
fields from which i want there values returned in a GET request so I can
use the in an next api call.


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.


You received this message because you are subscribed to a topic in the
Google Groups “Foreman users” group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/foreman-users/3767vNhuHpY/unsubscribe.
To unsubscribe from this group and all its topics, 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.