Beispiel #1
0
    def process_rs(self, pid, bid, rid):
        """
        Process data for a given virtual server and real server.

        @param pid: process ID of the instance managing the real server
        @param bid: backend ID of the real server
        @param rid: server ID of the real server

        @return: a deferred C{IRealServer} or None
        """
        # Retrieve some data if needed:
        oids = []
        for o in self.oids:
            if o.startswith("alBackend"):
                oids.append((o, pid, bid))
            elif o.startswith("alServer"):
                oids.append((o, pid, bid, rid))
        oids = tuple(oids)
        c = defer.waitForDeferred(self.cache_or_get(*oids))
        yield c
        c.getResult()

        # Build the real server
        rip = "0.0.0.0"
        rport = None
        bname = self.cache(("alBackendName", pid, bid))
        rname = self.cache(("alServerName", pid, bid, rid))
        if "--" in rname:
            rip, rname = rname.split("--", 1)
            if ":" in rip:
                rip, rport = rip.split(":", 1)
                rport = int(rport)
        weight = self.cache(("alServerWeight", pid, bid, rid))
        # The server is up if it is not considered "DOWN" (it can be UP, DOWN or MAINT)
        state = (self.cache(("alServerStatus", pid, bid, rid)) == "DOWN") and "down" or "up"
        backup = self.cache(("alServerBackup", pid, bid, rid))
        if not backup:
            rs = RealServer(rname, rip, rport, "unknown", weight, state)
        else:
            rs = SorryServer(rname, rip, rport, "unknown", state)
        rs.extra["backend"] = bname
        try:
            down = self.cache(("alServerDownTime", pid, bid, rid))/100
            rs.extra["down time"] = "%02d:%02d:%02d" % (down / 3600, (down / 60) % 60, down % 60)
            down = self.cache(("alBackendDownTime", pid, bid))/100
            rs.extra["backend down time"] = "%02d:%02d:%02d" % (down / 3600, (down / 60) % 60, down % 60)
        except KeyError:
            # No downtime available, don't panic
            pass
        rs.extra["status"] = self.cache(("alServerStatus", pid, bid, rid))
        rs.extra["backend status"] = self.cache(("alBackendStatus", pid, bid))
        # Actions
        if self.proxy.writable:
            if rs.extra["status"] == "MAINT":
                rs.actions['enable'] = "Enable (temporary)"
            else:
                rs.actions['disable'] = "Disable (temporary)"
        yield rs
        return
Beispiel #2
0
    def process_rs(self, owner, content, service, backup=False):
        """
        Process data for a given virtual server and real server.

        @param service: service name
        @param backup: C{False} or a string representing backup position
           C{None} is we don't know if it is a backup or not

        @return: a deferred C{IRealServer} or None
        """
        oservice = str2oid(service)
        # Retrieve some data if needed:
        oids = []
        for o in self.oids:
            if o.startswith("apSvc"):
                oids.append((o, oservice))
        oids = tuple(oids)
        c = defer.waitForDeferred(self.cache_or_get(*oids))
        yield c
        c.getResult()

        # Is it a backup?
        if backup is None:
            oowner = str2oid(owner)
            ocontent = str2oid(content)
            for b in ["primary", "second"]:
                s = defer.waitForDeferred(
                    self.cache_or_get(('apCnt%sSorryServer' % b.capitalize(),
                                       oowner, ocontent)))
                yield s
                s = s.getResult()
                if s and s == service:
                    backup = b
                    break
            if backup is None:
                backup = False

        # Build the real server
        rip = self.cache(('apSvcIPAddress', oservice))
        rport = self.cache(('apSvcPort', oservice))
        protocol = self.protocols[
            self.cache(('apSvcIPProtocol', oservice))]
        state = self.states[
            self.cache(('apSvcState', oservice))]
        if not backup:
            weight = self.cache(('apSvcWeight', oservice))
            rs = RealServer(service, rip, rport, protocol, weight, state)
        else:
            rs = SorryServer(service, rip, rport, protocol, state)
            rs.extra["backup type"] = backup

        rs.extra["KAL type"] = self.kals[
            self.cache(('apSvcKALType', oservice))]


        for key, oid in [
            ('KAL frequency', 'apSvcKALFrequency'),
            ('KAL max failure', 'apSvcKALMaxFailure'),
            ('KAL retry period', 'apSvcKALRetryPeriod'),
            ('KAL URI', 'apSvcKALUri'),
            ('KAL port', 'apSvcKALPort')
            ]:
            try:
                rs.extra[key] = self.cache((oid, oservice))
            except KeyError:
                pass
        yield rs
        return
Beispiel #3
0
    def process_rs(self, v, s, g, r, backup=False):
        """
        Process data for a given virtual server and real server.

        @param v: virtual server
        @param s: service
        @param g: group
        @param r: real server
        @param backup: is it a backup server?
        @return: a maybe deferred C{IRealServer} or C{None}
        """
        # Retrieve some data if needed:
        c = defer.waitForDeferred(
            self.cache_or_get(('slbCurCfgRealServerIpAddr', r),
                              ('slbCurCfgRealServerName', r),
                              ('slbCurCfgVirtServiceRealPort', v, s),
                              ('slbCurCfgVirtServiceUDPBalance', v, s),
                              ('slbCurCfgRealServerWeight', r),
                              ('slbVirtServicesInfoState', v, s, r),
                              ('slbCurCfgGroupRealServerState', g, r),
                              ('slbOperGroupRealServerState', g, r),
                              ('slbOperRealServerStatus', r),
                              ('slbRealServerInfoState', r),
                              ('slbCurCfgRealServerState', r),
                              ('slbCurCfgRealServerPingInterval', r),
                              ('slbCurCfgRealServerFailRetry', r),
                              ('slbCurCfgRealServerSuccRetry', r),
                              ('slbStatRServerFailures', r)))
        yield c
        c.getResult()

        # Build the real server
        rip, name, rport = self.cache(('slbCurCfgRealServerIpAddr', r),
                                      ('slbCurCfgRealServerName', r),
                                      ('slbCurCfgVirtServiceRealPort', v, s))
        if rip is None:
            log.msg("In %r, inexistant real server %d for v%ds%dg%d" %
                    (self.lb.name, r, v, s, g))
            yield None
            return
        if not name: name = rip
        protocol = "TCP"
        if self.cache(('slbCurCfgVirtServiceUDPBalance', v, s)) != 3:
            protocol = "UDP"
        if not backup:
            weight = self.cache(('slbCurCfgRealServerWeight', r))
            try:
                state = self.status[self.cache(
                    ('slbVirtServicesInfoState', v, s, r))]
            except KeyError:
                state = 'disabled'
            if state != "disabled" and \
                tuple(self.cache(('slbOperGroupRealServerState', g, r),
                                 ('slbOperRealServerStatus', r))) != (1,1):
                state = "disabled"
            rs = RealServer(name, rip, rport, protocol, weight, state)
            # Actions
            if self.proxy.writable:
                if self.cache(('slbOperGroupRealServerState', g, r)) == 1:
                    rs.actions["operdisable"] = "Disable (temporary)"
                else:
                    rs.actions["operenable"] = "Enable (temporary)"
                if self.cache(('slbOperRealServerStatus', r)) == 1:
                    rs.actions[
                        "operdisableall"] = "Disable globally (temporary)"
                else:
                    rs.actions["operenableall"] = "Enable globally (temporary)"
                if self.cache(('slbCurCfgGroupRealServerState', g, r)) == 1:
                    rs.actions["disable"] = "Disable (permanent)"
                else:
                    rs.actions["enable"] = "Enable (permanent)"
                if self.cache(('slbCurCfgRealServerState', r)) == 2:
                    rs.actions["disableall"] = "Disable globally (permanent)"
                else:
                    rs.actions["enableall"] = "Enable globally (permanent)"
        else:
            state = self.status[self.cache(('slbRealServerInfoState', r))]
            rs = SorryServer(name, rip, rport, protocol, state)
        pi, fr, sr, fail = self.cache(('slbCurCfgRealServerPingInterval', r),
                                      ('slbCurCfgRealServerFailRetry', r),
                                      ('slbCurCfgRealServerSuccRetry', r),
                                      ('slbStatRServerFailures', r))
        rs.extra.update({
            'ping interval': pi,
            'fail retry': fr,
            'success retry': sr,
            'failures': fail
        })
        yield rs
        return
Beispiel #4
0
    def process_rs(self, v, r):
        """
        Process data for a given virtual server and real server.

        @param v: virtual server
        @param r: real server

        @return: a deferred C{IRealServer} or None
        """
        # Retrieve some data if needed:
        oids = []
        for o in self.oids:
            if o.startswith("realServer"):
                oids.append((o, v, r))
        oids = tuple(oids)
        c = defer.waitForDeferred(self.cache_or_get(*oids))
        yield c
        c.getResult()

        # Build the real server
        rip = socket.inet_ntop(
            self.cache(('realServerAddrType', v, r)) == 1 and socket.AF_INET
            or socket.AF_INET6, self.cache(('realServerAddress', v, r)))
        name = rip
        rport = self.cache(('realServerPort', v, r))
        protocol = defer.waitForDeferred(
            self.cache_or_get(('virtualServerProtocol', v)))
        yield protocol
        protocol = protocol.getResult()
        protocol = self.protocols[protocol]
        if self.cache(('realServerType', v, r)) == 1:
            # Not a sorry server
            weight = self.cache(('realServerWeight', v, r))
            if weight == 0:
                state = 'disabled'
            else:
                state = self.status[self.cache(
                    ('realServerStatus', v, r))] and "up" or "down"
            rs = RealServer(name, rip, rport, protocol, weight, state)
            for key, oid in [
                ('upper connection limit', 'realServerUpperConnectionLimit'),
                ('lower connection limit', 'realServerLowerConnectionLimit'),
                ('notify up command', 'realServerNotifyUp'),
                ('notify down command', 'realServerNotifyDown'),
                ('failed checks', 'realServerFailedChecks')
            ]:
                try:
                    rs.extra[key] = self.cache((oid, v, r))
                except KeyError:
                    pass
            rs.extra["on fail"] = \
                self.cache(('realServerActionWhenDown', v, r)) == 1 and "remove" or \
                "inhibit"
            # Actions
            if self.proxy.writable:
                rs.actions['disableall'] = 'Disable globally (temporary)'
                rs.actions['enableall'] = 'Enable globally (temporary)'
                curweight = self.cache(('realServerWeight', v, r))
                for weight in range(0, 6):
                    if weight == curweight:
                        continue
                    if weight == 0:
                        rs.actions['disable'] = 'Disable (temporary)'
                    else:
                        rs.actions['enable/%d' % weight] = \
                            curweight == 0 and 'Enable with weight %d (temporary)' % weight or \
                            'Set weight to %d (temporary)' % weight
        else:
            # Sorry server, not much information
            rs = SorryServer(name, rip, rport, protocol, "up")
        yield rs
        return
Beispiel #5
0
    def process_rs(self, v, r):
        """
        Process data for a given virtual server and real server.

        @param v: virtual server
        @param r: real server

        @return: a deferred C{IRealServer} or None
        """
        # Retrieve some data if needed:
        oids = []
        for o in self.oids:
            if o.startswith("realServer"):
                oids.append((o, v, r))
        oids = tuple(oids)
        c = defer.waitForDeferred(self.cache_or_get(*oids))
        yield c
        c.getResult()

        # Build the real server
        rip = socket.inet_ntop(self.cache(('realServerAddrType', v, r)) == 1 and
                               socket.AF_INET or socket.AF_INET6,
                               self.cache(('realServerAddress', v, r)))
        name = rip
        rport = self.cache(('realServerPort', v, r))
        protocol = defer.waitForDeferred(self.cache_or_get(('virtualServerProtocol', v)))
        yield protocol
        protocol = protocol.getResult()
        protocol = self.protocols[protocol]
        if self.cache(('realServerType', v, r)) == 1:
            # Not a sorry server
            weight = self.cache(('realServerWeight', v, r))
            if weight == 0:
                state = 'disabled'
            else:
                state = self.status[self.cache(('realServerStatus', v, r))] and "up" or "down"
            rs = RealServer(name, rip, rport, protocol, weight, state)
            for key, oid in [
                ('upper connection limit', 'realServerUpperConnectionLimit'),
                ('lower connection limit', 'realServerLowerConnectionLimit'),
                ('notify up command', 'realServerNotifyUp'),
                ('notify down command', 'realServerNotifyDown'),
                ('failed checks', 'realServerFailedChecks')
                ]:
                try:
                    rs.extra[key] = self.cache((oid, v, r))
                except KeyError:
                    pass
            rs.extra["on fail"] = \
                self.cache(('realServerActionWhenDown', v, r)) == 1 and "remove" or \
                "inhibit"
            # Actions
            if self.proxy.writable:
                rs.actions['disableall'] = 'Disable globally (temporary)'
                rs.actions['enableall'] = 'Enable globally (temporary)'
                curweight = self.cache(('realServerWeight', v, r))
                for weight in range(0, 6):
                    if weight == curweight:
                        continue
                    if weight == 0:
                        rs.actions['disable'] = 'Disable (temporary)'
                    else:
                        rs.actions['enable/%d' % weight] = \
                            curweight == 0 and 'Enable with weight %d (temporary)' % weight or \
                            'Set weight to %d (temporary)' % weight
        else:
            # Sorry server, not much information
            rs = SorryServer(name, rip, rport, protocol, "up")
        yield rs
        return
Beispiel #6
0
    def process_rs(self, v, httpclass, rip, port):
        """
        Process data for a given virtual server and real server.

        @param v: virtual server
        @param httpclass: HTTP class (or C{None} for default pool)
        @param rip: real IP
        @param port: port
        """
        # Retrieve some data if needed:
        ov = str2oid(v)
        orip = ip2oid(rip)
        if httpclass is None:
            p = defer.waitForDeferred(self.cache_or_get(('ltmVirtualServDefaultPool', ov)))
        else:
            oc = str2oid(httpclass)
            p = defer.waitForDeferred(self.cache_or_get(('ltmHttpClassPoolName', oc)))
        yield p
        p = p.getResult()
        op = str2oid(p)
        oids = []
        for o in self.oids:
            if o.startswith("ltmPoolMbr") or o.startswith("ltmPoolMember"):
                oids.append((o, op, orip, port))
        oids = tuple(oids)
        c = defer.waitForDeferred(self.cache_or_get(*oids))
        yield c
        c.getResult()

        oids = []
        for o in self.oids:
            if o.startswith("ltmNodeAddr"):
                oids.append((o, orip))
        oids = tuple(oids)
        c = defer.waitForDeferred(self.cache_or_get(*oids))
        yield c
        c.getResult()

        name = self.cache(('ltmNodeAddrScreenName', orip))
        protocol = defer.waitForDeferred(self.get_protocol(ov))
        yield protocol
        protocol = protocol.getResult()
        weight = self.cache(('ltmPoolMemberWeight', op, orip, port))
        avail, enabled, session = self.cache(
            ('ltmPoolMbrStatusAvailState', op, orip, port),
            ('ltmPoolMbrStatusEnabledState', op, orip, port),
            ('ltmPoolMemberSessionStatus', op, orip, port))
        if session != 1 or self.enabledstates[enabled] != "enabled":
            state = "disabled"
        else:
            state = self.availstates[avail]
        rs = RealServer(name, rip, port, protocol, weight, state)
        rs.extra["detailed reason"] = self.cache(('ltmPoolMbrStatusDetailReason',
                                                  op, orip, port))
        rs.extra["monitor rule"] = self.cache(('ltmPoolMemberMonitorRule',
                                               op, orip, port))
        # Actions
        if self.proxy.writable:
            # ltmPoolMemberNewSessionEnable == 1 means user disabled
            if self.cache(('ltmPoolMemberNewSessionEnable', op, orip, port)) != 1:
                rs.actions['disable'] = 'Disable (permanent)'
            else:
                rs.actions['enable'] = 'Enable (permanent)'
            if self.cache(('ltmNodeAddrNewSessionEnable', orip)) != 1:
                rs.actions['disableall'] = 'Disable globally (permanent)'
            else:
                rs.actions['enableall'] = 'Enable globally (permanent)'
        yield rs
        return
Beispiel #7
0
    def process_rs(self, owner, content, service, backup=False):
        """
        Process data for a given virtual server and real server.

        @param service: service name
        @param backup: C{False} or a string representing backup position
           C{None} is we don't know if it is a backup or not

        @return: a deferred C{IRealServer} or None
        """
        oservice = str2oid(service)
        # Retrieve some data if needed:
        oids = []
        for o in self.oids:
            if o.startswith("apSvc"):
                oids.append((o, oservice))
        oids = tuple(oids)
        c = defer.waitForDeferred(self.cache_or_get(*oids))
        yield c
        c.getResult()

        # Is it a backup?
        if backup is None:
            oowner = str2oid(owner)
            ocontent = str2oid(content)
            for b in ["primary", "second"]:
                s = defer.waitForDeferred(
                    self.cache_or_get(('apCnt%sSorryServer' % b.capitalize(),
                                       oowner, ocontent)))
                yield s
                s = s.getResult()
                if s and s == service:
                    backup = b
                    break
            if backup is None:
                backup = False

        # Build the real server
        rip = self.cache(('apSvcIPAddress', oservice))
        rport = self.cache(('apSvcPort', oservice))
        protocol = self.protocols[self.cache(('apSvcIPProtocol', oservice))]
        state = self.states[self.cache(('apSvcState', oservice))]
        if not backup:
            weight = self.cache(('apSvcWeight', oservice))
            rs = RealServer(service, rip, rport, protocol, weight, state)
        else:
            rs = SorryServer(service, rip, rport, protocol, state)
            rs.extra["backup type"] = backup

        rs.extra["KAL type"] = self.kals[self.cache(
            ('apSvcKALType', oservice))]

        for key, oid in [('KAL frequency', 'apSvcKALFrequency'),
                         ('KAL max failure', 'apSvcKALMaxFailure'),
                         ('KAL retry period', 'apSvcKALRetryPeriod'),
                         ('KAL URI', 'apSvcKALUri'),
                         ('KAL port', 'apSvcKALPort')]:
            try:
                rs.extra[key] = self.cache((oid, oservice))
            except KeyError:
                pass
        yield rs
        return
Beispiel #8
0
    def process_rs(self, v, s, g, r, backup=False):
        """
        Process data for a given virtual server and real server.

        @param v: virtual server
        @param s: service
        @param g: group
        @param r: real server
        @param backup: is it a backup server?
        @return: a maybe deferred C{IRealServer} or C{None}
        """
        # Retrieve some data if needed:
        c = defer.waitForDeferred(self.cache_or_get(
            ('slbCurCfgRealServerIpAddr', r),
            ('slbCurCfgRealServerName', r),
            ('slbCurCfgVirtServiceRealPort', v, s),
            ('slbCurCfgVirtServiceUDPBalance', v, s),
            ('slbCurCfgRealServerWeight', r),
            ('slbVirtServicesInfoState', v, s, r),
            ('slbCurCfgGroupRealServerState', g, r),
            ('slbOperGroupRealServerState', g, r),
            ('slbOperRealServerStatus', r),
            ('slbRealServerInfoState', r),
            ('slbCurCfgRealServerState', r),
            ('slbCurCfgRealServerPingInterval', r),
            ('slbCurCfgRealServerFailRetry', r),
            ('slbCurCfgRealServerSuccRetry', r),
            ('slbStatRServerFailures', r)))
        yield c
        c.getResult()

        # Build the real server
        rip, name, rport = self.cache(
            ('slbCurCfgRealServerIpAddr', r),
            ('slbCurCfgRealServerName', r),
            ('slbCurCfgVirtServiceRealPort', v, s))
        if rip is None:
            log.msg("In %r, inexistant real server %d for v%ds%dg%d" % (self.lb.name,
                                                                        r, v, s, g))
            yield None
            return
        if not name: name = rip
        protocol = "TCP"
        if self.cache(('slbCurCfgVirtServiceUDPBalance', v, s)) != 3:
            protocol = "UDP"
        if not backup:
            weight = self.cache(('slbCurCfgRealServerWeight', r))
            try:
                state = self.status[self.cache(('slbVirtServicesInfoState', v, s, r))]
            except KeyError:
                state = 'disabled'
            if state != "disabled" and \
                tuple(self.cache(('slbOperGroupRealServerState', g, r),
                                 ('slbOperRealServerStatus', r))) != (1,1):
                state = "disabled"
            rs = RealServer(name, rip, rport, protocol, weight, state)
            # Actions
            if self.proxy.writable:
                if self.cache(('slbOperGroupRealServerState', g, r)) == 1:
                    rs.actions["operdisable"] = "Disable (temporary)"
                else:
                    rs.actions["operenable"] = "Enable (temporary)"
                if self.cache(('slbOperRealServerStatus', r)) == 1:
                    rs.actions["operdisableall"] = "Disable globally (temporary)"
                else:
                    rs.actions["operenableall"] = "Enable globally (temporary)"
                if self.cache(('slbCurCfgGroupRealServerState', g, r)) == 1:
                    rs.actions["disable"] = "Disable (permanent)"
                else:
                    rs.actions["enable"] = "Enable (permanent)"
                if self.cache(('slbCurCfgRealServerState', r)) == 2:
                    rs.actions["disableall"] = "Disable globally (permanent)"
                else:
                    rs.actions["enableall"] = "Enable globally (permanent)"
        else:
            state = self.status[self.cache(('slbRealServerInfoState', r))]
            rs = SorryServer(name, rip, rport, protocol, state)
        pi, fr, sr, fail = self.cache(
            ('slbCurCfgRealServerPingInterval', r),
            ('slbCurCfgRealServerFailRetry', r),
            ('slbCurCfgRealServerSuccRetry', r),
            ('slbStatRServerFailures', r))
        rs.extra.update({'ping interval': pi,
                         'fail retry': fr,
                         'success retry': sr,
                         'failures': fail})
        yield rs
        return
Beispiel #9
0
    def process_rs(self, v, httpclass, rip, port):
        """
        Process data for a given virtual server and real server.

        @param v: virtual server
        @param httpclass: HTTP class (or C{None} for default pool)
        @param rip: real IP
        @param port: port
        """
        # Retrieve some data if needed:
        ov = str2oid(v)
        orip = ip2oid(rip)
        if httpclass is None:
            p = defer.waitForDeferred(
                self.cache_or_get(('ltmVirtualServDefaultPool', ov)))
        else:
            oc = str2oid(httpclass)
            p = defer.waitForDeferred(
                self.cache_or_get(('ltmHttpClassPoolName', oc)))
        yield p
        p = p.getResult()
        op = str2oid(p)
        oids = []
        for o in self.oids:
            if o.startswith("ltmPoolMbr") or o.startswith("ltmPoolMember"):
                oids.append((o, op, orip, port))
        oids = tuple(oids)
        c = defer.waitForDeferred(self.cache_or_get(*oids))
        yield c
        c.getResult()

        oids = []
        for o in self.oids:
            if o.startswith("ltmNodeAddr"):
                oids.append((o, orip))
        oids = tuple(oids)
        c = defer.waitForDeferred(self.cache_or_get(*oids))
        yield c
        c.getResult()

        name = self.cache(('ltmNodeAddrScreenName', orip))
        protocol = defer.waitForDeferred(self.get_protocol(ov))
        yield protocol
        protocol = protocol.getResult()
        weight = self.cache(('ltmPoolMemberWeight', op, orip, port))
        avail, enabled, session = self.cache(
            ('ltmPoolMbrStatusAvailState', op, orip, port),
            ('ltmPoolMbrStatusEnabledState', op, orip, port),
            ('ltmPoolMemberSessionStatus', op, orip, port))
        if session != 1 or self.enabledstates[enabled] != "enabled":
            state = "disabled"
        else:
            state = self.availstates[avail]
        rs = RealServer(name, rip, port, protocol, weight, state)
        rs.extra["detailed reason"] = self.cache(
            ('ltmPoolMbrStatusDetailReason', op, orip, port))
        rs.extra["monitor rule"] = self.cache(
            ('ltmPoolMemberMonitorRule', op, orip, port))
        # Actions
        if self.proxy.writable:
            # ltmPoolMemberNewSessionEnable == 1 means user disabled
            if self.cache(
                ('ltmPoolMemberNewSessionEnable', op, orip, port)) != 1:
                rs.actions['disable'] = 'Disable (permanent)'
            else:
                rs.actions['enable'] = 'Enable (permanent)'
            if self.cache(('ltmNodeAddrNewSessionEnable', orip)) != 1:
                rs.actions['disableall'] = 'Disable globally (permanent)'
            else:
                rs.actions['enableall'] = 'Enable globally (permanent)'
        yield rs
        return