use ufw to configure iptable in ubuntu for mgmt server ports

This commit is contained in:
frank 2011-09-12 15:21:33 -07:00
parent f41b352d36
commit f19e9252a4
3 changed files with 23 additions and 3 deletions

20
python/lib/cloudutils/serviceConfig.py Normal file → Executable file
View File

@ -651,3 +651,23 @@ class firewallConfigServer(firewallConfigBase):
self.ports = "443 8080 8096 8250 8443 9090".split()
else:
self.ports = "8080 8096 8250 9090".split()
class ubuntuFirewallConfigServer(firewallConfigServer):
def allowPort(self, port):
status = False
try:
status = bash("iptables-save|grep INPUT|grep -w %s"%port).isSuccess()
except:
pass
if not status:
bash("ufw allow %s/tcp"%port)
def config(self):
try:
for port in self.ports:
self.allowPort(port)
return True
except:
raise

2
python/lib/cloudutils/syscfg.py Normal file → Executable file
View File

@ -178,4 +178,4 @@ class sysConfigServerUbuntu(sysConfigServer):
super(sysConfigServerUbuntu, self).__init__(glbEnv)
self.svo = serviceOpsUbuntu()
self.services = [sudoersConfig(self),
firewallConfigServer(self)]
ubuntuFirewallConfigServer(self)]

4
python/lib/cloudutils/utilities.py Normal file → Executable file
View File

@ -155,7 +155,7 @@ class serviceOpsRedhat(serviceOps):
class serviceOpsUbuntu(serviceOps):
def isServiceRunning(self, servicename):
try:
o = bash("service " + servicename + " status")
o = bash("/usr/sbin/service " + servicename + " status")
if "running" in o.getStdout() or "start" in o.getStdout():
return True
else:
@ -165,7 +165,7 @@ class serviceOpsUbuntu(serviceOps):
def stopService(self, servicename,force=False):
if self.isServiceRunning(servicename) or force:
return bash("service " + servicename +" stop").isSuccess()
return bash("/usr/sbin/service " + servicename +" stop").isSuccess()
def disableService(self, servicename):
result = self.stopService(servicename)