def start(self):
   if self.IsFederationLicensed() and os.path.exists(self.config_file):
     logging.info(' -- starting federation network -- ')
 
     # start logging only if federation is enabled
     log_file_name = ('/export/hda3/tmp/fed_network_client_%s' %
                      time.strftime('%d-%b-%y'))
     log_file = open(log_file_name, 'a+')
     logging.set_logfile(log_file)
     logging.set_verbosity(logging.DEBUG)
     sys_abstraction = stunnel_jail.GetSystemAbstraction()
     
     # setup the stunnel jail
     jail = stunnel_jail.StunnelJail(fed_stunnel_config.STUNNEL_CLIENT_CHROOT,
                                     sys_abstraction)
     (status_jail, message) = jail.Setup()
     if status_jail:
       logging.error('The CHROOT Jail could not be setup %s' % message)
       return 1
     try:
       fed_config = fed_network_config.FederationConfig(self.config_file,
                                                        None,
                                                        sys_abstraction)
       logging.info('Federation config read successfully')
       client = fed_network_util.SuperRootStunnelService(sys_abstraction,
                                                         fed_config)
     except fed_network_config.FederationConfigException, ex:
       logging.error('Exception in configuration %s' % ex.message)
       return 1
     else:
       # Connect to all the slaves
       (status_connect, message) = client.Start()
       
       # Create the config root
       (status_config, message) = CreateSuperRootConfig(self.ent_home)
 def __init__(self,
              sys_abstraction=None,
              config=None,
              config_file=None,
              ec=None):
     """The corpus root service needs the xml file for configuration.
 
 Args:
   sys_abstraction: Provides the dependency calls for this object.
   config: The constructed configuration.
   config_file: The configuration xml file location.
   ec: Enterprise configuration.
 """
     if sys_abstraction is None:
         self.__os = stunnel_jail.SystemAbstraction()
     else:
         self.__os = sys_abstraction
     if config_file is None:
         self.__config = config
     else:
         self.__config = fed_network_config.FederationConfig(
             config_file, None, self.__os)
     self.__stunnel_config = fed_stunnel_config.CorpusRootStunnelConfig(
         self.__config, self.__os, ec)
     self.__jail = stunnel_jail.StunnelJail(
         fed_stunnel_config.STUNNEL_CHROOT, self.__os)
 def __init__(self,
              sys_abstraction,
              config=None,
              config_file=None,
              ec=None):
     self.__os = sys_abstraction
     if config is None:
         self.__config = fed_network_config.FederationConfig(
             config_file, None, self.__os)
     else:
         self.__config = config
     if ec is not None:
         self.__ec = ec
     else:
         self.__ec = fed_stunnel_config.GetEnterpriseConfiguration()
     self.__stunnel_config = fed_stunnel_config.SuperRootStunnelConfig(
         self.__config, self.__os, self.__ec)
     self.__super_root = self.__config.GetSuperRootConfig(
         self.__ec.ENT_CONFIG_NAME)
 def stop(self):
   logging.info(' -- stopping federation network -- ')
   if self.IsFederationLicensed() and os.path.exists(self.config_file):
     sys_abstraction = stunnel_jail.GetSystemAbstraction()
     jail = stunnel_jail.StunnelJail(fed_stunnel_config.STUNNEL_CLIENT_CHROOT,
                                     sys_abstraction)
     try:
       fed_config = fed_network_config.FederationConfig(self.config_file,
                                                        None,
                                                        sys_abstraction)
       logging.info('Federation config read successfully')
       client = fed_network_util.SuperRootStunnelService(sys_abstraction,
                                                         fed_config)
     except fed_network_config.FederationConfigException, ex:
       logging.error('Exception in configuration %s' % ex.message)
       (status_jail, message) = jail.Destroy()
       return 1
     else:
       (status_connect, message) = client.Stop()  # Disconnect all the clients
       (status_jail, message) = jail.Destroy()
def main(argv):
  FLAGS(argv)
  if FLAGS.deb:
    logging.set_verbosity(logging.DEBUG)
  
  # start a service if the command is the default specified in flags
  if FLAGS.command is 'DEFAULT':
    fed_network_client = FederationNetworkClientService()
    logging.debug('Launched as a service. Start the service.')
    fed_network_client.execute(argv)
    return
  ec = fed_stunnel_config.GetEnterpriseConfiguration()
  file_path = FEDERATION_NETWORK_CONFIG % ec.ENTERPRISE_HOME
  sys_abstraction = stunnel_jail.GetSystemAbstraction()
  try:
    fed_config = fed_network_config.FederationConfig(file_path, None,
                                                     sys_abstraction)
    logging.info('Federation config read successfully')
    client = fed_network_util.SuperRootStunnelService(sys_abstraction,
                                                      fed_config)
  except fed_network_config.FederationConfigException, ex:
    print ex.message
    logging.error('Exception in configuration %s' % ex.message)
    sys.exit(-1)