def getRunIDs( self): property = System.getProperty("file.separator") eventDirectory = Props.getHome() + property + Props.getDirectoryToStoreEvents() + property idList = [] #print "Possible RunIDs: " for f in java.io.File(eventDirectory).listFiles(): #print str(f) run_id = str(f.getName()).split(".")[0] idList.append(run_id) return idList
def get_taddm_api(): global api_inst if api_inst is None: api_inst = eahelper.get_taddm_api(Props.getRmiBindHostname(), userid, password) return api_inst else: return api_inst
def getEvents( self,runId ): property = System.getProperty("file.separator"); events = ArrayList(4); fileName = Props.getHome() + property + Props.getDirectoryToStoreEvents() + property + runId + ".ser"; file = File(fileName); if (file.exists()): fileInputStream = FileInputStream(fileName); ois = java.io.ObjectInputStream(fileInputStream); while (1) : try: event = ois.readObject(); events.add(event); except: #print "end of file" break ois.close(); else: print "RunID: " + str(runId) + " Not Found!!!" System.exit(1) return events
def worker(mo_array): conn = ApiFactory.getInstance().getApiConnection( Props.getRmiBindHostname(), -1, None, 0) sess = ApiFactory.getInstance().getSession(conn, userid, password, ApiSession.DEFAULT_VERSION) api = sess.createCMDBApi() mo = mo_array.get() while mo: try: output.print_model_object(mo) output.println(" " + str(mo.getGuid()) + " --> Updating object") api.update([mo], None) output.println(" " + str(mo.getGuid()) + " --> Success") except: output.println(" " + str(mo.getGuid()) + " --> Failed") mo = mo_array.get() api.close() sess.close() conn.close()
def guid_worker(guid_array): conn = ApiFactory.getInstance().getApiConnection( Props.getRmiBindHostname(), -1, None, 0) sess = ApiFactory.getInstance().getSession(conn, userid, password, ApiSession.DEFAULT_VERSION) api = sess.createCMDBApi() guid = guid_array.get() while guid: try: output.print_guid(guid) output.println(" " + str(guid) + " --> Removing object") api.delete([guid], None) output.println(" " + str(guid) + " --> Success") except: output.println(" " + str(guid) + " --> Failed") guid = guid_array.get() api.close() sess.close() conn.close()
if create_ea: import ext_attr_helper as ea # Import TADDM Pros library from com.collation.platform.util import Props #------------------------------------------------ # Set Defaults... #------------------------------------------------ if userid is None: userid = "administrator" if password is None: password = "******" # # Initialize # api = ea.get_taddm_api(Props.getRmiBindHostname(), userid, password) attr_names = [ 'sudo_verified', 'sudo_lsof', 'sudo_dmidecode', 'sudo_hba', 'sudo_hba_path', 'sudo_rdm' ] for attr_name in attr_names: print 'Creating ' + attr_name + ' String EA on UnitaryComputerSystem' created = ea.createExtendedAttributes( api, attr_name, 'String', 'com.collation.platform.model.topology.sys.UnitaryComputerSystem' ) print ' Success: ' + str(created) api.close() else: main()
userid = "administrator" if password is None: password = "******" res = CommandLineAuthManager.authorize(userid, password) if res == 0: print 'Authentication Failed!!!' sys.exit(8) #else: #print 'Authentication successful' #print '**** Querying scope set \'' + scopeset + '\' ****' conn = ApiFactory.getInstance().getApiConnection( Props.getRmiBindHostname(), -1, None, 0) sess = ApiFactory.getInstance().getSession(conn, userid, password, ApiSession.DEFAULT_VERSION) api = sess.createCMDBApi() query = 'select name, elements from Scope where name == \'' + scopeset + '\'' data = api.executeQuery(query, 3, None, None) if data.next(): age = 14 #days now = time.time() age_l = long(60 * 60 * 24 * age) # Convert to Milliseconds... end_time = (now - age_l) * 1000 scope = data.getModelObject(3) if scope.hasElements():
if userid is None: userid = "administrator" if password is None: password = "******" res = CommandLineAuthManager.authorize(userid, password) if res == 0 : print 'Authentication Failed!!!' sys.exit(8); #else: #print 'Authentication successful' #print '**** Querying scope set \'' + scopeset + '\' ****' conn = ApiFactory.getInstance().getApiConnection(Props.getRmiBindHostname(),-1,None,0) sess = ApiFactory.getInstance().getSession(conn, userid, password, ApiSession.DEFAULT_VERSION) api = sess.createCMDBApi() query = 'select name, elements from Scope where name == \'' + scopeset + '\'' data = api.executeQuery(query,3,None,None) if data.next(): age = 14 #days now = time.time() age_l = long(60*60*24*age) # Convert to Milliseconds... end_time = (now - age_l)*1000 scope = data.getModelObject(3) if scope.hasElements(): notverified = []
def main(): # define DB connection dbConn = None try: try: opts, args = getopt.getopt(sys.argv[1:], 'u:p:hm:g:t:', ['help']) except getopt.GetoptError, err: # print help information and exit: print str( err) # will print something like "option -a not recognized" usage() sys.exit(2) global userid userid = None global password password = None mql_query = None guid_list = None num_threads = 1 for o, a in opts: if o == "-u": userid = a elif o == "-p": password = a elif o == "-m": mql_query = a elif o == "-g": guid_list = a.split(',') elif o == "-t": num_threads = int(a) elif o in ("-h", "--help"): usage() sys.exit() else: assert False, "unhandled option" #------------------------------------------------ # Set Defaults... #------------------------------------------------ if userid is None: userid = "administrator" if password is None: password = "******" # # Initialize # if mql_query is not None or guid_list is not None: model_objects = [] conn = ApiFactory.getInstance().getApiConnection( Props.getRmiBindHostname(), -1, None, 0) sess = ApiFactory.getInstance().getSession( conn, userid, password, ApiSession.DEFAULT_VERSION) api = sess.createCMDBApi() else: usage() sys.exit() if mql_query is not None: to_expire_count = api.findCount(str(mql_query), None) else: to_expire_count = len(guid_list) print "Deleting: " + str(to_expire_count) if mql_query is not None: mo_data = api.executeQuery(str(mql_query), 0, None, None) # Now we take mo_data and process it... print_model_object_header() to_process_mos = [] if mql_query is not None: while (mo_data.next()): mo = mo_data.getModelObject(0) to_process_mos.append(mo) else: for guid in guid_list: to_process_mos.append(Guid(guid)) if to_process_mos: global output output = Output() to_process_mos.reverse() mo_array = MO_Array(to_process_mos) threads = [] # only create enough threads needed if len(to_process_mos) < num_threads: num_threads = len(to_process_mos) for c in range(0, num_threads): if mql_query is not None: t = threading.Thread(target=worker, args=(mo_array, )) else: t = threading.Thread(target=guid_worker, args=(mo_array, )) t.start() threads.append(t) for t in threads: t.join()