<commit_before>module Vcloud

  class FogServiceInterface
    def initialize
      @vcloud = Fog::Compute::VcloudDirector.new
    end

    def org
      link = session[:Link].select { |l| l[:rel] == Vcloud::RELATION::CHILD }.detect do |l|
        l[:type] == Vcloud::ContentTypes::ORG
      end
      @vcloud.get_organization(link[:href].split('/').last).body
    end

    def get_vapp_by_name_and_vdc_name name, vdc_name
      response = @vcloud.get_vapps_in_lease_from_query({:filter => "name==#{name}"})
      response.body[:VAppRecord].detect{|record| record[:vdcName] == vdc_name}
    end

    def catalog(name)
      link = org[:Link].select { |l| l[:rel] == Vcloud::RELATION::CHILD }.detect do |l|
        l[:type] == Vcloud::ContentTypes::CATALOG && l[:name] == name
      end
      @vcloud.get_catalog(extract_id(link)).body
    end

    def vdc(name)
      link = org[:Link].select { |l| l[:rel] == Vcloud::RELATION::CHILD }.detect do |l|
        l[:type] == Vcloud::ContentTypes::VDC && l[:name] == name
      end
      @vcloud.get_vdc(link[:href].split('/').last).body
    end

    def template(catalog_name, template_name)
      link = catalog(catalog_name)[:CatalogItems][:CatalogItem].detect do |l|
        l[:type] == Vcloud::ContentTypes::CATALOG_ITEM && l[:name].match(template_name)
      end
      if link.nil?
        Vcloud.logger.warn("Template #{template_name} not found in catalog #{catalog_name}")
        return nil
      end
      catalog_item = @vcloud.get_catalog_item(extract_id(link)).body
      catalog_item[:Entity]
    end

    def session
      @vcloud.get_current_session.body
    end

    def post_instantiate_vapp_template(vdc, template, name, params)
      Vcloud.logger.info("instantiating #{name} vapp in #{vdc[:name]}")
      vapp = @vcloud.post_instantiate_vapp_template(extract_id(vdc), template, name, params).body
      @vcloud.process_task(vapp[:Tasks][:Task])
      @vcloud.get_vapp(extract_id(vapp)).body
    end

    def put_memory(vm_id, memory)
      Vcloud.logger.info("putting #{memory}KB memory into VM #{vm_id}")
      task = @vcloud.put_memory(vm_id, memory).body<commit_msg>VM Memory is MB, not KB<commit_after>module Vcloud

  class FogServiceInterface
    def initialize
      @vcloud = Fog::Compute::VcloudDirector.new
    end

    def org
      link = session[:Link].select { |l| l[:rel] == Vcloud::RELATION::CHILD }.detect do |l|
        l[:type] == Vcloud::ContentTypes::ORG
      end
      @vcloud.get_organization(link[:href].split('/').last).body
    end

    def get_vapp_by_name_and_vdc_name name, vdc_name
      response = @vcloud.get_vapps_in_lease_from_query({:filter => "name==#{name}"})
      response.body[:VAppRecord].detect{|record| record[:vdcName] == vdc_name}
    end

    def catalog(name)
      link = org[:Link].select { |l| l[:rel] == Vcloud::RELATION::CHILD }.detect do |l|
        l[:type] == Vcloud::ContentTypes::CATALOG && l[:name] == name
      end
      @vcloud.get_catalog(extract_id(link)).body
    end

    def vdc(name)
      link = org[:Link].select { |l| l[:rel] == Vcloud::RELATION::CHILD }.detect do |l|
        l[:type] == Vcloud::ContentTypes::VDC && l[:name] == name
      end
      @vcloud.get_vdc(link[:href].split('/').last).body
    end

    def template(catalog_name, template_name)
      link = catalog(catalog_name)[:CatalogItems][:CatalogItem].detect do |l|
        l[:type] == Vcloud::ContentTypes::CATALOG_ITEM && l[:name].match(template_name)
      end
      if link.nil?
        Vcloud.logger.warn("Template #{template_name} not found in catalog #{catalog_name}")
        return nil
      end
      catalog_item = @vcloud.get_catalog_item(extract_id(link)).body
      catalog_item[:Entity]
    end

    def session
      @vcloud.get_current_session.body
    end

    def post_instantiate_vapp_template(vdc, template, name, params)
      Vcloud.logger.info("instantiating #{name} vapp in #{vdc[:name]}")
      vapp = @vcloud.post_instantiate_vapp_template(extract_id(vdc), template, name, params).body
      @vcloud.process_task(vapp[:Tasks][:Task])
      @vcloud.get_vapp(extract_id(vapp)).body
    end

    def put_memory(vm_id, memory)
      Vcloud.logger.info("putting #{memory}MB memory into VM #{vm_id}")
      task = @vcloud.put_memory(vm_id, memory).body
{'fraction_non_alphanumeric': 0.14850327408793265, 'fraction_numerical': 0.0, 'mean_word_length': 3.4832285115303985, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2869631', 'n_tokens_mistral': 1469, 'n_tokens_neox': 1444, 'n_words': 264}