[rudder-users] Update Group on API rudder

Francois Armand francois.armand at normation.com
Tue Feb 3 10:19:17 CET 2015


On 03/02/15 02:28, Maxime Longuet wrote:
> Anybody have already work with update group from API. I'm search how do you write query param on  :
>
> http://www.rudder-project.org/rudder-api-doc/#api-Groups-updateGroup
>
>
> query optional	JSON	
>
> Query to get Nodes. Empty Query is possible, but this group will not have nodes anymore.
>
>
> I'm think this :
>
> '{"select":"node","composition":"And","where":[{"objectType":"node","attribute":"nodeHostname","comparator":"eq","value":"server01.domaine.com"}]}'
>
>
>
> Good ? :)
>

You're good :)

I openned that issue ( http://www.rudder-project.org/redmine/issues/6221
) to track the missing documentation. 

The json structure is organized like that:

  * "*select*" : mandatory value,  "*node*" or "*nodeAndPolicyServer*"
  * "*composition*": either "*and*" or "*or*". Optionnal, default to "and"
  * "*where*": an array of json objects composed of:
      o "*objectType*": the kind of object to look for. They are all
        defined in
        https://github.com/Normation/rudder/blob/branches/rudder/3.0/rudder-core/src/main/scala/com/normation/rudder/domain/queries/DitQueryData.scala
        around line #280 (def objectTypes = Map... ). Some interesting ones:
          + node : for all the OS, RAM, etc
          + environmentVariable
          + software
      o "*attribute*": the name of the attribute to lookup for the given
        object. The possible names are defined in DitQueryData to: it's
        the huge list of "ObjectCriterion". Problem: most use name
        defined elsewhere in the form of "A_OS_VERSION" etc. The name
        are defined in one the two files:
          + https://github.com/Normation/ldap-inventory/blob/branches/rudder/3.0/inventory-repository/src/main/scala/com/normation/inventory/ldap/core/LDAPConstants.scala
          + https://github.com/Normation/rudder/blob/branches/rudder/3.0/rudder-core/src/main/scala/com/normation/rudder/domain/RudderLDAPConstants.scala
      o "*comparator*": the kind of comparator to use:
          + exits / notExists: only check the presence of that kind of
            attribute for the object in the node
          + eq: equals
          + notEq: not equals
          + gt / gteq: greater than / greater or equals
          + lt / lteq : lesser than / lesser or equals
          + regex: match the given pattern. The authorized regex are the
            Java one, as defined in
            http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html
          + notRegex : all entries not matching the given regex
          + and there is a special syntax for key=value objects, like
            "environmentVariable". For them, you use the attribute
            "name.value", the comparator to use, with a new one:
              # hasKey: to only check for the key part equals the given
                value
              # else, the comparison is done on "key=value", and you can
                do almost anything with regex
              # Ex:
                {"select":"nodeAndPolicyServer","composition":"And","where":[{"objectType":"environmentVariable","attribute":"name.value","comparator":"regex","value":".*NAME=r[o]{2}t"}]}



There is example in the tests for query:
https://github.com/Normation/rudder/blob/branches/rudder/3.0/rudder-core/src/test/scala/com/normation/rudder/services/queries/TestJsonQueryLexing.scala
https://github.com/Normation/rudder/blob/branches/rudder/3.0/rudder-core/src/test/scala/com/normation/rudder/services/queries/TestQueryProcessor.scala

So, if you read until hear, you now see that the current format is quite
ad-hoc - or more preciselly, it reflects far to much the underlying
storage format.
A more versatile version is think about, based on the JSON format of the
node details returned by the API and a XPATH kind of query. But well,
it's not for now, and the current language is already in the nature, so
it will be supported :)
At least, in 3.1 we are going to try to normalize object and attribute
names so that they match the names in the node details returned by the API.

Hope it helps.

-- 
------------------------------------------------------------------------
*François ARMAND*
/Directeur de la R&D/
Normation <http://www.normation.com>
------------------------------------------------------------------------
*87 rue de Turbigo, 75003 Paris, France*
Telephone: 	+33 (0)1 83 62 99 23
Mobile: 	+33 (0)6 63 37 60 55
------------------------------------------------------------------------

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.rudder-project.org/pipermail/rudder-users/attachments/20150203/54207e9a/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sig-normation-logo-square.png
Type: image/png
Size: 3503 bytes
Desc: not available
URL: <http://www.rudder-project.org/pipermail/rudder-users/attachments/20150203/54207e9a/attachment.png>


More information about the rudder-users mailing list