<commit_before># (c) Copyright 2017 Hewlett Packard Enterprise Development LP
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.

require_relative '../../resource_provider'

module OneviewCookbook
  module API200
    # Firmware API200 provider
    class FirmwareDriverProvider < ResourceProvider
      def load_firmware(filename = nil)
        return @item if @item.retrieve!
        filename ||= @name
        filename = ::File.basename(filename, ::File.extname(filename)).tr('.', '_')
        firmware_list = resource_named(:FirmwareDriver).find_by(@item.client, {})
        firmware_list.find { |fw| filename == fw['resourceId'] }
      end

      def add_or_edit
        client = @item.client
        @item = load_firmware
        return Chef::Log.info "#{@resource_name} '#{@name}' is already up to date." if @item
        @context.converge_by "Add #{@resource_name} '#{@name}'" do
          version = OneviewSDK.const_get("API#{@sdk_api_version}")
          version = version.const_get(@sdk_api_variant) if @sdk_api_variant
          version.const_get(:FirmwareBundle).add(client, @name)
        end
      end

      def create_custom_spp
        hotfix_present = @context.hotfixes_names || @context.hotfixes_files
        raise "Unspecified property: 'hotfixes_names' or 'hotfixes_files'. Please set it before attempting this action." unless hotfix_present

        spp_present = @context.spp_name || @context.spp_file
        raise "Unspecified property: 'spp_name' or 'spp_file'. Please set it before attempting this action." unless spp_present

        return Chef::Log.info "#{@resource_name} '#{@name}' is already up to date." if @item.exists?

        load_spp
        load_hotfixes

        @item['customBaselineName'] = @name
        Chef::Log.info "Created custom #{@resource_name} '#{@name}'"
        @context.converge_by "Created custom #{@resource_name} '#{@name}'" do
          @item.data.delete('name')
          @item.create
        end
      end
<commit_msg>Added firmware upload log statement<commit_after># (c) Copyright 2017 Hewlett Packard Enterprise Development LP
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.

require_relative '../../resource_provider'

module OneviewCookbook
  module API200
    # Firmware API200 provider
    class FirmwareDriverProvider < ResourceProvider
      def load_firmware(filename = nil)
        return @item if @item.retrieve!
        filename ||= @name
        filename = ::File.basename(filename, ::File.extname(filename)).tr('.', '_')
        firmware_list = resource_named(:FirmwareDriver).find_by(@item.client, {})
        firmware_list.find { |fw| filename == fw['resourceId'] }
      end

      def add_or_edit
        client = @item.client
        @item = load_firmware
        return Chef::Log.info "#{@resource_name} '#{@name}' is already up to date." if @item
        Chef::Log.info "Adding #{@resource_name} '#{@name}'. This may take some time..."
        @context.converge_by "Add #{@resource_name} '#{@name}'" do
          # resource_named(:FirmwareBundle).add(client, @name) # Waiting on SDK #176
          version = OneviewSDK.const_get("API#{@sdk_api_version}")
          version = version.const_get(@sdk_api_variant) if @sdk_api_variant
          version.const_get(:FirmwareBundle).add(client, @name)
        end
      end

      def create_custom_spp
        hotfix_present = @context.hotfixes_names || @context.hotfixes_files
        raise "Unspecified property: 'hotfixes_names' or 'hotfixes_files'. Please set it before attempting this action." unless hotfix_present

        spp_present = @context.spp_name || @context.spp_file
        raise "Unspecified property: 'spp_name' or 'spp_file'. Please set it before attempting this action." unless spp_present

        return Chef::Log.info "#{@resource_name} '#{@name}' is already up to date." if @item.exists?

        load_spp
        load_hotfixes

        @item['customBaselineName'] = @name
        Chef::Log.info "Creating custom #{@resource_name} '#{@name}'"
        @context.converge_by "Create custom #{@resource_name} '#{@name}'" do
          @item.data.delete('name')
          @item.create
        end
      end

{'fraction_non_alphanumeric': 0.10764430577223089, 'fraction_numerical': 0.006045241809672387, 'mean_word_length': 3.331925675675676, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '936719', 'n_tokens_mistral': 1507, 'n_tokens_neox': 1456, 'n_words': 455}