Ejemplo n.º 1
0
def attach(env):
    """Map an existing vlmc Image to a block device

    This function maps an existing vlmc Image to a block device
    e.g. /dev/xsegbd{X} and returns the device path. If the mapping
    already exists, it returns the corresponding device path.

    """

    name = env.get("name")

    # Check if the mapping already exists
    d_id = vlmc.is_mapped(name)
    if d_id is not None:
      sys.stderr.write("The mapping exists for %s\n" % name)
      # The mapping exists. Return it.
      sys.stdout.write("%s" % str(DEVICE_PREFIX + str(d_id)))
      return 0
    # The mapping doesn't exist. Create it.
    d_id = vlmc.map_volume(name=name)
    # The device was successfully mapped. Return it.
    #maybe assert (d_id == vlmc.is_mapped(name)
    sys.stdout.write("%s" % str(DEVICE_PREFIX + str(d_id)))
    sys.stderr.write("Create the mapping for %s\n" % name)
    return 0
Ejemplo n.º 2
0
def mkfs_and_mount(volume, mountdir):
    d_id = vlmc.map_volume(name=volume)
    device = DEVICE_PREFIX + str(d_id)

    cmd = ['mkfs.ext3', device]
    check_call(cmd, shell=False)
    try:
        mount(device, mountdir)
        umount(device)
    finally:
        vlmc.unmap_volume(name=device)
Ejemplo n.º 3
0
def mkfs_and_mount(volume, mountdir):
    d_id=vlmc.map_volume(name=volume)
    device = DEVICE_PREFIX + str(d_id)

    cmd = ['mkfs.ext3', device]
    check_call(cmd, shell=False)
    try:
        mount(device, mountdir)
        umount(device)
    finally:
        vlmc.unmap_volume(name=device)
Ejemplo n.º 4
0
def write(volume, volumesize):
    d_id = vlmc.map_volume(name=volume)
    device = DEVICE_PREFIX + str(d_id)
    try:
        fd = os.open(device, os.O_WRONLY)
        os.lseek(fd, (volumesize * 1024 * 1024) + 1, os.SEEK_SET)
        os.write(fd, "This should not succeed")
        print("wtf")
    except OSError, (err, reason):
        if err != errno.EINVAL:
            raise Error("Cannot write to device %s : %s" % (device, reason))
Ejemplo n.º 5
0
def write(volume, volumesize):
    d_id=vlmc.map_volume(name=volume)
    device = DEVICE_PREFIX + str(d_id)
    try:
        fd = os.open(device, os.O_WRONLY)
        os.lseek(fd, (volumesize*1024*1024)+1, os.SEEK_SET)
        os.write(fd, "This should not succeed")
        print ("wtf")
    except OSError, (err, reason):
        if err != errno.EINVAL:
            raise Error("Cannot write to device %s : %s" % (device,reason))
Ejemplo n.º 6
0
def write_data(volume, mountdir, randomfiles):
    d_id = vlmc.map_volume(name=volume)
    device = DEVICE_PREFIX + str(d_id)
    try:
        mount(device, mountdir)
        for rf in randomfiles:
            print "writing " + rf[0]
            f = open(os.path.join(mountdir, rf[0]), 'w')
            f.write(rf[1])
            f.close()
    finally:
        umount(device)
        vlmc.unmap_volume(name=device)
Ejemplo n.º 7
0
def write_data(volume, mountdir, randomfiles):
    d_id=vlmc.map_volume(name=volume)
    device = DEVICE_PREFIX + str(d_id)
    try:
        mount(device, mountdir)
        for rf in randomfiles:
            print "writing " + rf[0]
            f = open(os.path.join(mountdir, rf[0]), 'w')
            f.write(rf[1])
            f.close()
    finally:
        umount(device)
        vlmc.unmap_volume(name=device)
Ejemplo n.º 8
0
def read_data(volume, mountdir, randomfiles):
    d_id = vlmc.map_volume(name=volume)
    device = DEVICE_PREFIX + str(d_id)
    try:
        mount(device, mountdir)
        for rf in randomfiles:
            print "reading " + rf[0]
            f = open(os.path.join(mountdir, rf[0]), 'r')
            data = f.read()
            f.close()
            if data != rf[1]:
                raise Error("Data mismatch %s" % rf[0])
    finally:
        umount(device)
        vlmc.unmap_volume(name=device)
Ejemplo n.º 9
0
def read_data(volume, mountdir, randomfiles):
    d_id=vlmc.map_volume(name=volume)
    device = DEVICE_PREFIX + str(d_id)
    try:
        mount(device, mountdir)
        for rf in randomfiles:
            print "reading " + rf[0]
            f = open(os.path.join(mountdir, rf[0]), 'r')
            data = f.read()
            f.close()
            if data != rf[1]:
                raise Error("Data mismatch %s" % rf[0])
    finally:
        umount(device)
        vlmc.unmap_volume(name=device)