예제 #1
0
    def action(self, fqdn=None):
        self.log.info("Updating package index")

        self.db = dbstore.connect(self.cfg.dbPath, driver=self.cfg.dbDriver)
        self.db.connect()
        self.db.loadSchema()
        cu = self.db.cursor()
        labelsTable = projects.LabelsTable(self.db, self.cfg)
        self.db.commit()

        cu = self.db.cursor()
        sql = """SELECT projectId, fqdn, EXISTS(SELECT * FROM InboundMirrors
                           WHERE projectId=targetProjectId) AS localMirror
                         FROM Projects
                         WHERE external AND NOT hidden AND NOT disabled"""
        args = []
        if fqdn:
            sql += " AND fqdn = ?"
            args.append(fqdn)
        cu.execute(sql, args)

        labels = {}
        projectIds = {}
        netclients = {}
        hasErrors = False

        for projectId, hostname, localMirror in cu.fetchall():
            try:
                self.log.info("Retrieving labels from %s...", hostname)
                l, repMap, userMap, entMap = labelsTable.getLabelsForProject(projectId)

                hostname = repMap.keys()[0]
                labels[hostname] = versions.Label(l.keys()[0])
                projectIds[hostname] = projectId

                ccfg = conarycfg.ConaryConfiguration(False)
                ccfg.configLine("proxyMap * conarys://localhost")
                ccfg.root = ccfg.dbPath = ":memory:"
                ccfg.repositoryMap = repMap
                if not localMirror:
                    for host, authInfo in userMap:
                        ccfg.user.addServerGlob(host, authInfo[0], authInfo[1])
                    for host, entitlement in entMap:
                        ccfg.entitlement.addEntitlement(host, entitlement[1])
                ccfg = helperfuncs.configureClientProxies(
                    ccfg, self.cfg.useInternalConaryProxy, self.cfg.proxy, self.cfg.getInternalProxies()
                )
                repos = conaryclient.ConaryClient(ccfg).getRepos()
                netclients[hostname] = repos
            except Exception, e:
                self.log.error("Exception from %s", hostname)
                self.log.error(str(e))
                hasErrors = True
예제 #2
0
파일: admin.py 프로젝트: pombredanne/mint
    def _validateExternalProject(self, name, hostname, label, url,
                        externalUser, externalPass,
                        externalEntKey,
                        useMirror, authType,
                        additionalLabelsToMirror, allLabels, backupExternal):
        additionalLabels = []
        extLabel = ""
        pText = getProjectText().lower()

        # Validate simple parameters
        if not name:
            self._addErrors("Missing %s title"%pText)
        if not hostname:
            self._addErrors("Missing %s name"%pText)
        if not label:
            self._addErrors("Missing %s label"%pText)
        else:
            try:
                extLabel = versions.Label(label)
            except versions.ParseError:
                self._addErrors("Invalid label %s" % label)

        if self._getErrors():
            return None, None

        # Parse and check additional labels
        if useMirror == 'net' and additionalLabelsToMirror:
            for l in additionalLabelsToMirror.split():
                # skip a redundant label specification
                if l != label:
                    try:
                        versions.Label(l)
                        additionalLabels.append(l)
                    except versions.ParseError:
                        self._addErrors("Invalid additional label %s" % l)

        # Check authentication data
        if authType != 'none':
            if authType == 'userpass':
                if not externalUser:
                    self._addErrors("Missing username for local mirror authentication")
                if not externalPass:
                    self._addErrors("Missing password for local mirror authentication")
            elif authType == 'entitlement':
                if not externalEntKey:
                    self._addErrors('Missing entitlement key for local mirror authentication')
                else:
                    # Test that the entitlement is valid
                    cfg = conarycfg.ConaryConfiguration()
                    if url:
                        cfg.configLine('repositoryMap %s %s' % (extLabel.host,
                                                                url))

                    cfg.entitlement.addEntitlement(extLabel.host, externalEntKey)
                    cfg = configureClientProxies(cfg, False, self.cfg.proxy)
                    nc = conaryclient.ConaryClient(cfg).getRepos()
                    try:
                        # use 2**64 to ensure we won't make the server do much
                        nc.getNewTroveList(extLabel.host, '4611686018427387904')
                    except errors.InsufficientPermission:
                        self._addErrors("Entitlement does not grant mirror access to external repository")
                    except errors.OpenError, e:
                        if url:
                            self._addErrors("Error contacting remote repository. Please ensure entitlement and repository URL are correct. (%s)" % str(e))
                        else:
                            self._addErrors("Error contacting remote repository. Please ensure entitlement is correct. (%s)" % str(e) )