Module: OmfRc::Util::Ip

Extended by:
ResourceProxyDSL::ClassMethods
Includes:
Cocaine, ResourceProxyDSL
Included in:
ResourceProxy::Net, Iw
Defined in:
omf_rc/lib/omf_rc/util/ip.rb

Constant Summary

Constant Summary

Constants included from ResourceProxyDSL

ResourceProxyDSL::DEFAULT_PROP_ACCESS, ResourceProxyDSL::PROXY_DIR, ResourceProxyDSL::UTIL_DIR

FRCP Request Methods (collapse)

FRCP Configure Methods (collapse)

OMF RC Work Helper Methods (collapse)

Methods included from ResourceProxyDSL::ClassMethods

call_hook, configure, configure_all, extend_configure, extend_hook, extend_request, extend_work, hook, namespace, property, register_proxy, request, utility, work

Methods included from ResourceProxyDSL

#call_hook, #hook_defined?, included

Instance Method Details

- (String) configure_ip_addr

Note:

Method 'configure_ip_addr' generated by DSL method 'configure'

Configure IP address

Parameters:

  • value

    value of IP address, it should have netmask. (e.g. 0.0.0.0/24)

Returns:

Raises:

  • (ArgumentError)

    if provided no IP address or incorrect format



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'omf_rc/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

- (Object) flush_ip_addrs

Note:

Method 'flush_ip_addrs' generated by DSL method 'work'

Remove IP addresses associated with the interface



88
89
90
91
# File 'omf_rc/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

- (Object) interface_up

Note:

Method 'interface_up' generated by DSL method 'work'

Bring up network interface



74
75
76
77
# File 'omf_rc/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

- (String) request_ip_addr

Note:

Method 'request_ip_addr' generated by DSL method 'request'

Retrieve IP address

Returns:



20
21
22
23
24
# File 'omf_rc/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

- (String) request_mac_addr

Note:

Method 'request_mac_addr' generated by DSL method 'request'

Retrieve MAC address

Returns:



31
32
33
34
35
# File 'omf_rc/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