Example #1
0
def parse_haproxy(filename,
                  host,
                  username,
                  password,
                  container=None,
                  **kwargs):
    haproxy_dict = defaultdict(list)
    output = run_cmd_on_server('cat %s' % filename,
                               host,
                               username,
                               password,
                               as_sudo=True,
                               container=container,
                               **kwargs)
    keywords = ['frontend', 'backend', 'global', 'defaults']
    pattern = '(?:^|\n)\s*(?:{})'.format('|'.join(map(re.escape, keywords)))
    iters = re.finditer(pattern, output)
    if iters:
        indices = [match.start() for match in iters]
        matches = list(
            map(output.__getslice__, indices, indices[1:] + [len(output)]))

    for match in matches:
        match = match.strip()
        if match.startswith('frontend'):
            haproxy_dict['frontends'].append(get_vip_dict(match))
        elif match.startswith('backend'):
            haproxy_dict['backends'].append(get_pool_dict(match))
    return haproxy_dict
Example #2
0
 def run(self, cmd, **kwargs):
     output = run_cmd_on_server(cmd, self.mgmt_ip,
                                username=self.username,
                                password=self.password,
                                **kwargs)
     self.logger.debug('Executing cmd %s on %s returned %s'%(
                       cmd, self.mgmt_ip, output))
     return output
Example #3
0
def parse_haproxy(filename, host, username, password, container=None, **kwargs):
    haproxy_dict = defaultdict(list)
    output = run_cmd_on_server('cat %s'%filename, host, username, password,
             as_sudo=True, container=container, **kwargs)
    keywords = ['frontend', 'backend', 'global', 'defaults']
    pattern = '(?:^|\n)\s*(?:{})'.format('|'.join(map(re.escape, keywords)))
    iters = re.finditer(pattern, output)
    if iters:
        indices = [match.start() for match in iters]
        matches = map(output.__getslice__, indices, indices[1:] + [len(output)])

    for match in matches:
        match = match.strip()
        if match.startswith('frontend'):
            haproxy_dict['frontends'].append(get_vip_dict(match))
        elif match.startswith('backend'):
            haproxy_dict['backends'].append(get_pool_dict(match))
    return haproxy_dict