From b7626aa140e511be18892f458b7d7a28dd9ef0fb Mon Sep 17 00:00:00 2001 From: Steve McLellan Date: Wed, 7 May 2014 12:34:43 -0500 Subject: [PATCH] Use HOT instead of CFN heat template format New Heaet features will get added to HOT but possibly not the older CFN format, and it's easier to make the change now than later. The only code change is in heat_stack to look for 'resources' instead of 'Resources'; all other changes are to the Heat template sections within PL class definitions. Keys are lower-cased and in some cases changed to match HOT (e.g. key_name instead of KeyName), and sections specifying Heat resources add heat_template_version to the template. Implements blueprint replace-cfn-templates-with-hot Change-Id: If4d34cd25a4e964d7555fedf218512d5c0f5615c --- .../Classes/NewNetwork.yaml | 70 ++++++++++--------- .../Classes/SecurityGroupManager.yaml | 13 ++-- .../io.murano/Classes/resources/Instance.yaml | 22 +++--- muranoapi/engine/system/heat_stack.py | 8 ++- 4 files changed, 61 insertions(+), 52 deletions(-) diff --git a/meta/io.murano.lib.networks.Neutron/Classes/NewNetwork.yaml b/meta/io.murano.lib.networks.Neutron/Classes/NewNetwork.yaml index 715b783e6..3c124dcfd 100644 --- a/meta/io.murano.lib.networks.Neutron/Classes/NewNetwork.yaml +++ b/meta/io.murano.lib.networks.Neutron/Classes/NewNetwork.yaml @@ -61,18 +61,19 @@ Workflow: - $.ensureNetworkConfigured() - $portname: $instance.name + '-port-to-' + $.id() - $template: - Resources: + heat_template_version: '2013-05-23' + resources: $portname: - Type: 'OS::Neutron::Port' - Properties: - network_id: {Ref: $.net_res_name} - fixed_ips: [{subnet_id: {Ref: $.subnet_res_name}}] + type: 'OS::Neutron::Port' + properties: + network_id: { get_resource: $.net_res_name } + fixed_ips: [{ subnet_id: { get_resource: $.subnet_res_name } }] security_groups: - - Ref: $securityGroupName + - get_resource: $securityGroupName $instance.name: - Properties: - NetworkInterfaces: - - Ref: $portname + properties: + networks: + - port: { get_resource: $portname } - $.environment.stack.updateTemplate($template) - If: $assignFloatingIp @@ -82,25 +83,23 @@ Workflow: Then: - $fip_name: $instance.name + '-FloatingIP-' + $.id() - $template: - Resources: + resources: $fip_name: - Type: 'OS::Neutron::FloatingIP' - Properties: + type: 'OS::Neutron::FloatingIP' + properties: floating_network_id: $extNetId $instance.name + '-FloatingIpAssoc-' + $.id(): - Type: 'OS::Neutron::FloatingIPAssociation' - Properties: + type: 'OS::Neutron::FloatingIPAssociation' + properties: floatingip_id: - Ref: $fip_name + get_resource: $fip_name port_id: - Ref: $portname - Outputs: + get_resource: $portname + outputs: $instance.name + '-FloatingIPaddress': - Value: - Fn::GetAtt: - - $fip_name - - floating_ip_address - Description: Floating IP assigned + value: + get_attr: [$fip_name, floating_ip_address] + description: Floating IP assigned - $.environment.stack.updateTemplate($template) ensureNetworkConfigured: @@ -132,33 +131,36 @@ Workflow: createNetwork: Body: - $template: - Resources: + heat_template_version: '2013-05-23' + resources: $.net_res_name: - Type: 'OS::Neutron::Net' - Properties: + type: 'OS::Neutron::Net' + properties: name: $.name - $.environment.stack.updateTemplate($template) createSubnet: Body: - $template: - Resources: + heat_template_version: '2013-05-23' + resources: $.subnet_res_name: - Type: 'OS::Neutron::Subnet' - Properties: - network_id: {Ref: $.net_res_name} + type: 'OS::Neutron::Subnet' + properties: + network_id: { get_resource: $.net_res_name } ip_version: 4 - dns_nameservers: [$.dnsNameserver] + dns_nameservers: [ $.dnsNameserver ] cidr: $.subnetCidr - $.environment.stack.updateTemplate($template) createRouterInterface: Body: - $template: - Resources: + heat_template_version: '2013-05-23' + resources: $.name + '-ri-' + $.id(): - Type: 'OS::Neutron::RouterInterface' - Properties: + type: 'OS::Neutron::RouterInterface' + properties: router_id: $.externalRouterId - subnet_id: {Ref: $.subnet_res_name} + subnet_id: { get_resource: $.subnet_res_name } - $.environment.stack.updateTemplate($template) diff --git a/meta/io.murano/Classes/SecurityGroupManager.yaml b/meta/io.murano/Classes/SecurityGroupManager.yaml index 5256ea282..fc389dfd3 100644 --- a/meta/io.murano/Classes/SecurityGroupManager.yaml +++ b/meta/io.murano/Classes/SecurityGroupManager.yaml @@ -36,10 +36,11 @@ Workflow: - $stack: $.environment.stack - $template: - Resources: + heat_template_version: '2013-05-23' + resources: $groupName: - Type: 'OS::Neutron::SecurityGroup' - Properties: + type: 'OS::Neutron::SecurityGroup' + properties: description: format('Composite security group of Murano environment {0}', $.environment.name) rules: - port_range_min: null @@ -56,10 +57,10 @@ Workflow: )) - $template: - Resources: + resources: $groupName: - Type: 'OS::Neutron::SecurityGroup' - Properties: + type: 'OS::Neutron::SecurityGroup' + properties: rules: $ingress - $.environment.stack.updateTemplate($template) diff --git a/meta/io.murano/Classes/resources/Instance.yaml b/meta/io.murano/Classes/resources/Instance.yaml index 0526cc5d4..64a1260f3 100644 --- a/meta/io.murano/Classes/resources/Instance.yaml +++ b/meta/io.murano/Classes/resources/Instance.yaml @@ -69,20 +69,22 @@ Workflow: - $userData: $.prepareUserData() - $template: - Resources: + heat_template_version: '2013-05-23' + resources: $.name: - Type: 'AWS::EC2::Instance' - Properties: - InstanceType: $.flavor - ImageId: $.image - UserData: $userData - KeyName: $.keyname + type: 'OS::Nova::Server' + properties: + flavor: $.flavor + image: $.image + user_data: $userData + key_name: $.keyname - Outputs: + outputs: format('{0}-PublicIp', $.name): - Value: - - Fn::GetAtt: [$.name, PublicIp] + description: format('Public IP assigned to {0} instance', $.name) + value: + get_attr: [$.name, PublicIp] - $.environment.stack.updateTemplate($template) - $.environment.stack.push() - $outputs: $.environment.stack.output() diff --git a/muranoapi/engine/system/heat_stack.py b/muranoapi/engine/system/heat_stack.py index 0b115ea02..c870f1293 100644 --- a/muranoapi/engine/system/heat_stack.py +++ b/muranoapi/engine/system/heat_stack.py @@ -165,7 +165,9 @@ class HeatStack(murano_object.MuranoObject): current_status = self._get_status() if current_status == 'NOT_FOUND': - if self._template.get('Resources'): + # For now, allow older CFN style templates as well, but this + # should be removed to avoid mixing them + if 'resources' in self._template or 'Resources' in self._template: self._heat_client.stacks.create( stack_name=self._name, parameters=self._parameters, @@ -175,7 +177,9 @@ class HeatStack(murano_object.MuranoObject): self._wait_state( lambda status: status == 'CREATE_COMPLETE') else: - if self._template.get('Resources'): + # For now, allow older CFN style templates as well, but this + # should be removed to avoid mixing them + if 'resources' in self._template or 'Resources' in self._template: self._heat_client.stacks.update( stack_id=self._name, parameters=self._parameters,