Class: Lenovo::PowerVFw
- Inherits:
-
Object
- Object
- Lenovo::PowerVFw
- Defined in:
- lib/lenovo-powervfw.rb
Instance Method Summary collapse
-
#add_rule(name, options = {}) ⇒ Object
Add a packet filter rule which type is deny.
- #close ⇒ Object
- #closed? ⇒ Boolean
-
#initialize(host, user, password) ⇒ PowerVFw
constructor
A new instance of PowerVFw.
Constructor Details
#initialize(host, user, password) ⇒ PowerVFw
Returns a new instance of PowerVFw.
5 6 7 8 9 10 11 |
# File 'lib/lenovo-powervfw.rb', line 5 def initialize(host, user, password) begin @session = Net::SSH.start(host, user, :password => password) rescue puts $! end end |
Instance Method Details
#add_rule(name, options = {}) ⇒ Object
Add a packet filter rule which type is deny.
:name => 'Rule Name', # rule name, required.
:id => 'id', # rule id, must be in 1..65535, optional,
# default value is the last one.
:sa => 'any' | '<name>' | '<ip>', # source address, optional, default value is any.
:sport => 'any' | '<port>', # source port, must be in 1..65535, optional, default value is any.
:smac => 'any' | '<mac>', # source mac address, optional, default value is any.
:da => 'any' | '<name>' | '<ip>', # destination address, optional, default value is any.
:iif => 'any' | '<interface>', # input interface, optional, default value is any.
:oif => 'any' | '<interface>', # output interface, optional, default value is any.
:service => 'any' | '<name>', # service name, could be service name or group of services,
# optional, default value is any.
:time => '<name>' | 'none', # optional, default value is none.
:log => 'on' | 'off', # whether to log, optional, default value is off.
:active => 'on' | 'off', # whether to enable this rule, optional, default value is on.
:comment => '<comment>' # comment of this rule, optional
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/lenovo-powervfw.rb', line 40 def add_rule(name, = {}) type = 'deny' cmd = "rule add type #{type} name #{name} " cmd << "id #{[:id]} " if .has_key? :id cmd << "sa #{[:sa] || 'any'} " if .has_key? :sa cmd << "sport #{[:sport] || 'any'} " if .has_key? :sport cmd << "smac #{[:smac] || 'any'} " if .has_key? :smac cmd << "da #{[:da] || 'any'} " if .has_key? :da cmd << "iif #{[:iif] || 'any'} " if .has_key? :iif cmd << "oif #{[:oif] || 'any'} " if .has_key? :oif cmd << "service #{[:service] || 'any'} " if .has_key? :service cmd << "time #{[:time] || 'none'} " if .has_key? :time cmd << "log #{[:log] || 'off'} " if .has_key? :log cmd << "active #{[:active] || 'on'} " if .has_key? :active cmd << "comment #{[:comment]}" if .has_key? :comment output = @session.exec!(cmd.strip) not output.include? 'Error' end |
#close ⇒ Object
17 18 19 |
# File 'lib/lenovo-powervfw.rb', line 17 def close @session.close end |
#closed? ⇒ Boolean
13 14 15 |
# File 'lib/lenovo-powervfw.rb', line 13 def closed? @session.nil? or @session.closed? end |