<commit_before>#--------------------------------------------------------------------------
# Copyright (c) Microsoft Open Technologies, Inc.
# All Rights Reserved. Licensed under the MIT License.
#--------------------------------------------------------------------------
require 'log4r'

module VagrantPlugins
  module WinAzure
    module Action
      class ReadState
        def initialize(app, env)
          @app = app
          @logger = Log4r::Logger.new('vagrant_azure::action::read_state')
        end

        def call(env)
          env[:machine_state_id] = read_state(env)

          @app.call(env)
        end

        def read_state(env)
          return :NotCreated if env[:machine].id.nil?

          env[:machine].id =~ /@/

          env[:ui].info "Attempting to read state for #{$`} in #{$'}"

          vm = env[:azure_vm_service].get_virtual_machine($`, $')

          env[:ui].info "VM Status: #{vm.status.to_sym}"

          if vm.nil?
            @logger.info 'Machine cannot be found'
            env[:machine].id = nil
            return :NotCreated
          end

          return vm.status.to_sym
        end
      end
    end
  end
end
<commit_msg>ReadState is now able to read the machine id from Vagrantfile if none present in the env[:machine].id<commit_after>#--------------------------------------------------------------------------
# Copyright (c) Microsoft Open Technologies, Inc.
# All Rights Reserved. Licensed under the MIT License.
#--------------------------------------------------------------------------
require 'log4r'

module VagrantPlugins
  module WinAzure
    module Action
      class ReadState
        def initialize(app, env)
          @app = app
          @logger = Log4r::Logger.new('vagrant_azure::action::read_state')
        end

        def call(env)
          env[:machine_state_id] = read_state(env)

          @app.call(env)
        end

        def read_state(env)
          env[:machine].id = "#{env[:machine].provider_config.vm_name}@#{env[:machine].provider_config.cloud_service_name}" unless env[:machine].id

          env[:machine].id =~ /@/

          env[:ui].info "Attempting to read state for #{$`} in #{$'}"

          vm = env[:azure_vm_service].get_virtual_machine($`, $')

          env[:ui].info "VM Status: #{vm.status.to_sym}"

          if vm.nil?
            @logger.info 'Machine cannot be found'
            env[:machine].id = nil
            return :NotCreated
          end

          return vm.status.to_sym
        end
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.21902131018153118, 'fraction_numerical': 0.0015785319652722968, 'mean_word_length': 1.4926253687315634, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6186695', 'n_tokens_mistral': 690, 'n_tokens_neox': 668, 'n_words': 174}