Class: Lenovo::PowerVFw

Inherits:
Object
  • Object
show all
Defined in:
lib/lenovo-powervfw.rb

Instance Method Summary collapse

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' | '' | '', # source address, optional, default value is any. :sport => 'any' | '', # source port, must be in 1..65535, optional, default value is any. :smac => 'any' | '', # source mac address, optional, default value is any. :da => 'any' | '' | '', # destination address, optional, default value is any. :iif => 'any' | '', # input interface, optional, default value is any. :oif => 'any' | '', # output interface, optional, default value is any. :service => 'any' | '', # service name, could be service name or group of services, # optional, default value is any. :time => '' | '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 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, options = {})
  type = 'deny'
  cmd = "rule add type #{type} name #{name} "
  cmd << "id #{options[:id]} " if options.has_key? :id
  cmd << "sa #{options[:sa] || 'any'} " if options.has_key? :sa
  cmd << "sport #{options[:sport] || 'any'} " if options.has_key? :sport
  cmd << "smac #{options[:smac] || 'any'} " if options.has_key? :smac
  cmd << "da #{options[:da] || 'any'} " if options.has_key? :da
  cmd << "iif #{options[:iif] || 'any'} " if options.has_key? :iif
  cmd << "oif #{options[:oif] || 'any'} " if options.has_key? :oif
  cmd << "service #{options[:service] || 'any'} " if options.has_key? :service
  cmd << "time #{options[:time] || 'none'} " if options.has_key? :time
  cmd << "log #{options[:log] || 'off'} " if options.has_key? :log
  cmd << "active #{options[:active] || 'on'} " if options.has_key? :active
  cmd << "comment #{options[:comment]}" if options.has_key? :comment

  output = @session.exec!(cmd.strip)
  not output.include? 'Error'
end

#closeObject



17
18
19
# File 'lib/lenovo-powervfw.rb', line 17

def close
  @session.close
end

#closed?Boolean

Returns:



13
14
15
# File 'lib/lenovo-powervfw.rb', line 13

def closed?
  @session.nil? or @session.closed?
end