def configure_agent(action, options)
      agent_type = options[:agent_type]
      agent_name = options[:agent_name]
      if agent_name != agent_type && (cfg = AgentConfig.load_cfg(agent_type))
        base_id = (options[:base_id] || AgentIdentity.parse(cfg[:identity]).base_id.to_s).to_i
        unless (identity = AgentConfig.agent_options(agent_name)[:identity]) &&
               AgentIdentity.parse(identity).base_id == base_id
          identity = AgentIdentity.new(options[:prefix] || 'rs', options[:agent_type], base_id, options[:token]).to_s
        end
        cfg.merge!(:identity => identity)
        cfg_file = AgentConfig.store_cfg(agent_name, cfg)
        puts "Generated configuration file for #{agent_name} agent: #{cfg_file}"
      elsif !(cfg = AgentConfig.load_cfg(agent_name))
        fail("Deployment is missing configuration file #{AgentConfig.cfg_file(agent_name).inspect}")
      end
      cfg
    end
def configure_agent(action, options)
      agent_type = options[:agent_type]
      agent_name = options[:agent_name]
      if agent_name != agent_type && (cfg = AgentConfig.load_cfg(agent_type))
        base_id = (options[:base_id] || AgentIdentity.parse(cfg[:identity]).base_id.to_s).to_i
        unless (identity = AgentConfig.agent_options(agent_name)[:identity]) &&
               AgentIdentity.parse(identity).base_id == base_id
          identity = AgentIdentity.new(options[:prefix] || 'rs', options[:agent_type], base_id, options[:token]).to_s
        end
        cfg.merge!(:identity => identity)
        cfg_file = AgentConfig.store_cfg(agent_name, cfg)
        puts "Generated configuration file for #{agent_name} agent: #{cfg_file}"
      elsif !(cfg = AgentConfig.load_cfg(agent_name))
        fail("Deployment is missing configuration file #{AgentConfig.cfg_file(agent_name).inspect}")
      end
      cfg
    end
Determine configuration settings for this agent and persist them if needed
 Reuse existing agent identity when possible

 === Parameters
 action(String):: Requested action
 options(Hash):: Command line options

 === Return
 cfg(Hash):: Persisted configuration options