Where is this stuff?
Sometime you need to deal with complex structures which are passed as a parameter to your Murano workflow. Lets take the following example:
There is a Docker container based application which exposes some ports to the host and some ports are used for internal linking between containers. Ports are stored in a list of complex objects like:
ports:
- port: 3306 scope: host
applicationPort: 3306
- port: 22 scope: local
applicationPort: 22
In application Murano workflow I want to select all ports which should be exposed to a host system and add proper parameters to docker run command line. It is possible to use For loop to iterate over $.ports list and check each component individually like the following:
- For: port
In: $.ports
Do: - If: $port.scope = 'host'
Then:
- $.doSomethingWithIt($port)
But there is more elegant solution with using list.where(condition) construction:
- $.ports.where($.scope = 'host').select($this.doSomethingWithIt($))
Please remember that the meaning of "$" sign is overloaded in such syntax. I described this in the previous post in details: http://muranohints.blogspot.com/2015/03/murano-couple-words-about-take-and-skip.html
You can also use this function in For loops for filtering lists on the fly:
- For: port
In: $.ports.where($.scope in list(public, host))
Do: - $.doSomethingWithIt($port)
Enjoy!
No comments:
Post a Comment