Sha256: 2f1455d2ec70100b5b8ed31250112e97b9c3deb6d42978baca3032d79876a889

Contents?: true

Size: 1.86 KB

Versions: 20

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 tag_resource(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)
          parent_resource_id = ''

          msg = "Creating Tag #{tag_name} for Resource #{resource_name}"
          Fog::Logger.debug msg

          begin
            resource = @rmc.resources.get(resource_group_name, resource_provider_namespace, parent_resource_id, resource_type, resource_name, API_VERSION)
            resource.tags = {} if resource.tags.nil?
            resource.tags[tag_name] = tag_value
            @rmc.resources.create_or_update(resource_group_name, resource_provider_namespace, parent_resource_id, resource_type, resource_name, API_VERSION, resource)
          rescue MsRestAzure::AzureOperationError => e
            raise_azure_exception(e, msg)
          end
          Fog::Logger.debug "Tag #{tag_name} created successfully for Resource #{resource_name}"
          true
        end
      end

      # This class provides the mock implementation for unit tests.
      class Mock
        def tag_resource(_resource_id, tag_name, _tag_value)
          Fog::Logger.debug "Tag #{tag_name} created successfully for Resource 'resource_name'"
          true
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 3 rubygems

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