Class: Firewalld::FWCmd
- Inherits:
-
Object
- Object
- Firewalld::FWCmd
- Includes:
- Yast::Logger
- Defined in:
- library/network/src/lib/network/firewalld.rb
Overview
Execute firewalld commands using firewall-cmd
Constant Summary collapse
- BASH_SCR_PATH =
Yast::Path.new(".target.bash_output")
- COMMAND =
Base firewall-cmd command
"LANG=C /usr/bin/firewall-cmd".freeze
Instance Attribute Summary collapse
-
#option_str ⇒ Object
readonly
Returns the value of attribute option_str.
Instance Method Summary collapse
- #command ⇒ Object
- #fwd_output(output = true) ⇒ String, Boolean
-
#initialize(option_str) ⇒ FWCmd
constructor
A new instance of FWCmd.
Constructor Details
#initialize(option_str) ⇒ FWCmd
Returns a new instance of FWCmd.
47 48 49 |
# File 'library/network/src/lib/network/firewalld.rb', line 47 def initialize(option_str) @option_str = option_str end |
Instance Attribute Details
#option_str ⇒ Object (readonly)
Returns the value of attribute option_str.
45 46 47 |
# File 'library/network/src/lib/network/firewalld.rb', line 45 def option_str @option_str end |
Instance Method Details
#command ⇒ Object
51 52 53 |
# File 'library/network/src/lib/network/firewalld.rb', line 51 def command "#{COMMAND} #{option_str}".strip.squeeze(" ") end |
#fwd_output(output = true) ⇒ String, Boolean
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'library/network/src/lib/network/firewalld.rb', line 58 def fwd_output(output = true) cmd_result = Yast::SCR.Execute(BASH_SCR_PATH, command) # See firewall-cmd manpage for exit codes. Not all of them justify an # exception. 0 and 1 can be used as true and false respectively. case cmd_result["exit"] when 0, 1 if output cmd_result["stdout"] else log.debug "#{command} returned: #{cmd_result["stdout"]}" cmd_result["exit"].zero? end else raise FirewallCMDError, "Calling firewall-cmd (cmd: #{command}) failed: #{cmd_result["stderr"]}" end end |