1 .. Licensed under a Creative Commons Attribution 4.0 International License.
2 .. http://creativecommons.org/licenses/by/4.0
3 .. Copyright 2017 AT&T Intellectual Property. All rights reserved.
5 .. _ONAP Heat Heat Template Constructs:
7 ONAP Heat Heat Template Constructs
8 --------------------------------------
10 .. _Nested Heat Templates:
13 ^^^^^^^^^^^^^^^^^^^^^^^^^
15 ONAP supports nested Heat templates per the OpenStack specifications.
16 Nested templates may be suitable for larger VNFs that contain many
17 repeated instances of the same VM type(s). A common usage pattern is to
18 create a nested template for each {vm-type} along with its supporting
19 resources. The VNF module may then reference these component templates
20 either statically by repeated definition or dynamically by using the
21 resource OS::Heat::ResourceGroup.
23 Nested Heat Template Requirements
24 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26 ONAP supports nested Heat Orchestration Templates. A Base Module,
27 Incremental Module, and Cinder Volume Module may use nested heat.
35 A VNF's Heat Orchestration Template **MAY**
36 reference the nested heat statically by repeated definition.
43 A VNF's Heat Orchestration Template **MAY**
44 reference the nested heat dynamically using the resource
45 'OS::Heat::ResourceGroup'.
52 A VNF's Heat Orchestration Template **MUST** have no more than
53 two levels of nesting.
55 As stated in :need:`R-67231` a VNF's Heat Orchestration template's
56 Environment File's **MUST NOT** contain the "resource_registry:" section.
58 Two levels of nesting is defined as follows: A base module, incremental
59 module, or cinder volume module references a nested heat file either
60 statically or by using the resource 'OS::Heat::ResourceGroup'.
61 This file is the first level of nesting.
62 If first level file then references a nested file, that file is
63 the second level of nesting.
71 The VNF Heat Orchestration Template **MUST** have unique
72 file names within the scope of the VNF for a nested heat yaml file.
79 A VNF's Heat Orchestration Template's Nested YAML file
80 **MUST** be in the same directory hierarchy as the VNF's Heat
81 Orchestration Templates.
88 A VNF's Nested YAML file **MAY** be invoked more than
89 once by a VNF's Heat Orchestration Template.
96 A VNF's Nested YAML file **MAY** be invoked by more than one of
97 a VNF's Heat Orchestration Templates (when the VNF is composed of two
98 or more Heat Orchestration Templates).
105 All parameters defined in a VNFs Nested YAML file
106 **MUST** be passed in as properties of the resource calling
107 the nested yaml file.
111 - As stated in requirement :need:`R-00011`, a VNF's Heat Orchestration
112 Template's Nested YAML file's parameter's **MUST NOT** have
113 a parameter constraint defined.
115 - As stated in Requirement :need:`R-44491`, if a VNF's Heat Orchestration
116 Template's OS::Nova::Server Resource metadata map value parameter
117 'vnf\_id' is passed into a Nested YAML
118 file, the parameter name 'vnf\_id' **MUST NOT** change.
120 - As stated in Requirement :need:`R-86237`, if a VNF's Heat Orchestration
121 Template's OS::Nova::Server Resource metadata map value parameter
122 'vf\_module\_id' is passed into a Nested YAML
123 file, the parameter name 'vf\_module\_id' **MUST NOT** change.
125 - As stated in Requirement :need:`R-16576`, if a VNF's Heat Orchestration
126 Template's OS::Nova::Server Resource metadata map value parameter
127 'vnf\_name' is passed into a Nested YAML
128 file, the parameter name 'vnf\_name' **MUST NOT** change.
130 - As stated in Requirement :need:`R-49177`, if a VNF's Heat Orchestration
131 Template's OS::Nova::Server Resource metadata map value parameter
132 'vf\_module\_name' is passed into a Nested YAML
133 file, the parameter name 'vf\_module\_name' **MUST NOT** change.
135 - As stated in Requirement :need:`R-70757`, if a VNF's Heat Orchestration
136 Template's OS::Nova::Server Resource metadata map value parameter
137 'vm\_role' is passed into a Nested YAML
138 file, the parameter name 'vm\_role' **MUST NOT** change.
140 - As stated in Requirement :need:`R-22441`, if a VNF's Heat Orchestration
141 Template's OS::Nova::Server Resource metadata map value parameter
142 'vf\_module\_index' is passed into a Nested YAML
143 file, the parameter name 'vf\_module\_index' **MUST NOT** change.
145 - As stated in Requirement :need:`R-75202`, if a VNF's Heat Orchestration
146 Template's OS::Nova::Server Resource metadata map value parameter
147 'workload\_context' is passed into a Nested YAML
148 file, the parameter name 'workload\_context' **MUST NOT** change.
150 - As stated in Requirement :need:`R-62954`, if a VNF's Heat Orchestration
151 Template's OS::Nova::Server Resource metadata map value parameter
152 'environment\_context' is passed into a Nested YAML
153 file, the parameter name 'environment\_context' **MUST NOT** change.
155 - With nested templates, outputs are required to expose any resource
156 properties of the child templates to the parent template. Those would
157 not explicitly be declared as parameters but simply referenced as
158 get\_attribute targets against the "parent" resource.
160 - A parameter declared in the outputs: section of a nested template can
161 be accessed from the parent template as an attribute (i.e., via
162 get\_attr) of the "pseudo resource" whose type is in the nested
163 template. In the case of a OS::Heat::ResourceGroup, an output will be
164 an attribute of the OS::Heat::ResourceGroup itself, and will be an
165 array from the perspective of the parent template.
172 A VNF's Heat Orchestration Template's first level Nested YAML file
173 **MUST NOT** contain more than one ``OS::Nova::Server`` resource.
174 A VNF's Heat Orchestration Template's second level Nested YAML file
175 **MUST NOT** contain an ``OS::Nova::Server`` resource.
177 Nested Heat Template Example: Static
178 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
188 dns_image_name: { get_param: dns_image_name }
189 dns_flavor_name: { get_param: dns_flavor_name }
190 availability_zone: { get_param: availability_zone_0 }
191 security_group: { get_param: DNS_shared_sec_grp_id }
192 oam_net_id: { get_param: oam_protected_net_id }
193 dns_oam_ip: { get_param: dns_oam_ip_0 }
194 dns_name: { get_param: dns_name_0 }
195 vnf_name: { get_param: vnf_name }
196 vnf_id: { get_param: vnf_id }
197 vf_module_id: {get_param: vf_module_id}
202 dns_image_name: { get_param: dns_image_name }
203 dns_flavor_name: { get_param: dns_flavor_name }
204 availability_zone: { get_param: availability_zone_1 }
205 security_group: { get_param: DNS_shared_sec_grp_id }
206 oam_net_id: { get_param: oam_protected_net_id }
207 dns_oam_ip: { get_param: dns_oam_ip_1 }
208 dns_name: { get_param: dns_name_1 }
209 vnf_name: { get_param: vnf_name }
210 vnf_id: { get_param: vnf_id }
211 vf_module_id: {get_param: vf_module_id}
218 type: OS::Neutron::Port
222 template: VNF_NAME_dns_oam_port
224 VNF_NAME: {get_param: vnf_name}
225 network: { get_param: oam_net_id }
226 fixed_ips: [{ "ip_address": { get_param: dns_oam_ip }}]
227 security_groups: [{ get_param: security_group }]
230 type: OS::Nova::Server
232 name: { get_param: dns_names }
233 image: { get_param: dns_image_name }
234 flavor: { get_param: dns_flavor_name }
235 availability_zone: { get_param: availability_zone }
237 - port: { get_resource: dns_oam_0_port }
239 vnf_id: { get_param: vnf_id }
240 vf_module_id: { get_param: vf_module_id }
241 vnf_name {get_param: vnf_name }
243 Use of Heat ResourceGroup
244 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
246 The OS::Heat::ResourceGroup is a useful Heat element for creating
247 multiple instances of a given resource or collection of resources.
248 Typically, it is used with a nested Heat template, to create, for
249 example, a set of identical OS::Nova::Server resources plus their
250 related OS::Neutron::Port resources via a single resource in a master
253 OS::Heat::ResourceGroup may be used to simplify the structure of a Heat
254 template that creates multiple instances of the same VM type.
256 However, there are important caveats to be aware of:
258 OS::Heat::ResourceGroup does not deal with structured parameters
259 (comma-delimited-list and json) as one might typically expect. In
260 particular, when using a list-based parameter, where each list element
261 corresponds to one instance of the ResourceGroup, it is not possible to
262 use the intrinsic "loop variable" %index% in the OS::Heat::ResourceGroup
265 For instance, the following is **not** valid Heat for
266 OS::Heat::ResourceGroup:
270 type: OS::Heat::ResourceGroup
272 type: my_nested_vm_template.yaml
274 name: {get_param: [vm_name_list, "%index%"]}
276 Although this appears to use the nth entry of the vm_name_list list for
277 the nth element of the OS::Heat::ResourceGroup, it will in fact result
278 in a Heat exception. When parameters are provided as a list (one for
279 each element of a OS::Heat::ResourceGroup), you must pass the complete
280 parameter to the nested template along with the current index as
283 Below is an example of an **acceptable** Heat Syntax for a
288 type: OS::Heat::ResourceGroup
290 type: my_nested_vm_template.yaml
292 names: {get_param: vm_name_list}
295 You can then reference within the nested template as:
297 { get\_param: [names, {get\_param: index} ] }
299 OS::Heat::ResourceGroup Property count
300 ++++++++++++++++++++++++++++++++++++++++
308 A VNF's Heat Orchestration Template's 'OS::Heat::ResourceGroup'
309 property 'count' **MUST** be enumerated in the VNF's
310 Heat Orchestration Template's Environment File and **MUST** be
313 This is required for ONAP to build the TOSCA model for the VNF.
317 type: OS::Heat::ResourceGroup
319 count: { get_param: count }
322 type: my_nested_vm_template.yaml
324 names: {get_param: vm_name_list}
327 Availability Zone and ResourceGroups
328 ++++++++++++++++++++++++++++++++++++++++
330 The resource OS::Heat::ResourceGroup and the property availability\_zone
331 has been an "issue" with a few VNFs since ONAP only supports
332 availability\_zone as a string parameter and not a
333 comma\_delimited\_list. This makes it difficult to use a
334 OS::Heat::ResourceGroup to create Virtual Machines in more
335 than one availability zone.
337 There are numerous solutions to this issue. Below are two suggested
340 **Option 1:** create a CDL in the OS::Heat::ResourceGroup. In the
341 resource type: OS::Heat::ResourceGroup, create a comma\_delimited\_list
342 availability\_zones by using the intrinsic function list\_join.
347 type: OS::Heat::ResourceGroup
349 count: { get_param: node_count }
355 avaialability_zones: { list_join: [',', [ { get_param: availability_zone_0 }, { get_param: availability_zone_1 } ] ] }
363 type: comma_delimited_list
368 type: OS::Nova::Server
370 name: { get_param: [ dns_names, get_param: index ] }
371 image: { get_param: dns_image_name }
372 flavor: { get_param: dns_flavor_name }
373 availability_zone: { get_param: [ avaialability_zones, get_param: index ] }
375 **Option 2:** Create a CDL by passing the availability zone parameter
376 into a nested heat template. An example is provided below.
382 availability_zone_list:
383 type: az_list_generate.yaml
385 availability_zone_0: { get_param: availability_zone_0 }
386 availability_zone_1: { get_param: availability_zone_1 }
388 create_virtual_machines:
389 type: OS::Heat::ResourceGroup
391 count: { get_param: count }
397 availability_zone_0 : { get_attr: [availability_zone_list, general_zones ] }
400 az_list_generate.yaml
407 description: availability zone 0
411 description: availability zone 1
417 { get_param: availability_zone_0 },
418 { get_param: availability_zone_1 },
419 { get_param: availability_zone_0 },
420 { get_param: availability_zone_1 },
421 { get_param: availability_zone_0 },
422 { get_param: availability_zone_1 },
426 Nested Heat Template Example: OS::Heat::ResourceGroup
427 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
429 In this example, ocgapp\_volume.yml creates volumes using a
430 OS::Heat::ResourceGroup that uses nested heat by calling
431 ocgapp_nested_volume.yml. ocgapp\_volume.yml has an outputs: parameter
432 ocgapp\_volume\_ids which is declared a input parameter of type: json in
436 This is an example of requirement :need:`R-07443`, where
437 a VNF's Heat Orchestration Templates' Cinder Volume Module Output
438 Parameter's name and type **MUST** match the input parameter name and type
439 in the corresponding Base Module or Incremental Module unless the Output
440 Parameter is of the type 'comma\_delimited\_list', then the corresponding
441 input parameter **MUST** be declared as type 'json'.
447 heat_template_version: 2014-10-16
449 description: Template for the volumes
455 description: OCG VNF Name
456 ocgapp_volume_size_0:
458 label: Cinder volume 1 size
459 description: the size of the Cinder volume
461 - range: { min: 100, max: 400 }
462 ocgapp_volume_type_0:
464 label: app vm 1 volume type
465 description: the name of the target volume backend for the first OCG APP
469 description: number of volumes needed
472 ocgapp_volume_resource_group:
473 type: OS::Heat::ResourceGroup
475 count: {get_param: volume_count}
478 type: ocgapp_nested_volume.yml
481 size: {get_param: ocgapp_volume_size_0}
482 volume_type: {get_param: ocgapp_volume_type_0}
483 vnf_name: {get_param: vnf_name}
487 description: ocgapp volume ids
488 value: {get_attr: [ocgapp_volume_resource_group, ocgapp_volume_id_0]}
490 ocgapp_nested_volume.yml
494 heat_template_version: 2014-10-16
496 description: nested heat
502 description: number of volumes to spin up
506 description: size of the cinder volumes
510 description: type of cinder volumes
514 description: vnf name
518 type: OS::Cinder::Volume
520 size: {get_param: size}
521 volume_type: {get_param: volume_type}
524 template: VF_NAME_STACK_NAME_INDEX
526 VF_NAME: { get_param: vnf_name }
527 STACK_NAME: { get_param: 'OS::stack_name' }
528 INDEX: {get_param: index}
532 description: the ocgapp volume uuid
533 value: {get_resource: ocgapp_volume_0}
535 The heat template below is a partial heat template,
541 heat_template_version: 2014-10-16
544 description: OCG Apps template
549 description: Unique IDs for volumes
553 type: OS::Nova::Server
557 type: OS::Nova::Server
560 ocgapp_volume_attachment_0:
561 type: OS::Cinder::VolumeAttachment
563 volume_id: {get_param: [ocgapp_volume_ids, 0]}
564 instance_uuid: {get_resource: ocgapp_server_0}
565 ocgapp_volume_attachment_1:
566 type: OS::Cinder::VolumeAttachment
568 volume_id: {get_param: [ocgapp_volume_ids, 1]}
569 instance_uuid: {get_resource: ocgapp_server_1}
572 ^^^^^^^^^^^^^^^^^^^^^^
574 Heat templates *should not* reference any HTTP-based resource
575 definitions, any HTTP-based nested configurations, or any HTTP-based
578 - During orchestration, ONAP *should not* retrieve any such resources
579 from external/untrusted/unknown sources.
581 - VNF images should not contain such references in user-data or other
582 configuration/operational scripts that are specified via Heat or
583 encoded into the VNF image itself.
585 *Note:* HTTP-based references are acceptable if the HTTP-based reference
586 is accessing information with the VM private/internal network.
588 Note that Namespaces in XML (defined at
589 http://www.w3.org/TR/2009/REC-xml-names-20091208/) are allowed if the
590 Heat Orchestration Template is describing and storing software
591 configuration information. An XML namespace is identified by a URI
592 reference. A Uniform Resource Identifier (URI) is a string of characters
593 which identifies an Internet Resource. The most common URI is the
594 Uniform Resource Locator (URL) which identifies an Internet domain
595 address. Another, not so common type of URI is the Universal Resource
596 Name (URN). The namespace URI is not used by XML the parser to look up
597 information. The purpose of using an URI is to give the namespace a
600 Heat Files Support (get\_file)
601 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
603 Heat Templates may contain the inclusion of text files into Heat
604 templates via the Heat get\_file directive. This may be used, for
605 example, to define a common "user-data" script, or to inject files into
606 a VM on startup via the "personality" property.
608 Support for Heat Files is subject to the following limitations:
616 If a VNF's Heat Orchestration Template uses the intrinsic function
617 'get\_file', the 'get\_file' target **MUST** be referenced in
618 the Heat Orchestration Template by file name.
620 The 'get\_file' target files are on-boarded to SDC in the same package
621 that contains the VNF's complete Heat Orchestration Template.
629 A VNF's Heat Orchestration Template intrinsic function
630 'get\_file' **MUST NOT** utilize URL-based file retrieval.
637 When using the intrinsic function get_file, the included files
638 **MUST** have unique file names within the scope of the VNF.
645 A VNF's Heat Orchestration Template's 'get\_file' target files
646 **MUST** be in the same directory hierarchy as the VNF's Heat
647 Orchestration Templates.
649 ONAP does not support a hierarchical structure. A VNF's YAML files
650 must be in a single, flat directory.
658 A VNF's Heat Orchestration Templates intrinsic function
659 'get\_file' <content key> **MAY** be used:
661 * more than once in a VNF's Heat Orchestration Template
662 * in two or more of a VNF's Heat Orchestration Templates
663 * in a VNF's Heat Orchestration Templates nested YAML file
668 When Nova Servers are created via Heat templates, they may be passed a
669 "keypair" which provides an ssh key to the 'root' login on the newly
670 created VM. This is often done so that an initial root key/password does
671 not need to be hard-coded into the image.
673 Key pairs are unusual in OpenStack, because they are the one resource
674 that is owned by an OpenStack User as opposed to being owned by an
675 OpenStack Tenant. As a result, they are usable only by the User that
676 created the keypair. This causes a problem when a Heat template attempts
677 to reference a keypair by name, because it assumes that the keypair was
678 previously created by a specific ONAP user ID.
680 When a keypair is assigned to a server, the SSH public-key is
681 provisioned on the VMs at instantiation time. They keypair itself is not
682 referenced further by the VM (i.e. if the keypair is updated with a new
683 public key, it would only apply to subsequent VMs created with that
686 Due to this behavior, the recommended usage of keypairs is in a more
687 generic manner which does not require the pre-requisite creation of a
688 keypair. The Heat should be structured in such a way as to:
690 - Pass a public key as a parameter value instead of a keypair name
692 - Create a new keypair within The VNF Heat Orchestration Template (in the
693 base module) based on an existing public key for use within that VNF
695 By following this approach, the end result is the same as pre-creating
696 the keypair using the public key – i.e., that public key will be
697 provisioned in the new VM. However, this recommended approach also makes
698 sure that a known public key is supplied (instead of having OpenStack
699 generate a public/private pair to be saved and tracked outside of ONAP).
700 It also removes any access/ownership issues over the created keypair.
702 The public keys may be enumerated as a VNF Orchestration Constant in the
703 environment file (since it is public, it is not a secret key), or passed
704 at run-time as instance-specific parameters. ONAP will never
705 automatically assign a public/private key pair.
707 *Example (create keypair with an existing ssh public-key for {vm-type}
708 of lb (for load balancer)):*
720 type: OS::Nova::Keypair
724 template: VNF_NAME_key_pair
726 VNF_NAME: { get_param: vnf_name }
727 public_key: {get_param: lb_ssh_public_key}
728 save_private_key: false
733 OpenStack allows a tenant to create Security groups and define rules
734 within the security groups.
736 Security groups, with their rules, may either be created in the Heat
737 Orchestration Template or they can be pre-created in OpenStack and
738 referenced within the Heat template via parameter(s). There can be a
739 different approach for security groups assigned to ports on internal
740 (intra-VNF) networks or external networks (inter-VNF). Furthermore,
741 there can be a common security group across all VMs for a specific
742 network or it can vary by VM (i.e., {vm-type}) and network type (i.e.,
745 Anti-Affinity and Affinity Rules
746 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
748 Anti-affinity or affinity rules are supported using normal OpenStack
749 OS::Nova::ServerGroup resources. Separate ServerGroups are typically
750 created for each VM type to prevent them from residing on the same host,
751 but they can be applied to multiple VM types to extend the
752 affinity/anti-affinity across related VM types as well.
756 In this example, the {network-role} has been defined as oam to represent
757 an oam network and the {vm-type} have been defined as lb for load
758 balancer and db for database.
764 type: OS::Nova::ServerGroup
769 $vnf_name: {get_param: vnf_name}
770 template: $vnf_name-server_group1
775 type: OS::Nova::ServerGroup
780 $vnf_name: {get_param: vnf_name}
781 template: $vnf_name-server_group2
786 type: OS::Nova::Server
790 group: {get_resource: db_server_group}
793 type: OS::Nova::Server
797 group: {get_resource: db_server_group}
800 type: OS::Nova::Server
804 group: {get_resource: lb_server_group}
806 Resource Data Synchronization
807 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
809 For cases where synchronization is required in the orchestration of Heat
810 resources, two approaches are recommended:
812 - Standard Heat depends\_on property for resources
814 - Assures that one resource completes before the dependent resource
817 - Definition of completeness to OpenStack may not be sufficient
818 (e.g., a VM is considered complete by OpenStack when it is ready
819 to be booted, not when the application is up and running).
821 - Use of Heat Notifications
823 - Create OS::Heat::WaitCondition and OS::Heat::WaitConditionHandle
826 - Pre-requisite resources issue *wc\_notify* commands in user\_data.
828 - Dependent resource define depends\_on in the
829 OS::Heat::WaitCondition resource.
831 *Example: "depends\_on" case*
833 In this example, the {network-role} has been defined as oam to represent
834 an oam network and the {vm-type} has been defined as oam to represent an
841 type: OS::Nova::Server
843 name: {get_param: [oam_ names, 0]}
844 image: {get_param: oam_image_name}
845 flavor: {get_param: oam_flavor_name}
846 availability_zone: {get_param: availability_zone_0}
848 - port: {get_resource: oam01_port_0}
849 - port: {get_resource: oam01_port_1}
851 scheduler_hints: {group: {get_resource: oam_servergroup}}
852 user_data_format: RAW
855 type: OS::Neutron::Port
857 network: {get_resource: oam_net_name}
858 fixed_ips: [{"ip_address": {get_param: [oam_oam_net_ips, 1]}}]
859 security_groups: [{get_resource: oam_security_group}]
862 type: OS::Neutron::Port
864 network: {get_param: oam_net_name}
865 fixed_ips: [{"ip_address": {get_param: [oam_oam_net_ips, 2]}}]
866 security_groups: [{get_resource: oam_security_group}]
868 oam_01_vol_attachment:
869 type: OS::Cinder::VolumeAttachment
870 depends_on: oam_server_01
872 volume_id: {get_param: oam_vol_1}
874 instance_uuid: {get_resource: oam_server_01}