libraries/resource_provider.rb
def parse_namespace
      klass_name = self.class.to_s
      Chef::Log.debug("Resource '#{@resource_name}' received with the '#{klass_name}' class name")
      name_arr = klass_name.split('::')
      @sdk_resource_type = name_arr.pop.gsub(/Provider$/i, '') # e.g., EthernetNetwork
      case name_arr.size
      when 1
        Chef::Log.debug("Resource '#{klass_name}' has no variant or api version specified.")
        # This case should really only be used for testing
        # Uses the SDK's default api version and variant
        return OneviewSDK.resource_named(@sdk_resource_type)
      when 2 # No variant specified. e.g., OneviewCookbook::API200::EthernetNetworkProvider
        Chef::Log.debug("Resource '#{klass_name}' has no variant specified.")
        @sdk_api_version = name_arr.pop.gsub(/API/i, '').to_i # e.g., 200
        @sdk_variant = nil # Not needed
      when 3
        # Parses all the namespace when it is fully specified with API version, variant or base module
        case klass_name
        when /ImageStreamer/
          Chef::Log.debug("Resource '#{klass_name}' is a Image Streamer resource.")
          @sdk_api_version = name_arr.pop.gsub(/API/i, '').to_i # e.g., 300
          @sdk_base_module = OneviewSDK.const_get(name_arr.pop) # ImageStreamer
          @sdk_variant = nil # Not needed
        else # The variant is specified. e.g., OneviewCookbook::API200::C7000::EthernetNetworkProvider
          Chef::Log.debug("Resource '#{klass_name}' has variant and api version specified.")
          @sdk_variant = name_arr.pop # e.g., C7000
          @sdk_api_version = name_arr.pop.gsub(/API/i, '').to_i # e.g., 200
        end
      else # Something is wrong
        raise NameError, "Can't build a resource object from the class #{self.class}"
      end
      klass = @sdk_base_module.resource_named(@sdk_resource_type, @sdk_api_version, @sdk_variant)
      Chef::Log.debug("#{@resource_name} namespace parsed:
        > SDK Base Module: #{@sdk_base_module} <#{@sdk_base_module.class}>
        > SDK API Version: #{@sdk_api_version} <#{@sdk_api_version.class}>
        > SDK Variant: #{@sdk_variant} <#{@sdk_variant.class}>
        > SDK Resource Type: #{@sdk_resource_type} <#{@sdk_resource_type.class}>
      ")
      klass
    end
# rubocop:disable Metrics/MethodLength
# Helper method that analyzes the namespace and defines the class variables and the resource class itself
# @return [OneviewSDK::Resource] SDK resource class
# @raise [NameError] If for some reason the method could not resolve the namespace to a OneviewSDK::Resource
disable Metrics/MethodLength
Helper method that analyzes the namespace and defines the class variables and the resource class itself
disable Metrics / MethodLength Helper method that analyzes the namespace and defines the class variables and the resource class itself
def parse_namespace
      klass_name = self.class.to_s
      Chef::Log.debug("Resource '#{@resource_name}' received with the '#{klass_name}' class name")
      name_arr = klass_name.split('::')
      @sdk_resource_type = name_arr.pop.gsub(/Provider$/i, '') 
      case name_arr.size
      when 1
        Chef::Log.debug("Resource '#{klass_name}' has no variant or api version specified.")
        return OneviewSDK.resource_named(@sdk_resource_type)
      when 2 
        Chef::Log.debug("Resource '#{klass_name}' has no variant specified.")
        @sdk_api_version = name_arr.pop.gsub(/API/i, '').to_i 
        @sdk_variant = nil 
      when 3
        case klass_name
        when /ImageStreamer/
          Chef::Log.debug("Resource '#{klass_name}' is a Image Streamer resource.")
          @sdk_api_version = name_arr.pop.gsub(/API/i, '').to_i 
          @sdk_base_module = OneviewSDK.const_get(name_arr.pop) 
          @sdk_variant = nil 
        else 
          Chef::Log.debug("Resource '#{klass_name}' has variant and api version specified.")
          @sdk_variant = name_arr.pop 
          @sdk_api_version = name_arr.pop.gsub(/API/i, '').to_i 
        end
      else 
        raise NameError, "Can't build a resource object from the class #{self.class}"
      end
      klass = @sdk_base_module.resource_named(@sdk_resource_type, @sdk_api_version, @sdk_variant)
      Chef::Log.debug("#{@resource_name} namespace parsed:
        > SDK Base Module: #{@sdk_base_module} <#{@sdk_base_module.class}>
        > SDK API Version: #{@sdk_api_version} <#{@sdk_api_version.class}>
        > SDK Variant: #{@sdk_variant} <#{@sdk_variant.class}>
        > SDK Resource Type: #{@sdk_resource_type} <#{@sdk_resource_type.class}>
      ")
      klass
    end
def parse_namespace klass_name = self . class . to_s Chef :: Log . debug ( "Resource '#{@resource_name}' received with the '#{klass_name}' class name" ) name_arr = klass_name . split ( '::' ) @sdk_resource_type = name_arr . pop . gsub ( / Provider$ /i , '' ) case name_arr . size when 1 Chef :: Log . debug ( "Resource '#{klass_name}' has no variant or api version specified." ) return OneviewSDK . resource_named ( @sdk_resource_type ) when 2 Chef :: Log . debug ( "Resource '#{klass_name}' has no variant specified." ) @sdk_api_version = name_arr . pop . gsub ( / API /i , '' ) . to_i @sdk_variant = nil when 3 case klass_name when / ImageStreamer / Chef :: Log . debug ( "Resource '#{klass_name}' is a Image Streamer resource." ) @sdk_api_version = name_arr . pop . gsub ( / API /i , '' ) . to_i @sdk_base_module = OneviewSDK . const_get ( name_arr . pop ) @sdk_variant = nil else Chef :: Log . debug ( "Resource '#{klass_name}' has variant and api version specified." ) @sdk_variant = name_arr . pop @sdk_api_version = name_arr . pop . gsub ( / API /i , '' ) . to_i end else raise NameError , "Can't build a resource object from the class #{self.class}" end klass = @sdk_base_module . resource_named ( @sdk_resource_type , @sdk_api_version , @sdk_variant ) Chef :: Log . debug ( "#{@resource_name} namespace parsed:
        > SDK Base Module: #{@sdk_base_module} <#{@sdk_base_module.class}>
        > SDK API Version: #{@sdk_api_version} <#{@sdk_api_version.class}>
        > SDK Variant: #{@sdk_variant} <#{@sdk_variant.class}>
        > SDK Resource Type: #{@sdk_resource_type} <#{@sdk_resource_type.class}>
      " ) klass end
rubocop:disable Metrics/MethodLength
Helper method that analyzes the namespace and defines the class variables and the resource class itself
rubocop : disable Metrics / MethodLength Helper method that analyzes the namespace and defines the class variables and the resource class itself
# e.g., EthernetNetwork # This case should really only be used for testing # Uses the SDK's default api version and variant # No variant specified. e.g., OneviewCookbook::API200::EthernetNetworkProvider # e.g., 200 # Not needed # Parses all the namespace when it is fully specified with API version, variant or base module # e.g., 300 # ImageStreamer # Not needed # The variant is specified. e.g., OneviewCookbook::API200::C7000::EthernetNetworkProvider # e.g., C7000 # e.g., 200 # Something is wrong
SDK resource class
SDK resource class
OneviewSDK::Resource
[NameError] If for some reason the method could not resolve the namespace to a OneviewSDK::Resource
[ NameError ] If for some reason the method could not resolve the namespace to a OneviewSDK :: Resource