Show hosts in a HostGroup help

I think it'd be good if Foreman had a tab on the "Host Group edit" page
that showed all the hosts in a given HostGroup.

I've gotten what I think are the correct commands to do this (via
foreman-console), however, I'm not sure how to actually translate that to
html/erb.

2 below is an example id. I believe the id would already be available

once you get to the "Host Group edit" page, no?

hgroup = Hostgroup.find_by_id('2')

Get all the host groups that have hgroup.id as a partne

inc_hgroups = Hostgroup.descendants_of(hgroup.id)

Get all the hosts in all the host groups. Boom.

all_inc_hosts = []
inc_hgroups.each do |key, value|
inc_hosts = Hostgroup.find_by_id(key.id).hosts
inc_hosts.each do |hkey, hvalue|
all_inc_hosts << hkey.name
end
end

Yeah, it's ugly and probably has a lot of flaws, but, I'm pretty damn new
to ruby :slight_smile:

Anyway, how do I translate this to something that would actually render in
the Foreman web UI?

Thanks!
David

Hey,

> I think it'd be good if Foreman had a tab on the "Host Group edit" page
> that showed all the hosts in a given HostGroup.

are you aware of our flexible and awesome search box? :slight_smile:

What you can do there on the Hosts page is:

"hostgroup = CentOS-devel"

and you will get the desired list. Then you can select them all and
select action from the dropdown.

··· -- Later,

Lukas “lzap” Zapletal
irc: lzap #theforeman

Yep, I'm aware of that :slight_smile: A couple reasons this won't work for what I want:

"hostgroup = CentOS-devel" won't match any Nested group from
"CentOS-devel". I want Hosts the nested groups, too. i.e.
Hostgroup->Datacenter->VM->App_name->Dev/QA/Prod. I'd want all the Hosts
that are in App_name to show, regardless of Environment, which my query
above does.

I prefer a tab on the "Host Group edit" page, similar to "Puppet
Classes", etc. To me, it makes more sense to have that information handy
there, than have to pull up a different page (All Hosts) and search. Also,
I don't really want any action associated with the list of Hosts in this
tab, except for maybe the Hostname being a link to that Hosts page in
Foreman.

David

··· On Friday, June 6, 2014 12:27:39 AM UTC-7, Lukas Zapletal wrote: > > Hey, > > > I think it'd be good if Foreman had a tab on the "Host Group edit" page > > that showed all the hosts in a given HostGroup. > > are you aware of our flexible and awesome search box? :-) > > What you can do there on the Hosts page is: > > "hostgroup = CentOS-devel" > > and you will get the desired list. Then you can select them all and > select action from the dropdown. > > -- > Later, > > Lukas "lzap" Zapletal > irc: lzap #theforeman >

> "hostgroup = CentOS-devel" won't match any Nested group from
> "CentOS-devel". I want Hosts the nested groups, too. i.e.
> Hostgroup->Datacenter->VM->App_name->Dev/QA/Prod. I'd want all the Hosts
> that are in App_name to show, regardless of Environment, which my query
> above does.

Per discussion with Joseph, we have a pending patch that fixes this
behavior:

https://github.com/theforeman/foreman/pull/1502

Feel free to test it and report if it works for you.

··· -- Later,

Lukas “lzap” Zapletal
irc: lzap #theforeman

Just a heads up David, https://github.com/theforeman/foreman/pull/1502 is
now merged, you should be able to do your query through the search box now,
however you'd still have to bring up a new tab to do so :slight_smile:

··· On Mon, Jun 9, 2014 at 10:35 AM, Lukas Zapletal wrote:

“hostgroup = CentOS-devel” won’t match any Nested group from
"CentOS-devel". I want Hosts the nested groups, too. i.e.
Hostgroup->Datacenter->VM->App_name->Dev/QA/Prod. I’d want all the Hosts
that are in App_name to show, regardless of Environment, which my query
above does.

Per discussion with Joseph, we have a pending patch that fixes this
behavior:

https://github.com/theforeman/foreman/pull/1502

Feel free to test it and report if it works for you.


Later,

Lukas “lzap” Zapletal
irc: lzap #theforeman


You received this message because you are subscribed to the Google Groups
"foreman-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to foreman-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Daniel Lobato

@elobatoss
blog.daniellobato.me
daniellobato.me

GPG: http://keys.gnupg.net/pks/lookup?op=get&search=0x7A92D6DD38D6DE30

Sorry for the late reply, work got in the way, heh! That worked perfectly,
thanks! Is there a way to include that search in a page I mentioned
earlier? Almost every single person (management down to the developers)
I've shown Foreman to during the proof-of-concept wanted to have that. I'm
looking through everything and trying to figure it out, but it'll be a long
process, since my ruby sucks :slight_smile:

And no, doing a search isn't the same thing, heh!

Thanks!
David

··· On Thursday, June 19, 2014 3:15:13 PM UTC-7, Daniel Lobato wrote: > > Just a heads up David, https://github.com/theforeman/foreman/pull/1502 is > now merged, you should be able to do your query through the search box now, > however you'd still have to bring up a new tab to do so :) > > > On Mon, Jun 9, 2014 at 10:35 AM, Lukas Zapletal > wrote: > >> > "hostgroup = CentOS-devel" won't match any Nested group from >> > "CentOS-devel". I want Hosts the nested groups, too. i.e. >> > Hostgroup->Datacenter->VM->App_name->Dev/QA/Prod. I'd want all the >> Hosts >> > that are in App_name to show, regardless of Environment, which my query >> > above does. >> >> Per discussion with Joseph, we have a pending patch that fixes this >> behavior: >> >> https://github.com/theforeman/foreman/pull/1502 >> >> Feel free to test it and report if it works for you. >> >> -- >> Later, >> >> Lukas "lzap" Zapletal >> irc: lzap #theforeman >> >> -- >> You received this message because you are subscribed to the Google Groups >> "foreman-dev" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to foreman-dev...@googlegroups.com . >> For more options, visit https://groups.google.com/d/optout. >> > > > > -- > Daniel Lobato > > @elobatoss > blog.daniellobato.me > daniellobato.me > > GPG: http://keys.gnupg.net/pks/lookup?op=get&search=0x7A92D6DD38D6DE30 >