Esempio n. 1
0
def copy_image(src, dest, host=None, receive=False):
    """Copy a disk image to an existing directory

    :param src: Source image
    :param dest: Destination path
    :param host: Remote host
    :param receive: Reverse the rsync direction
    """

    if not host:
        # We shell out to cp because that will intelligently copy
        # sparse files.  I.E. holes will not be written to DEST,
        # rather recreated efficiently.  In addition, since
        # coreutils 8.11, holes can be read efficiently too.
        execute('cp', src, dest)
    else:
        if receive:
            src = "%s:%s" % (utils.safe_ip_format(host), src)
        else:
            dest = "%s:%s" % (utils.safe_ip_format(host), dest)
        # Try rsync first as that can compress and create sparse dest files.
        # Note however that rsync currently doesn't read sparse files
        # efficiently: https://bugzilla.samba.org/show_bug.cgi?id=8918
        # At least network traffic is mitigated with compression.
        try:
            # Do a relatively light weight test first, so that we
            # can fall back to scp, without having run out of space
            # on the destination for example.
            execute('rsync', '--sparse', '--compress', '--dry-run', src, dest)
        except processutils.ProcessExecutionError:
            execute('scp', src, dest)
        else:
            execute('rsync', '--sparse', '--compress', src, dest)
Esempio n. 2
0
def copy_image(src, dest, host=None, receive=False):
    """Copy a disk image to an existing directory

    :param src: Source image
    :param dest: Destination path
    :param host: Remote host
    :param receive: Reverse the rsync direction
    """

    if not host:
        # We shell out to cp because that will intelligently copy
        # sparse files.  I.E. holes will not be written to DEST,
        # rather recreated efficiently.  In addition, since
        # coreutils 8.11, holes can be read efficiently too.
        execute('cp', src, dest)
    else:
        if receive:
            src = "%s:%s" % (utils.safe_ip_format(host), src)
        else:
            dest = "%s:%s" % (utils.safe_ip_format(host), dest)
        # Try rsync first as that can compress and create sparse dest files.
        # Note however that rsync currently doesn't read sparse files
        # efficiently: https://bugzilla.samba.org/show_bug.cgi?id=8918
        # At least network traffic is mitigated with compression.
        try:
            # Do a relatively light weight test first, so that we
            # can fall back to scp, without having run out of space
            # on the destination for example.
            execute('rsync', '--sparse', '--compress', '--dry-run', src, dest)
        except processutils.ProcessExecutionError:
            execute('scp', src, dest)
        else:
            execute('rsync', '--sparse', '--compress', src, dest)
Esempio n. 3
0
 def test_safe_ip_format(self):
     self.assertEqual("[::1]", utils.safe_ip_format("::1"))
     self.assertEqual("127.0.0.1", utils.safe_ip_format("127.0.0.1"))
     self.assertEqual("[::ffff:127.0.0.1]",
                      utils.safe_ip_format("::ffff:127.0.0.1"))
     self.assertEqual("localhost", utils.safe_ip_format("localhost"))
Esempio n. 4
0
 def test_safe_ip_format(self):
     self.assertEqual("[::1]", utils.safe_ip_format("::1"))
     self.assertEqual("127.0.0.1", utils.safe_ip_format("127.0.0.1"))
     self.assertEqual("[::ffff:127.0.0.1]", utils.safe_ip_format(
                      "::ffff:127.0.0.1"))
     self.assertEqual("localhost", utils.safe_ip_format("localhost"))