firewall: Get service ports details

Add interface to get port types and numbers for a service.

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
James Valleroy 2019-04-03 06:44:18 -04:00 committed by Sunil Mohan Adapa
parent 51fc87f1bc
commit e5081018a3
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2
2 changed files with 23 additions and 2 deletions

View File

@ -46,6 +46,12 @@ def parse_arguments():
'--zone', help='Zone from which the list is to be retrieved',
required=True)
# Get service ports
get_service_ports = subparsers.add_parser(
'get-service-ports', help='Get list of ports for service')
get_service_ports.add_argument('--service', help='Name of service',
required=True)
# Get interface status
get_interfaces = subparsers.add_parser(
'get-interfaces', help='Get list of interfaces in a zone')
@ -105,8 +111,8 @@ def _flush_iptables_rules():
def set_firewall_backend(backend):
"""Set FirewallBackend attribute to the specified string."""
conf_file = '/etc/firewalld/firewalld.conf'
aug = augeas.Augeas(flags=augeas.Augeas.NO_LOAD +
augeas.Augeas.NO_MODL_AUTOLOAD)
aug = augeas.Augeas(
flags=augeas.Augeas.NO_LOAD + augeas.Augeas.NO_MODL_AUTOLOAD)
# lens for shell-script config file
aug.set('/augeas/load/Shellvars/lens', 'Shellvars.lns')
@ -150,6 +156,14 @@ def subcommand_get_enabled_services(arguments):
['firewall-cmd', '--zone', arguments.zone, '--list-services'])
def subcommand_get_service_ports(arguments):
"""Print list of ports for service"""
subprocess.call([
'firewall-cmd', '--permanent', '--service', arguments.service,
'--get-ports'
])
def subcommand_get_interfaces(arguments):
"""Print the list of interfaces in a zone."""
subprocess.call(

View File

@ -95,6 +95,13 @@ def get_enabled_services(zone):
return output.split()
def get_port_details(service_port):
"""Return the port types and numbers for a service port"""
output = _run(
['get-service-ports', '--service', service_port], superuser=True)
return output.split()
def get_interfaces(zone):
"""Return the list of interfaces in a zone."""
output = _run(['get-interfaces', '--zone', zone], superuser=True)