Esempio n. 1
0
    def process_all(self):
        """
        Process data when no virtual server and no real server are provided.
        """
        # Retrieve all data
        for oid in self.oids:
            w = defer.waitForDeferred(self.proxy.walk(self.oids[oid]))
            yield w
            w.getResult()

        # For each virtual server, build it
        for ov in self.cache('ltmVirtualServAddrType'):
            # Grab HTTP class
            try:
                classes = self.cache(('ltmVsHttpClassProfileName', ".".join([str(x) for x in ov]))).values()
            except KeyError:
                classes = []
            for httpclass in classes + [None]:
                v = oid2str(ov)
                vs = defer.waitForDeferred(self.process_vs(v, httpclass))
                yield vs
                vs = vs.getResult()
                if vs is not None:
                    if httpclass is not None:
                        self.lb.virtualservers["%s;%s" % (v, httpclass)] = vs
                    else:
                        self.lb.virtualservers[v] = vs
        yield self.lb
        return
Esempio n. 2
0
    def process_all(self):
        """
        Process data when no virtual server and no real server are provided.
        """
        # Retrieve all data
        for oid in self.oids:
            w = defer.waitForDeferred(self.proxy.walk(self.oids[oid]))
            yield w
            w.getResult()

        # For each virtual server, build it
        for ov in self.cache('ltmVirtualServAddrType'):
            # Grab HTTP class
            try:
                classes = self.cache(
                    ('ltmVsHttpClassProfileName',
                     ".".join([str(x) for x in ov]))).values()
            except KeyError:
                classes = []
            for httpclass in classes + [None]:
                v = oid2str(ov)
                vs = defer.waitForDeferred(self.process_vs(v, httpclass))
                yield vs
                vs = vs.getResult()
                if vs is not None:
                    if httpclass is not None:
                        self.lb.virtualservers["%s;%s" % (v, httpclass)] = vs
                    else:
                        self.lb.virtualservers[v] = vs
        yield self.lb
        return
Esempio n. 3
0
    def get_protocol(self, ov):
        """
        Get protocol for a given virtual server.

        @param ov: virtual server as an OID string
        @return: deferred protocol
        """
        if not self.is_cached(('ltmVirtualServProfileType', ov)):
            # This OID is buggy. It is not possible to walk it
            c = defer.waitForDeferred(self.proxy.walk(self.oids['ltmVirtualServProfileType']))
            yield c
            c.getResult()
        for k in self.cache(('ltmVirtualServProfileType', ov)):
            yield oid2str(k)
            break
        return
Esempio n. 4
0
    def get_protocol(self, ov):
        """
        Get protocol for a given virtual server.

        @param ov: virtual server as an OID string
        @return: deferred protocol
        """
        if not self.is_cached(('ltmVirtualServProfileType', ov)):
            # This OID is buggy. It is not possible to walk it
            c = defer.waitForDeferred(
                self.proxy.walk(self.oids['ltmVirtualServProfileType']))
            yield c
            c.getResult()
        for k in self.cache(('ltmVirtualServProfileType', ov)):
            yield oid2str(k)
            break
        return
Esempio n. 5
0
    def process_all(self):
        """
        Process data when no virtual server and no real server are provided.

        @return: a deferred C{ILoadBalancer}
        """
        # Retrieve all data
        for oid in self.oids:
            w = defer.waitForDeferred(self.proxy.walk(self.oids[oid]))
            yield w
            w.getResult()

        # For each virtual server, build it
        for o in self.cache('apCntIPAddress'):
            owner, content = oid2str(o)
            vs = defer.waitForDeferred(self.process_vs(owner, content))
            yield vs
            vs = vs.getResult()
            if vs is not None:
                self.lb.virtualservers["%s|%s" % (owner, content)] = vs
        yield self.lb
        return
Esempio n. 6
0
    def process_all(self):
        """
        Process data when no virtual server and no real server are provided.

        @return: a deferred C{ILoadBalancer}
        """
        # Retrieve all data
        for oid in self.oids:
            w = defer.waitForDeferred(self.proxy.walk(self.oids[oid]))
            yield w
            w.getResult()

        # For each virtual server, build it
        for o in self.cache('apCntIPAddress'):
            owner, content = oid2str(o)
            vs = defer.waitForDeferred(self.process_vs(owner, content))
            yield vs
            vs = vs.getResult()
            if vs is not None:
                self.lb.virtualservers["%s|%s" % (owner, content)] = vs
        yield self.lb
        return
Esempio n. 7
0
    def process_vs(self, owner, content):
        """
        Process data for a given virtual server when no real server is provided

        @param owner: owner of the content
        @param content: content name
        @return: a deferred C{IVirtualServer} or None
        """
        oowner = str2oid(owner)
        ocontent = str2oid(content)
        # Retrieve some data if needed
        oids = []
        for o in self.oids:
            if o.startswith("apCnt") and not o.startswith("apCntsvc"):
                oids.append((o, oowner, ocontent))
        oids = tuple(oids)
        c = defer.waitForDeferred(self.cache_or_get(*oids))
        yield c
        c.getResult()

        # Let's build our virtual server
        vip = "%s:%d" % tuple(self.cache(('apCntIPAddress', oowner, ocontent),
                                         ('apCntPort', oowner, ocontent)))
        protocol = self.protocols[self.cache(('apCntIPProtocol', oowner, ocontent))]
        mode = self.modes[self.cache(('apCntBalance', oowner, ocontent))]
        vs = VirtualServer(content, vip, protocol, mode)

        # Add some extra information
        vs.extra["URL"] = self.cache(('apCntUrl', oowner, ocontent))
        vs.extra["sticky"] = self.sticky[
            self.cache(('apCntSticky', oowner, ocontent))]
        vs.extra["virtual server status"] = self.status[
            self.cache(('apCntEnable', oowner, ocontent))] and "up" or "down"
        vs.extra["persistence"] = self.status[
            self.cache(('apCntPersistence', oowner, ocontent))] and "enabled" or "disabled"
        vs.extra["content type"] = self.contents[
            self.cache(('apCntContentType', oowner, ocontent))]

        # Find and attach real servers
        if not self.is_cached(('apCntsvcSvcName', oowner, ocontent)):
            services = defer.waitForDeferred(
                self.proxy.walk("%s.%s.%s" % (self.oids['apCntsvcSvcName'],
                                              oowner, ocontent)))
            yield services
            services.getResult()
        for r in self.cache(('apCntsvcSvcName', oowner, ocontent)):
            service = oid2str(r)
            rs = defer.waitForDeferred(self.process_rs(owner, content, service))
            yield rs
            rs = rs.getResult()
            if rs is not None:
                vs.realservers[service] = rs

        # Add backups
        for backup in ["primary", "second"]:
            service = self.cache(('apCnt%sSorryServer' % backup.capitalize(),
                                  oowner, ocontent))
            if not service: continue
            rs = defer.waitForDeferred(self.process_rs(owner, content, service, backup))
            yield rs
            rs = rs.getResult()
            if rs is not None:
                vs.realservers[service] = rs

        yield vs
        return
Esempio n. 8
0
    def process_vs(self, owner, content):
        """
        Process data for a given virtual server when no real server is provided

        @param owner: owner of the content
        @param content: content name
        @return: a deferred C{IVirtualServer} or None
        """
        oowner = str2oid(owner)
        ocontent = str2oid(content)
        # Retrieve some data if needed
        oids = []
        for o in self.oids:
            if o.startswith("apCnt") and not o.startswith("apCntsvc"):
                oids.append((o, oowner, ocontent))
        oids = tuple(oids)
        c = defer.waitForDeferred(self.cache_or_get(*oids))
        yield c
        c.getResult()

        # Let's build our virtual server
        vip = "%s:%d" % tuple(
            self.cache(('apCntIPAddress', oowner, ocontent),
                       ('apCntPort', oowner, ocontent)))
        protocol = self.protocols[self.cache(
            ('apCntIPProtocol', oowner, ocontent))]
        mode = self.modes[self.cache(('apCntBalance', oowner, ocontent))]
        vs = VirtualServer(content, vip, protocol, mode)

        # Add some extra information
        vs.extra["URL"] = self.cache(('apCntUrl', oowner, ocontent))
        vs.extra["sticky"] = self.sticky[self.cache(
            ('apCntSticky', oowner, ocontent))]
        vs.extra["virtual server status"] = self.status[self.cache(
            ('apCntEnable', oowner, ocontent))] and "up" or "down"
        vs.extra["persistence"] = self.status[self.cache(
            ('apCntPersistence', oowner,
             ocontent))] and "enabled" or "disabled"
        vs.extra["content type"] = self.contents[self.cache(
            ('apCntContentType', oowner, ocontent))]

        # Find and attach real servers
        if not self.is_cached(('apCntsvcSvcName', oowner, ocontent)):
            services = defer.waitForDeferred(
                self.proxy.walk(
                    "%s.%s.%s" %
                    (self.oids['apCntsvcSvcName'], oowner, ocontent)))
            yield services
            services.getResult()
        for r in self.cache(('apCntsvcSvcName', oowner, ocontent)):
            service = oid2str(r)
            rs = defer.waitForDeferred(self.process_rs(owner, content,
                                                       service))
            yield rs
            rs = rs.getResult()
            if rs is not None:
                vs.realservers[service] = rs

        # Add backups
        for backup in ["primary", "second"]:
            service = self.cache(
                ('apCnt%sSorryServer' % backup.capitalize(), oowner, ocontent))
            if not service: continue
            rs = defer.waitForDeferred(
                self.process_rs(owner, content, service, backup))
            yield rs
            rs = rs.getResult()
            if rs is not None:
                vs.realservers[service] = rs

        yield vs
        return