From 84161ebda6fe224ce4fc4e3df1a2d640852a4fc5 Mon Sep 17 00:00:00 2001
From: Alexander Lutay <alutay@sipwise.com>
Date: Tue, 17 Jun 2014 14:20:40 +0200
Subject: [PATCH] MT#7367 SSH will listen 0.0.0.0 for Vagrant VMs (DHCP case)

In case of DHCP server is being used, and system was rebooted
with new IP, network.yml still has old IP and SSH will listen old IP only.
Vagrant cannot connect VM using old IP to change it to new one.

In case of CE with one network interface (common case)
ngcp-eadresss will update network.yml and apply new config.

PRO should not be installed using DHCP (at least in production).

Vagrant VMs has two interfaces, so ngcp-eadresss does nothing,
so we add option to config.yml which overwrites ssh_ext types in
network.yml.
---
 deployment.sh | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/deployment.sh b/deployment.sh
index 6d92f3d..5be994c 100755
--- a/deployment.sh
+++ b/deployment.sh
@@ -1985,7 +1985,7 @@ use YAML::Tiny;
 
 my $yaml = YAML::Tiny->new;
 my $inputfile  = "/etc/ngcp-config/config.yml";
-my $outputfile = "/etc/ngcp-config/config.yml";
+my $outputfile = $inputfile;
 
 $yaml = YAML::Tiny->read($inputfile) or die "File $inputfile could not be read";
 
@@ -2004,6 +2004,25 @@ print $fh $yaml->write_string() or die "Could not write YAML to $outputfile";
 EOF
   fi
 
+  # CE
+  chroot "$TARGET" perl -wCSD << "EOF"
+use strict;
+use warnings;
+use YAML::Tiny;
+
+my $yaml = YAML::Tiny->new;
+my $inputfile  = "/etc/ngcp-config/config.yml";
+my $outputfile = $inputfile;
+
+$yaml = YAML::Tiny->read($inputfile) or die "File $inputfile could not be read";
+
+# Enable SSH on all IPs/interfaces (0.0.0.0)
+push @{$yaml->[0]->{sshd}->{listen_addresses}}, '0.0.0.0';
+
+open(my $fh, ">", "$outputfile") or die "Could not open $outputfile for writing";
+print $fh $yaml->write_string() or die "Could not write YAML to $outputfile";
+EOF
+
   # record configuration file changes
   chroot "$TARGET" etckeeper commit "Snapshot after enabling VM defaults [$(date)]" || true
   chroot "$TARGET" bash -c "cd /etc/ngcp-config ; git commit -a -m \"Snapshot after enabling VM defaults [$(date)]\" || true"