def extend_cloud_by_scripts(cloud, logger)
      # search for script directories based first on any clouds which were
      # extended by the cloud and then by the exact cloud name.
      cloud_name = cloud.name.to_s
      base_klass = RightScale::Cloud
      # Note ancestors call returns current class as well. So the end result of 
      # this chain is a ordered list of classes from super-est to the current
      # class
      cloud_klasses = cloud.class.ancestors.select {|klass| klass.ancestors.include?(base_klass) && !(klass == base_klass)}

      search_paths = []
      cloud_klasses.reverse.each do |cloud_klass|
        cloud_alias = cloud_klass.cloud_name
        # first add default search path for cloud name.
        search_path = File.join(RightScale::Platform.filesystem.private_bin_dir, cloud_alias)
        if File.directory?(search_path)
          search_paths << search_path
          logger.debug("Added #{search_path.inspect} to search path for extension scripts.")
        else
          logger.debug("Optional extension script dir #{search_path.inspect} does not exist.")
        end

        # custom paths are last in order to supercede any preceeding extensions.
        cloud.extension_script_base_paths.each do |base_path|
          search_path = File.join(base_path, cloud_alias)
          if File.directory?(search_path)
            search_paths << search_path
            logger.debug("Added #{search_path.inspect} to search path for extension scripts.")
          else
            logger.debug("Optional extension script dir #{search_path.inspect} does not exist.")
          end
        end
      end

      # inject any scripts discovered in script paths as instance methods which
      # return the result of calling the external script.
      search_paths.each do |search_path|
        search_path = File.normalize_path(search_path)
        Dir.glob(File.join(search_path, "*")).each do |script_path|
          script_ext = File.extname(script_path)
          script_name = File.basename(script_path, script_ext)

          # ignore any script names which contain strange characters (like
          # semicolon) for security reasons.
          if script_name =~ /^[_A-Za-z][_A-Za-z0-9]*$/
            logger.debug("Extending #{cloud_name} from #{script_path.inspect}")
            eval_me = <<EOF
def #{script_name}(*arguments)
  return execute_script(\"#{script_path}\", *arguments)
end
EOF
            cloud.instance_eval(eval_me)
          end
        end
      end
    end
def extend_cloud_by_scripts(cloud, logger)
      # search for script directories based first on any clouds which were
      # extended by the cloud and then by the exact cloud name.
      cloud_name = cloud.name.to_s
      base_klass = RightScale::Cloud
      # Note ancestors call returns current class as well. So the end result of 
      # this chain is a ordered list of classes from super-est to the current
      # class
      cloud_klasses = cloud.class.ancestors.select {|klass| klass.ancestors.include?(base_klass) && !(klass == base_klass)}

      search_paths = []
      cloud_klasses.reverse.each do |cloud_klass|
        cloud_alias = cloud_klass.cloud_name
        # first add default search path for cloud name.
        search_path = File.join(RightScale::Platform.filesystem.private_bin_dir, cloud_alias)
        if File.directory?(search_path)
          search_paths << search_path
          logger.debug("Added #{search_path.inspect} to search path for extension scripts.")
        else
          logger.debug("Optional extension script dir #{search_path.inspect} does not exist.")
        end

        # custom paths are last in order to supercede any preceeding extensions.
        cloud.extension_script_base_paths.each do |base_path|
          search_path = File.join(base_path, cloud_alias)
          if File.directory?(search_path)
            search_paths << search_path
            logger.debug("Added #{search_path.inspect} to search path for extension scripts.")
          else
            logger.debug("Optional extension script dir #{search_path.inspect} does not exist.")
          end
        end
      end

      # inject any scripts discovered in script paths as instance methods which
      # return the result of calling the external script.
      search_paths.each do |search_path|
        search_path = File.normalize_path(search_path)
        Dir.glob(File.join(search_path, "*")).each do |script_path|
          script_ext = File.extname(script_path)
          script_name = File.basename(script_path, script_ext)

          # ignore any script names which contain strange characters (like
          # semicolon) for security reasons.
          if script_name =~ /^[_A-Za-z][_A-Za-z0-9]*$/
            logger.debug("Extending #{cloud_name} from #{script_path.inspect}")
            eval_me = <<EOF
def #{script_name}(*arguments)
  return execute_script(\"#{script_path}\", *arguments)
end
EOF
            cloud.instance_eval(eval_me)
          end
        end
      end
    end
Supports runtime extension of the cloud object by external scripts which
 are associated with instance methods. These scripts can also override the
 predefined methods (e.g. write_metadata) to further customize a cloud's
 behavior on a given instance. It may also be better to run some complex
 operation in a child process instead of in the process which is loading
 the cloud object.

 === Parameters
 @param [String] cloud as a registered_type or UNKNOWN_CLOUD_NAME
 @param [Logger] logger