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
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/omf_rc/util/ip.rb', line 52 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 CommandLine.new("ip", "addr add :ip_address dev :device", :ip_address => value, :device => resource.property.if_name ).run resource.interface_up resource.request_ip_addr end |
#flush_ip_addrs ⇒ Object
Remove IP addresses associated with the interface
83 84 85 86 |
# File 'lib/omf_rc/util/ip.rb', line 83 work :flush_ip_addrs do |resource| CommandLine.new("ip", "addr flush dev :device", :device => resource.property.if_name).run end |
#interface_up ⇒ Object
Bring up network interface
71 72 73 |
# File 'lib/omf_rc/util/ip.rb', line 71 work :interface_up do |resource| CommandLine.new("ip", "link set :dev up", :dev => resource.property.if_name).run end |
#request_ip_addr ⇒ String
Retrieve IP address
20 21 22 23 |
# File 'lib/omf_rc/util/ip.rb', line 20 request :ip_addr do |resource| addr = CommandLine.new("ip", "addr show dev :device", :device => resource.property.if_name).run addr && addr.chomp.match(/inet ([[0-9]\:\/\.]+)/) && $1 end |
#request_mac_addr ⇒ String
Retrieve MAC address
30 31 32 33 |
# File 'lib/omf_rc/util/ip.rb', line 30 request :mac_addr do |resource| addr = CommandLine.new("ip", "addr show dev :device", :device => resource.property.if_name).run addr && addr.chomp.match(/link\/ether ([\d[a-f][A-F]\:]+)/) && $1 end |