Sha256: 9e735bf0d17aa26181df573a8e7a3c45ece6d9dcfc132ce3c0608239e6171098

Contents?: true

Size: 1.86 KB

Versions: 1

Compression:

Stored size: 1.86 KB

Contents

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

          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)

          Fog::Logger.debug "Deleting Tag #{tag_name} from Resource #{resource_name}"
          begin
            resource = @rmc.resources.get(resource_group_name, resource_provider_namespace, '', resource_type, resource_name, API_VERSION)

            if resource.tags.key?(tag_name)
              resource.tags.delete_if { |key, value| key == tag_name && value == tag_value }
            end
            @rmc.resources.create_or_update(resource_group_name, resource_provider_namespace, '', resource_type, resource_name, API_VERSION, resource)
            Fog::Logger.debug "Tag #{tag_name} deleted successfully from Resource #{resource_name}"
            true
          rescue  MsRestAzure::AzureOperationError => e
            raise Fog::AzureRm::OperationError.new(e)
          end
        end
      end

      # This class provides the mock implementation for unit tests.
      class Mock
        def delete_resource_tag(_resource_id, tag_name, _tag_value)
          Fog::Logger.debug "Tag #{tag_name} deleted successfully from Resource your-resource-name"
          true
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fog-azure-rm-0.0.5 lib/fog/azurerm/requests/resources/delete_resource_tag.rb