示例#1
0
    def get_all_listeners_status(self, other_listeners=None):
        """Gets the status of all listeners

        This method will not consult the stats socket
        so a listener might show as ACTIVE but still be
        in ERROR

        Currently type==SSL is also not detected
        """
        listeners = list()

        for listener in util.get_listeners():
            status = self._check_listener_status(listener)
            listener_type = ''

            if status == consts.ACTIVE:
                listener_type = self._parse_haproxy_file(listener)['mode']

            listeners.append({
                'status': status,
                'uuid': listener,
                'type': listener_type,
            })

        if other_listeners:
            listeners = listeners + other_listeners
        return webob.Response(json=listeners, content_type='application/json')
示例#2
0
    def get_all_listeners_status(self, other_listeners=None):
        """Gets the status of all listeners

        This method will not consult the stats socket
        so a listener might show as ACTIVE but still be
        in ERROR

        Currently type==SSL is also not detected
        """
        listeners = list()

        for listener in util.get_listeners():
            status = self._check_listener_status(listener)
            listener_type = ''

            if status == consts.ACTIVE:
                listener_type = self._parse_haproxy_file(listener)['mode']

            listeners.append({
                'status': status,
                'uuid': listener,
                'type': listener_type,
            })

        if other_listeners:
            listeners = listeners + other_listeners
        return webob.Response(json=listeners, content_type='application/json')
示例#3
0
    def get_all_listeners_status(self):
        """Gets the status of all listeners

        This method will not consult the stats socket
        so a listener might show as ACTIVE but still be
        in ERROR

        Currently type==SSL is also not detected
        """
        listeners = list()

        for listener in util.get_listeners():
            status = self._check_listener_status(listener)
            listener_type = ''

            if status == consts.ACTIVE:
                listener_type = self._parse_haproxy_file(listener)['mode']

            listeners.append({
                'status': status,
                'uuid': listener,
                'type': listener_type,
            })

        # Can't use jsonify since lists are not supported
        # for security reason: http://stackoverflow.com/
        # questions/12435297/how-do-i-jsonify-a-list-in-flask
        return flask.Response(json.dumps(listeners),
                              mimetype='application/json')
示例#4
0
def compile_amphora_details():
    listener_list = util.get_listeners()
    meminfo = _get_meminfo()
    cpu = _cpu()
    st = os.statvfs('/')
    return flask.jsonify(
        {'hostname': socket.gethostname(),
         'haproxy_version': _get_version_of_installed_package('haproxy'),
         'api_version': api_server.VERSION,
         'networks': _get_networks(),
         'active': True,
         'haproxy_count': _count_haproxy_processes(listener_list),
         'cpu': {
             'total': cpu['total'],
             'user': cpu['user'],
             'system': cpu['system'],
             'soft_irq': cpu['softirq'], },
         'memory': {
             'total': meminfo['MemTotal'],
             'free': meminfo['MemFree'],
             'buffers': meminfo['Buffers'],
             'cached': meminfo['Cached'],
             'swap_used': meminfo['SwapCached'],
             'shared': meminfo['Shmem'],
             'slab': meminfo['Slab'], },
         'disk': {
             'used': (st.f_blocks - st.f_bfree) * st.f_frsize,
             'available': st.f_bavail * st.f_frsize},
         'load': [
             _load()],
         'topology': consts.TOPOLOGY_SINGLE,
         'topology_status': consts.TOPOLOGY_STATUS_OK,
         'listeners': listener_list,
         'packages': {}})
示例#5
0
 def compile_amphora_details(self):
     listener_list = util.get_listeners()
     meminfo = self._get_meminfo()
     cpu = self._cpu()
     st = os.statvfs('/')
     return flask.jsonify(
         {'hostname': socket.gethostname(),
          'haproxy_version':
              self._get_version_of_installed_package('haproxy'),
          'api_version': api_server.VERSION,
          'networks': self._get_networks(),
          'active': True,
          'haproxy_count': self._count_haproxy_processes(listener_list),
          'cpu': {
              'total': cpu['total'],
              'user': cpu['user'],
              'system': cpu['system'],
              'soft_irq': cpu['softirq'], },
          'memory': {
              'total': meminfo['MemTotal'],
              'free': meminfo['MemFree'],
              'buffers': meminfo['Buffers'],
              'cached': meminfo['Cached'],
              'swap_used': meminfo['SwapCached'],
              'shared': meminfo['Shmem'],
              'slab': meminfo['Slab'], },
          'disk': {
              'used': (st.f_blocks - st.f_bfree) * st.f_frsize,
              'available': st.f_bavail * st.f_frsize},
          'load': self._load(),
          'topology': consts.TOPOLOGY_SINGLE,
          'topology_status': consts.TOPOLOGY_STATUS_OK,
          'listeners': listener_list,
          'packages': {}})
示例#6
0
    def get_all_listeners_status(self):
        """Gets the status of all listeners

        This method will not consult the stats socket
        so a listener might show as ACTIVE but still be
        in ERROR

        Currently type==SSL is also not detected
        """
        listeners = list()

        for listener in util.get_listeners():
            status = self._check_listener_status(listener)
            listener_type = ''

            if status == consts.ACTIVE:
                listener_type = self._parse_haproxy_file(listener)['mode']

            listeners.append({
                'status': status,
                'uuid': listener,
                'type': listener_type,
            })

        # Can't use jsonify since lists are not supported
        # for security reason: http://stackoverflow.com/
        # questions/12435297/how-do-i-jsonify-a-list-in-flask
        return flask.Response(json.dumps(listeners),
                              mimetype='application/json')
示例#7
0
def list_sock_stat_files(hadir=None):
    stat_sock_files = {}
    if hadir is None:
        hadir = CONF.haproxy_amphora.base_path
    listener_ids = util.get_listeners()
    for listener_id in listener_ids:
        sock_file = listener_id + ".sock"
        stat_sock_files[listener_id] = os.path.join(hadir, sock_file)
    return stat_sock_files
示例#8
0
def list_sock_stat_files(hadir=None):
    stat_sock_files = {}
    if hadir is None:
        hadir = CONF.haproxy_amphora.base_path
    listener_ids = util.get_listeners()
    for listener_id in listener_ids:
        sock_file = listener_id + ".sock"
        stat_sock_files[listener_id] = os.path.join(hadir, sock_file)
    return stat_sock_files
示例#9
0
 def compile_amphora_details(self, extend_lvs_driver=None):
     haproxy_listener_list = sorted(util.get_listeners())
     extend_body = {}
     lvs_listener_list = []
     if extend_lvs_driver:
         lvs_listener_list = util.get_lvs_listeners()
         extend_data = self._get_extend_body_from_lvs_driver(
             extend_lvs_driver)
         lvs_count = self._count_lvs_listener_processes(
             extend_lvs_driver,
             lvs_listener_list)
         extend_body['lvs_listener_process_count'] = lvs_count
         extend_body.update(extend_data)
     meminfo = self._get_meminfo()
     cpu = self._cpu()
     st = os.statvfs('/')
     body = {'hostname': socket.gethostname(),
             'haproxy_version':
                 self._get_version_of_installed_package('haproxy'),
             'api_version': api_server.VERSION,
             'networks': self._get_networks(),
             'active': True,
             'haproxy_count':
                 self._count_haproxy_processes(haproxy_listener_list),
             'cpu': {
                 'total': cpu['total'],
                 'user': cpu['user'],
                 'system': cpu['system'],
                 'soft_irq': cpu['softirq'], },
             'memory': {
                 'total': meminfo['MemTotal'],
                 'free': meminfo['MemFree'],
                 'buffers': meminfo['Buffers'],
                 'cached': meminfo['Cached'],
                 'swap_used': meminfo['SwapCached'],
                 'shared': meminfo['Shmem'],
                 'slab': meminfo['Slab'], },
             'disk': {
                 'used': (st.f_blocks - st.f_bfree) * st.f_frsize,
                 'available': st.f_bavail * st.f_frsize},
             'load': self._load(),
             'topology': consts.TOPOLOGY_SINGLE,
             'topology_status': consts.TOPOLOGY_STATUS_OK,
             'listeners': sorted(list(
                 set(haproxy_listener_list + lvs_listener_list)))
             if lvs_listener_list else haproxy_listener_list,
             'packages': {}}
     if extend_body:
         body.update(extend_body)
     return webob.Response(json=body)
示例#10
0
    def vrrp_check_script_update(self, listener_id, action):
        listener_ids = util.get_listeners()
        if action == consts.AMP_ACTION_STOP:
            listener_ids.remove(listener_id)
        args = []
        for lid in listener_ids:
            args.append(util.haproxy_sock_path(lid))

        if not os.path.exists(util.keepalived_dir()):
            os.makedirs(util.keepalived_dir())
            os.makedirs(util.keepalived_check_scripts_dir())

        cmd = 'haproxy-vrrp-check {args}; exit $?'.format(args=' '.join(args))
        with open(util.haproxy_check_script_path(), 'w') as text_file:
            text_file.write(cmd)
示例#11
0
def get_all_listeners_status():
    listeners = list()

    for listener in util.get_listeners():
        listeners.append({
            'status': _check_listener_status(listener),
            'uuid': listener,
            'type': _parse_haproxy_file(listener)['mode'],
        })

    # Can't use jsonify since lists are not supported
    # for security reason: http://stackoverflow.com/
    # questions/12435297/how-do-i-jsonify-a-list-in-flask
    return flask.Response(json.dumps(listeners),
                          mimetype='application/json')
示例#12
0
    def vrrp_check_script_update(self, listener_id, action):
        listener_ids = util.get_listeners()
        if action == consts.AMP_ACTION_STOP:
            listener_ids.remove(listener_id)
        args = []
        for lid in listener_ids:
            args.append(util.haproxy_sock_path(lid))

        if not os.path.exists(util.keepalived_dir()):
            os.makedirs(util.keepalived_dir())
            os.makedirs(util.keepalived_check_scripts_dir())

        cmd = 'haproxy-vrrp-check {args}; exit $?'.format(args=' '.join(args))
        with open(util.haproxy_check_script_path(), 'w') as text_file:
            text_file.write(cmd)