<commit_before>require 'ruby_vim_sdk'
require 'cloud/vsphere/cloud_searcher'
require 'cloud/vsphere/soap_stub'

module VSphereCloud

  class Client
    include VimSdk
    class AlreadyLoggedInException < StandardError; end
    class NotLoggedInException < StandardError; end

    attr_reader :cloud_searcher, :service_content, :service_instance, :soap_stub

    def initialize(host, options={})
      @soap_stub = SoapStub.new(host, options[:soap_log]).create

      @service_instance =Vim::ServiceInstance.new('ServiceInstance', @soap_stub)
      @service_content = @service_instance.content

      @metrics_cache  = {}
      @lock = Mutex.new
      @logger = Bosh::Clouds::Config.logger

      @cloud_searcher = CloudSearcher.new(service_content, @logger)
    end

    def login(username, password, locale)
      raise AlreadyLoggedInException if @session
      @session = @service_content.session_manager.login(username, password, locale)
    end

    def logout
      raise NotLoggedInException unless @session
      @session = nil
      @service_content.session_manager.logout
    end

    def find_parent(obj, parent_type)
      while obj && obj.class != parent_type
        obj = @cloud_searcher.get_property(obj, obj.class, "parent", :ensure_all => true)
      end
      obj
    end
<commit_msg>VSphereClient can optionally have its logger specified<commit_after>require 'ruby_vim_sdk'
require 'cloud/vsphere/cloud_searcher'
require 'cloud/vsphere/soap_stub'

module VSphereCloud

  class Client
    include VimSdk
    class AlreadyLoggedInException < StandardError; end
    class NotLoggedInException < StandardError; end

    attr_reader :cloud_searcher, :service_content, :service_instance, :soap_stub

    def initialize(host, options={})
      @soap_stub = SoapStub.new(host, options[:soap_log]).create

      @service_instance =Vim::ServiceInstance.new('ServiceInstance', @soap_stub)
      @service_content = @service_instance.content

      @metrics_cache  = {}
      @lock = Mutex.new
      @logger = options.fetch(:logger) { Bosh::Clouds::Config.logger }

      @cloud_searcher = CloudSearcher.new(service_content, @logger)
    end

    def login(username, password, locale)
      raise AlreadyLoggedInException if @session
      @session = @service_content.session_manager.login(username, password, locale)
    end

    def logout
      raise NotLoggedInException unless @session
      @session = nil
      @service_content.session_manager.logout
    end

    def find_parent(obj, parent_type)
      while obj && obj.class != parent_type
        obj = @cloud_searcher.get_property(obj, obj.class, "parent", :ensure_all => true)
      end
      obj
    end

{'fraction_non_alphanumeric': 0.09050112191473449, 'fraction_numerical': 0.0, 'mean_word_length': 3.7513321492007106, 'pattern_counts': {'":': 0, '<': 7, '<?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': '1332373', 'n_tokens_mistral': 812, 'n_tokens_neox': 805, 'n_words': 175}