Sha256: 0253e1f86b4be616be688b22312130792949628f4b8784c0d284deaa4d550bb1

Contents?: true

Size: 1.19 KB

Versions: 13

Compression:

Stored size: 1.19 KB

Contents

module Fog
  module Compute
    class AzureRM
      # This class provides the actual implementation for service calls.
      class Real
        def check_vm_exists(resource_group, name, async)
          msg = "Checking Virtual Machine #{name}"
          Fog::Logger.debug msg
          begin
            if async
              response = @compute_mgmt_client.virtual_machines.get_async(resource_group, name, 'instanceView')
            else
              @compute_mgmt_client.virtual_machines.get(resource_group, name, 'instanceView')
            end
          rescue MsRestAzure::AzureOperationError => e
            if e.body['error']['code'] == 'ResourceNotFound'
              Fog::Logger.debug "Virtual machine #{name} doesn't exist."
              return false
            else
              raise_azure_exception(e, msg)
            end
          end
          if async
            response
          else
            Fog::Logger.debug "Virtual machine #{name} exists."
            true
          end
        end
      end
      # This class provides the mock implementation for unit tests.
      class Mock
        def check_vm_exists(_resource_group, _name)
          true
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
fog-azure-rm-0.4.0 lib/fog/azurerm/requests/compute/check_vm_exists.rb
fog-azure-rm-0.3.9 lib/fog/azurerm/requests/compute/check_vm_exists.rb
fog-azure-rm-0.3.8 lib/fog/azurerm/requests/compute/check_vm_exists.rb
fog-azure-rm-0.3.7 lib/fog/azurerm/requests/compute/check_vm_exists.rb
fog-azure-rm-0.3.6 lib/fog/azurerm/requests/compute/check_vm_exists.rb
fog-azure-rm-0.3.5 lib/fog/azurerm/requests/compute/check_vm_exists.rb
fog-azure-rm-0.3.4 lib/fog/azurerm/requests/compute/check_vm_exists.rb
fog-azure-rm-temp-0.0.4 lib/fog/azurerm/requests/compute/check_vm_exists.rb
fog-azure-rm-temp-0.0.3 lib/fog/azurerm/requests/compute/check_vm_exists.rb
fog-azure-rm-0.3.3 lib/fog/azurerm/requests/compute/check_vm_exists.rb
fog-azure-rm-temp-0.0.2 lib/fog/azurerm/requests/compute/check_vm_exists.rb
fog-azure-rm-temp-0.0.1 lib/fog/azurerm/requests/compute/check_vm_exists.rb
fog-azure-rm-0.3.2 lib/fog/azurerm/requests/compute/check_vm_exists.rb