示例#1
0
def load_accounts(jobs):
    accounts_file = cfg_get('accounts_file')

    accounts = []
    if accounts_file:
        log.info("Loading accounts from file {}.".format(accounts_file))
        with codecs.open(accounts_file, mode='r', encoding='utf-8') as f:
            for line in f:
                fields = line.split(",")
                fields = map(unicode.strip, fields)
                accounts.append(ScoutGuard(fields[0], fields[1], fields[2], jobs))
    elif cfg_get('pgpool_url') and cfg_get('pgpool_system_id') and cfg_get('pgpool_num_accounts') > 0:

        acc_json = load_pgpool_accounts(cfg_get('pgpool_num_accounts'), reuse=True)
        if isinstance(acc_json, dict) and len(acc_json) > 0:
            acc_json = [acc_json]

        for i in range(0, cfg_get('pgpool_num_accounts')):
            if i < len(acc_json):
                accounts.append(ScoutGuard(acc_json[i]['auth_service'], acc_json[i]['username'], acc_json[i]['password'],
                                           jobs))
            else:
                #We are using PGPool, load empty ScoutGuards that can be filled later
                accounts.append(ScoutGuard(auth="", username="******", password="", job_queue=jobs))

    if len(accounts) == 0:
        log.error("Could not load any accounts. Nothing to do. Exiting.")
        sys.exit(1)

    return accounts
示例#2
0
def load_accounts(jobs):
    accounts_file = cfg_get('accounts_file')

    accounts = []
    if accounts_file:
        log.info("Loading accounts from file {}.".format(accounts_file))
        with open(accounts_file, 'r') as f:
            for num, line in enumerate(f, 1):
                fields = line.split(",")
                fields = map(str.strip, fields)
                accounts.append(
                    ScoutGuard(fields[0], fields[1], fields[2], jobs))
    elif cfg_get('pgpool_url') and cfg_get(
            'pgpool_system_id') and cfg_get('pgpool_num_accounts') > 0:

        acc_json = load_pgpool_accounts(cfg_get('pgpool_num_accounts'),
                                        reuse=True)
        if isinstance(acc_json, dict):
            acc_json = [acc_json]

        if len(acc_json) > 0:
            log.info("Loaded {} accounts from PGPool.".format(len(acc_json)))
            for acc in acc_json:
                accounts.append(
                    ScoutGuard(acc['auth_service'], acc['username'],
                               acc['password'], jobs))

    if len(accounts) == 0:
        log.error("Could not load any accounts. Nothing to do. Exiting.")
        sys.exit(1)

    return accounts
示例#3
0
 def swap_account(self):
     while True:
         new_acc = load_pgpool_accounts(1)
         if new_acc:
             log.info("Swapping bad account {} with new account {}".format(self.acc.username, new_acc['username']))
             self.acc = self.init_scout(new_acc)
             break
         log.warning("Could not request new account from PGPool. Out of accounts? Retrying in 1 minute.")
         time.sleep(60)
示例#4
0
    def __init__(self, auth, username, password, job_queue):
        self.job_queue = job_queue
        self.active = True

        # Set up initial account
        initial_account = {
            'auth_service': auth,
            'username': username,
            'password': password
        }
        if not username and use_pgpool():
            initial_account = load_pgpool_accounts(1, reuse=True)
        self.acc = self.init_scout(initial_account)
示例#5
0
 def __init__(self, auth, username, password, job_queue, duplicate, index):
     self.job_queue = job_queue
     self.active = False
     self.index = index
     self.newacc = {}
     self.scouts = []
     
     # Set up initial account
     initial_account = {
         'auth_service': auth,
         'username': username,
         'password': password
     }
     if not username and use_pgpool():
         initial_account = load_pgpool_accounts(1, reuse=True)
     self.acc = self.init_scout(initial_account, duplicate)
     self.active = True
示例#6
0
 def swap_account(self, scouts):
     username = self.acc.username
     password = self.acc.password
     markedwaiting = False
     while True:
         new_acc = load_pgpool_accounts(1)
         if new_acc:
             log.info("Swapping bad account {} with new account {}".format(self.acc.username, new_acc['username']))
             self.update_multiplier_accounts(scouts,self.index,username,password,new_acc,2)
             self.acc = self.init_scout(new_acc, 0)
             break
         elif not markedwaiting:
             self.acc.username = "******"
             self.acc.last_msg = ""
             self.update_multiplier_accounts(scouts,self.index,username,password,{'username' : self.acc.username},1)
             markedwaiting = True
         log.warning("Could not request new account from PGPool. Out of accounts? Retrying in 1 minute.")
         time.sleep(60)
示例#7
0
 def swap_account(self):
     # First get new account, then release to avoid getting same account back.
     self.acc.update_pgpool(release=True, reason=self.acc.last_msg)
     self.acc = self.init_scout(load_pgpool_accounts(1))