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 start(self):
     if self.IsFederationLicensed() and self.corpus is not None:
         log_file_name = "/export/hda3/tmp/fed_network_%s" % time.strftime("%d-%b-%y")
         log_file = open(log_file_name, "a+")
         logging.set_logfile(log_file)
         logging.set_verbosity(logging.DEBUG)
         logging.info(" -- starting federation network -- ")
         self.corpus.Start()
     else:
         logging.info(" Federation network not started -- No License or Invalid Configuration")
     return 1
 def start(self):
   if self.IsFederationLicensed() and self.corpus is not None:
     log_file_name = ('/export/hda3/tmp/fed_network_%s' %
                      time.strftime('%d-%b-%y'))
     log_file = open(log_file_name, 'a+')
     logging.set_logfile(log_file)
     logging.set_verbosity(logging.DEBUG)
     logging.info(" -- starting federation network -- ")
     self.corpus.Start()
   else:
     logging.info(" Federation network not started -- No License or Invalid Configuration")
   return 1
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)
    tunnel_config += ('accept=%s\n' % listen_port)
    tunnel_config += ('exec=%s\n' % STUNNEL_PPPD_EXEC)
    
    # Get the ip that the ppp interface will bind to on the local
    corpus_root_config_ip = corpus_root_config.GetPppIp()
    exec_args = ('execargs=%s %s %s:\n') % (STUNNEL_PPPD_EXEC_ARGS,
                                            self.__ec.ENT_CONFIG_NAME,
                                            corpus_root_config_ip)
    tunnel_config += exec_args
    tunnel_config += ('pty=%s\n' % STUNNEL_PTY)
    return tunnel_config
    
  def GetStunnelConfigurationInFile(self, file_name):
    """Generate and write stunnel configuration into file.
    
    Args:
      file_name: the file that the generated config is to be written to.
    
    Returns:
      the file that was open for writing.
    """
    config_file = self.__os.OpenWrite(file_name)
    if config_file:
      tunnel_config = self.GetStunnelConfiguration()
      config_file.write(tunnel_config)
      config_file.close()
    return (0, 'Successful configuration')

if __name__ == '__main__':
  logging.set_verbosity(logging.INFO)
        return (-1, '')

  def Status(self, appliance_id):
    """Checks if the slave can be reached over the connection.
    
    Args:
      appliance_id: The appliance that the status need to be checked with.
    
    Returns:
      (0, 'Success') if reachable, (non zero. 'failure message') otherwise.
    """
    try:
      corpus_root = self.__super_root.GetCorpusRoot(appliance_id)
    except fed_network_config.FederationConfigException, ex:
      logging.error('Exception in getting corpus root %s' % ex.message)
      return (-1, 'failure')
    else:
      ip = corpus_root.GetPppIp()
      cmd = '/bin/ping -qc 2 -w 3 %s' % ip
      logging.info('Executing %s' % cmd)
      (status, output) = self.__os.Execute(cmd)
      logging.info('Executed %s' % cmd)
      if not status:
        lines = output.rsplit('\n')
        logging.error('Ping returned (%s) errors for (%s)' % 
                      (str(lines), appliance_id))
      return (status, output)
          
if __name__ == '__main__':
  logging.set_verbosity(logging.DEBUG)
    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)
  else:
    if FLAGS.command is 'CONNECT':
      if FLAGS.appliance_id is 'ALL':
        (status_connect, message) = client.Start()
      else:
        (status_connect, message) = client.Connect(FLAGS.appliance_id)
      logging.info('Connect resulted in %d %s', status_connect, message)
      sys.exit(status_connect)
    elif FLAGS.command is 'DISCONNECT':
      if FLAGS.appliance_id is 'ALL':
        (status_disconnect, message) = client.Stop()
      else:
        (status_disconnect, message) = client.Disconnect(FLAGS.appliance_id)
      logging.info('Disconnect resulted in %d %s', status_disconnect, message)
      sys.exit(status_disconnect)


if __name__ == '__main__':
  logging.set_verbosity(logging.INFO)
  main(sys.argv)

    def Status(self, appliance_id):
        """Checks if the slave can be reached over the connection.
    
    Args:
      appliance_id: The appliance that the status need to be checked with.
    
    Returns:
      (0, 'Success') if reachable, (non zero. 'failure message') otherwise.
    """
        try:
            corpus_root = self.__super_root.GetCorpusRoot(appliance_id)
        except fed_network_config.FederationConfigException, ex:
            logging.error('Exception in getting corpus root %s' % ex.message)
            return (-1, 'failure')
        else:
            ip = corpus_root.GetPppIp()
            cmd = '/bin/ping -qc 2 -w 3 %s' % ip
            logging.info('Executing %s' % cmd)
            (status, output) = self.__os.Execute(cmd)
            logging.info('Executed %s' % cmd)
            if not status:
                lines = output.rsplit('\n')
                logging.error('Ping returned (%s) errors for (%s)' %
                              (str(lines), appliance_id))
            return (status, output)


if __name__ == '__main__':
    logging.set_verbosity(logging.DEBUG)