Class: IpInterface
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- IpInterface
- Defined in:
- lib/antfarm/ip_interface.rb
Overview
IpInterface class that wraps the ip_interfaces table in the ANTFARM database.
-
belongs to a layer 3 interface
The node_name and node_device_type attributes are only applicable when an existing node is not specified.
The node and layer2_interface_media_type attributes are only applicable when an existing layer 2 interface is not specified.
The layer3_network_protocol attribute is only applicable when an existing layer 3 network is not specified.
Instance Attribute Summary collapse
-
#ethernet_address ⇒ Object
writeonly
Ethernet (MAC) address of the ethernet interface to be created for this IP interface.
-
#layer2_interface ⇒ Object
writeonly
Existing layer 2 interface the layer 3 interface automatically created for this IP interface should belong to.
-
#layer2_interface_media_type ⇒ Object
writeonly
Media type of the layer 2 interface automatically creted for this layer 3 interface.
-
#layer3_interface_protocol ⇒ Object
writeonly
Protocol of the layer 3 interface automatically created for this IP interface.
-
#layer3_network ⇒ Object
writeonly
Existing layer 3 network the layer 3 interface automatically created for this IP interface should belong to.
-
#layer3_network_protocol ⇒ Object
writeonly
Protocol of the layer 3 network automatically created for the layer 3 interface created for this IP interface.
-
#node ⇒ Object
writeonly
Existing node the layer 2 interface automatically created for this layer 3 interface should belong to.
-
#node_device_type ⇒ Object
writeonly
Device type of the node automatically created by the layer 2 interface created for this layer 3 interface.
-
#node_name ⇒ Object
writeonly
Name of the node automatically created by the layer 2 interface created for this layer 3 interface.
Instance Method Summary collapse
-
#address=(ip_addr) ⇒ Object
Overriding the address setter in order to create an instance variable for an Antfarm::IPAddrExt object ip_addr.
-
#to_label ⇒ Object
This is for ActiveScaffold.
-
#validate ⇒ Object
Validate data for requirements before saving interface to the database.
Instance Attribute Details
#ethernet_address=(value) ⇒ Object (writeonly)
Ethernet (MAC) address of the ethernet interface to be created for this IP interface.
56 57 58 |
# File 'lib/antfarm/ip_interface.rb', line 56 def ethernet_address=(value) @ethernet_address = value end |
#layer2_interface=(value) ⇒ Object (writeonly)
Existing layer 2 interface the layer 3 interface automatically created for this IP interface should belong to.
61 62 63 |
# File 'lib/antfarm/ip_interface.rb', line 61 def layer2_interface=(value) @layer2_interface = value end |
#layer2_interface_media_type=(value) ⇒ Object (writeonly)
Media type of the layer 2 interface automatically creted for this layer 3 interface.
65 66 67 |
# File 'lib/antfarm/ip_interface.rb', line 65 def layer2_interface_media_type=(value) @layer2_interface_media_type = value end |
#layer3_interface_protocol=(value) ⇒ Object (writeonly)
Protocol of the layer 3 interface automatically created for this IP interface.
52 53 54 |
# File 'lib/antfarm/ip_interface.rb', line 52 def layer3_interface_protocol=(value) @layer3_interface_protocol = value end |
#layer3_network=(value) ⇒ Object (writeonly)
Existing layer 3 network the layer 3 interface automatically created for this IP interface should belong to.
43 44 45 |
# File 'lib/antfarm/ip_interface.rb', line 43 def layer3_network=(value) @layer3_network = value end |
#layer3_network_protocol=(value) ⇒ Object (writeonly)
Protocol of the layer 3 network automatically created for the layer 3 interface created for this IP interface.
48 49 50 |
# File 'lib/antfarm/ip_interface.rb', line 48 def layer3_network_protocol=(value) @layer3_network_protocol = value end |
#node=(value) ⇒ Object (writeonly)
Existing node the layer 2 interface automatically created for this layer 3 interface should belong to.
69 70 71 |
# File 'lib/antfarm/ip_interface.rb', line 69 def node=(value) @node = value end |
#node_device_type=(value) ⇒ Object (writeonly)
Device type of the node automatically created by the layer 2 interface created for this layer 3 interface.
77 78 79 |
# File 'lib/antfarm/ip_interface.rb', line 77 def node_device_type=(value) @node_device_type = value end |
#node_name=(value) ⇒ Object (writeonly)
Name of the node automatically created by the layer 2 interface created for this layer 3 interface.
73 74 75 |
# File 'lib/antfarm/ip_interface.rb', line 73 def node_name=(value) @node_name = value end |
Instance Method Details
#address=(ip_addr) ⇒ Object
Overriding the address setter in order to create an instance variable for an Antfarm::IPAddrExt object ip_addr. This way the rest of the methods in this class can confidently access the ip address for this interface. IPAddr also validates the address.
the method address= is called by the constructor of this class.
85 86 87 88 |
# File 'lib/antfarm/ip_interface.rb', line 85 def address=(ip_addr) #:nodoc: @ip_addr = Antfarm::IPAddrExt.new(ip_addr) super(@ip_addr.to_s) end |
#to_label ⇒ Object
This is for ActiveScaffold
115 116 117 |
# File 'lib/antfarm/ip_interface.rb', line 115 def to_label #:nodoc: return address end |
#validate ⇒ Object
Validate data for requirements before saving interface to the database.
Was using validate_on_create, but decided that restraints should occur on anything saved to the database at any time, including a create and an update.
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/antfarm/ip_interface.rb', line 96 def validate #:nodoc: # Don't save the interface if it's a loopback address. if @ip_addr.loopback_address? errors.add(:address, "loopback address not allowed") end # If the address is public and it already exists in the database, don't create # a new one but still create a new IP Network just in case the data given for # this address includes more detailed information about its network. unless @ip_addr.private_address? interfaces = IpInterface.find :all, :conditions => { :address => address } if interfaces && interfaces.length > 0 create_ip_network errors.add(:address, 'address already exists, but a new IP Network was created') end end end |