<commit_before>require "edurange/version"
require "edurange/parser"
require "edurange/puppet_master"
require "edurange/edu_machine"
require "edurange/instance"
require "edurange/helper"

module Edurange
  class Init
    # ==== Attributes
    # 
    # * +config_filename+ - Takes a YAML configuration file.
    #
    # === Usage
    #
    #   Edurange::Init.init(yaml_file)
    def self.init(config_filename)

      # Gets name of key file in use from config.yml, depends on line number 
      keyname = IO.readlines(File.expand_path('~/.edurange/config.yml'))[0].gsub("ec2_key:", "").strip
      
      # Get required info for generating config file
      #our_ssh_key = Edurange::PuppetMaster.get_our_ssh_key()
      #puppetmaster_ip = Edurange::PuppetMaster.puppetmaster_ip()

      # Parse the configuration file, extract list of nodes
      nodes = Edurange::Parser.parse_yaml(config_filename, keyname) # format: nodes[node_name, ami_id, users, firewall_rules, packages]
      #puts nodes
      return 

      # For each node
      nodes.each do |node|
        # Extract vital information
        node_name = node[0]
        ami_id = node[1]
        users = node[2]
        firewall_rules = node[3]
        packages = node[4]

        puts "Preparing #{node_name} - Packages: #{packages} ami_id: #{ami_id}"
        # Generate ssl cert, puppet.conf, and Facter facts (based on config)
        certs = Edurange::PuppetMaster.gen_client_ssl_cert()
        conf = Edurange::PuppetMaster.generate_puppet_conf(certs[0])
        facts = Edurange::Parser.facter_facts(certs[0], packages)
        # Write a shell file that configures the client AMI
        Edurange::PuppetMaster.write_shell_config_file(our_ssh_key,puppetmaster_ip, certs, conf, facts)
<commit_msg>Made keyname one-liner more readable<commit_after>require 'edurange/version'
require 'edurange/parser'
require 'edurange/puppet_master'
require 'edurange/edu_machine'
require 'edurange/instance'
require 'edurange/helper'

module Edurange
  class Init
    # ==== Attributes
    # 
    # * +config_filename+ - Takes a YAML configuration file.
    #
    # === Usage
    #
    #   Edurange::Init.init(yaml_file)
    def self.init(config_filename)

      # Gets name of key file in use from config.yml, depends on line number 
      # keyname = IO.readlines(File.expand_path('~/.edurange/config.yml'))[0].gsub("ec2_key:", "").strip
			keyname = File.open(File.expand_path('~/.edurange/config.yml'), 'r') { |f| f.readline.gsub('ec2_key:', '').strip }
      
      # Get required info for generating config file
      #our_ssh_key = Edurange::PuppetMaster.get_our_ssh_key()
      #puppetmaster_ip = Edurange::PuppetMaster.puppetmaster_ip()

      # Parse the configuration file, extract list of nodes
      nodes = Edurange::Parser.parse_yaml(config_filename, keyname) # format: nodes[node_name, ami_id, users, firewall_rules, packages]
      #puts nodes
      return 

      # For each node
      nodes.each do |node|
        # Extract vital information
        node_name = node[0]
        ami_id = node[1]
        users = node[2]
        firewall_rules = node[3]
        packages = node[4]

        puts "Preparing #{node_name} - Packages: #{packages} ami_id: #{ami_id}"
        # Generate ssl cert, puppet.conf, and Facter facts (based on config)
        certs = Edurange::PuppetMaster.gen_client_ssl_cert()
        conf = Edurange::PuppetMaster.generate_puppet_conf(certs[0])
        facts = Edurange::Parser.facter_facts(certs[0], packages)
        # Write a shell file that configures the client AMI
        Edurange::PuppetMaster.write_shell_config_file(our_ssh_key,puppetmaster_ip, certs, conf, facts)

{'fraction_non_alphanumeric': 0.1092001092001092, 'fraction_numerical': 0.005187005187005187, 'mean_word_length': 3.300469483568075, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3254888', 'n_tokens_mistral': 1247, 'n_tokens_neox': 1208, 'n_words': 270}