Exemple #1
0
    def _sync(self, verbosity, output_fd):
        fd_pipes = {1: output_fd, 2: output_fd}
        opts = list(self.opts)
        if self.rsh:
            opts.append("-e")
            opts.append(self.rsh)
        opts.extend("--exclude=%s" % x for x in self.excludes)
        opts.extend("--include=%s" % x for x in self.includes)
        if verbosity < 0:
            opts.append("--quiet")
        elif verbosity > 0:
            opts.extend('-v' for x in xrange(verbosity))

        # zip limits to the shortest iterable.
        ret = None
        for count, ip in zip(xrange(self.retries), self._get_ips()):
            o = [
                self.binary_path,
                self.uri.replace(self.hostname, ip, 1), self.basedir
            ] + opts

            ret = self._spawn(o, fd_pipes)
            if ret == 0:
                return True
            elif ret == 1:
                # syntax error.
                raise base.syncer_exception(o, "syntax error")
            elif ret == 11:
                raise base.syncer_exception(
                    "rsync returned error code of "
                    "11; this is an out of space exit code")
        # need to do something here instead of just restarting...
        # else:
        #     print(ret)
        raise base.syncer_exception(ret, "all attempts failed")
Exemple #2
0
    def _sync(self, verbosity, output_fd):
        fd_pipes = {1: output_fd, 2: output_fd}
        opts = list(self.opts)
        if self.rsh:
            opts.append("-e")
            opts.append(self.rsh)
        opts.extend("--exclude=%s" % x for x in self.excludes)
        opts.extend("--include=%s" % x for x in self.includes)
        if verbosity < 0:
            opts.append("--quiet")
        elif verbosity > 0:
            opts.extend('-v' for x in xrange(verbosity))

        # zip limits to the shortest iterable.
        ret = None
        for count, ip in zip(xrange(self.retries), self._get_ips()):
            o = [self.binary_path,
                 self.uri.replace(self.hostname, ip, 1),
                 self.basedir] + opts

            ret = self._spawn(o, fd_pipes)
            if ret == 0:
                return True
            elif ret == 1:
                # syntax error.
                raise base.syncer_exception(o, "syntax error")
            elif ret == 11:
                raise base.syncer_exception(
                    "rsync returned error code of "
                    "11; this is an out of space exit code")
           # need to do something here instead of just restarting...
           # else:
           #     print(ret)
        raise base.syncer_exception(ret, "all attempts failed")
Exemple #3
0
    def _get_ips(self):
        if self.use_proxy:
            # If we're using a proxy, name resolution is best left to the proxy
            yield self.hostname
            return

        af_fam = socket.AF_INET
        if self.is_ipv6:
            af_fam = socket.AF_INET6
        try:
            for ipaddr in socket.getaddrinfo(self.hostname, None, af_fam,
                                             socket.SOCK_STREAM):
                if ipaddr[0] == socket.AF_INET6:
                    yield "[%s]" % ipaddr[4][0]
                else:
                    yield ipaddr[4][0]

        except socket.error as e:
            raise_from(base.syncer_exception(self.hostname, af_fam, str(e)))
Exemple #4
0
    def _get_ips(self):
        if self.use_proxy:
            # If we're using a proxy, name resolution is best left to the proxy
            yield self.hostname
            return

        af_fam = socket.AF_INET
        if self.is_ipv6:
            af_fam = socket.AF_INET6
        try:
            for ipaddr in socket.getaddrinfo(
                    self.hostname, None, af_fam, socket.SOCK_STREAM):
                if ipaddr[0] == socket.AF_INET6:
                    yield "[%s]" % ipaddr[4][0]
                else:
                    yield ipaddr[4][0]

        except socket.error as e:
            raise_from(base.syncer_exception(self.hostname, af_fam, str(e)))