Beispiel #1
0
    def add_distro_tree(self, new_distro):
        lab_controller = identity.current.user.lab_controller

        variant = new_distro.get('variant')
        arch = Arch.lazy_create(arch=new_distro['arch'])

        osmajor = OSMajor.lazy_create(osmajor=new_distro['osmajor'])
        try:
            osmajor = OSMajor.by_alias(new_distro['osmajor'])
        except NoResultFound:
            pass
        else:
            raise BX(
                _('Cannot import distro as %s: it is configured as an alias for %s'
                  % (new_distro['osmajor'], osmajor.osmajor)))

        osversion = OSVersion.lazy_create(osmajor=osmajor,
                                          osminor=new_distro['osminor'])
        if 'arches' in new_distro:
            for arch_name in new_distro['arches']:
                osversion.add_arch(Arch.lazy_create(arch=arch_name))
        osversion.add_arch(arch)

        distro = Distro.lazy_create(name=new_distro['name'],
                                    osversion=osversion)
        # Automatically tag the distro if tags exists
        if 'tags' in new_distro:
            for tag in new_distro['tags']:
                distro.add_tag(tag)
        distro.date_created = datetime.utcfromtimestamp(
            float(new_distro['tree_build_time']))

        distro_tree = DistroTree.lazy_create(distro=distro,
                                             variant=variant,
                                             arch=arch)
        distro_tree.date_created = datetime.utcfromtimestamp(
            float(new_distro['tree_build_time']))

        if 'repos' in new_distro:
            for repo in new_distro['repos']:
                dtr = DistroTreeRepo.lazy_create(distro_tree=distro_tree,
                                                 repo_id=repo['repoid'],
                                                 repo_type=repo['type'],
                                                 path=repo['path'])

        if 'kernel_options' in new_distro:
            distro_tree.kernel_options = new_distro['kernel_options']

        if 'kernel_options_post' in new_distro:
            distro_tree.kernel_options_post = new_distro['kernel_options_post']

        if 'ks_meta' in new_distro:
            distro_tree.ks_meta = new_distro['ks_meta']

        if 'images' in new_distro:
            for image in new_distro['images']:
                try:
                    image_type = ImageType.from_string(image['type'])
                except ValueError:
                    continue  # ignore
                if 'kernel_type' not in image:
                    image['kernel_type'] = 'default'
                try:
                    kernel_type = KernelType.by_name(image['kernel_type'])
                except ValueError:
                    continue  # ignore
                dti = DistroTreeImage.lazy_create(distro_tree=distro_tree,
                                                  image_type=image_type,
                                                  kernel_type=kernel_type,
                                                  path=image['path'])

        new_urls_by_scheme = dict(
            (urlparse.urlparse(url).scheme, url) for url in new_distro['urls'])
        if None in new_urls_by_scheme:
            raise ValueError('URL %r is not absolute' %
                             new_urls_by_scheme[None])
        for lca in distro_tree.lab_controller_assocs:
            if lca.lab_controller == lab_controller:
                scheme = urlparse.urlparse(lca.url).scheme
                new_url = new_urls_by_scheme.pop(scheme, None)
                if new_url != None and lca.url != new_url:
                    distro_tree.activity.append(
                        DistroTreeActivity(user=identity.current.user,
                                           service=u'XMLRPC',
                                           action=u'Changed',
                                           field_name=u'lab_controller_assocs',
                                           old_value=u'%s %s' %
                                           (lca.lab_controller, lca.url),
                                           new_value=u'%s %s' %
                                           (lca.lab_controller, new_url)))
                    lca.url = new_url
        for url in new_urls_by_scheme.values():
            distro_tree.lab_controller_assocs.append(
                LabControllerDistroTree(lab_controller=lab_controller,
                                        url=url))
            distro_tree.activity.append(
                DistroTreeActivity(user=identity.current.user,
                                   service=u'XMLRPC',
                                   action=u'Added',
                                   field_name=u'lab_controller_assocs',
                                   old_value=None,
                                   new_value=u'%s %s' % (lab_controller, url)))

        return distro_tree.id
Beispiel #2
0
    def add_distro_tree(self, new_distro):
        lab_controller = identity.current.user.lab_controller

        variant = new_distro.get('variant')
        arch = Arch.lazy_create(arch=new_distro['arch'])

        osmajor = OSMajor.lazy_create(osmajor=new_distro['osmajor'])
        try:
            osmajor = OSMajor.by_alias(new_distro['osmajor'])
        except NoResultFound:
            pass
        else:
            raise BX(
                _('Cannot import distro as %s: it is configured as an alias for %s'
                  % (new_distro['osmajor'], osmajor.osmajor)))

        osversion = OSVersion.lazy_create(osmajor=osmajor,
                                          osminor=new_distro['osminor'])
        if 'arches' in new_distro:
            for arch_name in new_distro['arches']:
                osversion.add_arch(Arch.lazy_create(arch=arch_name))
        osversion.add_arch(arch)

        distro = Distro.lazy_create(name=new_distro['name'],
                                    osversion=osversion)
        # Automatically tag the distro if tags exists
        if 'tags' in new_distro:
            for tag in new_distro['tags']:
                distro.add_tag(tag)
        distro.date_created = datetime.utcfromtimestamp(
            float(new_distro['tree_build_time']))

        distro_tree = DistroTree.lazy_create(distro=distro,
                                             variant=variant,
                                             arch=arch)
        distro_tree.date_created = datetime.utcfromtimestamp(
            float(new_distro['tree_build_time']))

        if 'repos' in new_distro:
            for repo in new_distro['repos']:
                dtr = DistroTreeRepo.lazy_create(distro_tree=distro_tree,
                                                 repo_id=repo['repoid'],
                                                 repo_type=repo['type'],
                                                 path=repo['path'])

        if 'kernel_options' in new_distro:
            distro_tree.kernel_options = new_distro['kernel_options']

        if 'kernel_options_post' in new_distro:
            distro_tree.kernel_options_post = new_distro['kernel_options_post']

        if 'ks_meta' in new_distro:
            distro_tree.ks_meta = new_distro['ks_meta']

        if 'images' in new_distro:
            for image in new_distro['images']:
                try:
                    image_type = ImageType.from_string(image['type'])
                except ValueError:
                    continue  # ignore
                if 'kernel_type' not in image:
                    image['kernel_type'] = 'default'
                try:
                    kernel_type = KernelType.by_name(image['kernel_type'])
                except ValueError:
                    continue  # ignore
                dti = DistroTreeImage.lazy_create(distro_tree=distro_tree,
                                                  image_type=image_type,
                                                  kernel_type=kernel_type,
                                                  path=image['path'])

        DistroTrees.add_distro_urls(distro_tree, lab_controller,
                                    new_distro['urls'])

        return distro_tree.id
Beispiel #3
0
    def add_distro_tree(self, new_distro):
        lab_controller = identity.current.user.lab_controller

        variant = new_distro.get('variant')
        arch = Arch.lazy_create(arch=new_distro['arch'])

        osmajor = OSMajor.lazy_create(osmajor=new_distro['osmajor'])
        try:
            osmajor = OSMajor.by_alias(new_distro['osmajor'])
        except NoResultFound:
            pass
        else:
            raise BX(_('Cannot import distro as %s: it is configured as an alias for %s' 
                       % (new_distro['osmajor'], osmajor.osmajor)))

        osversion = OSVersion.lazy_create(osmajor=osmajor, osminor=new_distro['osminor'])
        if 'arches' in new_distro:
            for arch_name in new_distro['arches']:
                osversion.add_arch(Arch.lazy_create(arch=arch_name))
        osversion.add_arch(arch)

        distro = Distro.lazy_create(name=new_distro['name'], osversion=osversion)
        # Automatically tag the distro if tags exists
        if 'tags' in new_distro:
            for tag in new_distro['tags']:
                distro.add_tag(tag)
        distro.date_created = datetime.utcfromtimestamp(float(new_distro['tree_build_time']))

        distro_tree = DistroTree.lazy_create(distro=distro,
                variant=variant, arch=arch)
        distro_tree.date_created = datetime.utcfromtimestamp(float(new_distro['tree_build_time']))

        if 'repos' in new_distro:
            for repo in new_distro['repos']:
                dtr = DistroTreeRepo.lazy_create(distro_tree=distro_tree,
                        repo_id=repo['repoid'], repo_type=repo['type'],
                        path=repo['path'])

        if 'kernel_options' in new_distro:
            distro_tree.kernel_options = new_distro['kernel_options']

        if 'kernel_options_post' in new_distro:
            distro_tree.kernel_options_post = new_distro['kernel_options_post']

        if 'ks_meta' in new_distro:
            distro_tree.ks_meta = new_distro['ks_meta']

        if 'images' in new_distro:
            for image in new_distro['images']:
                try:
                    image_type = ImageType.from_string(image['type'])
                except ValueError:
                    continue # ignore
                if 'kernel_type' not in image:
                    image['kernel_type'] = 'default'
                try:
                    kernel_type = KernelType.by_name(image['kernel_type'])
                except ValueError:
                    continue # ignore
                dti = DistroTreeImage.lazy_create(distro_tree=distro_tree,
                        image_type=image_type, kernel_type=kernel_type,
                        path=image['path'])

        new_urls_by_scheme = dict((urlparse.urlparse(url).scheme, url)
                for url in new_distro['urls'])
        if None in new_urls_by_scheme:
            raise ValueError('URL %r is not absolute' % new_urls_by_scheme[None])
        for lca in distro_tree.lab_controller_assocs:
            if lca.lab_controller == lab_controller:
                scheme = urlparse.urlparse(lca.url).scheme
                new_url = new_urls_by_scheme.pop(scheme, None)
                if new_url != None and lca.url != new_url:
                    distro_tree.activity.append(DistroTreeActivity(
                            user=identity.current.user, service=u'XMLRPC',
                            action=u'Changed', field_name=u'lab_controller_assocs',
                            old_value=u'%s %s' % (lca.lab_controller, lca.url),
                            new_value=u'%s %s' % (lca.lab_controller, new_url)))
                    lca.url = new_url
        for url in new_urls_by_scheme.values():
            distro_tree.lab_controller_assocs.append(LabControllerDistroTree(
                    lab_controller=lab_controller, url=url))
            distro_tree.activity.append(DistroTreeActivity(
                    user=identity.current.user, service=u'XMLRPC',
                    action=u'Added', field_name=u'lab_controller_assocs',
                    old_value=None, new_value=u'%s %s' % (lab_controller, url)))

        return distro_tree.id