Sha256: 8f6ec1302eb4d2677bef31b7074d7b18139039fcade6879ac65dff33d82c0189

Contents?: true

Size: 1.55 KB

Versions: 18

Compression:

Stored size: 1.55 KB

Contents

module Fog
  module Resources
    class AzureRM
      # This class provides the actual implementation for service calls.
      class Real
        def check_azure_resource_exists(resource_id, api_version)
          split_resource = resource_id.split('/') unless resource_id.nil?
          raise 'Invalid Resource Id' if split_resource.count != 9

          resource_group_name = get_resource_from_resource_id(resource_id, RESOURCE_GROUP_NAME)
          resource_provider_namespace = get_resource_from_resource_id(resource_id, RESOURCE_PROVIDER_NAMESPACE)
          resource_type = get_resource_from_resource_id(resource_id, RESOURCE_TYPE)
          resource_name = get_resource_from_resource_id(resource_id, RESOURCE_NAME)
          parent_resource_id = ''

          msg = "Checking Resource #{resource_name}"
          Fog::Logger.debug msg
          begin
            @rmc.resources.check_existence(resource_group_name, resource_provider_namespace, parent_resource_id, resource_type, resource_name, api_version)
            Fog::Logger.debug "Resource #{resource_name} exists."
            true
          rescue MsRestAzure::AzureOperationError => e
            if e.response.status == 405
              Fog::Logger.debug "Resource #{resource_name} doesn't exist."
              false
            else
              raise_azure_exception(e, msg)
            end
          end
        end
      end
      # This class provides the mock implementation for unit tests.
      class Mock
        def check_azure_resource_exists(*)
          true
        end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 3 rubygems

Version Path
fog-azure-rm-temp-0.0.4 lib/fog/azurerm/requests/resources/check_azure_resource_exists.rb
fog-azure-rm-temp-0.0.3 lib/fog/azurerm/requests/resources/check_azure_resource_exists.rb
fog-azure-rm-0.3.3 lib/fog/azurerm/requests/resources/check_azure_resource_exists.rb
fog-azure-rm-temp-0.0.2 lib/fog/azurerm/requests/resources/check_azure_resource_exists.rb
fog-azure-rm-temp-0.0.1 lib/fog/azurerm/requests/resources/check_azure_resource_exists.rb
fog-azure-rm-0.3.2 lib/fog/azurerm/requests/resources/check_azure_resource_exists.rb
fog-azure-rm-downgraded-0.3.1 lib/fog/azurerm/requests/resources/check_azure_resource_exists.rb
fog-azure-rm-0.3.1 lib/fog/azurerm/requests/resources/check_azure_resource_exists.rb
fog-azure-rm-downgraded-0.3.0 lib/fog/azurerm/requests/resources/check_azure_resource_exists.rb
fog-azure-rm-0.3.0 lib/fog/azurerm/requests/resources/check_azure_resource_exists.rb
fog-azure-rm-0.2.7 lib/fog/azurerm/requests/resources/check_azure_resource_exists.rb
fog-azure-rm-0.2.6 lib/fog/azurerm/requests/resources/check_azure_resource_exists.rb
fog-azure-rm-0.2.5 lib/fog/azurerm/requests/resources/check_azure_resource_exists.rb
fog-azure-rm-0.2.4 lib/fog/azurerm/requests/resources/check_azure_resource_exists.rb
fog-azure-rm-0.2.3 lib/fog/azurerm/requests/resources/check_azure_resource_exists.rb
fog-azure-rm-0.2.2 lib/fog/azurerm/requests/resources/check_azure_resource_exists.rb
fog-azure-rm-0.2.1 lib/fog/azurerm/requests/resources/check_azure_resource_exists.rb
fog-azure-rm-0.2.0 lib/fog/azurerm/requests/resources/check_azure_resource_exists.rb