<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Feb 17, 2015 at 7:06 AM, Dmitri Zimine <span dir="ltr"><<a href="mailto:dzimine@stackstorm.com" target="_blank">dzimine@stackstorm.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><div>SUMMARY: </div><div>----------------</div><div><br></div>We are changing the syntax for inlining YAQL expressions in Mistral YAML from {1+$.my.var} (or “{1+$.my.var}”) to <% 1+$.my.var %><div><br></div><div>Below I explain the rationale and the criteria for the choice. Comments and suggestions welcome.</div><div><div><br></div><div>DETAILS: </div><div>-------------</div><div><br></div><div>We faced a number of problems with using YAQL expressions in Mistral DSL: [1] must handle any YAQL, not only the ones started with $; [2] must preserve types and [3] must comply with YAML. We fixed these problems by applying Ansible style syntax, requiring quotes around delimiters (e.g. “{1+$.my.yaql.var}”). However, it lead to unbearable confusion in DSL readability, in regards to types:</div><div><br></div><div><div>    publish:<br>       intvalue1: "{1+1}” # Confusing: you expect quotes to be string.<br>       intvalue2: "{int(1+1)}” # Even this doestn’ clean the confusion<br>       whatisthis:"{$.x + $.y}” # What type would this return? </div></div><div><br></div><div>We got a very strong push back from users in the filed on this syntax. </div><div><br></div><div>The crux of the problem is using { } as delimiters YAML. It is plain wrong to use the reserved character. The clean solution is to find a delimiter that won’t conflict with YAML.</div><div><br></div><div><div>Criteria for selecting best alternative are: </div><div>1) Consistently applies to to all cases of using YAML in DSL</div><div>2) Complies with YAML </div><div>3) Familiar to target user audience - openstack and devops</div></div><div><br></div><div>We prefer using two-char delimiters to avoid requiring extra escaping within the expressions.</div><div><br></div><div><div>The current winner is <% %>. It fits YAML well. It is familiar to openstack/devops as this is used for embedding Ruby expressions in Puppet and Chef (for instance, [4]). It plays relatively well across all cases of using expressions in Mistral (see examples in [5]):</div></div></div></div></blockquote><div><br>A really long time ago I posted this patch for Heat: <a href="https://review.openstack.org/#/c/41858/2/doc/source/template_guide/functions.rst">https://review.openstack.org/#/c/41858/2/doc/source/template_guide/functions.rst</a><br></div><div>(adds a jinja2 function to Heat <a href="http://jinja.pocoo.org/docs/dev/">http://jinja.pocoo.org/docs/dev/</a>)<br><br></div><div>I also used <% %>, it seems to be what people use when using jinja2 on yaml.<br><br></div><div>This was rejected because of security concerns of Jinja2.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><div><div><br></div><div><div>ALTERNATIVES considered:</div><div>--------------------------------------------------</div><div><br></div><div>1) Use Ansible-like syntax: <a href="http://docs.ansible.com/YAMLSyntax.html#gotchas" target="_blank">http://docs.ansible.com/YAMLSyntax.html#gotchas</a></div><div>Rejected for confusion around types. See above.</div><div><br></div><div>2) Use functions, like Heat HOT or TOSCA:</div><div><br></div><div>HOT templates and TOSCA doesn’t seem to have a concept of typed variables to borrow from (please correct me if I missed it). But they have functions: function: { function_name: {foo: [parameter1, parameter 2], bar:"xxx”}}. Applied to Mistral, it would look like:</div><div><br></div><div>    publish:</div><div>     - bool_var: { yaql: “1+1+$.my.var < 100” } </div></div></div></div></blockquote><div><br></div><div>You *could* have the expression as a list, like this (but might not work in all cases):<br>{ yaql: [1, +, 1, $.my.var, <, 100] } <br> <br></div><div>Generally in Heat we make the functions and args a natural part of the yaml so it's not one big string that gets parsed separately.<br></div><div>Tho' it would be nice to have a common approach to this, so I am partial to the one you have here.<br><br></div><div>-Angus<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><div><div><div><br></div><div>Not bad, but currently rejected as it reads worse than delimiter-based syntax, especially in simplified one-line action invocation.</div><div><br></div><div>3) < > paired with other symbols: php-styoe  <? ..?></div><div><br></div></div><div><br></div><div><b>REFERENCES: </b></div><div>----------------------</div><div><br></div><div>[1] Allow arbitrary YAQL expressions, not just ones started with $ : <a href="https://github.com/stackforge/mistral/commit/5c10fb4b773cd60d81ed93aec33345c0bf8f58fd" target="_blank">https://github.com/stackforge/mistral/commit/5c10fb4b773cd60d81ed93aec33345c0bf8f58fd</a></div><div>[2] Use Ansible-like syntax to make YAQL expressions YAML complient <a href="https://github.com/stackforge/mistral/commit/d9517333b1fc9697d4847df33d3b774f881a111b" target="_blank">https://github.com/stackforge/mistral/commit/d9517333b1fc9697d4847df33d3b774f881a111b</a></div><div>[3] Preserving types in YAQL <a href="https://github.com/stackforge/mistral/blob/d9517333b1fc9697d4847df33d3b774f881a111b/mistral/tests/unit/test_expressions.py#L152-L184" target="_blank">https://github.com/stackforge/mistral/blob/d9517333b1fc9697d4847df33d3b774f881a111b/mistral/tests/unit/test_expressions.py#L152-L184</a></div><div>[4]Using <% %> in Puppet <a href="https://docs.puppetlabs.com/guides/templating.html#erb-is-plain-text-with-embedded-ruby" style="font-family:"Helvetica Neue";font-size:13px" target="_blank">https://docs.puppetlabs.com/guides/templating.html#erb-is-plain-text-with-embedded-ruby</a> </div><div>[5] Etherpad with discussion <a href="https://etherpad.openstack.org/p/mistral-YAQL-delimiters" target="_blank">https://etherpad.openstack.org/p/mistral-YAQL-delimiters</a></div><div><div>[6] Blueprint <a href="https://blueprints.launchpad.net/mistral/+spec/yaql-delimiters" target="_blank">https://blueprints.launchpad.net/mistral/+spec/yaql-delimiters</a></div></div></div><div><br></div></div><br>__________________________________________________________________________<br>
OpenStack Development Mailing List (not for usage questions)<br>
Unsubscribe: <a href="http://OpenStack-dev-request@lists.openstack.org?subject:unsubscribe" target="_blank">OpenStack-dev-request@lists.openstack.org?subject:unsubscribe</a><br>
<a href="http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev" target="_blank">http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev</a><br>
<br></blockquote></div><br></div></div>