<commit_before>module Atmosphere
  class Cloud::VmCreator
    def initialize(tmpl, options={})
      @tmpl = tmpl
      @flavor = options[:flavor] || tmpl.compute_site.default_flavor
      @name = options[:name] || tmpl.name
      @user_data = options[:user_data]
      @user_key = options[:user_key]
      @nic = options[:nic]
      @appliance_type = @tmpl.appliance_type
    end

    def execute
      register_user_key!
      server_params = {}
      server_params[:user_data] = user_data if user_data
      server_params[:key_name] = key_name if key_name
      if @nic
        Rails.logger.info "Spawning server with forced NIC: #{@nic}"
        server_params[:nics] = [{ net_id: @nic }]
      end

      case (@tmpl.compute_site.technology)
      when 'azure'
        server_params[:vm_name] = SecureRandom.hex(5)
        server_params[:vm_user] = Atmosphere.azure_vm_user
        server_params[:password] = Atmosphere.azure_vm_password
        server_params[:image] = tmpl_id
        server_params[:location] = 'West Europe'
        server_params[:cs_id] = @tmpl.compute_site.id
        server_params[:vm_size] = flavor_id
        set_azure_endpoints(server_params)
      else # TODO: Untangle AWS and OpenStack
        server_params[:atmo_user_key] = @user_key
        server_params[:flavor_ref] = flavor_id
        server_params[:flavor_id] = flavor_id
        server_params[:name] = @name
        server_params[:image_ref] = tmpl_id
        server_params[:image_id] = tmpl_id
        server_params[:user_data] = user_data if user_data
        server_params[:key_name] = key_name if key_name
        set_security_groups!(server_params)
      end

      Rails.logger.debug "Params of instantiating server #{server_params}"
      server = servers_client.create(server_params)

      server.id
    end

    private

    attr_reader :user_data

    def set_azure_endpoints(params)
      tcp_endpoints_str = ''
      udp_endpoints_str = ''
      @appliance_type.port_mapping_templates.
        each do |pmt|<commit_msg>changed Azure region to North Europe<commit_after>module Atmosphere
  class Cloud::VmCreator
    def initialize(tmpl, options={})
      @tmpl = tmpl
      @flavor = options[:flavor] || tmpl.compute_site.default_flavor
      @name = options[:name] || tmpl.name
      @user_data = options[:user_data]
      @user_key = options[:user_key]
      @nic = options[:nic]
      @appliance_type = @tmpl.appliance_type
    end

    def execute
      register_user_key!
      server_params = {}
      server_params[:user_data] = user_data if user_data
      server_params[:key_name] = key_name if key_name
      if @nic
        Rails.logger.info "Spawning server with forced NIC: #{@nic}"
        server_params[:nics] = [{ net_id: @nic }]
      end

      case (@tmpl.compute_site.technology)
      when 'azure'
        server_params[:vm_name] = SecureRandom.hex(5)
        server_params[:vm_user] = Atmosphere.azure_vm_user
        server_params[:password] = Atmosphere.azure_vm_password
        server_params[:image] = tmpl_id
        server_params[:location] = 'North Europe'
        server_params[:cs_id] = @tmpl.compute_site.id
        server_params[:vm_size] = flavor_id
        set_azure_endpoints(server_params)
      else # TODO: Untangle AWS and OpenStack
        server_params[:atmo_user_key] = @user_key
        server_params[:flavor_ref] = flavor_id
        server_params[:flavor_id] = flavor_id
        server_params[:name] = @name
        server_params[:image_ref] = tmpl_id
        server_params[:image_id] = tmpl_id
        server_params[:user_data] = user_data if user_data
        server_params[:key_name] = key_name if key_name
        set_security_groups!(server_params)
      end

      Rails.logger.debug "Params of instantiating server #{server_params}"
      server = servers_client.create(server_params)

      server.id
    end

    private

    attr_reader :user_data

    def set_azure_endpoints(params)
      tcp_endpoints_str = ''
      udp_endpoints_str = ''
      @appliance_type.port_mapping_templates.
        each do |pmt|
{'fraction_non_alphanumeric': 0.09488692232055064, 'fraction_numerical': 0.0004916420845624386, 'mean_word_length': 2.9814090019569472, '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': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5552786', 'n_tokens_mistral': 1321, 'n_tokens_neox': 1290, 'n_words': 240}