Jump to: navigation, search

Difference between revisions of "Heat Mistral resources usage examples"

Line 5: Line 5:
 
---
 
---
 
version: '2.0'
 
version: '2.0'
 
 
create_vm:
 
create_vm:
 
   type: direct
 
   type: direct
Line 14: Line 13:
 
   output:
 
   output:
 
     vm_id: $.vm_id
 
     vm_id: $.vm_id
 
 
   tasks:
 
   tasks:
 
     create_server:
 
     create_server:
Line 22: Line 20:
 
       on-success:
 
       on-success:
 
         - check_server_exists
 
         - check_server_exists
 
 
     check_server_exists:
 
     check_server_exists:
 
       action: nova.servers_get server={$.vm_id}
 
       action: nova.servers_get server={$.vm_id}
Line 29: Line 26:
 
       on-success:
 
       on-success:
 
         - wait_instance
 
         - wait_instance
 
 
     wait_instance:
 
     wait_instance:
 
       action: nova.servers_find id={$.vm_id} status='ACTIVE'
 
       action: nova.servers_find id={$.vm_id} status='ACTIVE'
Line 41: Line 37:
  
 
heat_template_version: 2013-05-23
 
heat_template_version: 2013-05-23
 
 
parameters:
 
parameters:
 
   cron_pattern:
 
   cron_pattern:
 
     type: string
 
     type: string
 
     default: '54 15 25 * *'
 
     default: '54 15 25 * *'
 
 
resources:
 
resources:
 
   workflow:
 
   workflow:
Line 53: Line 47:
 
       definition: { get_file: nova_actions.yaml }
 
       definition: { get_file: nova_actions.yaml }
 
       input: {"vm_name": "test_vm", "image_ref": "64200b6e-9c5e-46d7-a373-676e1335eb24", "flavor_ref": "84"}
 
       input: {"vm_name": "test_vm", "image_ref": "64200b6e-9c5e-46d7-a373-676e1335eb24", "flavor_ref": "84"}
 
 
   trigger:
 
   trigger:
 
     type: OS::Mistral::CronTrigger
 
     type: OS::Mistral::CronTrigger
Line 59: Line 52:
 
       pattern: { get_param: cron_pattern }
 
       pattern: { get_param: cron_pattern }
 
       workflow: { get_attr: [workflow, available_workflows, create_vm] }
 
       workflow: { get_attr: [workflow, available_workflows, create_vm] }
 
 
outputs:
 
outputs:
 
   execution_time:
 
   execution_time:
 
     value: { get_attr: [trigger, next_execution_time] }
 
     value: { get_attr: [trigger, next_execution_time] }
 
  
  

Revision as of 08:48, 26 February 2015

Case 1: Creating resources using Heat template and check that they are available in Mistral service.

1. Create workflow template file nova_actions.yaml . This workflow allows to create nova server.

--- version: '2.0' create_vm:

 type: direct
 input:
   - vm_name
   - image_ref
   - flavor_ref
 output:
   vm_id: $.vm_id
 tasks:
   create_server:
     action: nova.servers_create name={$.vm_name} image={$.image_ref} flavor={$.flavor_ref}
     publish:
       vm_id: $.id
     on-success:
       - check_server_exists
   check_server_exists:
     action: nova.servers_get server={$.vm_id}
     publish:
       server_exists: True
     on-success:
       - wait_instance
   wait_instance:
     action: nova.servers_find id={$.vm_id} status='ACTIVE'
     policies:
       retry:
         delay: 5
         count: 15


2. Create template with OS::Mistral::Workflow and OS::Mistral::CronTrigger resources (template.yaml).

heat_template_version: 2013-05-23 parameters:

 cron_pattern:
   type: string
   default: '54 15 25 * *'

resources:

 workflow:
   type: OS::Mistral::Workflow
   properties:
     definition: { get_file: nova_actions.yaml }
     input: {"vm_name": "test_vm", "image_ref": "64200b6e-9c5e-46d7-a373-676e1335eb24", "flavor_ref": "84"}
 trigger:
   type: OS::Mistral::CronTrigger
   properties:
     pattern: { get_param: cron_pattern }
     workflow: { get_attr: [workflow, available_workflows, create_vm] }

outputs:

 execution_time:
   value: { get_attr: [trigger, next_execution_time] }


3. Create stack.

heat stack-create test1 -f template.yaml

4. Check that resources were created in Mistral.

mistral workflow-list

+--------------------------+--------+------------------------------+---------------------+------------+ | Name | Tags | Input | Created at | Updated at | +--------------------------+--------+------------------------------+---------------------+------------+ | std.create_instance | <none> | name, image_id, flavor_id... | 2015-01-26 00:00:49 | None | | std.delete_instance | <none> | instance_id | 2015-01-26 00:00:49 | None | | test1.workflow.create_vm | <none> | vm_name, image_ref, flavo... | 2015-01-26 22:04:12 | None | +--------------------------+--------+------------------------------+---------------------+------------+

mistral cron-trigger-list

+----------------------------+--------------+--------------------------+---------------------+---------------------+------------+ | Name | Pattern | Workflow | Next execution time | Created at | Updated at | +----------------------------+--------------+--------------------------+---------------------+---------------------+------------+ | test1-trigger-kqetnotnmvsx | 54 15 25 * * | test1.workflow.create_vm | 2015-02-25 15:54:00 | 2015-01-26 22:04:25 | None | +----------------------------+--------------+--------------------------+---------------------+---------------------+------------+