def address(self): """The assigned address of server. :getter: :rtype: ``string`` :setter: :param address: address to set. :type address: ``string`` :rtype: ``bool`` """ values = cmd_across_all_procs(self._server_per_proc, 'metric', 'addr') try: value = compare_values(values) except IncosistentData as exc: # haproxy returns address:port and compare_values() may raise # IncosistentData exception because assigned port is different # per process and not the assigned address. # Since we want to report the address, we simply catch that case # and report the assigned address. addr_across_proc = [value[1].split(':')[0] for value in values] if not elements_of_list_same(addr_across_proc): raise exc else: return addr_across_proc[0] else: return value.split(':')[0]
def address(self): """The assigned address of server. :getter: :rtype: ``string`` :setter: :param address: address to set. :type address: ``string`` :rtype: ``bool`` """ values = cmd_across_all_procs( self._server_per_proc, 'metric', 'addr' ) try: value = compare_values(values) except IncosistentData as exc: # haproxy returns address:port and compare_values() may raise # IncosistentData exception because assigned port is different # per process and not the assigned address. # Since we want to report the address, we simply catch that case # and report the assigned address. addr_across_proc = [value[1].split(':')[0] for value in values] if not elements_of_list_same(addr_across_proc): raise exc else: return addr_across_proc[0] else: return value.split(':')[0]
def check_code(self): """Return the check code. :rtype: ``integer`` """ values = cmd_across_all_procs(self._server_per_proc, 'metric', 'check_code') return compare_values(values)
def check_status(self): """Return the check status. :rtype: ``string`` """ values = cmd_across_all_procs(self._server_per_proc, 'metric', 'check_status') return compare_values(values)
def last_agent_check(self): """Return the last agent check contents or textual error. :rtype: ``string`` """ values = cmd_across_all_procs(self._server_per_proc, 'metric', 'last_agt') return compare_values(values)
def weight(self): """Return the weight. :rtype: ``integer`` :raise: :class:`IncosistentData` exception if weight is different per process """ values = cmd_across_all_procs(self._server_per_proc, 'metric', 'weight') return compare_values(values)
def last_agent_check(self): """Return the last agent check contents or textual error. :rtype: ``string`` """ values = cmd_across_all_procs( self._server_per_proc, 'metric', 'last_agt' ) return compare_values(values)
def check_status(self): """Return the check status. :rtype: ``string`` """ values = cmd_across_all_procs( self._server_per_proc, 'metric', 'check_status' ) return compare_values(values)
def check_code(self): """Return the check code. :rtype: ``integer`` """ values = cmd_across_all_procs( self._server_per_proc, 'metric', 'check_code' ) return compare_values(values)
def setaddress(self, new_address): """ Set this server's address. :rtype: ``string`` """ values = cmd_across_all_procs(self._server_per_proc, 'setaddress', new_address=str(new_address)) return compare_values(values)
def status(self): """Return the status of the server. :rtype: ``string`` :raise: :class:`IncosistentData` exception if status is different per process """ values = cmd_across_all_procs(self._server_per_proc, 'metric', 'status') return compare_values(values)
def status(self): """Return the status of the backend. :rtype: ``string`` :raise: :class:`IncosistentData` exception if status is different per process. """ results = cmd_across_all_procs(self._backend_per_proc, 'metric', 'status') return compare_values(results)
def setaddress(self, new_address, new_port=None): """Set this servers address. :param new_address: new ip address of server :param new_port: new port of server (optional) :rtype: ``string`` """ values = cmd_across_all_procs( self._server_per_proc, 'setaddress', new_address=str(new_address), new_port=new_port ) return compare_values(values)
def nodename(self): """Return nodename of HAProxy :rtype: ``string`` Usage:: >>> from haproxyadmin import haproxy >>> hap = haproxy.HAProxy(socket_dir='/run/haproxy') >>> hap.nodename 'test.foo.com' """ values = cmd_across_all_procs(self._hap_processes, 'metric', 'node') return compare_values(values)
def description(self): """Return description of HAProxy :rtype: ``string`` Usage:: >>> from haproxyadmin import haproxy >>> hap = haproxy.HAProxy(socket_dir='/run/haproxy') >>> hap.description 'test' """ values = cmd_across_all_procs(self._hap_processes, 'metric', 'description') return compare_values(values)
def releasedate(self): """Return release date of HAProxy :rtype: ``string`` Usage:: >>> from haproxyadmin import haproxy >>> hap = haproxy.HAProxy(socket_dir='/run/haproxy') >>> hap.releasedate '2014/10/31' """ values = cmd_across_all_procs(self._hap_processes, 'metric', 'Release_date') return compare_values(values)
def version(self): """Return version of HAProxy :rtype: ``string`` Usage:: >>> from haproxyadmin import haproxy >>> hap = haproxy.HAProxy(socket_dir='/run/haproxy') >>> hap.version '1.5.8' """ # If multiple version of HAProxy share the same socket directory # then this wil always raise IncosistentData exception. # TODO: Document this on README values = cmd_across_all_procs(self._hap_processes, 'metric', 'Version') return compare_values(values)
def status(self): """Return the status of the frontend. :rtype: ``string`` :raise: :class:`IncosistentData` exception if status is different per process Usage:: >>> from haproxyadmin import haproxy >>> hap = haproxy.HAProxy(socket_dir='/run/haproxy') >>> frontend = hap.frontend('frontend2_proc34') >>> frontend.status 'OPEN' """ results = cmd_across_all_procs(self._frontend_per_proc, 'metric', 'status') return compare_values(results)