class Wire::Resource::IPAddressOnIntf
Generic IP Address on an interface Able to add and remove ips on interfaces
Attributes
device
(bridge) device name, i.e. “eth1” executables
array of paths to needed binaries
device
(bridge) device name, i.e. “eth1” executables
array of paths to needed binaries
Public Class Methods
initialize the object with given name and device params: name
ip address in cidr notation device
device/interface name
# File lib/wire/resource/ipaddr_on_intf.rb, line 25 def initialize(name, device) super(name) fail(ArgumentError, 'ip may not be empty') unless name && name.size > 0 fail(ArgumentError, 'device may not be empty') unless device && device.size > 0 @device = device @executables = { :ip => '/sbin/ip' } end
Public Instance Methods
constructs an ip addr add command to set up an ip returns
-
command as [String]
# File lib/wire/resource/ipaddr_on_intf.rb, line 64 def construct_add_command "#{@executables[:ip]} addr add #{name} dev #{device}" end
constructs an ip addr del command to delete an ip returns
-
command as [String]
# File lib/wire/resource/ipaddr_on_intf.rb, line 82 def construct_delete_command "#{@executables[:ip]} addr del #{name} dev #{device}" end
constructs an ip addr show / grep command to see if an ip address is up on a device returns
-
command as [String]
# File lib/wire/resource/ipaddr_on_intf.rb, line 41 def construct_exist_command "#{@executables[:ip]} addr show #{device} | grep -wq -E \"^\\W*inet #{@name}.*#{@device}\"" end
takes an ip down on given device returns
-
[Boolean]: true: ok, false otherwise
# File lib/wire/resource/ipaddr_on_intf.rb, line 94 def down LocalExecution.with(construct_delete_command, [], { :b_shell => false, :b_sudo => true }) do |exec_obj| exec_obj.run return (exec_obj.exitstatus == 0) end end
thats the opposite of up
# File lib/wire/resource/ipaddr_on_intf.rb, line 87 def down? !(up?) end
runs the “exist” command returns
-
[Boolean]: true: ip is on on device, false otherwise
# File lib/wire/resource/ipaddr_on_intf.rb, line 48 def exist? LocalExecution.with(construct_exist_command, [], { :b_shell => false, :b_sudo => false }) do |exec_obj| exec_obj.run return (exec_obj.exitstatus == 0) end end
generate a string representation
# File lib/wire/resource/ipaddr_on_intf.rb, line 103 def to_s "IPAddressOnIntf:[#{name},device=#{device}]" end
takes an ip up on given device returns
-
[Boolean]: true: ok, false otherwise
# File lib/wire/resource/ipaddr_on_intf.rb, line 71 def up LocalExecution.with(construct_add_command, [], { :b_shell => false, :b_sudo => true }) do |exec_obj| exec_obj.run return (exec_obj.exitstatus == 0) end end
same as exist?
# File lib/wire/resource/ipaddr_on_intf.rb, line 57 def up? exist? end