()
return (res1.returncode == 0)
Check if the firewall is based on firewalld
Check if the firewall is based on firewalld
Check if the firewall is based on firewalld
def is_firewalld():
    """Check if the firewall is based on firewalld"""
    if (which('firewall-cmd') is None):
        return False

    if (which('systemctl') is None):
        # Can't check whether firewalld is running
        return False

    # Run the following commands even in dry-run mode
    res1 = runner.run(['systemctl', 'is-active', '--quiet', 'firewalld'],
                      nodry=True,
                      nocheck=True)
    res2 = runner.run(['systemctl', 'is-active', '--quiet', 'iptables'],
                      nodry=True,
                      nocheck=True)

    # If running (active), 'is-active' returns 0
    if (res1.returncode == 0 and res2.returncode == 0):
        raise ValueError(
            "Failed to detect firewall system (firewalld or iptables)")

    return (res1.returncode == 0)
def is_firewalld ( ) : if ( which ( 'firewall-cmd' ) is None ) : return False if ( which ( 'systemctl' ) is None ) : # Can't check whether firewalld is running return False # Run the following commands even in dry-run mode res1 = runner . run ( [ 'systemctl' , 'is-active' , '--quiet' , 'firewalld' ] , nodry = True , nocheck = True ) res2 = runner . run ( [ 'systemctl' , 'is-active' , '--quiet' , 'iptables' ] , nodry = True , nocheck = True ) # If running (active), 'is-active' returns 0 if ( res1 . returncode == 0 and res2 . returncode == 0 ) : raise ValueError ( "Failed to detect firewall system (firewalld or iptables)" ) return ( res1 . returncode == 0 )