示例#1
0
def createImage(options):
    (validImage, config) = verifyImageTypeAndConfig(options.config_file,
                                                    options.img_name)
    if not validImage:
        raise Exception("Image type/config not supported")

    if 'ova' in config['artifacttype'] and shutil.which("ovftool") is None:
        raise Exception("ovftool is not available")
    workingDir = os.path.abspath(options.stage_path + "/" +
                                 config['image_type'])
    if os.path.exists(workingDir) and os.path.isdir(workingDir):
        shutil.rmtree(workingDir)
    os.mkdir(workingDir)
    if 'password' in config:
        cryptPassword(config, config['password']['text'])
    script_dir = os.path.dirname(os.path.realpath(__file__))
    # Use image specific scripts
    disk_setup_script = replaceScript(script_dir, config['image_type'],
                                      "mk-setup-vmdk.sh")
    disk_cleanup_script = replaceScript(script_dir, config['image_type'],
                                        "mk-clean-vmdk.sh")
    grub_script = replaceScript(script_dir, config['image_type'],
                                "mk-setup-grub.sh", options.installer_path)
    prepare_script = replaceScript(script_dir, config['image_type'],
                                   "mk-prepare-system.sh",
                                   options.installer_path)
    config['prepare_script'] = prepare_script
    config['setup_grub_script'] = grub_script

    if options.additional_rpms_path:
        os.mkdir(options.rpm_path + '/additional')
        for item in os.listdir(options.additional_rpms_path):
            s = os.path.join(options.additional_rpms_path, item)
            d = os.path.join(options.rpm_path + '/additional', item)
            shutil.copy2(s, d)

    os.chdir(workingDir)
    vmdk_path = workingDir + "/photon-" + config['image_type']
    config['disk'], success = create_vmdk_and_partition(
        config, vmdk_path, disk_setup_script)
    if not success:
        raise Exception(
            "Unexpected failure in creating disk, please check the logs")
        sys.exit(1)
    config['iso_system'] = False
    config['vmdk_install'] = True
    result = runInstaller(options, config)
    process = subprocess.Popen([disk_cleanup_script, config['disk']['disk']])
    process.wait()
    if not result:
        raise Exception("Installation process failed")
    os.chdir(script_dir)
    imagegenerator.generateImage(vmdk_path + '.raw',
                                 options.rpm_path + '/additional/',
                                 options.src_root + '/tools/bin/',
                                 options.src_root, config)
示例#2
0
def createImage(options):
    (validImage, config) = verifyImageTypeAndConfig(options.config_file, options.img_name)
    if not validImage:
        raise Exception("Image type/config not supported")
    
    if 'ova' in config['artifacttype'] and shutil.which("ovftool") is None:
        raise Exception("ovftool is not available")
    workingDir = os.path.abspath(options.stage_path + "/" + config['image_type'])
    if os.path.exists(workingDir) and os.path.isdir(workingDir):
        shutil.rmtree(workingDir)
    os.mkdir(workingDir)
    if 'password' in config:
        cryptPassword(config, config['password']['text'])
    script_dir = os.path.dirname(os.path.realpath(__file__))
    # Use image specific scripts
    disk_setup_script = replaceScript(script_dir, config['image_type'], "mk-setup-vmdk.sh")
    disk_cleanup_script = replaceScript(script_dir, config['image_type'], "mk-clean-vmdk.sh")
    grub_script = replaceScript(script_dir, config['image_type'], "mk-setup-grub.sh", options.installer_path)
    prepare_script = replaceScript(script_dir, config['image_type'], "mk-prepare-system.sh", options.installer_path)
    config['prepare_script'] = prepare_script
    config['setup_grub_script'] = grub_script
    
    if options.additional_rpms_path:
        os.mkdir(options.rpm_path + '/additional')
        for item in os.listdir(options.additional_rpms_path):
            s = os.path.join(options.additional_rpms_path, item)
            d = os.path.join(options.rpm_path + '/additional', item)
            shutil.copy2(s, d)

    os.chdir(workingDir)
    vmdk_path = workingDir + "/photon-" + config['image_type']
    config['disk'], success = create_vmdk_and_partition(config, vmdk_path, disk_setup_script)
    if not success:
        raise Exception("Unexpected failure in creating disk, please check the logs")
        sys.exit(1)
    config['iso_system'] = False
    config['vmdk_install'] = True
    result = runInstaller(options, config)
    process = subprocess.Popen([disk_cleanup_script, config['disk']['disk']])
    process.wait()
    if not result:
        raise Exception("Installation process failed")
    os.chdir(script_dir)
    imagegenerator.generateImage(
                                vmdk_path + '.raw',
                                options.rpm_path + '/additional/',
                                options.src_root + '/tools/bin/',
                                options.src_root,
                                config
                              )