---
heat_template_version: newton

description: >
  This is for multinode
parameters:
  key_name:
    type: string
    description: Name of keypair to assign to servers
  image:
    type: string
    description: Name of image to use for servers
  public_net_name:
    type: string
    description: >
      ID or name of public network for which floating IP addresses will be allocated
  private_net_name:
    type: string
    description: Name of private network to be created
  private_net_cidr:
    type: string
    description: Private network address (CIDR notation)
  private_net_gateway:
    type: string
    description: Private network gateway address
  private_net_pool_start:
    type: string
    description: Start of private network IP address allocation pool
  private_net_pool_end:
    type: string
    description: End of private network IP address allocation pool
  subnode_flavor:
    type: string
    description: Flavor for subnode node
  subnode_count:
    type: string
    description: How many subnodes

resources:

  private_net:
    type: OS::Neutron::Net
    properties:
      name: {get_param: private_net_name}

  private_subnet:
    type: OS::Neutron::Subnet
    properties:
      network_id: {get_resource: private_net}
      cidr: {get_param: private_net_cidr}
      gateway_ip: {get_param: private_net_gateway}
      allocation_pools:
        - start: {get_param: private_net_pool_start}
          end: {get_param: private_net_pool_end}

  router:
    type: OS::Neutron::Router
    properties:
      external_gateway_info:
        network: {get_param: public_net_name}

  router_interface:
    type: OS::Neutron::RouterInterface
    properties:
      router_id: {get_resource: router}
      subnet_id: {get_resource: private_subnet}


  server_security_group:
    type: OS::Neutron::SecurityGroup
    properties:
      description: Add security group rules for server
      name: subnode_security_group
      rules:
        - remote_ip_prefix: 0.0.0.0/0
          protocol: tcp
          port_range_min: 22
          port_range_max: 22
        - remote_ip_prefix: 0.0.0.0/0
          protocol: icmp
        - remote_ip_prefix: 0.0.0.0/0
          protocol: udp
          port_range_min: 4789
          port_range_max: 4789

  subnodes:
    type: OS::Heat::ResourceGroup
    depends_on: router_interface
    properties:
      count: {get_param: subnode_count}
      resource_def:
        type: "{{ local_working_dir }}/subnode.yaml"
        properties:
          name: "{{ prefix }}subnode-%index%"
          private_net: {get_resource: private_net}
          private_subnet: {get_resource: private_subnet}
          server_security_group: {get_resource: server_security_group}
          subnode_flavor: {get_param: subnode_flavor}
          public_net_name: {get_param: public_net_name}
          key_name: {get_param: key_name}
          image: {get_param: image}

outputs:
  subnode_ip_pairs:
    value: {get_attr: [subnodes, subnode_ip_pair]}
