def setmaxconn(self, value): """Set maximum connection to the frontend. :param die: control the handling of errors. :type die: ``bool`` :param value: max connection value. :type value: ``integer`` :return: ``True`` if value was set. :rtype: ``bool`` :raise: If ``die`` is ``True`` :class:`haproxyadmin.exceptions.CommandFailed` or :class:`haproxyadmin.exceptions.MultipleCommandResults` is raised when something bad happens otherwise returns ``False``. Usage:: >>> from haproxyadmin import haproxy >>> hap = haproxy.HAProxy(socket_dir='/run/haproxy') >>> frontend = hap.frontend('frontend1_proc34') >>> frontend.maxconn >>> frontend.setmaxconn(50000) True >>> frontend.maxconn 100000 """ if not isinstance(value, int): raise ValueError("Expected integer and got {}".format(type(value))) cmd = "set maxconn frontend {} {}".format(self.name, value) results = cmd_across_all_procs(self._frontend_per_proc, 'command', cmd) return check_command(results)
def clear_map(self, mapid): """Remove all entries from a mapid. :param mapid: map id or a file :type mapid: ``integer`` or a file path passed as ``string`` :return: ``True`` if command succeeds otherwise ``False`` :rtype: ``bool`` Usage:: >>> from haproxyadmin import haproxy >>> hap = haproxy.HAProxy(socket_dir='/run/haproxy') >>> hap.clear_map(0) True >>> hap.clear_map(mapid='/etc/haproxy/bl_frontend') True """ if isint(mapid): cmd = "clear map #{}".format(mapid) else: cmd = "clear map {}".format(mapid) results = cmd_across_all_procs(self._hap_processes, 'command', cmd) return check_command(results)
def add_map(self, mapid, key, value): """Add an entry into the map. :param mapid: map id or a file. :type mapid: ``integer`` or a file path passed as ``string`` :param key: key to add. :type key: ``string`` :param value: Value assciated to the key. :type value: ``string`` :return: ``True`` if command succeeds otherwise ``False``. :rtype: ``bool`` Usage:: >>> from haproxyadmin import haproxy >>> hap = haproxy.HAProxy(socket_dir='/run/haproxy') >>> hap.show_map(0) ['0x1a78b20 1 www.foo.com-1'] >>> hap.add_map(0, '9', 'foo') True >>> hap.show_map(0) ['0x1a78b20 1 www.foo.com-1', '0x1b15c80 9 foo'] """ if isint(mapid): cmd = "add map #{} {} {}".format(mapid, key, value) else: cmd = "add map {} {} {}".format(mapid, key, value) results = cmd_across_all_procs(self._hap_processes, 'command', cmd) return check_command(results)
def clear_acl(self, acl): """Remove all entries from a acl. :param acl: acl id or a file. :type acl: ``integer`` or a file path passed as ``string`` :return: True if command succeeds otherwise False :rtype: bool Usage:: >>> from haproxyadmin import haproxy >>> hap = haproxy.HAProxy(socket_dir='/run/haproxy') >>> hap.clear_acl(acl=4) True >>> hap.clear_acl(acl='/etc/haproxy/bl_frontend') True """ if isint(acl): cmd = "clear acl #{}".format(acl) else: cmd = "clear acl {}".format(acl) results = cmd_across_all_procs(self._hap_processes, 'command', cmd) return check_command(results)
def add_acl(self, acl, pattern): """Add an entry into the acl. :param acl: acl id or a file. :type acl: ``integer`` or a file path passed as ``string`` :param pattern: entry to add. :type pattern: ``string`` :return: ``True`` if command succeeds otherwise ``False`` :rtype: ``bool`` Usage:: >>> from haproxyadmin import haproxy >>> hap = haproxy.HAProxy(socket_dir='/run/haproxy') >>> hap.show_acl(acl=4) ['0x23181c0 /static/css/'] >>> hap.add_acl(acl=4, pattern='/foo/' ) True >>> hap.show_acl(acl=4) ['0x23181c0 /static/css/', '0x238f790 /foo/'] """ if isint(acl): cmd = "add acl #{} {}".format(acl, pattern) elif os.path.isfile(acl): cmd = "add acl {} {}".format(acl, pattern) else: raise ValueError("Invalid input") results = cmd_across_all_procs(self._hap_processes, 'command', cmd) return check_command(results)
def add_acl(self, acl, pattern): """Add an entry into the acl. :param acl: acl id or a file. :type acl: ``integer`` or a file path passed as ``string`` :param pattern: entry to add. :type pattern: ``string`` :return: ``True`` if command succeeds otherwise ``False`` :rtype: ``bool`` Usage:: >>> from haproxyadmin import haproxy >>> hap = haproxy.HAProxy(socket_dir='/run/haproxy') >>> hap.show_acl(acl=4) ['0x23181c0 /static/css/'] >>> hap.add_acl(acl=4, pattern='/foo/' ) True >>> hap.show_acl(acl=4) ['0x23181c0 /static/css/', '0x238f790 /foo/'] """ if isint(acl): cmd = "add acl #{} {}".format(acl, pattern) else: cmd = "add acl {} {}".format(acl, pattern) results = cmd_across_all_procs(self._hap_processes, 'command', cmd) return check_command(results)
def clear_acl(self, acl): """Remove all entries from a acl. :param acl: acl id or a file. :type acl: ``integer`` or a file path passed as ``string`` :return: True if command succeeds otherwise False :rtype: bool Usage:: >>> from haproxyadmin import haproxy >>> hap = haproxy.HAProxy(socket_dir='/run/haproxy') >>> hap.clear_acl(acl=4) True >>> hap.clear_acl(acl='/etc/haproxy/bl_frontend') True """ if isint(acl): cmd = "clear acl #{}".format(acl) elif os.path.isfile(acl): cmd = "clear acl {}".format(acl) else: raise ValueError("Invalid input") results = cmd_across_all_procs(self._hap_processes, 'command', cmd) return check_command(results)
def add_map(self, mapid, key, value): """Add an entry into the map. :param mapid: map id or a file. :type mapid: ``integer`` or a file path passed as ``string`` :param key: key to add. :type key: ``string`` :param value: Value assciated to the key. :type value: ``string`` :return: ``True`` if command succeeds otherwise ``False``. :rtype: ``bool`` Usage:: >>> from haproxyadmin import haproxy >>> hap = haproxy.HAProxy(socket_dir='/run/haproxy') >>> hap.show_map(0) ['0x1a78b20 1 www.foo.com-1'] >>> hap.add_map(0, '9', 'foo') True >>> hap.show_map(0) ['0x1a78b20 1 www.foo.com-1', '0x1b15c80 9 foo'] """ if isint(mapid): cmd = "add map #{} {} {}".format(mapid, key, value) elif os.path.isfile(mapid): cmd = "add map {} {} {}".format(mapid, key, value) else: raise ValueError("Invalid input") results = cmd_across_all_procs(self._hap_processes, 'command', cmd) return check_command(results)
def setmaxconn(self, value): """Set maximum connection to the frontend. :param die: control the handling of errors. :type die: ``bool`` :param value: max connection value. :type value: ``integer`` :return: ``True`` if value was set. :rtype: ``bool`` :raise: If ``die`` is ``True`` :class:`haproxyadmin.exceptions.CommandFailed` or :class:`haproxyadmin.exceptions.MultipleCommandResults` is raised when something bad happens otherwise returns ``False``. Usage:: >>> from haproxyadmin import haproxy >>> hap = haproxy.HAProxy(socket_dir='/run/haproxy') >>> frontend = hap.frontend('frontend1_proc34') >>> frontend.maxconn >>> frontend.setmaxconn(50000) True >>> frontend.maxconn 100000 """ if not isinstance(value, int): raise ValueError("Expected integer and got {}".format(type(value))) cmd = "set maxconn frontend {} {}".format(self.name, value) results = cmd_across_all_procs(self._frontend_per_proc, 'command', cmd) return check_command(results)
def clear_map(self, mapid): """Remove all entries from a mapid. :param mapid: map id or a file :type mapid: ``integer`` or a file path passed as ``string`` :return: ``True`` if command succeeds otherwise ``False`` :rtype: ``bool`` Usage:: >>> from haproxyadmin import haproxy >>> hap = haproxy.HAProxy(socket_dir='/run/haproxy') >>> hap.clear_map(0) True >>> hap.clear_map(mapid='/etc/haproxy/bl_frontend') True """ if isint(mapid): cmd = "clear map #{}".format(mapid) elif os.path.isfile(mapid): cmd = "clear map {}".format(mapid) else: raise ValueError("Invalid input") results = cmd_across_all_procs(self._hap_processes, 'command', cmd) return check_command(results)
def shutdown(self): """Terminate all the sessions attached to the specified server. :return: ``True`` if command succeeds otherwise ``False``. :rtype: ``bool`` """ cmd = "shutdown sessions server {b}/{s}".format(b=self.backendname, s=self.name) results = cmd_across_all_procs(self._server_per_proc, 'command', cmd) return check_command(results)
def shutdown(self): """Terminate all the sessions attached to the specified server. :return: ``True`` if command succeeds otherwise ``False``. :rtype: ``bool`` """ cmd = "shutdown sessions server {b}/{s}".format(b=self.backendname, s=self.name) results = cmd_across_all_procs(self._server_per_proc, 'command', cmd) return check_command(results)
def shutdown(self): """Disable the frontend. .. warning:: HAProxy removes from the running configuration a frontend, so further operations on the frontend will return an error. :rtype: ``bool`` """ cmd = "shutdown frontend {}".format(self.name) results = cmd_across_all_procs(self._frontend_per_proc, 'command', cmd) return check_command(results)
def shutdown(self): """Disable the frontend. .. warning:: HAProxy removes from the running configuration a frontend, so further operations on the frontend will return an error. :rtype: ``bool`` """ cmd = "shutdown frontend {}".format(self.name) results = cmd_across_all_procs(self._frontend_per_proc, 'command', cmd) return check_command(results)
def setstate(self, state): """Set the state of a server in the backend. State can be any of the following * :const:`haproxyadmin.haproxy.STATE_ENABLE`: Mark the server UP and checks are re-enabled * :const:`haproxyadmin.haproxy.STATE_DISABLE`: Mark the server DOWN for maintenance and checks disabled. * :const:`haproxyadmin.haproxy.STATE_READY`: Put server in normal mode. * :const:`haproxyadmin.haproxy.STATE_DRAIN`: Remove the server from load balancing. * :const:`haproxyadmin.haproxy.STATE_MAINT`: Remove the server from load balancing and health checks are disabled. :param state: state to set. :type state: ``string`` :return: ``True`` if command succeeds otherwise ``False``. :rtype: ``bool`` Usage: >>> from haproxyadmin import haproxy >>> hap = haproxy.HAProxy(socket_dir='/run/haproxy') >>> server = hap.server('member_bkall', backend='backend_proc1')[0] >>> server.setstate(haproxy.STATE_DISABLE) True >>> server.status 'MAINT' >>> server.setstate(haproxy.STATE_ENABLE) True >>> server.status 'no check' """ if state not in VALID_STATES: states = ', '.join(VALID_STATES) raise ValueError("Wrong state, allowed states {}".format(states)) if state == 'enable' or state == 'disable': cmd = "{} server {}/{}".format(state, self.backendname, self.name) else: cmd = "set server {}/{} state {}".format( self.backendname, self.name, state ) results = cmd_across_all_procs(self._server_per_proc, 'command', cmd) return check_command(results)
def setstate(self, state): """Set the state of a server in the backend. State can be any of the following * :const:`haproxyadmin.haproxy.STATE_ENABLE`: Mark the server UP and checks are re-enabled * :const:`haproxyadmin.haproxy.STATE_DISABLE`: Mark the server DOWN for maintenance and checks disabled. * :const:`haproxyadmin.haproxy.STATE_READY`: Put server in normal mode. * :const:`haproxyadmin.haproxy.STATE_DRAIN`: Remove the server from load balancing. * :const:`haproxyadmin.haproxy.STATE_MAINT`: Remove the server from load balancing and health checks are disabled. :param state: state to set. :type state: ``string`` :return: ``True`` if command succeeds otherwise ``False``. :rtype: ``bool`` Usage: >>> from haproxyadmin import haproxy >>> hap = haproxy.HAProxy(socket_dir='/run/haproxy') >>> server = hap.server('member_bkall', backend='backend_proc1')[0] >>> server.setstate(haproxy.STATE_DISABLE) True >>> server.status 'MAINT' >>> server.setstate(haproxy.STATE_ENABLE) True >>> server.status 'no check' """ if state not in VALID_STATES: states = ', '.join(VALID_STATES) raise ValueError("Wrong state, allowed states {}".format(states)) if state == 'enable' or state == 'disable': cmd = "{} server {}/{}".format(state, self.backendname, self.name) else: cmd = "set server {}/{} state {}".format( self.backendname, self.name, state ) results = cmd_across_all_procs(self._server_per_proc, 'command', cmd) return check_command(results)
def enable(self): """Enable frontend. :param die: control the handling of errors. :type die: ``bool`` :return: ``True`` if frontend is enabled otherwise ``False``. :rtype: bool :raise: If ``die`` is ``True`` :class:`haproxyadmin.exceptions.CommandFailed` or :class:`haproxyadmin.exceptions.MultipleCommandResults` is raised when something bad happens otherwise returns ``False``. """ cmd = "enable frontend {}".format(self.name) results = cmd_across_all_procs(self._frontend_per_proc, 'command', cmd) return check_command(results)
def setratelimitsslsess(self, value): """Set process-wide ssl session rate limit. :param value: rate ssl session limit. :type value: ``integer`` :return: ``True`` if command succeeds otherwise ``False``. :rtype: ``bool`` :raises: ``ValueError`` if value is not an ``integer``. """ if not isinstance(value, int): raise ValueError("Expected integer and got {}".format(type(value))) cmd = "set rate-limit ssl-sessions global {}".format(value) results = cmd_across_all_procs(self._hap_processes, 'command', cmd) return check_command(results)
def enable(self): """Enable frontend. :param die: control the handling of errors. :type die: ``bool`` :return: ``True`` if frontend is enabled otherwise ``False``. :rtype: bool :raise: If ``die`` is ``True`` :class:`haproxyadmin.exceptions.CommandFailed` or :class:`haproxyadmin.exceptions.MultipleCommandResults` is raised when something bad happens otherwise returns ``False``. """ cmd = "enable frontend {}".format(self.name) results = cmd_across_all_procs(self._frontend_per_proc, 'command', cmd) return check_command(results)
def setratelimitsslsess(self, value): """Set process-wide ssl session rate limit. :param value: rate ssl session limit. :type value: ``integer`` :return: ``True`` if command succeeds otherwise ``False``. :rtype: ``bool`` :raises: ``ValueError`` if value is not an ``integer``. """ if not isinstance(value, int): raise ValueError("Expected integer and got {}".format(type(value))) cmd = "set rate-limit ssl-sessions global {}".format(value) results = cmd_across_all_procs(self._hap_processes, 'command', cmd) return check_command(results)
def setweight(self, value): """Set a weight. If the value ends with the '%' sign, then the new weight will be relative to the initially configured weight. Absolute weights are permitted between 0 and 256. :param value: Weight to set :type value: integer or string with '%' sign :return: ``True`` if command succeeds otherwise ``False``. :rtype: ``bool`` Usage: >>> from haproxyadmin import haproxy >>> hap = haproxy.HAProxy(socket_dir='/run/haproxy') >>> server = hap.server('member_bkall', backend='backend_proc1')[0] >>> server.weight 100 >>> server.setweight('20%') True >>> server.weight 20 >>> server.setweight(58) True >>> server.weight 58 """ msg = ( "Invalid weight, absolute weights are permitted between 0 and " "256 and need to be passed as integers or relative weights " "are allowed when the value ends with the '%' sign pass as " "string" ) if isinstance(value, int) and 0 <= value < 256 or ( isinstance(value, str) and value.endswith('%')): cmd = "set weight {}/{} {}".format(self.backendname, self.name, value) else: raise ValueError(msg) results = cmd_across_all_procs(self._server_per_proc, 'command', cmd) return check_command(results)
def setweight(self, value): """Set a weight. If the value ends with the '%' sign, then the new weight will be relative to the initially configured weight. Absolute weights are permitted between 0 and 256. :param value: Weight to set :type value: integer or string with '%' sign :return: ``True`` if command succeeds otherwise ``False``. :rtype: ``bool`` Usage: >>> from haproxyadmin import haproxy >>> hap = haproxy.HAProxy(socket_dir='/run/haproxy') >>> server = hap.server('member_bkall', backend='backend_proc1')[0] >>> server.weight 100 >>> server.setweight('20%') True >>> server.weight 20 >>> server.setweight(58) True >>> server.weight 58 """ msg = ( "Invalid weight, absolute weights are permitted between 0 and " "256 and need to be passed as integers or relative weights " "are allowed when the value ends with the '%' sign pass as " "string" ) if isinstance(value, int) and 0 <= value < 256 or ( isinstance(value, str) and value.endswith('%')): cmd = "set weight {}/{} {}".format(self.backendname, self.name, value) else: raise ValueError(msg) results = cmd_across_all_procs(self._server_per_proc, 'command', cmd) return check_command(results)
def set_map(self, mapid, key, value): """Modify the value corresponding to each key in a map. mapid is the #<id> or <file> returned by :func:`show_map <haproxyadmin.haproxy.HAProxy.show_map>`. :param mapid: map id or a file. :type mapid: ``integer`` or a file path passed as ``string`` :param key: key id :type key: ``string`` :param value: value to set for the key. :type value: ``string`` :return: ``True`` if command succeeds otherwise ``False``. :rtype: ``bool`` Usage:: >>> from haproxyadmin import haproxy >>> hap = haproxy.HAProxy(socket_dir='/run/haproxy') >>> hap.show_map(0) ['0x1a78980 11 9', '0x1b15c00 22 0'] >>> hap.set_map(0, '11', 'new') True >>> hap.show_map(0) ['0x1a78980 11 new', '0x1b15c00 22 0'] >>> hap.set_map(0, '0x1a78980', 'new2') True >>> hap.show_map(0) ['0x1a78980 11 new2', '0x1b15c00 22 0'] """ if key.startswith('0x'): key = "#{}".format(key) if isint(mapid): cmd = "set map #{} {} {}".format(mapid, key, value) elif os.path.isfile(mapid): cmd = "set map {} {} {}".format(mapid, key, value) else: raise ValueError("Invalid input") results = cmd_across_all_procs(self._hap_processes, 'command', cmd) return check_command(results)
def del_map(self, mapid, key): """Delete all the map entries from the map corresponding to the key. :param mapid: map id or a file. :type mapid: ``integer`` or a file path passed as ``string``. :param key: key to delete :type key: ``string`` :return: ``True`` if command succeeds otherwise ``False``. :rtype: ``bool`` Usage:: >>> from haproxyadmin import haproxy >>> hap = haproxy.HAProxy(socket_dir='/run/haproxy') >>> hap.show_map(0) ['0x1b15cd0 9 foo', '0x1a78980 11 bar'] >>> hap.del_map(0, '0x1b15cd0') True >>> hap.show_map(0) ['0x1a78980 11 bar'] >>> hap.add_map(0, '22', 'bar22') True >>> hap.show_map(0) ['0x1a78980 11 bar', '0x1b15c00 22 bar22'] >>> hap.del_map(0, '22') True >>> hap.show_map(0) ['0x1a78980 11 bar'] """ if key.startswith('0x'): key = "#{}".format(key) if isint(mapid): cmd = "del map #{} {}".format(mapid, key) elif os.path.isfile(mapid): cmd = "del map {} {}".format(mapid, key) else: raise ValueError("Invalid input") results = cmd_across_all_procs(self._hap_processes, 'command', cmd) return check_command(results)
def set_map(self, mapid, key, value): """Modify the value corresponding to each key in a map. mapid is the #<id> or <file> returned by :func:`show_map <haproxyadmin.haproxy.HAProxy.show_map>`. :param mapid: map id or a file. :type mapid: ``integer`` or a file path passed as ``string`` :param key: key id :type key: ``string`` :param value: value to set for the key. :type value: ``string`` :return: ``True`` if command succeeds otherwise ``False``. :rtype: ``bool`` Usage:: >>> from haproxyadmin import haproxy >>> hap = haproxy.HAProxy(socket_dir='/run/haproxy') >>> hap.show_map(0) ['0x1a78980 11 9', '0x1b15c00 22 0'] >>> hap.set_map(0, '11', 'new') True >>> hap.show_map(0) ['0x1a78980 11 new', '0x1b15c00 22 0'] >>> hap.set_map(0, '0x1a78980', 'new2') True >>> hap.show_map(0) ['0x1a78980 11 new2', '0x1b15c00 22 0'] """ if key.startswith('0x'): key = "#{}".format(key) if isint(mapid): cmd = "set map #{} {} {}".format(mapid, key, value) elif os.path.isfile(mapid): cmd = "set map {} {} {}".format(mapid, key, value) else: raise ValueError("Invalid input") results = cmd_across_all_procs(self._hap_processes, 'command', cmd) return check_command(results)
def del_map(self, mapid, key): """Delete all the map entries from the map corresponding to the key. :param mapid: map id or a file. :type mapid: ``integer`` or a file path passed as ``string``. :param key: key to delete :type key: ``string`` :return: ``True`` if command succeeds otherwise ``False``. :rtype: ``bool`` Usage:: >>> from haproxyadmin import haproxy >>> hap = haproxy.HAProxy(socket_dir='/run/haproxy') >>> hap.show_map(0) ['0x1b15cd0 9 foo', '0x1a78980 11 bar'] >>> hap.del_map(0, '0x1b15cd0') True >>> hap.show_map(0) ['0x1a78980 11 bar'] >>> hap.add_map(0, '22', 'bar22') True >>> hap.show_map(0) ['0x1a78980 11 bar', '0x1b15c00 22 bar22'] >>> hap.del_map(0, '22') True >>> hap.show_map(0) ['0x1a78980 11 bar'] """ if key.startswith('0x'): key = "#{}".format(key) if isint(mapid): cmd = "del map #{} {}".format(mapid, key) elif os.path.isfile(mapid): cmd = "del map {} {}".format(mapid, key) else: raise ValueError("Invalid input") results = cmd_across_all_procs(self._hap_processes, 'command', cmd) return check_command(results)
def clearcounters(self, all=False): """Clear the max values of the statistics counters. When ``all`` is set to ``True`` clears all statistics counters in each proxy (frontend & backend) and in each server. This has the same effect as restarting. :param all: (optional) clear all statistics counters. :type all: ``bool`` :return: ``True`` if command succeeds otherwise ``False``. :rtype: ``bool`` """ if all: cmd = "clear counters all" else: cmd = "clear counters" results = cmd_across_all_procs(self._hap_processes, 'command', cmd) return check_command(results)
def clearcounters(self, all=False): """Clear the max values of the statistics counters. When ``all`` is set to ``True`` clears all statistics counters in each proxy (frontend & backend) and in each server. This has the same effect as restarting. :param all: (optional) clear all statistics counters. :type all: ``bool`` :return: ``True`` if command succeeds otherwise ``False``. :rtype: ``bool`` """ if all: cmd = "clear counters all" else: cmd = "clear counters" results = cmd_across_all_procs(self._hap_processes, 'command', cmd) return check_command(results)
def setmaxconn(self, value): """Set maximum connection to the frontend. :param value: value to set. :type value: ``integer`` :return: ``True`` if command succeeds otherwise ``False``. :rtype: ``bool`` Usage: >>> from haproxyadmin import haproxy >>> hap = haproxy.HAProxy(socket_dir='/run/haproxy') >>> hap.setmaxconn(5555) True """ if not isinstance(value, int): raise ValueError("Expected integer and got {}".format(type(value))) cmd = "set maxconn global {}".format(value) results = cmd_across_all_procs(self._hap_processes, 'command', cmd) return check_command(results)
def del_acl(self, acl, key): """Delete all the acl entries from the acl corresponding to the key. :param acl: acl id or a file :type acl: ``integer`` or a file path passed as ``string`` :param key: key to delete. :type key: ``string`` :return: ``True`` if command succeeds otherwise ``False``. :rtype: ``bool`` Usage:: >>> from haproxyadmin import haproxy >>> hap = haproxy.HAProxy(socket_dir='/run/haproxy') >>> hap.show_acl(acl=4) ['0x23181c0 /static/css/', '0x238f790 /foo/', '0x238f810 /bar/'] >>> hap.del_acl(acl=4, key='/static/css/') True >>> hap.show_acl(acl=4) ['0x238f790 /foo/', '0x238f810 /bar/'] >>> hap.del_acl(acl=4, key='0x238f790') True >>> hap.show_acl(acl=4) ['0x238f810 /bar/'] """ if key.startswith('0x'): key = "#{}".format(key) if isint(acl): cmd = "del acl #{} {}".format(acl, key) elif os.path.isfile(acl): cmd = "del acl {} {}".format(acl, key) else: raise ValueError("Invalid input") results = cmd_across_all_procs(self._hap_processes, 'command', cmd) return check_command(results)
def setmaxconn(self, value): """Set maximum connection to the frontend. :param value: value to set. :type value: ``integer`` :return: ``True`` if command succeeds otherwise ``False``. :rtype: ``bool`` Usage: >>> from haproxyadmin import haproxy >>> hap = haproxy.HAProxy(socket_dir='/run/haproxy') >>> hap.setmaxconn(5555) True """ if not isinstance(value, int): raise ValueError("Expected integer and got {}".format(type(value))) cmd = "set maxconn global {}".format(value) results = cmd_across_all_procs(self._hap_processes, 'command', cmd) return check_command(results)
def del_acl(self, acl, key): """Delete all the acl entries from the acl corresponding to the key. :param acl: acl id or a file :type acl: ``integer`` or a file path passed as ``string`` :param key: key to delete. :type key: ``string`` :return: ``True`` if command succeeds otherwise ``False``. :rtype: ``bool`` Usage:: >>> from haproxyadmin import haproxy >>> hap = haproxy.HAProxy(socket_dir='/run/haproxy') >>> hap.show_acl(acl=4) ['0x23181c0 /static/css/', '0x238f790 /foo/', '0x238f810 /bar/'] >>> hap.del_acl(acl=4, key='/static/css/') True >>> hap.show_acl(acl=4) ['0x238f790 /foo/', '0x238f810 /bar/'] >>> hap.del_acl(acl=4, key='0x238f790') True >>> hap.show_acl(acl=4) ['0x238f810 /bar/'] """ if key.startswith('0x'): key = "#{}".format(key) if isint(acl): cmd = "del acl #{} {}".format(acl, key) elif os.path.isfile(acl): cmd = "del acl {} {}".format(acl, key) else: raise ValueError("Invalid input") results = cmd_across_all_procs(self._hap_processes, 'command', cmd) return check_command(results)