<commit_before>module KnifeProfitbricks
  module Base

    LVS_ATTRIBUTES = [
      :cpuHotPlug,
      :ramHotPlug,
      :nicHotPlug,
      :nicHotUnplug,
      :discVirtioHotPlug,
      :discVirtioHotUnplug
    ]

    def self.included(base)
      base.class_eval do 
        deps do 
          require 'profitbricks'
          require 'chef/knife'
          require 'knife_profitbricks/extension/profitbricks/profitbricks'
          require 'knife_profitbricks/extension/profitbricks/model'
          require 'knife_profitbricks/extension/profitbricks/has_location'
          require 'knife_profitbricks/extension/profitbricks/server'
          require 'knife_profitbricks/extension/profitbricks/datacenter'
          require 'knife_profitbricks/extension/profitbricks/volume'
          require 'knife_profitbricks/extension/profitbricks/nic'
          require 'knife_profitbricks/extension/profitbricks/location'
          require 'knife_profitbricks/extension/profitbricks/image'
          require 'knife_profitbricks/extension/profitbricks/lan'
          require 'knife_profitbricks/extension/profitbricks/request'
          require 'knife_profitbricks/extension/profitbricks/ipblock'
          require 'knife_profitbricks/extension/profitbricks/firewall'
          require 'knife_profitbricks/extension/profitbricks/location'
          require 'knife_profitbricks/extension/profitbricks/wait_for'
          require 'knife_profitbricks/extension/profitbricks/billing'
          require 'knife_profitbricks/extension/profitbricks/billing/traffic'
          
          Chef::Knife.load_deps
          
          Chef::Config[:solo] = true
        end

        option :profitbricks_data_bag,
          :short => "-a NAME",
          :long => "--profitbricks-data-bag NAME",
          :description => "Data bag for profitbricks account",
          :proc => lambda { |o| Chef::Config[:knife][:profitbricks_data_bag] = o }

        def self.method_added(name)
          if name.to_s == 'run' && !@run_added
            @run_added = true
            alias run_without_establish_connection run
            alias run run_with_establish_connection
          end
        end
      end
    end

    def run_with_establish_connection
      establish_connection
      run_without_establish_connection
    end

    private
    def establish_connection
      user, password = detect_user_and_password
      log "Establish connection to ProfitBricks for #{user.inspect}"
      
      ProfitBricks.configure do |config|
        config.username = user
        config.password = password
        config.global_classes = false
        config.timeout = 300
      end
      
      log "Established ..."
      log "\n"
    end

    def load_data_bag(*args)
      secret_path = Chef::Config[:encrypted_data_bag_secret]<commit_msg> * config for chef solo fixed<commit_after>module KnifeProfitbricks
  module Base

    LVS_ATTRIBUTES = [
      :cpuHotPlug,
      :ramHotPlug,
      :nicHotPlug,
      :nicHotUnplug,
      :discVirtioHotPlug,
      :discVirtioHotUnplug
    ]

    def self.included(base)
      base.class_eval do 
        deps do 
          require 'profitbricks'
          require 'chef/knife'
          require 'knife_profitbricks/extension/profitbricks/profitbricks'
          require 'knife_profitbricks/extension/profitbricks/model'
          require 'knife_profitbricks/extension/profitbricks/has_location'
          require 'knife_profitbricks/extension/profitbricks/server'
          require 'knife_profitbricks/extension/profitbricks/datacenter'
          require 'knife_profitbricks/extension/profitbricks/volume'
          require 'knife_profitbricks/extension/profitbricks/nic'
          require 'knife_profitbricks/extension/profitbricks/location'
          require 'knife_profitbricks/extension/profitbricks/image'
          require 'knife_profitbricks/extension/profitbricks/lan'
          require 'knife_profitbricks/extension/profitbricks/request'
          require 'knife_profitbricks/extension/profitbricks/ipblock'
          require 'knife_profitbricks/extension/profitbricks/firewall'
          require 'knife_profitbricks/extension/profitbricks/location'
          require 'knife_profitbricks/extension/profitbricks/wait_for'
          require 'knife_profitbricks/extension/profitbricks/billing'
          require 'knife_profitbricks/extension/profitbricks/billing/traffic'
          
          Chef::Knife.load_deps
          
          Chef::Config[:solo] = true
          Chef::Config[:solo_legacy_mode] = true
        end

        option :profitbricks_data_bag,
          :short => "-a NAME",
          :long => "--profitbricks-data-bag NAME",
          :description => "Data bag for profitbricks account",
          :proc => lambda { |o| Chef::Config[:knife][:profitbricks_data_bag] = o }

        def self.method_added(name)
          if name.to_s == 'run' && !@run_added
            @run_added = true
            alias run_without_establish_connection run
            alias run run_with_establish_connection
          end
        end
      end
    end

    def run_with_establish_connection
      establish_connection
      run_without_establish_connection
    end

    private
    def establish_connection
      user, password = detect_user_and_password
      log "Establish connection to ProfitBricks for #{user.inspect}"
      
      ProfitBricks.configure do |config|
        config.username = user
        config.password = password
        config.global_classes = false
        config.timeout = 300
        
        if config.path_prefix == '/rest/v2'
          config.path_prefix = '/cloudapi/v3/'
        end
      end

      log "Established ..."
      log "\n"
    end

    def load_data_bag(*args)
      secret_path = Chef::Config[:encrypted_data_bag_secret]
{'fraction_non_alphanumeric': 0.07681684791990333, 'fraction_numerical': 0.001380977041256689, 'mean_word_length': 2.5030229746070134, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '6790459', 'n_tokens_mistral': 1722, 'n_tokens_neox': 1664, 'n_words': 282}