You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by re...@apache.org on 2015/10/14 18:32:07 UTC
[3/9] git commit: updated refs/heads/master to 2ce5a0c
CLOUDSTACK-8947 - Configure the firewall when the load balancer is setup
- Only restart HAproxy if it's not running yet
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/59bd935f
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/59bd935f
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/59bd935f
Branch: refs/heads/master
Commit: 59bd935f3eb43d06580c737c69d5e5e46d481868
Parents: 4a17703
Author: Wilder Rodrigues <wr...@schubergphilis.com>
Authored: Tue Oct 13 15:54:59 2015 +0200
Committer: Wilder Rodrigues <wr...@schubergphilis.com>
Committed: Wed Oct 14 07:44:38 2015 +0200
----------------------------------------------------------------------
.../config/opt/cloud/bin/cs/CsLoadBalancer.py | 25 ++++++++++++++------
1 file changed, 18 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/59bd935f/systemvm/patches/debian/config/opt/cloud/bin/cs/CsLoadBalancer.py
----------------------------------------------------------------------
diff --git a/systemvm/patches/debian/config/opt/cloud/bin/cs/CsLoadBalancer.py b/systemvm/patches/debian/config/opt/cloud/bin/cs/CsLoadBalancer.py
index 4dce95f..a288eac 100755
--- a/systemvm/patches/debian/config/opt/cloud/bin/cs/CsLoadBalancer.py
+++ b/systemvm/patches/debian/config/opt/cloud/bin/cs/CsLoadBalancer.py
@@ -19,6 +19,7 @@ import os.path
import re
import shutil
from cs.CsDatabag import CsDataBag
+from CsProcess import CsProcess
from CsFile import CsFile
import CsHelper
@@ -27,7 +28,7 @@ HAPROXY_CONF_P = "/etc/haproxy/haproxy.cfg"
class CsLoadBalancer(CsDataBag):
- """ Manage Load Balance entries """
+ """ Manage Load Balancer entries """
def process(self):
if "config" not in self.dbag.keys():
@@ -43,23 +44,33 @@ class CsLoadBalancer(CsDataBag):
if not file2.compare(file1):
file1.commit()
shutil.copy2(HAPROXY_CONF_T, HAPROXY_CONF_P)
- CsHelper.service("haproxy", "restart")
-
+
+ proc = CsProcess(['/var/run/haproxy.pid'])
+ if not proc.find():
+ logging.debug("CsLoadBalancer:: will restart HAproxy!")
+ CsHelper.service("haproxy", "restart")
+ else:
+ logging.debug("CsLoadBalancer:: will reload HAproxy!")
+ CsHelper.service("haproxy", "reload")
+
add_rules = self.dbag['config'][0]['add_rules']
remove_rules = self.dbag['config'][0]['remove_rules']
self._configure_firewall(add_rules, remove_rules)
def _configure_firewall(self, add_rules, remove_rules):
- firewall = self.fw
-
+ firewall = self.config.get_fw()
+
+ logging.debug("CsLoadBalancer:: configuring firewall. Add rules ==> %s" % add_rules)
+ logging.debug("CsLoadBalancer:: configuring firewall. Remove rules ==> %s" % remove_rules)
+
for rules in add_rules:
path = rules.split(':')
ip = path[0]
port = path[1]
- fw.append(["filter", "", "-A INPUT -p tcp -m tcp -d %s --dport %s -m state --state NEW -j ACCEPT" % (ip, port)])
+ firewall.append(["filter", "", "-A INPUT -p tcp -m tcp -d %s --dport %s -m state --state NEW -j ACCEPT" % (ip, port)])
for rules in remove_rules:
path = rules.split(':')
ip = path[0]
port = path[1]
- fw.append(["filter", "", "-D INPUT -p tcp -m tcp -d %s --dport %s -m state --state NEW -j ACCEPT" % (ip, port)])
+ firewall.append(["filter", "", "-D INPUT -p tcp -m tcp -d %s --dport %s -m state --state NEW -j ACCEPT" % (ip, port)])