Esempio n. 1
0
  def run(self):
    if(self.loggerFlag):
      logger = logging.getLogger(type(self).__name__)
      logger.info("Starting %s thread." % (self.getName()))
    try:
      processData = True
      config = ConfigParser.RawConfigParser()
      configFile = open(self.configFilename, 'r')
      config.readfp(configFile)
  
      dbUser = config.get('Database', 'user')
      dbPwd = config.get('Database', 'password')
      dbHost = config.get('Database', 'host')
      dbName = config.get('Database', 'name')
      dbConnType = config.get('Database', 'connectionstring')
      
      configFile.close()
      db = xeniaAlchemy()      
      if(db.connectDB(dbConnType, dbUser, dbPwd, dbHost, dbName, False) == True):
        if(logger):
          logger.info("Succesfully connect to DB: %s at %s" %(dbName,dbHost))
      else:
        logger.error("Unable to connect to DB: %s at %s. Terminating script." %(dbName,dbHost))
        processData = False

        #sys.exit(-1)            
    except ConfigParser.Error, e:  
      if(logger):
        logger.exception(e)
Esempio n. 2
0
class platformInventory:
  def __init__(self, organizationID, configurationFile, logger=True):
    self.organizationID = organizationID
    self.configurationFile = configurationFile    
    self.logger = None
    if(logger):
      self.logger = logging.getLogger(type(self).__name__)
    
  def connectDB(self):
    try:
      config = ConfigParser.RawConfigParser()
      config.read(self.configurationFile)  
      dbUser = config.get('Database', 'user')
      dbPwd = config.get('Database', 'password')
      dbHost = config.get('Database', 'host')
      dbName = config.get('Database', 'name')
      dbConnType = config.get('Database', 'connectionstring')
    except ConfigParser.Error, e:  
      if(self.logger):
        self.logger.exception(e)
      return(False)
    try:
      self.db = xeniaAlchemy(self.logger)      
      if(self.db.connectDB(dbConnType, dbUser, dbPwd, dbHost, dbName, False) == True):
        if(self.logger):
          self.logger.info("Succesfully connect to DB: %s at %s" %(dbName,dbHost))
          return(True)
      else:
        self.logger.error("Unable to connect to DB: %s at %s." %(dbName,dbHost))
    except Exception,e:
      self.logger.exception(e)
Esempio n. 3
0
                      dest="dbPwd",
                      help="The xenia database password name to connect with.")
    parser.add_option("-f", "--ResultsFile", dest="resultsFile", help="")

    (options, args) = parser.parse_args()

    try:
        outFile = open(options.resultsFile, "w")

        inventory = assetInventory(baseUrl=options.baseUrl)
        directoryObjs = inventory.getDirectory()
        if (directoryObjs == None):
            print("Did not receive a valid directory object, cannot continue.")
            sys.exit(-1)

        db = xeniaAlchemy()
        if (db.connectDB("postgresql+psycopg2", options.dbUser, options.dbPwd,
                         options.dbHost, options.dbName, False) != True):
            print("Unable to connect to database. Host: %s DBName: %s" %
                  (options.dbHost, options.dbName))
            sys.exit(-1)

        #First pass to log out platforms that aren't in our database.
        outFile.write("Platforms not in database.\n\n")
        for mooring in directoryObjs:
            if (len(mooring['regionalId']) == 0):
                type = inventory.getPlatformType(mooring['urlId'])
                if (type == None):
                    type = ""
                status = inventory.getPlatformStatus(mooring['urlId'])
                if (status == None):
Esempio n. 4
0
                   help="The xenia database password name to connect with." )
 parser.add_option("-f", "--ResultsFile", dest="resultsFile",
                   help="" )
 
 (options, args) = parser.parse_args()
 
 try:
   outFile = open(options.resultsFile, "w")
   
   inventory = assetInventory(baseUrl=options.baseUrl)
   directoryObjs = inventory.getDirectory()
   if(directoryObjs == None):
     print("Did not receive a valid directory object, cannot continue.")
     sys.exit(-1)
     
   db = xeniaAlchemy()
   if(db.connectDB("postgresql+psycopg2", options.dbUser, options.dbPwd, options.dbHost, options.dbName, False) != True):
     print("Unable to connect to database. Host: %s DBName: %s" %(options.dbHost, options.dbName))
     sys.exit(-1)
   
   #First pass to log out platforms that aren't in our database.
   outFile.write("Platforms not in database.\n\n")
   for mooring in directoryObjs:
     if(len(mooring['regionalId']) == 0):
       type = inventory.getPlatformType(mooring['urlId'])
       if(type == None):
         type = ""
       status = inventory.getPlatformStatus(mooring['urlId'])
       if(status == None):
         status = ""
       responsible = inventory.getResponsibleMember(mooring['urlId'])
Esempio n. 5
0
      dbUser = self.config.get('Database', 'user')
      dbPwd = self.config.get('Database', 'password')
      dbHost = self.config.get('Database', 'host')
      dbName = self.config.get('Database', 'name')
      dbConnType = self.config.get('Database', 'connectionstring')
                 
    except ConfigParser.Error, e:  
      if(self.logger):
        self.logger.exception(e)
    except Exception,e:
      if(self.logger):
        self.logger.exception(e)
    else:                              
      try:
        #Attempt to connect to the xenia database
        self.xeniaDb = xeniaAlchemy(self.logger)      
        if(self.xeniaDb.connectDB(dbConnType, dbUser, dbPwd, dbHost, dbName, False) == True):
          if(self.logger):
            self.logger.info("Succesfully connect to DB: %s at %s" %(dbName,dbHost))
          return(True)
        else:
          if(self.logger):
            self.logger.info("Unable to connect to DB: %s at %s" %(dbName,dbHost)) 
          return(False)          
      except Exception,e:
        if(self.logger):
          self.logger.exception(e)                              
    return(False)

  def disconnect(self):
    try: