Esempio n. 1
0
def create_distro_tree(distro=None,
                       distro_name=None,
                       osmajor=u'DansAwesomeLinux6',
                       osminor=u'9',
                       distro_tags=None,
                       arch=u'i386',
                       variant=u'Server',
                       lab_controllers=None,
                       urls=None,
                       harness_dir=True,
                       osmajor_installopts_arch=None,
                       date_created=None,
                       **kwargs):
    if distro is None:
        distro = create_distro(name=distro_name,
                               osmajor=osmajor,
                               osminor=osminor,
                               tags=distro_tags,
                               harness_dir=harness_dir,
                               date_created=date_created)
    distro_tree = DistroTree(distro=distro,
                             arch=Arch.lazy_create(arch=arch),
                             variant=variant)
    if date_created is not None:
        distro_tree.date_created = date_created
    if distro_tree.arch not in distro.osversion.arches:
        distro.osversion.arches.append(distro_tree.arch)
    distro_tree.repos.append(
        DistroTreeRepo(repo_id=variant, repo_type=u'variant', path=u''))
    distro_tree.images.append(
        DistroTreeImage(image_type=ImageType.kernel,
                        kernel_type=KernelType.by_name(u'default'),
                        path=u'pxeboot/vmlinuz'))
    distro_tree.images.append(
        DistroTreeImage(image_type=ImageType.initrd,
                        kernel_type=KernelType.by_name(u'default'),
                        path=u'pxeboot/initrd'))
    session.flush()  # to get an id
    # make it available in all lab controllers by default
    if lab_controllers is None:
        lab_controllers = LabController.query
    for lc in lab_controllers:
        add_distro_tree_to_lab(distro_tree, lc, urls=urls)

    if osmajor_installopts_arch:
        io = OSMajorInstallOptions.lazy_create(
            osmajor_id=distro_tree.distro.osversion.osmajor.id,
            arch_id=distro_tree.arch.id)
        io.ks_meta = osmajor_installopts_arch.get('ks_meta', '')
        io.kernel_options = osmajor_installopts_arch.get('kernel_options', '')
        io.kernel_options_post = osmajor_installopts_arch.get(
            'kernel_options_post', '')

    log.debug('Created distro tree %r', distro_tree)
    return distro_tree