<commit_before>require 'base64'
require 'uri'
require 'fog/softlayer'
require 'fog/softlayer/models/compute/server'

# fog:SoftLayer:<datacenter>
class Chef
  module Provisioning
    module FogDriver
      module Providers
        class SoftLayer < FogDriver::Driver
          Driver.register_provider_class('SoftLayer', FogDriver::Providers::SoftLayer)

          POST_SCRIPT_DONE = 'post-script-done'

          def creator
            compute_options[:softlayer_username]
          end

          def convergence_strategy_for(machine_spec, machine_options)
            machine_options = Cheffish::MergedConfig.new(machine_options, {
                                                           :convergence_options => {:ohai_hints => {'softlayer' => {}}}
                                                         })
            super(machine_spec, machine_options)
          end

          def self.compute_options_for(provider, id, config)
            new_compute_options = {}
            new_compute_options[:provider] = provider
            new_config = { :driver_options => { :compute_options => new_compute_options }}
            new_defaults = {
              :driver_options => { :compute_options => Fog.credentials },
              :machine_options => { :bootstrap_options => {} }
            }
            result = Cheffish::MergedConfig.new(new_config, config, new_defaults)
            id ||= ''
            new_defaults[:machine_options][:bootstrap_options][:datacenter] = id if not id.empty?

            [result, id]
          end

          def bootstrap_options_for(machine_spec, machine_options)
            # probably best to only ADD options here since super class looks
            # for some values; for example, :key_name doesn't get saved to
            # chef_provisioning.reference if you remove it here.
            # Therefore, we remove things SoftLayer rejects in
            # create_many_servers just before the actual fog create calls.

            opts = super

            if opts[:key_name]
              key_label = opts[:key_name]
              opts[:key_pairs] = [compute.key_pairs.by_label(key_label)] if key_label.is_a? String
            end

            opts
          end

          def create_many_servers(num_servers, bootstrap_options, parallelizer)
            # need to filter out options that SoftLayer doesn't accept
            opts = bootstrap_options.dup

            # options are passed directly to SoftLayer API and
            # SoftLayer_Hardware_Server rejects requests with unrecognized
            # options
            opts.keep_if do |opt, val|
              ::Fog::Compute::Softlayer::Server.attributes.include?(opt)
            end
            # fog-softlayer defines :tags but SoftLayer_Hardware_Server rejects it...
            #opts.delete :tags

            # we hook in our own post-install script which uses userMetadata to
            # tell us when post-install is complete. If the user supplies their
            # own script it will be called by our hook before indicating
            # completion in userData.
            opts[:postInstallScriptUri] = 'https://dal05.objectstorage.service.networklayer.com/v1/AUTH_b1b23a05-1c03-4961-8b08-2339886e476f/dist/sl-post-hook.sh'

            super(num_servers, opts, parallelizer)
          end

          def find_floating_ips(server, action_handler)
            []
          end

          def server_for(machine_spec)
              if machine_spec.reference
                  id = machine_spec.reference['server_id']
                  if id and 0 != id
                    compute.servers.get(id)
                  else
                    sv = compute.servers.new(
                      :uid => machine_spec.reference['uid'],
                      :name => machine_spec.name,
                      :domain => machine_spec.reference['domain']
                    )

                    Chef::Log.info("waiting for server.id")
                    sv.wait_for_id<commit_msg>Machine allocation to a specific :private_vlan and :vlan. (#218)<commit_after>require 'base64'
require 'uri'
require 'fog/softlayer'
require 'fog/softlayer/models/compute/server'

# fog:SoftLayer:<datacenter>
class Chef
  module Provisioning
    module FogDriver
      module Providers
        class SoftLayer < FogDriver::Driver
          Driver.register_provider_class('SoftLayer', FogDriver::Providers::SoftLayer)

          POST_SCRIPT_DONE = 'post-script-done'

          def creator
            compute_options[:softlayer_username]
          end

          def convergence_strategy_for(machine_spec, machine_options)
            machine_options = Cheffish::MergedConfig.new(machine_options, {
                                                           :convergence_options => {:ohai_hints => {'softlayer' => {}}}
                                                         })
            super(machine_spec, machine_options)
          end

          def self.compute_options_for(provider, id, config)
            new_compute_options = {}
            new_compute_options[:provider] = provider
            new_config = { :driver_options => { :compute_options => new_compute_options }}
            new_defaults = {
              :driver_options => { :compute_options => Fog.credentials },
              :machine_options => { :bootstrap_options => {} }
            }
            result = Cheffish::MergedConfig.new(new_config, config, new_defaults)
            id ||= ''
            new_defaults[:machine_options][:bootstrap_options][:datacenter] = id if not id.empty?

            [result, id]
          end

          def bootstrap_options_for(machine_spec, machine_options)
            # probably best to only ADD options here since super class looks
            # for some values; for example, :key_name doesn't get saved to
            # chef_provisioning.reference if you remove it here.
            # Therefore, we remove things SoftLayer rejects in
            # create_many_servers just before the actual fog create calls.

            opts = super

            if opts[:key_name]
              key_label = opts[:key_name]
              opts[:key_pairs] = [compute.key_pairs.by_label(key_label)] if key_label.is_a? String
            end

            opts
          end

          def create_many_servers(num_servers, bootstrap_options, parallelizer)
            # need to filter out options that SoftLayer doesn't accept
            opts = bootstrap_options.dup

            # options are passed directly to SoftLayer API and
            # SoftLayer_Hardware_Server rejects requests with unrecognized
            # options
            opts.delete(:vlan) if opts[:vlan] && opts[:private_network_only]

            opts.keep_if do |opt, val|
              ::Fog::Compute::Softlayer::Server.attributes.include?(opt) || opt =~ /private_vlan|vlan/
            end
            # fog-softlayer defines :tags but SoftLayer_Hardware_Server rejects it...
            #opts.delete :tags

            # we hook in our own post-install script which uses userMetadata to
            # tell us when post-install is complete. If the user supplies their
            # own script it will be called by our hook before indicating
            # completion in userData.
            opts[:postInstallScriptUri] = 'https://dal05.objectstorage.service.networklayer.com/v1/AUTH_b1b23a05-1c03-4961-8b08-2339886e476f/dist/sl-post-hook.sh'

            super(num_servers, opts, parallelizer)
          end

          def find_floating_ips(server, action_handler)
            []
          end

          def server_for(machine_spec)
              if machine_spec.reference
                  id = machine_spec.reference['server_id']
                  if id and 0 != id
                    compute.servers.get(id)
                  else
                    sv = compute.servers.new(
                      :uid => machine_spec.reference['uid'],
                      :name => machine_spec.name,
                      :domain => machine_spec.reference['domain']
                    )

                    Chef::Log.info("waiting for server.id")
                    sv.wait_for_id
{'fraction_non_alphanumeric': 0.07964167382500921, 'fraction_numerical': 0.00797643882684992, 'mean_word_length': 1.8426927101499826, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 29, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4226161', 'n_tokens_mistral': 2147, 'n_tokens_neox': 2047, 'n_words': 499}