<commit_before>
module CORL
module Plugin
class Network < CORL.plugin_class(:nucleon, :base)
  
  init_plugin_collection(:add_node, :batch) 
  
  #-----------------------------------------------------------------------------
  # Cloud plugin interface
  
  def normalize(reload)
    super
    
    logger.info("Initializing network: reloading? #{reload}")
    myself.config = CORL.configuration(Config.new(myself._export).import({ :autosave => false, :create => false })) unless reload
    
    config.delete(:directory) # TODO: Figure out what to do with this??
    
    unless reload
      @build = Build.new
      ignore([ 'build', File.join('config', 'identities') ])
    end
  end
  
  #---
  
  def remove_plugin
    CORL.remove_plugin(config)
    
    each_plugin do |type, provider, name, plugin|
      CORL.remove_plugin(plugin)  
    end
  end
  
  #-----------------------------------------------------------------------------
  # Checks
  
  def has_nodes?(provider = nil)   
    node_config(provider).export.empty? ? false : true
  end
       
  #-----------------------------------------------------------------------------
  # Property accessors / modifiers
  
  plugin_collection :CORL, :node
  plugin_collection :CORL, :builder, :single_instance => true
  plugin_collection :CORL, :provisioner
  
  #---
  
  def hiera_var
    @hiera
  end
  
  def hiera_var=hiera
    @hiera = hiera
  end
  
  #---
  
  def hiera_override_dir
    File.join(directory, 'config')
  end
   
  #---
  
  def home
    extension_set(:home, ( ENV['USER'] == 'root' ? '/root' : ENV['HOME'] )) 
  end
  
  #---
  
  def directory
    config.directory
  end
  
  #---
  
  def build_directory
    File.join(directory, 'build')
  end
  
  #---
  
  def key_cache_directory
    File.join(build_directory, 'keys')
  end
  #---
  
  def cache
    config.cache
  end
  
  #---
  
  def ignore(files)
    config.ignore(files)
  end
  
  #---
  
  def remote(name)
    config.remote(name)
  end
  
  def set_remote(name, location)
    config.set_remote(name, location)
  end
  
  #---
  
  def node_groups
    groups = {}
    
    each_node_config do |provider, name, info|
      search_node(provider, name, :settings, [], :array).each do |group|
        group = group.to_sym
        groups[group] = [] unless groups.has_key?(group)<commit_msg>Adding key and config directory accessors to the base network plugin.<commit_after>
module CORL
module Plugin
class Network < CORL.plugin_class(:nucleon, :base)
  
  init_plugin_collection(:add_node, :batch) 
  
  #-----------------------------------------------------------------------------
  # Cloud plugin interface
  
  def normalize(reload)
    super
    
    logger.info("Initializing network: reloading? #{reload}")
    myself.config = CORL.configuration(Config.new(myself._export).import({ :autosave => false, :create => false })) unless reload
    
    config.delete(:directory) # TODO: Figure out what to do with this??
    
    unless reload
      @build = Build.new
      ignore([ 'build', File.join('config', 'identities') ])
    end
  end
  
  #---
  
  def remove_plugin
    CORL.remove_plugin(config)
    
    each_plugin do |type, provider, name, plugin|
      CORL.remove_plugin(plugin)  
    end
  end
  
  #-----------------------------------------------------------------------------
  # Checks
  
  def has_nodes?(provider = nil)   
    node_config(provider).export.empty? ? false : true
  end
       
  #-----------------------------------------------------------------------------
  # Property accessors / modifiers
  
  plugin_collection :CORL, :node
  plugin_collection :CORL, :builder, :single_instance => true
  plugin_collection :CORL, :provisioner
  
  #---
  
  def hiera_var
    @hiera
  end
  
  def hiera_var=hiera
    @hiera = hiera
  end
  
  #---
  
  def hiera_override_dir
    File.join(directory, 'config')
  end
   
  #---
  
  def home
    extension_set(:home, ( ENV['USER'] == 'root' ? '/root' : ENV['HOME'] )) 
  end
  
  #---
  
  def directory
    config.directory
  end
  
  #---
  
  def key_directory
    File.join(directory, 'keys')
  end
  
  #---
  
  def build_directory
    File.join(directory, 'build')
  end
  
  #---
  
  def key_cache_directory
    File.join(build_directory, 'keys')
  end
  
  #---
  
  def config_directory
    File.join(directory, 'config')
  end
  
  #---
  
  def cache
    config.cache
  end
  
  #---
  
  def ignore(files)
    config.ignore(files)
  end
  
  #---
  
  def remote(name)
    config.remote(name)
  end
  
  def set_remote(name, location)
    config.set_remote(name, location)
  end
  
  #---
  
  def node_groups
    groups = {}
    
    each_node_config do |provider, name, info|
      search_node(provider, name, :settings, [], :array).each do |group|
        group = group.to_sym
        groups[group] = [] unless groups.has_key?(group)
{'fraction_non_alphanumeric': 0.20406905055487054, 'fraction_numerical': 0.0, 'mean_word_length': 1.763770584894946, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '486648', 'n_tokens_mistral': 1571, 'n_tokens_neox': 1544, 'n_words': 329}