Module: Construqt::Tags
- Defined in:
- lib/construqt/tags.rb
Class Method Summary collapse
- .add(tag_str, &block) ⇒ Object
- .find(tag, clazz = nil) ⇒ Object
- .from(obj) ⇒ Object
- .ips_net(tag, family) ⇒ Object
Class Method Details
.add(tag_str, &block) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/construqt/tags.rb', line 6 def self.add(tag_str, &block) (name, *) = tag_str.split(/\s*#\s*/) obj = block.call(name, ) #binding.pry && .uniq.each do |tag| @tags[tag] ||= [] @tags[tag] << obj unless @tags[tag].include?(obj) end if obj.respond_to? :tags obj. = end @object_id_tags[obj.object_id] ||= [] @object_id_tags[obj.object_id] = (@object_id_tags[obj.object_id] + ).uniq [name, obj] end |
.find(tag, clazz = nil) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/construqt/tags.rb', line 26 def self.find(tag, clazz = nil) #binding.pry ret = (@tags[tag] || []).select{|o| clazz.nil? || o.kind_of?(clazz) } Construqt.logger.warn("tag #{tag} #{clazz.inspect} empty result") if ret.empty? ret end |
.from(obj) ⇒ Object
22 23 24 |
# File 'lib/construqt/tags.rb', line 22 def self.from(obj) @object_id_tags[obj.object_id] end |
.ips_net(tag, family) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/construqt/tags.rb', line 33 def self.ips_net(tag, family) ip_module = family==Construqt::Addresses::IPV4 ? IPAddress::IPv4: IPAddress::IPv6 IPAddress::IPv4::summarize(*(@tags[tag]||[]).map do |obj| if obj.kind_of?(IPAddress) obj elsif obj.respond_to? :ips obj.ips elsif obj.kind_of?(Construqt::Flavour::HostDelegate) #binding.pry res = obj.interfaces.values.map do |i| i.delegate.address.ips.map do |a| prefix = a.ipv4? ? 32 : 128 ret = IPAddress.parse("#{a.to_s}/#{prefix}") puts "ADR=#{tag} #{ret.to_string} #{a.to_s}" ret end end.flatten puts "HOST=>#{tag} #{res.map{|i| i.to_string }}" res else nil end end.flatten.compact.select do |i| (family==Construqt::Addresses::IPV4 && i.ipv4?) || (family==Construqt::Addresses::IPV6 && i.ipv6?) end) end |