<commit_before>module KnifeProfitbricksFog
  module CreateServer

    private
    def create_volumes
      unless server_config['volumes']
        error("No volumes specified! Please specify \"profitbricks\": {\"server\": \"volumes\": {\"root\": SIZE_IN_GB}} in your node!")
      end

      server_config['volumes'].collect do |hd_name, size_in_gb|
        name = "#{server_name}_#{hd_name}"
        log "Create Volume '#{name}' size: #{size_in_gb} GB"
        options = { :storageName => name }
        
        if hd_name == 'root'
          log "Based on #{boot_image.name}"
          options[:mountImageId] = boot_image.id 
          options[:profitBricksImagePassword] = <PASSWORD> if boot_image.public
        end

        volume = compute.volumes.create(:data_center_id => dc.id, :size => size_in_gb, :options => options)
        
        volume.wait_for { ready? }
        volume.reload
        log "Volume '#{name}' created"
        log ''

        volume
      end
    end

    def do_create_server(boot_volume)
      ram_in_gb = server_config['ram_in_gb']
      ram = ram_in_gb * 1024
      cores = server_config['cores']
      
      log "Create server '#{server_name}': #{ram_in_gb} GB - #{cores} Cores - Boot volume: #{boot_volume.name}"
      
      server = compute.servers.create(:data_center_id => dc.id, :cores => cores, :ram => ram, 
        :options => {
          :serverName => server_name, 
          :internetAccess => true, 
          :osType => 'LINUX',
          :bootFromStorageId => boot_volume.id}.merge(seld.class::LVS_CONFIG))
      
      server.wait_for { ready? }
      server.reload
      log "Server '#{server_name}' created"
      log ''

      server
    end

    def attach_volumes_to_server(volumes)
      current_device_number = server.attached_volumes.collect {|v| v['device_number'] }.max

      volumes.each_with_index do |volume, index|
        log "Attach volume #{volume.name} to server #{server.name} at device number #{current_device_number + index.next}"
        volume.attach(server.id, :device_number => current_device_number + index.next)

        server.wait_for { ready? }
        volume.wait_for { ready? }
        server.reload
        volume.reload
        log "Volume #{volume.name} attached"
        log ''
      end
    end

    def create_server
      @server_is_new = true<commit_msg> * create_server   * typo fixed<commit_after>module KnifeProfitbricksFog
  module CreateServer

    private
    def create_volumes
      unless server_config['volumes']
        error("No volumes specified! Please specify \"profitbricks\": {\"server\": \"volumes\": {\"root\": SIZE_IN_GB}} in your node!")
      end

      server_config['volumes'].collect do |hd_name, size_in_gb|
        name = "#{server_name}_#{hd_name}"
        log "Create Volume '#{name}' size: #{size_in_gb} GB"
        options = { :storageName => name }
        
        if hd_name == 'root'
          log "Based on #{boot_image.name}"
          options[:mountImageId] = boot_image.id 
          options[:profitBricksImagePassword] = <PASSWORD> if boot_image.public
        end

        volume = compute.volumes.create(:data_center_id => dc.id, :size => size_in_gb, :options => options)
        
        volume.wait_for { ready? }
        volume.reload
        log "Volume '#{name}' created"
        log ''

        volume
      end
    end

    def do_create_server(boot_volume)
      ram_in_gb = server_config['ram_in_gb']
      ram = ram_in_gb * 1024
      cores = server_config['cores']
      
      log "Create server '#{server_name}': #{ram_in_gb} GB - #{cores} Cores - Boot volume: #{boot_volume.name}"
      
      server = compute.servers.create(:data_center_id => dc.id, :cores => cores, :ram => ram, 
        :options => {
          :serverName => server_name, 
          :internetAccess => true, 
          :osType => 'LINUX',
          :bootFromStorageId => boot_volume.id}.merge(self.class::LVS_CONFIG))
      
      server.wait_for { ready? }
      server.reload
      log "Server '#{server_name}' created"
      log ''

      server
    end

    def attach_volumes_to_server(volumes)
      current_device_number = server.attached_volumes.collect {|v| v['device_number'] }.max

      volumes.each_with_index do |volume, index|
        log "Attach volume #{volume.name} to server #{server.name} at device number #{current_device_number + index.next}"
        volume.attach(server.id, :device_number => current_device_number + index.next)

        server.wait_for { ready? }
        volume.wait_for { ready? }
        server.reload
        volume.reload
        log "Volume #{volume.name} attached"
        log ''
      end
    end

    def create_server
      @server_is_new = true
{'fraction_non_alphanumeric': 0.12038999576091564, 'fraction_numerical': 0.001695633743111488, 'mean_word_length': 2.449561403508772, 'pattern_counts': {'":': 8, '<': 5, '<?xml version=': 0, '>': 31, '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': '5820629', 'n_tokens_mistral': 1470, 'n_tokens_neox': 1427, 'n_words': 324}