Showing posts with label dsl. Show all posts
Showing posts with label dsl. Show all posts

Friday, March 27, 2015

Murano: Filtering complex structures

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!

Thursday, March 26, 2015

Murano: Sequential or parallel execution

Select, or pselect, that is the question -


Yeah, sometime application developer has almost Hamlet level questions. Murano engine can execute workflows in parallel mode which is actually a default behavior.  If there are several application configured in a Murano environment all of them will deploy them-self in parallel if there is no special dependency handling in the workflow.

Another example is a cluster creation. When cluster has a list of instances which are all identical it makes sense to provision them simultaneously. Sometime there is a use case when you need to process instances one by one, for example in order to register slave on the master node.

There are two functions in Murano which handles both use cases.
List.select($.deploy()) will generate a sequence of executions of deploy method of each element in the list. It is equivalent to the for loop:
- For: inst
  In: $.instances.take($.currentCount)
  Do:    - $inst.deploy()

In contrary, List.pselect($.deploy()) will initiate a parallel execution of deploy() method on each element of the list.

- $.instances.take($.currentCount).pselect($.deploy())

Please, note that "$" has overloaded usage here. If you use select or pselect then a "$" will represent the element of a list.  If you want to call a method of the current class which will take list element as a parameter you will have to use full form of $this rather then $ like in example below:

- $.instances.take($.currentCount).pselect($this.configureKubeMinion($))
 In this example current class ($this) method configureKubernetesMinion() will be called for each element of the list instances with the element passed as an argument of the method configureKubernetesMinion($)

Enjoy !

Tuesday, March 24, 2015

Murano: Two ways of using Heat HOT snippets in Murano workflow

Murano uses Heat to orchestrate resource provisioning. How can I do this explicitly?

Murano is an Application catalog and it uses underlying orchestration layers to do actual provision for OpenStack resources and software components. Heat is a primary engine which is used to provision OpenStack infrastructure level resources. It can be also used for software provisioning via Heat Software Configs.
Most of the time, resource provisioning is hidden from the application writer by Murano Core library, where all standard resources are wrapped with Murano classes. In case, your application uses your own custom Heat resource you will need to create a workflow in Murano to provision it for your application. Murano provides two easy way to do this. The first way is to embed HOT snippet directly to the Murano workflow. Both Murano and Heat use YAML format, so this embedding will look naturally. Here is an example for a Cinder volume:

- $.environment.reporter.report($this, 'Creating a new volume ')
- $volumename: ('vol_'+$.name)
- $template:
    resources:
      $volumename:
         type: OS::Cinder::Volume
         properties:
           size: $.size            
         description: Volume for stack
- $.environment.stack.updateTemplate($template)
- $.environment.stack.push()

In this example we have a local variable $template which contains HOT resource definition for a Cinder volume resource. Please, make sure you have "resources" as a top level entry for this HOT snippet. It points to the section of the final HOT template where this new resource will be placed.
$volumename here is a local variable which contains a name of the resource. It uses class property $.name to generate a unique name for the resource as there might be multiple volumes created for different VMs. $.name property has a value entered by a user in the UI.

$.environment.stack is a reference for the Heat stack object which contains and manages Heat template which was generated for the Murano environment and updateTemplate is a method which updates a stack template with a new HOT snippet. You still need to push changes of the stack by invoking stack.push() method which will trigger Heat stack update API call.


Another way to use HOT snippets is to keep them as a separate files under Resources folder of the package definition.  There is a way to load these resources in runtime and store them in the local variable. Here is an example:

- $.environment.reporter.report($this, 'Attaching the volume 
                                        to the VM')
- $resources: new(sys:Resources)
- $volumename: ('vol_'+$.name)
- $template: $resources.yaml('attach-volume.hot').bind(dict(
     name => $.name,
     volumename => $volumename,
     instance_name => $instance.name
    ))
- $.environment.stack.updateTemplate($template)
- $.environment.stack.push()

$resources class provides an access to the content of Resource folder of an application definition. "attach-volume.hot" is a file with HOT template snippet which is also parametrized with name, volumename and instance_name parameters which reflects actual resource names for existing or previously created resources. Here is a content of the "attach-volume.hot" file:
resources:
volume_attachment_$name:
type: OS::Cinder::VolumeAttachment
properties:
volume_id: { get_resource: $volumename }
instance_uuid: { get_resource: $instance_name}

Once this snippet is loaded and all parameters are bound to the snippet via .bind() method the $template local variable will contain final version of the snippet with actual resource names. After that we proceed with stack update in the same way we did in the first example via stack.updateTemplate() and stack.push().


Happy coding with Murano!