Jump to: navigation, search

Difference between revisions of "Heat Mistral resources usage examples"

(1. Create workflow template file nova_actions.yaml . This workflow allows to create nova server.)
Line 3: Line 3:
 
=== 1. Create workflow template file nova_actions.yaml . This workflow allows to create nova server. ===
 
=== 1. Create workflow template file nova_actions.yaml . This workflow allows to create nova server. ===
  
---
+
  ---
version: '2.0'
+
  version: '2.0'
create_vm:
+
  create_vm:
  type: direct
+
    type: direct
  input:
+
    input:
    - vm_name
+
      - vm_name
    - image_ref
+
      - image_ref
    - flavor_ref
+
      - flavor_ref
  output:
+
    output:
    vm_id: $.vm_id
+
      vm_id: $.vm_id
  tasks:
+
    tasks:
    create_server:
+
      create_server:
      action: nova.servers_create name={$.vm_name} image={$.image_ref} flavor={$.flavor_ref}
+
        action: nova.servers_create name={$.vm_name} image={$.image_ref} flavor={$.flavor_ref}
      publish:
+
        publish:
        vm_id: $.id
+
          vm_id: $.id
      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}
      publish:
+
        publish:
        server_exists: True
+
          server_exists: True
      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'
      policies:
+
        policies:
        retry:
+
          retry:
          delay: 5
+
            delay: 5
          count: 15
+
            count: 15
 
 
  
 
=== 2. Create template with OS::Mistral::Workflow and OS::Mistral::CronTrigger resources (template.yaml). ===
 
=== 2. Create template with OS::Mistral::Workflow and OS::Mistral::CronTrigger resources (template.yaml). ===

Revision as of 08:50, 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 | +----------------------------+--------------+--------------------------+---------------------+---------------------+------------+