heat_template_version: 2013-05-23

description: sample

parameters:
  floating_id:
    type: string
    description: ID reseau public
    default: 77e7bded-b920-41c0-91b6-579c4a8e6b32

  internal_cidr:
    type: string
    description: CIDR for the internal net
    default: "10.42.42.0/24"

  key_name:
    type: string
    description: SSH key to deploy in instances
    default: mgaigniere

  image:
    type: string
    description: Glance image to use
    default: "CentOS7"

  flavor:
    type: string
    description: Flavor to use
    default: m1.large


resources:
  internal_net:
    type: OS::Neutron::Net

  internal_snet:
    type: OS::Neutron::Subnet
    properties:
      cidr: { get_param: internal_cidr }
      network_id: { get_resource: internal_net }

  router:
    type: OS::Neutron::Router
    properties:
      external_gateway_info:
        enable_snat: true
        network: { get_param: floating_id }

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


#########################################
# CONTROLLER 0
#########################################

  port_cntl0:
    type: OS::Neutron::Port
    properties:
      network: { get_resource: internal_net }
      security_groups:
        - openbar
      allowed_address_pairs:
        - { ip_address: "10.42.42.9" }
      fixed_ips:
        - { ip_address: "10.42.42.20" }

  floating_ip_cntl0:
    type: OS::Neutron::FloatingIP
    properties:
      floating_network_id: { get_param: floating_id }
      port_id: { get_resource: port_cntl0 }

  controller0:
    type: OS::Nova::Server
    depends_on: [router_interface]
    properties:
      image: { get_param: image }
      flavor: { get_param: flavor }
      key_name: { get_param: key_name }
      networks:
        - port: { get_resource: port_cntl0 }


#########################################
# CONTROLLER 1
#########################################

  port_cntl1:
    type: OS::Neutron::Port
    properties:
      network: { get_resource: internal_net }
      security_groups:
        - openbar
      allowed_address_pairs:
        - { ip_address: "10.42.42.9" }
      fixed_ips:
        - { ip_address: "10.42.42.21" }

  floating_ip_cntl1:
    type: OS::Neutron::FloatingIP
    properties:
      floating_network_id: { get_param: floating_id }
      port_id: { get_resource: port_cntl1 }

  controller1:
    type: OS::Nova::Server
    depends_on: [router_interface]
    properties:
      image: { get_param: image }
      flavor: { get_param: flavor }
      key_name: { get_param: key_name }
      networks:
        - port: { get_resource: port_cntl1 }


#########################################
# COMPUTE
#########################################

  port_compute:
    type: OS::Neutron::Port
    properties:
      network: { get_resource: internal_net }
      security_groups:
        - openbar
      fixed_ips:
        - { ip_address: "10.42.42.22" }

  floating_ip_compute:
    type: OS::Neutron::FloatingIP
    properties:
      floating_network_id: { get_param: floating_id }
      port_id: { get_resource: port_compute }

  compute:
    type: OS::Nova::Server
    depends_on: [router_interface]
    properties:
      image: { get_param: image }
      flavor: { get_param: flavor }
      key_name: { get_param: key_name }
      networks:
        - port: { get_resource: port_compute }

  volume_compute:
    type: OS::Cinder::Volume
    properties:
      name: volume_compute
      size: 5

  volume_compute_attachment:
    type: OS::Cinder::VolumeAttachment
    properties:
      volume_id: { get_resource: volume_compute }
      instance_uuid: { get_resource: compute }
      mountpoint: /dev/vdb


#########################################
# VIP keepalived
#########################################

  port_vip:
    type: OS::Neutron::Port
    properties:
      network: { get_resource: internal_net }
      security_groups:
        - openbar
      fixed_ips:
        - { ip_address: "10.42.42.5" }

  floating_ip_vip:
    type: OS::Neutron::FloatingIP
    properties:
      floating_network_id: { get_param: floating_id }
      port_id: { get_resource: port_vip }


# Commandes additionnelles :
# neutron port-create --fixed-ip ip_address=10.42.42.9 --security-group openbar ocata-centos-internal_net-vn6u3ep6f5jc
# neutron floatingip-create --port-id=8987c120-285d-4c6e-ab83-342c805d0382 public
#
# Lister les ports : neutron port-list --network-id=2020a3f0-53da-455f-b387-e2a1d2b0be33 | grep -e fip- -e fip2
#
# Pour chaque port faire : neutron port-update 652e47e9-f082-4a8c-9695-1ff69f19b1e7 --allowed_address_pairs list=true type=dict ip_address=10.42.42.9
