Can I get a listing of host<>environment from the foreman API? Or should
I go directly to the database?
Thx,
Larry Fast
PS: I just got full round trip working with my pre-existing agents.
agent=>puppetmaster=>foreman-ENC=>foreman-yaml=>puppetmaster=>agent. After
2 days, Foreman is already providing visibility on stuff that was
previously hidden.
Yes, you can get details of a host and/or environment from the API. Here's a simple curl example.
curl -u admin:secret -H "Accept:application/json" http://0.0.0.0:3000/api/hosts/example.host.com
curl -u admin:secret -H "Accept:application/json" http://0.0.0.0:3000/api/environments/production
The current default API version is v1. We are working on v2.
Regards,
Joseph
···
----- Original Message -----
From: "Larry Fast"
To: foreman-users@googlegroups.com
Sent: Friday, March 15, 2013 11:33:49 PM
Subject: [foreman-users] Can I get a list of host<>environment through the foreman API?
Can I get a listing of host<>environment from the foreman API? Or should I go directly to the database?
Thx,
Larry Fast
PS: I just got full round trip working with my pre-existing agents. agent=>puppetmaster=>foreman-ENC=>foreman-yaml=>puppetmaster=>agent. After 2 days, Foreman is already providing visibility on stuff that was previously hidden.
–
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?hl=en .
For more options, visit https://groups.google.com/groups/opt_out .
> Why don't you search for an environment? e.g.
> 1. ask for all envs
> 2. ask for all hosts in each env
> (should save you a lot of API calls).
>
> OK, but I can't find an example of how to construct that. I'm guessing
that I would use the search API but I haven't seen any complete examples of
the syntax. Something like this I suppose:
curl -u admin:secret -H "Accept:application/json" http://0.0.0.0:3000/api/<http://0.0.0.0:3000/api/environments/production>
hosts?"hosts.environments.environments.name=foo"
And if I'm barking up the wrong tree, please point me to the right tree :^)
Thanks,
Larry
Thank you all! This is a very helpful community! Let me summarize what
I've learned. And again, correct me if anything is misrepresented.
From any GUI page I can filter using the search rules in the filter box
environment=dev23 AND os~cent
Using curl I can wrap the same text as used in the GUI with something like
this:
curl -u admin:secret -H "Accept:application/json"
http://localhost/api/hosts?search="environment=dev23 AND os~cent"
In ruby I can do something like this (but I haven't worked out uid/pwd/SSL
yet):
require 'rest_client'
require 'json'
require 'pp'
myJson = RestClient.get('http://localhost/api/hosts?', :params =>{ :search
=> "environment=dev23" })
myHash = JSON.parse(myJson)
pp myHash
And I thought I saw reference to a ruby syntax like this:
require 'foreman'
myJson = foreman( … ) - so I'm guessing there's a foreman class I can
use ???
My final comment/question is about more generalized SQL-ish queries. What
I see so far is that each API page:
- returns a fixed field list - I can't ask for host details or facter
values in the Hosts page
- I can only filter from the list of records presented - I can't use one
request to get details & facter values for multiple hosts.
So if I want to collect a broader cross-section of data I would need to go
directly to the database? Or is there an API page that can return broader
search results? Eg. I want to see hosts.environment & hosts.facter.XYZ
for a list of hosts filtered by os=centOS.
Cheers,
Larry Fast
···
>
> It's not implemented yet, but I am considering to add to the API the
option for the user to specify the fields in the response as well as to
expand the child relationships. Is this what you mean?
Yes, that's it exactly. I'm looking foward to seeing it.
Thanks again,
Larry Fast
Thanks Joseph.
So the process of getting my list of host<>environment is three-ish steps
- curl hosts - gets a list of hosts
extract all the host names
- curl hosts/each_name - gets a record for each host
extract the host<>environment pairs
One more question. In Ruby, what's the best way for getting this data into
a hash?
Thanks,
Larry
···
On Sunday, March 17, 2013 1:10:02 AM UTC-7, Joseph Magen wrote:
>
> curl -u admin:secret -H "Accept:application/json"
> http://0.0.0.0:3000/api/hosts/example.host.com
> curl -u admin:secret -H "Accept:application/json"
> http://0.0.0.0:3000/api/environments/production
> Joseph
>
Try this using params[:search]. Foreman uses the scoped_search gem (github.com/wvanbergen/scoped_search).
Try it on the UI. There is an auto-completer so it's easy to learn.
curl -u admin:secret -H "Accept:application/json" http://0.0.0.0:3000/api/hosts?search='environment=production'
Joseph
···
----- Original Message -----
From: "Larry Fast"
To: foreman-users@googlegroups.com
Sent: Tuesday, March 19, 2013 6:18:18 AM
Subject: [foreman-users] Re: Can I get a list of host<>environment through the foreman API?
Why don’t you search for an environment? e.g.
- ask for all envs
- ask for all hosts in each env
(should save you a lot of API calls).
OK, but I can’t find an example of how to construct that. I’m guessing that I would use the search API but I haven’t seen any complete examples of the syntax. Something like this I suppose:
curl -u admin:secret -H “Accept:application/json” http://0.0.0.0:3000/api/ hosts?“hosts.environments.environments.name=foo”
And if I’m barking up the wrong tree, please point me to the right tree :^)
Thanks,
Larry
–
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?hl=en .
For more options, visit https://groups.google.com/groups/opt_out .
> So if I want to collect a broader cross-section of data I would need to go directly to the database?
> Or is there an API page that can return broader search results? Eg. I want to see hosts.environment & hosts.facter.XYZ for a list of hosts filtered by os=centOS.
It's not implemented yet, but I am considering to add to the API the option for the user to specify the fields in the response as well as to expand the child relationships. Is this what you mean?
···
----- Original Message -----
From: "Larry Fast"
To: foreman-users@googlegroups.com
Sent: Tuesday, March 19, 2013 4:47:34 PM
Subject: [foreman-users] Re: Can I get a list of host<>environment through the foreman API?
Thank you all! This is a very helpful community! Let me summarize what I’ve learned. And again, correct me if anything is misrepresented.
From any GUI page I can filter using the search rules in the filter box environment=dev23 AND os~cent
Using curl I can wrap the same text as used in the GUI with something like this:
curl -u admin:secret -H “Accept:application/json” http://localhost/api/hosts?search=“environment=dev23 AND os~cent”
In ruby I can do something like this (but I haven’t worked out uid/pwd/SSL yet):
require 'rest_client’
require 'json’
require 'pp’
myJson = RestClient.get('http://localhost/api/hosts?’, :params =>{ :search => “environment=dev23” })
myHash = JSON.parse(myJson)
pp myHash
And I thought I saw reference to a ruby syntax like this:
require 'foreman’
myJson = foreman( … ) - so I’m guessing there’s a foreman class I can use ???
My final comment/question is about more generalized SQL-ish queries. What I see so far is that each API page:
- returns a fixed field list - I can’t ask for host details or facter values in the Hosts page
- I can only filter from the list of records presented - I can’t use one request to get details & facter values for multiple hosts.
So if I want to collect a broader cross-section of data I would need to go directly to the database? Or is there an API page that can return broader search results? Eg. I want to see hosts.environment & hosts.facter.XYZ for a list of hosts filtered by os=centOS.
Cheers,
Larry Fast
–
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?hl=en .
For more options, visit https://groups.google.com/groups/opt_out .
Something like
require 'json'
require 'rest_client'
json = RestClient.get the_url
yourhash = JSON.parse(json)
···
On 18 March 2013 13:04, Larry Fast wrote:
> Thanks Joseph.
> So the process of getting my list of host<>environment is three-ish steps
> 1. curl hosts - gets a list of hosts
> extract all the host names
> 2. curl hosts/each_name - gets a record for each host
> extract the host<>environment pairs
>
> One more question. In Ruby, what's the best way for getting this data into
> a hash?
>
> Thanks,
> Larry
>
>
>
> On Sunday, March 17, 2013 1:10:02 AM UTC-7, Joseph Magen wrote:
>>
>> curl -u admin:secret -H "Accept:application/json"
>> http://0.0.0.0:3000/api/hosts/example.host.com
>> curl -u admin:secret -H "Accept:application/json"
>> http://0.0.0.0:3000/api/environments/production
>> Joseph
>
> --
> 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?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
> Thanks Joseph.
> So the process of getting my list of host<>environment is three-ish steps
> 1. curl hosts - gets a list of hosts
> extract all the host names
> 2. curl hosts/each_name - gets a record for each host
> extract the host<>environment pairs
>
Why don't you search for an environment? e.g.
- ask for all envs
- ask for all hosts in each env
(should save you a lot of API calls).
Ohad
···
On Mon, Mar 18, 2013 at 3:04 PM, Larry Fast wrote:
One more question. In Ruby, what’s the best way for getting this data
into a hash?
Thanks,
Larry
On Sunday, March 17, 2013 1:10:02 AM UTC-7, Joseph Magen wrote:
curl -u admin:secret -H "Accept:application/json"
http://0.0.0.0:3000/api/hosts/**example.host.comhttp://0.0.0.0:3000/api/hosts/example.host.com
curl -u admin:secret -H "Accept:application/json"
http://0.0.0.0:3000/api/**environments/productionhttp://0.0.0.0:3000/api/environments/production
Joseph
–
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
Thanks for this. I couldn't find how to do a search anywhere in the API
docs.
···
On Tuesday, 19 March 2013 03:20:21 UTC-4, Joseph Magen wrote:
>
> Try this using params[:search]. Foreman uses the scoped_search gem (
> github.com/wvanbergen/scoped_search).
>
> Try it on the UI. There is an auto-completer so it's easy to learn.
>
> curl -u admin:secret -H "Accept:application/json"
> http://0.0.0.0:3000/api/hosts?search='environment=production'
>
> Joseph
>
>
> ----- Original Message -----
> From: "Larry Fast" <lfas...@gmail.com >
> To: forema...@googlegroups.com
> Sent: Tuesday, March 19, 2013 6:18:18 AM
> Subject: [foreman-users] Re: Can I get a list of host<>environment through
> the foreman API?
>
>
>
>
>
> Why don't you search for an environment? e.g.
> 1. ask for all envs
> 2. ask for all hosts in each env
> (should save you a lot of API calls).
>
>
> OK, but I can't find an example of how to construct that. I'm guessing
> that I would use the search API but I haven't seen any complete examples of
> the syntax. Something like this I suppose:
>
>
> curl -u admin:secret -H "Accept:application/json" http://0.0.0.0:3000/api/
> hosts?"hosts.environments.environments.name=foo"
>
>
>
> And if I'm barking up the wrong tree, please point me to the right tree
> :^)
> Thanks,
> Larry
>
> --
> 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?hl=en .
> For more options, visit https://groups.google.com/groups/opt_out .
>
>