Project

General

Profile

Feature #185

Query "and not"

Added by Dis Connect over 10 years ago. Updated over 9 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Search
Target version:
Difficulty:
Triaged:
No
Bugzilla link:
Pull request:
Fixed in Releases:
Found in Releases:

Description

We need to be able to query for "class foo AND NOT class bar AND NOT class baz..."


Related issues

Follows Foreman - Feature #719: Add new search functionailyClosed2011-03-09

History

#1 Updated by Ohad Levy over 10 years ago

a which work around is to call the gethosts method multiple times e.g.
for an AND operations

gethosts(...) & gethosts(...)

this basically returns an array, so you can use logical operators on them.

#2 Updated by Dis Connect over 10 years ago

This is a usable workaround but it is pretty unpleasant.

The old iclassify scripts are simple one-liners:
QUERY="tag:appserver AND NOT tag:foo AND NOT tag:platform AND NOT..etc"

New ones look more like this: (use += for 'or')
hosts = gethosts( { "class" => "appserver" } )
hosts -= gethosts( {"class" => "platform" } )
hosts -= gethosts( {"class" => "foo" } )
...

Just fyi the 'and' case works works cleanly:
hosts=gethosts( { "class" => ["appserver","foo"] } )

(Extra detail in case anyone else stumbles across this bug report and needs a solution :) ..)

#3 Updated by Ohad Levy over 10 years ago

Dis Connect wrote:

This is a usable workaround but it is pretty unpleasant.

The old iclassify scripts are simple one-liners:
QUERY="tag:appserver AND NOT tag:foo AND NOT tag:platform AND NOT..etc"

I just said its a work around for now :)

Just fyi the 'and' case works works cleanly:

yes I know - I did remember spending some time on getting it to work ;)

#4 Updated by Dis Connect over 10 years ago

Doesn't work with verbose. So a basic query to get 5 facts about host class 'foo' and not class 'bar' can hammer the foreman server half to death:
  • get all hosts 'foo'
  • get all hosts 'bar' and subtract
  • for all remaining hosts, query again by hostname, verbose.
  • operate on the facts you want

This doesn't even pretend to scale..

With 'and not':
  • get all hosts 'foo' and not 'bar', verbose
  • operate on the facts you want

#5 Updated by Dis Connect over 10 years ago

[[http://www.davebalmain.com/api/classes/Ferret/QueryParser.html]] A query language that would add a ton of flexibility to foreman.

#6 Updated by Ohad Levy over 9 years ago

  • Category set to Search
  • Status changed from New to Closed
  • Assignee set to Ohad Levy
  • Target version set to 0.3

implemented as part of #719

Also available in: Atom PDF