def logout(self, instance, ras_msg): instance_info = self.user_obj.getInstanceInfo(instance) query = ibs_query.IBSQuery() #setup call_start_time and call_end_time self.__setTimes(ras_msg, instance_info) no_commit = False if ras_msg.hasAttr("no_commit") and ras_msg["no_commit"]: no_commit = True if no_commit or instance_info.has_key( "min_duration" ) and self.getCallEndTime(instance) - self.getCallStartTime( instance) < instance_info["min_duration"]: used_credit = 0 self.user_obj.setKillReason(instance, "Missed Call") else: used_credit = self.user_obj.charge.calcInstanceCreditUsage( instance, True) if instance_info["successful_auth"] and not no_commit: query += self.user_obj.commit(used_credit) instance_info["used_credit"] = used_credit instance_info["no_commit"] = no_commit return (query, used_credit)
def __insertToTableQuery(self, _date, table_name, val_dic): """ insert values for now in snapshot table val_dic(dic): dic in format {ras_id:value} """ query = ibs_query.IBSQuery() for ras_id in val_dic: query += ibs_db.createInsertQuery(table_name, {"snp_date":dbText(_date), "ras_id":ras_id, "value":val_dic[ras_id]}) return query
def logAnalysis(self, log_dict): """ log_dict(dict):{user_ip:[[request_details], ...]} Insert web request into db """ query = ibs_query.IBSQuery() for ip in log_dict: user_id = self.__getUserIDForIP(ip) if DEBUG: toLog("logAnalysis: user_id is %s" % user_id, LOG_DEBUG) if user_id != None: self.__logRecords(ip, user_id, log_dict[ip], query) query.runQuery()
def insertToTableQuery(self, table_name, val_dic): """ insert values for now in snapshot table """ date = dbText(dbTimeFromEpoch(time.time())) query = ibs_query.IBSQuery() createInsertQuery = ibs_db.createInsertQuery for user_id in val_dic: query += createInsertQuery( table_name, { "snp_date": date, "user_id": user_id, "in_rate": int(val_dic[user_id][0]), "out_rate": int(val_dic[user_id][1]) }) return query
def __postMessageToUserDB(self, user_ids, message_text): query = ibs_query.IBSQuery() message_ids = [] if user_ids: for user_id in user_ids: message_id = self.__getNextMessageIDForUser() message_ids.append(message_id) query += self.__postMessageToUserQuery(message_id, user_id, message_text) else: message_id = self.__getNextMessageIDForUser() message_ids.append(message_id) query += self.__postMessageToUserQuery(message_id, "NULL", message_text) query.runQuery() return message_ids
def logout(self, instance, ras_msg): used_credit = 0 query = ibs_query.IBSQuery() no_commit = False #no commit flag if ras_msg.hasAttr("no_commit") and ras_msg["no_commit"]: no_commit = True if self.user_obj.getInstanceInfo( instance)["successful_auth"] and not no_commit: used_credit = self.user_obj.charge.calcInstanceCreditUsage( instance, True) query += self.user_obj.commit(used_credit) self.user_obj.getInstanceInfo(instance)["used_credit"] = used_credit self.user_obj.getInstanceInfo(instance)["no_commit"] = no_commit return (query, used_credit)
def __deleteAdminDB(self, deleter_admin, admin_obj): admin_id = admin_obj.getAdminID() query_funcs = (self.__deleteAdminLocksQuery, self.__deleteAdminDepositChangesQuery, self.__deleteAdminPermsQuery, self.__deleteAddUserSavesQuery, self.__delAdminUpdateUserOwnersQuery, self.__delAdminUpdateGroupOwnersQuery, self.__delAdminUpdateAdminLockersQuery, self.__delAdminUpdateCreditChangersQuery, self.__delAdminUpdateAdminDepositChangersQuery, self.__delAdminUpdateUserAuditLogAdmins, self.__deleteAdminQuery, self.__delAdminUpdateAdminCreatorsQuery) query = ibs_query.IBSQuery() for func in query_funcs: query += apply(func, (admin_id, )) query += self.__deleteAdminIASQuery(deleter_admin, admin_obj) query.runQuery()
def __addPrefixDB(self,tariff_id,prefix_ids,prefix_codes,prefix_names,cpms,free_seconds,min_durations,round_tos,min_chargable_durations): query=ibs_query.IBSQuery() for _id,code,name,cpm,free_sec,min_duration,round_to,min_chargable_duration in itertools.izip(prefix_ids,prefix_codes,prefix_names,cpms,free_seconds,min_durations,round_tos,min_chargable_durations): query+=self.__addPrefixQuery(tariff_id,_id,code,name,cpm,free_sec,min_duration,round_to,min_chargable_duration) query.runQuery()
def __deleteEventsDB(self, event_ids): query = ibs_query.IBSQuery() for event_id in event_ids: query += self.__deleteEventQuery(event_id) query.runQuery()
def __delIPfromPoolDB(self, ippool_id, ips): query = ibs_query.IBSQuery() for ip in ips: query += self.__delIPfromPoolQuery(ippool_id, ip) query.runQuery()
def __addIPtoPoolDB(self, ippool_id, ips): query = ibs_query.IBSQuery() for ip in ips: query += self.__addIPToPoolQuery(ippool_id, ip) query.runQuery()