summaryrefslogtreecommitdiffstats
path: root/glustolibs-gluster/glustolibs/gluster/lib_utils.py
diff options
context:
space:
mode:
authorRajesh Madaka <rmadaka@redhat.com>2018-06-07 19:40:42 +0530
committerJonathan Holloway <jholloway@redhat.com>2018-06-08 04:37:56 +0000
commitf5b5e9dafa517a16259070f9dbd7aa90ad3d41bb (patch)
tree6ca8abf1ef1e3618ef60feec75dda3b5c14e163b /glustolibs-gluster/glustolibs/gluster/lib_utils.py
parent3eea36a83e35ae3571b8bd21ff4b2a1072347c4f (diff)
Add services to firewall and remove services from firewall
Change-Id: Ie81b6ecb7e7af0524a42b37f0256a2cfff5d7736 Signed-off-by: Rajesh Madaka <rmadaka@redhat.com>
Diffstat (limited to 'glustolibs-gluster/glustolibs/gluster/lib_utils.py')
-rw-r--r--glustolibs-gluster/glustolibs/gluster/lib_utils.py48
1 files changed, 46 insertions, 2 deletions
diff --git a/glustolibs-gluster/glustolibs/gluster/lib_utils.py b/glustolibs-gluster/glustolibs/gluster/lib_utils.py
index 3cb1e44..0b86291 100644
--- a/glustolibs-gluster/glustolibs/gluster/lib_utils.py
+++ b/glustolibs-gluster/glustolibs/gluster/lib_utils.py
@@ -834,8 +834,8 @@ def is_core_file_created(nodes, testrun_timestamp,
return True
-def open_firewall(nodes, firewall_service, permanent=False):
- """Opening firewall services on nodes
+def remove_service_from_firewall(nodes, firewall_service, permanent=False):
+ """Removing services from firewall on nodes
This library only for RHEL7, for RHEL6 not required
Args:
nodes(list|str): List of server on which firewalls services to be
@@ -877,3 +877,47 @@ def open_firewall(nodes, firewall_service, permanent=False):
_rc = False
return _rc
+
+
+def add_services_to_firewall(nodes, firewall_service, permanent=False):
+ """Adding services to firewall on nodes
+ This lib only for RHEL7, RHEL6 Not Required
+ Args:
+ nodes(list|str): List of server on which firewalls to be enabled
+ firewall_service(list|str): List of firewall services to be enabled
+ permanent(boolean): True|False
+ Return:
+ bool: True|False(Firewall Enabled or Failed)
+ """
+
+ if isinstance(nodes, str):
+ nodes = [nodes]
+
+ if isinstance(firewall_service, str):
+ firewall_service = [firewall_service]
+
+ _rc = True
+ if is_rhel7(nodes):
+ for service in firewall_service:
+ cmd = ("firewall-cmd --zone=public " + "--add-service=" + service)
+ results = g.run_parallel(nodes, cmd)
+ # Check for return status
+ for host in results:
+ ret, _, _ = results[host]
+ if ret != 0:
+ g.log.error("Failed to execute firewall command on %s"
+ % host)
+ _rc = False
+ if permanent and _rc:
+ for service in firewall_service:
+ cmd = ("firewall-cmd --zone=public " + "--add-service=" +
+ service + " --permanent")
+ results = g.run_parallel(nodes, cmd)
+ # Check for return status
+ for host in results:
+ ret, _, _ = results[host]
+ if ret != 0:
+ g.log.error("Failed to add firewall permanently")
+ _rc = False
+
+ return _rc