Module: OmfRc::Util::Ip
- Includes:
- Cocaine, ResourceProxyDSL
- Included in:
- ResourceProxy::Net, Iw
- Defined in:
- lib/omf_rc/util/ip.rb
Constant Summary
Constants included from ResourceProxyDSL
ResourceProxyDSL::DEFAULT_PROP_ACCESS, ResourceProxyDSL::PROXY_DIR, ResourceProxyDSL::UTIL_DIR
Instance Method Summary collapse
-
#configure_ip_addr ⇒ String
Configure IP address.
-
#flush_ip_addrs ⇒ Object
Remove IP addresses associated with the interface.
-
#interface_up ⇒ Object
Bring up network interface.
-
#request_ip_addr ⇒ String
Retrieve IP address.
-
#request_mac_addr ⇒ String
Retrieve MAC address.
Methods included from ResourceProxyDSL
#call_hook, #hook_defined?, included
Instance Method Details
#configure_ip_addr ⇒ String
Configure IP address
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/omf_rc/util/ip.rb', line 55 configure :ip_addr do |resource, value| if value.nil? || value.split('/')[1].nil? raise ArgumentError, "You need to provide a netmask with the IP address, e.g. #{value}/24. Got #{value}." end # Remove all ip addrs associated with the device resource.flush_ip_addrs c=CommandLine.new("ip", "addr add :ip_address dev :device") c.run({ :ip_address => value, :device => resource.property.if_name }) resource.interface_up resource.request_ip_addr end |
#flush_ip_addrs ⇒ Object
Remove IP addresses associated with the interface
88 89 90 91 |
# File 'lib/omf_rc/util/ip.rb', line 88 work :flush_ip_addrs do |resource| c=CommandLine.new("ip", "addr flush dev :device") c.run({ :device => resource.property.if_name }) end |
#interface_up ⇒ Object
Bring up network interface
74 75 76 77 |
# File 'lib/omf_rc/util/ip.rb', line 74 work :interface_up do |resource| c=CommandLine.new("ip", "link set :dev up") c.run({ :dev => resource.property.if_name }) end |
#request_ip_addr ⇒ String
Retrieve IP address
20 21 22 23 24 |
# File 'lib/omf_rc/util/ip.rb', line 20 request :ip_addr do |resource| c = CommandLine.new("ip", "addr show dev :device") addr = c.run( { :device => resource.property.if_name }) addr && addr.chomp.match(/inet ([[0-9]\:\/\.]+)/) && $1 end |
#request_mac_addr ⇒ String
Retrieve MAC address
31 32 33 34 35 |
# File 'lib/omf_rc/util/ip.rb', line 31 request :mac_addr do |resource| c = CommandLine.new("ip", "addr show dev :device") addr = c.run( { :device => resource.property.if_name }) addr && addr.chomp.match(/link\/ether ([\d[a-f][A-F]\:]+)/) && $1 end |