From 5b6354a38f6c5988cd38b66a532b63f98aa0c856 Mon Sep 17 00:00:00 2001
From: Alessandro Costantini <alessandro.costantini@cnaf.infn.it>
Date: Tue, 17 Nov 2015 13:15:30 +0000
Subject: [PATCH] Router added for doublemetwork

---
 manifests/profile/neutron/router.pp | 119 ++++++++++++++++++++--------
 manifests/setup/router.pp           |  35 +++++---
 manifests/setup/sharednetwork.pp    |  12 +--
 3 files changed, 120 insertions(+), 46 deletions(-)

diff --git a/manifests/profile/neutron/router.pp b/manifests/profile/neutron/router.pp
index a54121c..9b56338 100644
--- a/manifests/profile/neutron/router.pp
+++ b/manifests/profile/neutron/router.pp
@@ -51,6 +51,8 @@ class iaas::profile::neutron::router (
   }
 
   class { '::neutron::agents::l3':
+#double_external_network
+#    external_network_bridge => 'br-ex',
     external_network_bridge => ' ',
     use_namespaces => true,
     router_delete_namespaces => true,
@@ -73,6 +75,8 @@ class iaas::profile::neutron::router (
   }
 
   class { '::neutron::agents::vpnaas':
+#double_external_network
+#    external_network_bridge => "br-ex",
     external_network_bridge => ' ',
   }
   class { '::neutron::agents::lbaas': }
@@ -110,20 +114,25 @@ class iaas::profile::neutron::router (
       local_ip => $local_ip,
       enabled => true,
       tunnel_types => ['gre'],
+#double_external_network, variable modified
+#ori      bridge_mappings => ['external:br-ex'],
+#      bridge_mappings => [$bridge_mappings],
       bridge_mappings => [$bridge_mappings1,$bridge_mappings2],
       require => File['etc_default_neutron-server'],
   }
 
+#  $_external_device1 = device_for_network($external_network1)
 
-# notify { "br-ex1: $::brex1_eval":
-#  loglevel => alert,
-# }
-# notify { "br-ex2: $::brex2_eval":
-#  loglevel => alert,
-# }
-# notify { "external device1: $_external_device1 -- external network: $external_network1":
-#  loglevel => alert,
-# }
+notify { "br-ex1: $::brex1_eval":
+ loglevel => alert,
+}
+notify { "br-ex2: $::brex2_eval":
+ loglevel => alert,
+}
+
+#notify { "external device1: $_external_device1 -- external network: $external_network1":
+# loglevel => alert,
+#}
 
 # Set public network if public_interface != $external_device1
   if $public_gateway {
@@ -151,6 +160,8 @@ class iaas::profile::neutron::router (
   }
 
 
+#  if $_external_device1 != 'br_ex1' {
+
 # Evaluate br-ex1, if present set it
   if $::brex1_eval != 'br-ex1' {
 
@@ -225,9 +236,11 @@ class iaas::profile::neutron::router (
 
   if $external_device2 {
 
-# notify { "external device2: $_external_device2 -- external network: $external_network2":
-#  loglevel => alert,
-# }
+#    $_external_device2 = device_for_network($external_network2)
+#notify { "external device2: $_external_device2 -- external network: $external_network2":
+# loglevel => alert,
+#}
+#    if $_external_device2 != 'br_ex2' {
 
 # Evaluate br-ex2, if presetn set it
     if $::brex2_eval != 'br-ex2' {
@@ -237,29 +250,73 @@ class iaas::profile::neutron::router (
       $public_netmask2 = $::facts["netmask_${external_device2}"]
       $public_macaddr2 = $::facts["macaddress_${external_device2}"]
 
-      network_config { $external_device2:
-        ensure  => 'present',
-        family  => 'inet',
-        method  => 'manual',
-        options => {
-          'up' => "ifconfig ${external_device2} 0.0.0.0 promisc up",
-          'down' => "ifconfig ${external_device2} promisc down",
-        },
-      } ->
-      vs_port { $external_device2:
-        ensure => present,
-        bridge => 'br-ex2',
-        require => Class['::neutron::agents::ml2::ovs'],
-      } ->
-      exec { "set_br-ex2_hwaddr":
-        command => "ovs-vsctl set bridge br-ex2 other-config:hwaddr=$public_macaddr2",
-        path    => "/usr/local/bin/:/bin/:/usr/bin:/sbin/:/usr/sbin/",
-      } 
+#      if $public_ipaddress2 {
+#        network_config { $external_device2:
+#          ensure  => 'present',
+#          family  => 'inet',
+#          method  => 'manual',
+#          options => {
+#            'up' => "ifconfig ${external_device2} 0.0.0.0 promisc up",
+#            'down' => "ifconfig ${external_device2} promisc down",
+#          },
+#        } ->
+#        network_config { 'br-ex2':
+#          ensure  => 'present',
+#          family  => 'inet',
+#          method  => 'static',
+#          ipaddress => $public_ipaddress2,
+#          netmask => $public_netmask2,
+#        } ->
+#        vs_port { $external_device2:
+#          ensure => present,
+#          bridge => 'br-ex2',
+#          require => Class['::neutron::agents::ml2::ovs'],
+#        } -> 
+#        network_route { 'route_ext2':
+#          ensure => 'present',
+#          gateway => $external_gateway2,
+#          interface => 'br-ex2',
+#          netmask => '0.0.0.0',
+#          network => $external_network2,
+#          require => Package['ifupdown-extra']
+#        } ->
+#        exec { "set_br-ex2_hwaddr":
+#          command => "ovs-vsctl set bridge br-ex2 other-config:hwaddr=$public_macaddr2",
+#          path    => "/usr/local/bin/:/bin/:/usr/bin:/sbin/:/usr/sbin/",
+#        } -> 
+#        exec { "restart_external2":
+#          command => "ifconfig $external_device2 0.0.0.0 promisc",
+#          path    => "/usr/local/bin/:/bin/:/sbin/:/usr/sbin/",
+#        } ->
+#        exec { "restart_br-ex2":
+#          command => "ifdown br-ex2 && ifup br-ex2",
+#          path    => "/usr/local/bin/:/bin/:/sbin/:/usr/sbin/",     
+#        }
+#      } else {
+        network_config { $external_device2:
+          ensure  => 'present',
+          family  => 'inet',
+          method  => 'manual',
+          options => {
+            'up' => "ifconfig ${external_device2} 0.0.0.0 promisc up",
+            'down' => "ifconfig ${external_device2} promisc down",
+          },
+        } ->
+        vs_port { $external_device2:
+          ensure => present,
+          bridge => 'br-ex2',
+          require => Class['::neutron::agents::ml2::ovs'],
+        } ->
+        exec { "set_br-ex2_hwaddr":
+          command => "ovs-vsctl set bridge br-ex2 other-config:hwaddr=$public_macaddr2",
+          path    => "/usr/local/bin/:/bin/:/usr/bin:/sbin/:/usr/sbin/",
+        } 
+#      }
     }
   }
 
 
 ##Public/private network configuration for tenant - added
-#class { '::iaas::setup::sharednetwork': }
+class { '::iaas::setup::sharednetwork': }
 
 }
diff --git a/manifests/setup/router.pp b/manifests/setup/router.pp
index fbe31d4..990484d 100644
--- a/manifests/setup/router.pp
+++ b/manifests/setup/router.pp
@@ -1,22 +1,39 @@
 # A convenience method to set up a router between
 # a private subnet and the public network. The
-# $title of the resource is 'tenant:subnet',
+# $title of the resource is 'routername:subnet',
 # where tenant is the name of the tenant to assign
 # the router to and subnet is the name of the
 # subnet to connect the router to.
 
 define iaas::setup::router {
   $valarray = split($title, ':')
-  $tenant = $valarray[0]
+  $tenant = 'test'
+  $rname  = $valarray[0]
   $subnet = $valarray[1]
 
-  neutron_router { $tenant:
-    tenant_name          => $tenant,
-    gateway_network_name => 'public1',
-    require              => [Neutron_network['public1'], Neutron_subnet[$subnet]]
-  } ->
+  if $rname == 'test1' {
 
-  neutron_router_interface  { $title:
-    ensure => present
+    neutron_router { $rname:
+      tenant_name          => $tenant,
+      gateway_network_name => 'public1',
+      require              => [Neutron_network['public1'], Neutron_subnet[$subnet]]
+    } ->
+
+    neutron_router_interface  { $title:
+      ensure => present
+    }
   }
+
+  if $rname == 'test2' {
+
+    neutron_router { $rname:
+      tenant_name          => $tenant,
+      gateway_network_name => 'public2',
+      require              => [Neutron_network['public2'], Neutron_subnet[$subnet]]
+    } ->
+    neutron_router_interface  { $title:
+      ensure => present
+    }
+  }
+
 }
diff --git a/manifests/setup/sharednetwork.pp b/manifests/setup/sharednetwork.pp
index 55540b7..da4fa34 100644
--- a/manifests/setup/sharednetwork.pp
+++ b/manifests/setup/sharednetwork.pp
@@ -31,7 +31,7 @@ $ip_range2 = "start=${start_ip2},end=${end_ip2}"
     provider_physical_network => 'physnet1',
     shared                   => false,
   } ->
-  neutron_subnet { $external_network1:
+  neutron_subnet { 'public-sub1':
     cidr             => $external_network1,
     ip_version       => '4',
     gateway_ip       => $gateway1,
@@ -64,7 +64,7 @@ $ip_range2 = "start=${start_ip2},end=${end_ip2}"
       provider_physical_network => 'physnet2',
       shared                   => false,
     } ->
-    neutron_subnet { $external_network2:
+    neutron_subnet { 'public-sub2':
       cidr             => $external_network2,
       ip_version       => '4',
       gateway_ip       => $gateway2,
@@ -91,9 +91,9 @@ $ip_range2 = "start=${start_ip2},end=${end_ip2}"
   }
 
 # router setup for the tenant test
-# iaas::setup::router { "test:${private_network1}": }
-#  if $external_network2 {
-#    iaas::setup::router { "test:${private_network2}": }
-#  }
+  iaas::setup::router { "test1:${private_network1}": }
+  if $external_network2 {
+    iaas::setup::router { "test2:${private_network2}": }
+  }
 
 }
-- 
GitLab