#!/usr/bin/env python3
# Copyright (c) 2006 Arastra, Inc.  All rights reserved.
# Arastra, Inc. Confidential and Proprietary.

from __future__ import absolute_import, division, print_function
import Tac, Agent, os, SysdbUtil

def main():
   import Fru.Agent # pylint: disable=import-outside-toplevel

   tfm = Tac.singleton( 'Tac::TraceFacilityMan' )
   debugTrace = 'Fru.*/0-2,Fru.ModularSystem/9,Fru.Dep/9'
   if 'TRACE' in os.environ:
      os.environ[ 'TRACE' ] += ',' + debugTrace
   else:
      os.environ[ 'TRACE' ] = debugTrace
   tfm.doReadEnvironment()

   # BUG66587: Use longer timeout when waiting for Fru to be mounted on standby 
   # Sysdb since we need to account for active Sysdb initialization time.
   if SysdbUtil.onStandbySsoSupervisor():
      startupWaitTime = SysdbUtil.standbyConnectionTimeout
   else:
      startupWaitTime = None
   container = Agent.AgentContainer( [ Fru.Agent.Fru ], # pylint: disable=no-member
                                     startupWaitTime=startupWaitTime )

   container.addOption( "-f", "--fdlFile", action="store",
                        help="Path to the system fdl file (default %(default)s)",
                        default='/etc/fdl',
                        agentClass=Fru.Agent.Fru ) # pylint: disable=no-member
   container.addOption( "--fdlFileMustExist", action="store_true",
                        help="Whether the fdl file can be non-existent",
                        agentClass=Fru.Agent.Fru ) # pylint: disable=no-member

   # Like all agents, Fru waits for Sysdb to initialize.  This means that
   # LoadConfig runs to completion before Fru, so Cli plugins must not
   # depend on state populated by Fru to do their jobs.
   container.runAgents( )

if __name__ == "__main__":
   main()
