Jump to: navigation, search

Difference between revisions of "Mistral/UsingYAQL"

(YAQL Examples)
(Add YAQL Tools section)
Line 56: Line 56:
  
 
YAQL filters users with username == 'user2' and returns list containing only user 'user2' and we take the first one.
 
YAQL filters users with username == 'user2' and returns list containing only user 'user2' and we take the first one.
 +
 +
==YAQL Tools==
 +
 +
===YAQLuator===
 +
 +
An online YAQL evaluator is available at http://yaqluator.com
 +
 +
Key features:
 +
* Provide a YAML and a YAQL and view the evaluation result.
 +
* A catalog of common OpenStack API responses.
 +
* YAQL auto complete (very basic for now)

Revision as of 09:36, 10 August 2015

YAQL Examples

Prject github URL: https://github.com/ativelkov/yaql

Using YAQL it is possible to filter, process, access and pass data stored in JSON structure.

For example, this JSON will be used for showing some examples:

{
  "users": [
    {
       "tenant_id": "123",
       "username": "user1",
       "roles": ["admin"]
    },
    {
      "tenant_id": "321",
      "username": "user2",
       "roles": ["member"]
    },
    {
      "tenant_id": "123",
      "username": "user3",
       "roles": ["admin"]
    }
  ]
}

And suppose we just retrived this JSON from Task, or Action as its result. What we can do:

As the example, it is shown only publish section. The same with 'output' in Action.

Get number of users

publish: 
  users_count: <% $.users.length() %>

Function length() returns number of objects in container like it is done in major high-level programming languages.


Filter users with specific tenant_id

publish:
  tenant_123: <% $.users[$.tenant_id = '123'] %>

YAQL filters users with tenant_id == '123' and returns list containing only users 'user1' and 'user2'.


Get specific user

publish: 
  user2: <% $.users[$.username = 'user2'][0] %>

YAQL filters users with username == 'user2' and returns list containing only user 'user2' and we take the first one.

YAQL Tools

YAQLuator

An online YAQL evaluator is available at http://yaqluator.com

Key features:

  • Provide a YAML and a YAQL and view the evaluation result.
  • A catalog of common OpenStack API responses.
  • YAQL auto complete (very basic for now)