def detect_right_script(st, script)
      Log.debug  "[#{Chimp.get_job_uuid}] Looking for rightscript"
      executable = nil
      # In the event that chimpd find @op_scripts as nil, set it as an array.
      if @op_scripts.nil?
        @op_scripts = []
      end
      if st.nil?
        return executable
      end

      # Take the sts and extract all operational scripts
      @op_scripts = extract_operational_scripts(st)

      # if script is empty, we will list all common scripts
      # if not empty, we will list the first matching one
      if @script == "" and @script != nil
        # list all operational scripts
        reduce_to_common_scripts(st.size)

        script_id = list_and_select_op_script

        # Provide the name + href
        s = Executable.new
        s.params['right_script']['href'] = @op_scripts[script_id][1].right_script.href
        s.params['right_script']['name'] = @op_scripts[script_id][0]
        @script_to_run = s
      else
        # Try to find the rightscript in our list of common operational scripts
        @op_scripts.each  do |rb|
          script_name = rb[0]
          if script_name.downcase.include?(script.downcase)
            # We only need the name and the href
            s = Executable.new
            s.params['right_script']['href'] = rb[1].right_script.href
            s.params['right_script']['name'] = script_name
            @script_to_run = s

            Log.debug "[#{Chimp.get_job_uuid}] Found rightscript"
            return @script_to_run
          end
        end
        #
        # If we reach here it means we didnt find the script in the operationals
        #
        if @script_to_run == nil
          # Search outside common op scripts
          search_for_script_in_sts(script, st)
          if @script_to_run.nil?
            if @interactive
              puts "ERROR: Sorry, didnt find that ( "+script+" ), provide an URI instead"
              puts "I searched in:"
              st.each { |s|
                puts "   *  "+s[1]['name']+"  [Rev"+s[1]['version'].to_s+"]"
              }
              if not @ignore_errors
                exit 1
              end
            else
              Log.error "["+self.job_uuid+"] Sorry, didnt find the script: ( "+script+" )!"
              return nil
            end
          else
            if self.job_uuid.nil?
              self.job_uuid = ""
            end
            Log.warn "["+self.job_uuid+"] \"#{@script_to_run.params['right_script']['name']}\" is not a common operational script!"
            return @script_to_run
          end
        end
      end
    end
def detect_right_script(st, script)
      Log.debug  "[#{Chimp.get_job_uuid}] Looking for rightscript"
      executable = nil
      # In the event that chimpd find @op_scripts as nil, set it as an array.
      if @op_scripts.nil?
        @op_scripts = []
      end
      if st.nil?
        return executable
      end

      # Take the sts and extract all operational scripts
      @op_scripts = extract_operational_scripts(st)

      # if script is empty, we will list all common scripts
      # if not empty, we will list the first matching one
      if @script == "" and @script != nil
        # list all operational scripts
        reduce_to_common_scripts(st.size)

        script_id = list_and_select_op_script

        # Provide the name + href
        s = Executable.new
        s.params['right_script']['href'] = @op_scripts[script_id][1].right_script.href
        s.params['right_script']['name'] = @op_scripts[script_id][0]
        @script_to_run = s
      else
        # Try to find the rightscript in our list of common operational scripts
        @op_scripts.each  do |rb|
          script_name = rb[0]
          if script_name.downcase.include?(script.downcase)
            # We only need the name and the href
            s = Executable.new
            s.params['right_script']['href'] = rb[1].right_script.href
            s.params['right_script']['name'] = script_name
            @script_to_run = s

            Log.debug "[#{Chimp.get_job_uuid}] Found rightscript"
            return @script_to_run
          end
        end
        #
        # If we reach here it means we didnt find the script in the operationals
        #
        if @script_to_run == nil
          # Search outside common op scripts
          search_for_script_in_sts(script, st)
          if @script_to_run.nil?
            if @interactive
              puts "ERROR: Sorry, didnt find that ( "+script+" ), provide an URI instead"
              puts "I searched in:"
              st.each { |s|
                puts "   *  "+s[1]['name']+"  [Rev"+s[1]['version'].to_s+"]"
              }
              if not @ignore_errors
                exit 1
              end
            else
              Log.error "["+self.job_uuid+"] Sorry, didnt find the script: ( "+script+" )!"
              return nil
            end
          else
            if self.job_uuid.nil?
              self.job_uuid = ""
            end
            Log.warn "["+self.job_uuid+"] \"#{@script_to_run.params['right_script']['name']}\" is not a common operational script!"
            return @script_to_run
          end
        end
      end
    end
This function returns @script_to_run which is extracted from matching
 the desired script against all server templates or the script URL