# A static class to set up a shared network. Should appear on the
# controller node. It sets up the public network, a private network,
# two subnets (one for admin, one for test), and the routers that
# connect the subnets to the public network.
#
# After this class has run, you should have a functional network
# avaiable for your test user to launch and connect machines to.
class iaas::setup::sharednetwork (

##Variable definition
 $external_network = hiera('iaas::profile::neutron::external_network', undef),
 $gateway  = hiera('iaas::profile::neutron::external_gateway', undef),
 $dns      = hiera('iaas::profile::base::dns_servers', undef),
 $start_ip = hiera('iaas::profile::neutron::network_external_ippool_start', undef),
 $end_ip   = hiera('iaas::profile::neutron::network_external_ippool_end', undef),
 $private_network =  hiera('iaas::profile::neutron::network_neutron_private', undef),
) {

$ip_range = "start=${start_ip},end=${end_ip}"

  neutron_network { 'public':
    tenant_name              => 'admin',
    provider_network_type    => 'flat',
    router_external          => true,
    provider_physical_network => 'external',
    shared                   => false,
  } ->

  neutron_subnet { $external_network:
    cidr             => $external_network,
    ip_version       => '4',
    gateway_ip       => $gateway,
    enable_dhcp      => false,
    network_name     => 'public',
    tenant_name      => 'admin',
    allocation_pools => [$ip_range],
    dns_nameservers  => [$dns],
  }

  neutron_network { 'private':
    tenant_name              => 'test',
    provider_network_type    => 'gre',
    router_external          => false,
    shared                   => false,
  } ->

  neutron_subnet { $private_network:
    cidr            => $private_network,
    ip_version      => '4',
    enable_dhcp     => true,
    network_name    => 'private',
    tenant_name     => 'test',
    dns_nameservers => [$dns],
  }

# router setup for the tenant test
  iaas::setup::router { "test:${private_network}": }
}