Ejemplo n.º 1
0
def main():
    make_option = optparse.make_option

    opt = optparse.OptionParser(option_list=[
        make_option('-o', dest='output', help='write to FILE', metavar='FILE'),
        make_option('-m',
                    dest='manifest',
                    help='read manifest from FILE',
                    metavar='FILE'),
        make_option('-D',
                    type='string',
                    help='define VAR=DATA',
                    metavar='VAR=DATA',
                    action='callback',
                    callback=add_var),
    ])

    (options, args) = opt.parse_args()

    manifest = read_manifest(options.manifest)

    outfile = os.path.abspath(options.output)

    manifest = parse_manifest(manifest)

    gen_image(outfile, manifest)
Ejemplo n.º 2
0
def main():
    make_option = optparse.make_option

    opt = optparse.OptionParser(option_list=[
        make_option('-m',
                    dest='manifest',
                    help='read manifest from FILE',
                    metavar='FILE'),
        make_option('-D',
                    type='string',
                    help='define VAR=DATA',
                    metavar='VAR=DATA',
                    action='callback',
                    callback=add_var),
        make_option(
            '-e',
            dest='export',
            help=
            'exports the contents of the usr.manifest into a given folder (which is deleted first)',
            metavar='FILE'),
    ])

    (options, args) = opt.parse_args()

    manifest = read_manifest(options.manifest)
    export_package(manifest, options.export)
Ejemplo n.º 3
0
def main():
    make_option = optparse.make_option

    opt = optparse.OptionParser(option_list=[
            make_option('-o',
                        dest='output',
                        help='write to FILE',
                        metavar='FILE'),
            make_option('-m',
                        dest='manifest',
                        help='read manifest from FILE',
                        metavar='FILE'),
            make_option('-D',
                        type='string',
                        help='define VAR=DATA',
                        metavar='VAR=DATA',
                        action='callback',
                        callback=add_var),
    ])

    (options, args) = opt.parse_args()

    manifest = read_manifest(options.manifest)

    outfile = os.path.abspath(options.output)

    manifest = parse_manifest(manifest)

    gen_image(outfile, manifest)
Ejemplo n.º 4
0
def main():
    make_option = optparse.make_option

    opt = optparse.OptionParser(option_list=[
            make_option('-o',
                        dest='output',
                        help='write to FILE',
                        metavar='FILE'),
            make_option('-d',
                        dest='depends',
                        help='write dependencies to FILE',
                        metavar='FILE',
                        default=None),
            make_option('-m',
                        dest='manifest',
                        help='read manifest from FILE',
                        metavar='FILE'),
            make_option('-D',
                        type='string',
                        help='define VAR=DATA',
                        metavar='VAR=DATA',
                        action='callback',
                        callback=add_var),
            make_option('-k',
                        dest='kernel',
                        action='store_true',
                        help='run OSv in direct kernel mode')
    ])

    (options, args) = opt.parse_args()

    depends = StringIO()
    if options.depends:
        depends = file(options.depends, 'w')
    manifest = read_manifest(options.manifest)

    depends.write('%s: \\\n' % (options.output,))

    image_path = os.path.abspath(options.output)
    upload_port = find_free_port()
    if options.kernel:
        kernel_mode_flag = '-k --kernel-path build/release/loader-stripped.elf'
    else:
        kernel_mode_flag = ''
    osv = subprocess.Popen('cd ../..; scripts/run.py %s --vnc none -m 512 -c1 -i "%s" --block-device-cache unsafe -s -e "--norandom --nomount --noinit /tools/mkfs.so; /tools/cpiod.so --prefix /zfs/zfs/; /zfs.so set compression=off osv" --forward tcp:127.0.0.1:%s-:10000' % (kernel_mode_flag,image_path,upload_port), shell=True, stdout=subprocess.PIPE)

    upload(osv, manifest, depends, upload_port)

    ret = osv.wait()
    if ret != 0:
        sys.exit("Upload failed.")

    depends.write('\n\n')
    depends.close()
Ejemplo n.º 5
0
def main():
    make_option = optparse.make_option

    opt = optparse.OptionParser(option_list=[
            make_option('-o',
                        dest='output',
                        help='write to FILE',
                        metavar='FILE'),
            make_option('-d',
                        dest='depends',
                        help='write dependencies to FILE',
                        metavar='FILE',
                        default=None),
            make_option('-m',
                        dest='manifest',
                        help='read manifest from FILE',
                        metavar='FILE'),
            make_option('-D',
                        type='string',
                        help='define VAR=DATA',
                        metavar='VAR=DATA',
                        action='callback',
                        callback=add_var),
            make_option('-x',
                        dest='emulation',
                        help='use emulation instead of a hypervisor',
                        metavar='FILE'),
    ])

    (options, args) = opt.parse_args()

    depends = StringIO()
    if options.depends:
        depends = file(options.depends, 'w')
    manifest = read_manifest(options.manifest)

    depends.write('%s: \\\n' % (options.output,))

    image_path = os.path.abspath(options.output)
    osv = None

    if options.emulation == 'y':
        print("Using emulation (no hypervisor support) for image creation")
        osv = subprocess.Popen('cd ../..; scripts/run.py --vnc none -m 512 -c1 -i %s -u -s -p none -e "--norandom --nomount --noinit /tools/mkfs.so; /tools/cpiod.so --prefix /zfs/zfs/; /zfs.so set compression=off osv" --forward tcp:10000::10000' % image_path, shell=True, stdout=subprocess.PIPE)
    else:
        print("Using hypervisor support for image creation")
        osv = subprocess.Popen('cd ../..; scripts/run.py --vnc none -m 512 -c1 -i %s -u -s -e "--norandom --nomount --noinit /tools/mkfs.so; /tools/cpiod.so --prefix /zfs/zfs/; /zfs.so set compression=off osv" --forward tcp:10000::10000' % image_path, shell=True, stdout=subprocess.PIPE)

    upload(osv, manifest, depends)

    osv.wait()

    depends.write('\n\n')
    depends.close()
Ejemplo n.º 6
0
def main():
    make_option = optparse.make_option

    opt = optparse.OptionParser(option_list=[
        make_option('-o', dest='output', help='write to FILE', metavar='FILE'),
        make_option('-d',
                    dest='depends',
                    help='write dependencies to FILE',
                    metavar='FILE',
                    default=None),
        make_option('-m',
                    dest='manifest',
                    help='read manifest from FILE',
                    metavar='FILE'),
        make_option('-D',
                    type='string',
                    help='define VAR=DATA',
                    metavar='VAR=DATA',
                    action='callback',
                    callback=add_var),
    ])

    (options, args) = opt.parse_args()

    depends = StringIO()
    if options.depends:
        depends = file(options.depends, 'w')
    manifest = read_manifest(options.manifest)

    depends.write('%s: \\\n' % (options.output, ))

    image_path = os.path.abspath(options.output)
    upload_port = find_free_port()
    osv = subprocess.Popen(
        'cd ../..; scripts/run.py --vnc none -m 512 -c1 -i %s -u -s -e "--norandom --nomount --noinit /tools/mkfs.so; /tools/cpiod.so --prefix /zfs/zfs/; /zfs.so set compression=off osv" --forward tcp:127.0.0.1:%s-:10000'
        % (image_path, upload_port),
        shell=True,
        stdout=subprocess.PIPE)

    upload(osv, manifest, depends, upload_port)

    ret = osv.wait()
    if ret != 0:
        sys.exit("Upload failed.")

    depends.write('\n\n')
    depends.close()
Ejemplo n.º 7
0
def main():
    make_option = optparse.make_option

    opt = optparse.OptionParser(option_list=[
        make_option('-o', dest='output', help='write to FILE', metavar='FILE'),
        make_option('-d',
                    dest='depends',
                    help='write dependencies to FILE',
                    metavar='FILE',
                    default=None),
        make_option('-m',
                    dest='manifest',
                    help='read manifest from FILE',
                    metavar='FILE'),
        make_option('-D',
                    type='string',
                    help='define VAR=DATA',
                    metavar='VAR=DATA',
                    action='callback',
                    callback=add_var),
    ])

    (options, args) = opt.parse_args()

    # See unpack_bootfs() as the reference to this ad-hoc packing format.
    metadata_size = 128
    depends = io.StringIO()
    if options.depends:
        depends = open(options.depends, 'w')
    out = open(options.output, 'wb')

    depends.write(u'%s: \\\n' % (options.output, ))

    files = read_manifest(options.manifest)
    files = [(x, y % defines) for (x, y) in files]
    files = list(expand(files))
    files = [(x, unsymlink(y)) for (x, y) in files]
    files = [(x, y) for (x, y) in files if not x.endswith("-stripped.so")]
    files = [(x, strip_file(y)) for (x, y) in files]

    pos = (len(files) + 1) * metadata_size

    for name, hostname in files:
        type = 0
        if hostname.startswith("->"):
            link = hostname[2:]
            type = 1
            size = len(link.encode()) + 1
        elif os.path.isdir(hostname):
            size = 0
            if not name.endswith("/"):
                name += "/"
        else:
            size = os.stat(hostname).st_size

        # FIXME: check if name.encode()'s length is more than 110 (111
        # minus the necessary null byte) and fail if it is.
        metadata = struct.pack('QQb111s', size, pos, type, name.encode())
        out.write(metadata)
        pos += size
        depends.write(u'\t%s \\\n' % (hostname, ))

    out.write(struct.pack('128s', b''))

    for name, hostname in files:
        if os.path.isdir(hostname):
            continue
        if hostname.startswith("->"):
            link = hostname[2:]
            out.write(link.encode())
            out.write('\0')
        else:
            out.write(open(hostname, 'rb').read())

    depends.write(u'\n\n')

    out.close()
    depends.close()
Ejemplo n.º 8
0
def main():
    make_option = optparse.make_option

    opt = optparse.OptionParser(option_list=[
            make_option('-o',
                        dest='output',
                        help='write to FILE',
                        metavar='FILE'),
            make_option('-d',
                        dest='depends',
                        help='write dependencies to FILE',
                        metavar='FILE',
                        default=None),
            make_option('-m',
                        dest='manifest',
                        help='read manifest from FILE',
                        metavar='FILE'),
            make_option('-D',
                        type='string',
                        help='define VAR=DATA',
                        metavar='VAR=DATA',
                        action='callback',
                        callback=add_var),
    ])

    (options, args) = opt.parse_args()

    # See unpack_bootfs() as the reference to this ad-hoc packing format.
    metadata_size = 128
    depends = io.StringIO()
    if options.depends:
        depends = open(options.depends, 'w')
    out = open(options.output, 'wb')

    depends.write(u'%s: \\\n' % (options.output,))

    files = read_manifest(options.manifest)
    files = [(x, y % defines) for (x, y) in files]
    files = list(expand(files))
    files = [(x, unsymlink(y)) for (x, y) in files]
    files = [(x, y) for (x, y) in files if not x.endswith("-stripped.so")]
    files = [(x, strip_file(y)) for (x, y) in files]

    pos = (len(files) + 1) * metadata_size

    for name, hostname in files:
        type = 0
        if hostname.startswith("->"):
            link = hostname[2:]
            type = 1
            size = len(link.encode())+1
        elif os.path.isdir(hostname):
            size = 0;
            if not name.endswith("/"):
                name += "/"
        else:
            size = os.stat(hostname).st_size

        # FIXME: check if name.encode()'s length is more than 110 (111
        # minus the necessary null byte) and fail if it is.
        metadata = struct.pack('QQb111s', size, pos, type, name.encode())
        out.write(metadata)
        pos += size
        depends.write(u'\t%s \\\n' % (hostname,))

    out.write(struct.pack('128s', b''))

    for name, hostname in files:
        if os.path.isdir(hostname):
            continue
        if hostname.startswith("->"):
            link = hostname[2:]
            out.write(link.encode())
            out.write('\0')
        else:
            out.write(open(hostname, 'rb').read())

    depends.write(u'\n\n')

    out.close()
    depends.close()