class Wire::Resource::IPAddressOnIntf

Generic IP Address on an interface Able to add and remove ips on interfaces

Attributes

device[RW]

device (bridge) device name, i.e. “eth1” executables array of paths to needed binaries

executables[RW]

device (bridge) device name, i.e. “eth1” executables array of paths to needed binaries

Public Class Methods

new(name, device) click to toggle source

initialize the object with given name and device params: name ip address in cidr notation device device/interface name

Calls superclass method
# 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

construct_add_command() click to toggle source

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
construct_delete_command() click to toggle source

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
construct_exist_command() click to toggle source

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
down() click to toggle source

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
down?() click to toggle source

thats the opposite of up

# File lib/wire/resource/ipaddr_on_intf.rb, line 87
def down?
  !(up?)
end
exist?() click to toggle source

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
to_s() click to toggle source

generate a string representation

# File lib/wire/resource/ipaddr_on_intf.rb, line 103
def to_s
  "IPAddressOnIntf:[#{name},device=#{device}]"
end
up() click to toggle source

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
up?() click to toggle source

same as exist?

# File lib/wire/resource/ipaddr_on_intf.rb, line 57
def up?
  exist?
end