Class: Construqt::Networks::Network
- Inherits:
-
Object
- Object
- Construqt::Networks::Network
- Defined in:
- lib/construqt/networks.rb
Instance Method Summary collapse
- #add_blocks(*nets) ⇒ Object
- #addresses ⇒ Object
- #contact ⇒ Object
- #dns_resolver ⇒ Object
- #domain ⇒ Object
-
#fqdn(name) ⇒ Object
def domain(name) _fqdn = self.fqdn(name) _fqdn end.
-
#initialize(name) ⇒ Network
constructor
A new instance of Network.
- #networks ⇒ Object
- #set_contact(contact) ⇒ Object
- #set_dns_resolver(nameservers, search) ⇒ Object
- #set_domain(domain) ⇒ Object
- #to_network(ip) ⇒ Object
Constructor Details
#initialize(name) ⇒ Network
Returns a new instance of Network.
5 6 7 8 9 10 11 12 |
# File 'lib/construqt/networks.rb', line 5 def initialize(name) @name = name @networks = [] @domain = "construqt.org" @contact = "[email protected]" @addresses = Construqt::Addresses.new(self) @dns_resolver = nil end |
Instance Method Details
#add_blocks(*nets) ⇒ Object
18 19 20 21 22 |
# File 'lib/construqt/networks.rb', line 18 def add_blocks(*nets) nets.each do |net| @networks << IPAddress.parse(net) end end |
#addresses ⇒ Object
14 15 16 |
# File 'lib/construqt/networks.rb', line 14 def addresses @addresses end |
#contact ⇒ Object
53 54 55 |
# File 'lib/construqt/networks.rb', line 53 def contact @contact end |
#dns_resolver ⇒ Object
37 38 39 |
# File 'lib/construqt/networks.rb', line 37 def dns_resolver @dns_resolver end |
#domain ⇒ Object
45 46 47 |
# File 'lib/construqt/networks.rb', line 45 def domain @domain end |
#fqdn(name) ⇒ Object
def domain(name)
_fqdn = self.fqdn(name)
_fqdn[_fqdn.index('.')+1..-1]
end
62 63 64 65 66 67 |
# File 'lib/construqt/networks.rb', line 62 def fqdn(name) throw "name must set" unless name _name = name.gsub(/[\s_]+/, '-') return "#{_name}.#{self.domain}" unless _name.include?('.') return _name end |
#networks ⇒ Object
24 25 26 |
# File 'lib/construqt/networks.rb', line 24 def networks @networks end |
#set_contact(contact) ⇒ Object
49 50 51 |
# File 'lib/construqt/networks.rb', line 49 def set_contact(contact) @contact = contact end |
#set_dns_resolver(nameservers, search) ⇒ Object
33 34 35 |
# File 'lib/construqt/networks.rb', line 33 def set_dns_resolver(nameservers, search) @dns_resolver = OpenStruct.new :nameservers => nameservers, :search => search end |
#set_domain(domain) ⇒ Object
41 42 43 |
# File 'lib/construqt/networks.rb', line 41 def set_domain(domain) @domain = domain end |
#to_network(ip) ⇒ Object
28 29 30 31 |
# File 'lib/construqt/networks.rb', line 28 def to_network(ip) ret = (@networks.find{ |my| (ip.ipv6? == my.ipv6? && ip.ipv4? == my.ipv4?) && my.include?(ip) } || ip.network) ret end |