Jump to: navigation, search

Difference between revisions of "Mistral/UsingYAQL"

(YAQL Examples)
m (change link of yaqluator)
 
(3 intermediate revisions by 2 users not shown)
Line 28: Line 28:
  
 
And suppose we just retrived this JSON from Task, or Action as its result. What we can do:
 
And suppose we just retrived this JSON from Task, or Action as its result. What we can do:
* [#Get_number_of_users|Get number of users]
+
* [[#Get_number_of_users|Get number of users]]
* [#Filter_users_with_specific_tenant_id|Filter users with specific tenant_id]
+
* [[#Filter_users_with_specific_tenant_id|Filter users with specific tenant_id]]
* [#Get_specific_user|Get specific user]
+
* [[#Get_specific_user|Get specific user]]
  
 
As the example, it is shown only publish section. The same with 'output' in Action.
 
As the example, it is shown only publish section. The same with 'output' in Action.
Line 36: Line 36:
 
=== Get number of users ===
 
=== Get number of users ===
  
  publish: $.users.length()
+
  publish:  
 +
  users_count: <% $.users.length() %>
  
 
Function length() returns number of objects in container like it is done in major high-level programming languages.
 
Function length() returns number of objects in container like it is done in major high-level programming languages.
Line 43: Line 44:
 
=== Filter users with specific tenant_id ===
 
=== Filter users with specific tenant_id ===
  
  publish: $.users[$.tenant_id = '123']
+
  publish:
 +
  tenant_123: <% $.users[$.tenant_id = '123'] %>
  
 
YAQL filters users with tenant_id == '123' and returns list containing only users 'user1' and 'user2'.
 
YAQL filters users with tenant_id == '123' and returns list containing only users 'user1' and 'user2'.
Line 50: Line 52:
 
=== Get specific user ===
 
=== Get specific user ===
  
  publish $.users[$.username = 'user2'][0]
+
  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 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.ovh
 +
 +
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)

Latest revision as of 12:39, 28 June 2023

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.ovh

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)