예제 #1
0
    def by_name(self, input,*args,**kw):
        input = input.lower()
        if 'anywhere' in kw:
            search = OSVersion.list_osmajor_by_name(input, find_anywhere=True)
        else:
            search = OSVersion.list_osmajor_by_name(input)

        osmajors =  ["%s" % (match.osmajor.osmajor) for match in search] 
        osmajors = list(set(osmajors))
        return dict(matches=osmajors)
예제 #2
0
def create_distro(name=None,
                  osmajor=u'DansAwesomeLinux6',
                  osminor=u'9',
                  arches=None,
                  tags=None,
                  harness_dir=True,
                  osmajor_installopts=None):
    osmajor = OSMajor.lazy_create(osmajor=osmajor)
    osversion = OSVersion.lazy_create(osmajor=osmajor, osminor=osminor)
    if arches:
        osversion.arches = arches
    if not name:
        name = unique_name(u'%s.%s-%%s' % (osmajor, osminor))
    distro = Distro.lazy_create(name=name, osversion=osversion)
    for tag in (tags or []):
        distro.add_tag(tag)
    # add distro wide install options, if any
    if osmajor_installopts:
        for arch in arches:
            io = OSMajorInstallOptions.lazy_create(
                osmajor_id=osmajor.id, arch_id=Arch.by_name(arch).id)
            io.ks_meta = osmajor_installopts.get('ks_meta', '')
            io.kernel_options = osmajor_installopts.get('kernel_options', '')
            io.kernel_options_post = osmajor_installopts.get(
                'kernel_options_post', '')

    log.debug('Created distro %r', distro)
    if harness_dir:
        harness_dir = os.path.join(turbogears.config.get('basepath.harness'),
                                   distro.osversion.osmajor.osmajor)
        if not os.path.exists(harness_dir):
            os.makedirs(harness_dir)
    return distro
예제 #3
0
    def _from_csv(cls,system,data,csv_type,log):
        """
        Import data from CSV file into System Objects
        """
        try:
            arch = Arch.by_name(data['arch'])
        except ValueError:
            log.append("%s: Invalid Arch %s" % (system.fqdn, data['arch']))
            return False

        if data['update'] and data['family']:
            try:
                osversion = OSVersion.by_name(OSMajor.by_name(unicode(data['family'])),
                                                            unicode(data['update']))
            except InvalidRequestError:
                log.append("%s: Invalid Family %s Update %s" % (system.fqdn,
                                                        data['family'],
                                                        data['update']))
                return False
            if osversion not in [oldosversion.osversion for oldosversion in system.excluded_osversion_byarch(arch)]:
                if data['excluded'] == 'True':
                    exclude_osversion = ExcludeOSVersion(osversion=osversion,
                                                         arch=arch)
                    system.excluded_osversion.append(exclude_osversion)
                    system.record_activity(user=identity.current.user, service=u'CSV',
                            action=u'Added', field=u'Excluded_families',
                            old=u'', new=u'%s/%s' % (osversion, arch))
            else:
                if data['excluded'] == 'False':
                    for old_osversion in system.excluded_osversion_byarch(arch):
                        if old_osversion.osversion == osversion:
                            system.record_activity(user=identity.current.user,
                                    service=u'CSV', action=u'Removed',
                                    field=u'Excluded_families',
                                    old=u'%s/%s' % (old_osversion.osversion, arch),
                                    new=u'')
                            session.delete(old_osversion)
        if not data['update'] and data['family']:
            try:
                osmajor = OSMajor.by_name(data['family'])
            except InvalidRequestError:
                log.append("%s: Invalid family %s " % (system.fqdn,
                                                       data['family']))
                return False
            if osmajor not in [oldosmajor.osmajor for oldosmajor in system.excluded_osmajor_byarch(arch)]:
                if data['excluded'].lower() == 'true':
                    exclude_osmajor = ExcludeOSMajor(osmajor=osmajor, arch=arch)
                    system.excluded_osmajor.append(exclude_osmajor)
                    system.record_activity(user=identity.current.user, service=u'CSV',
                            action=u'Added', field=u'Excluded_families',
                            old=u'', new=u'%s/%s' % (osmajor, arch))
            else:
                if data['excluded'].lower() == 'false':
                    for old_osmajor in system.excluded_osmajor_byarch(arch):
                        if old_osmajor.osmajor == osmajor:
                            system.record_activity(user=identity.current.user, service=u'CSV',
                                    action=u'Removed', field=u'Excluded_families',
                                    old=u'%s/%s' % (old_osmajor.osmajor, arch), new=u'')
                            session.delete(old_osmajor)
        return True
예제 #4
0
파일: data_setup.py 프로젝트: omps/beaker
def create_distro(name=None, osmajor=u'DansAwesomeLinux6', osminor=u'9',
                  arches=None, tags=None, harness_dir=True, osmajor_installopts=None):
    osmajor = OSMajor.lazy_create(osmajor=osmajor)
    osversion = OSVersion.lazy_create(osmajor=osmajor, osminor=osminor)
    if arches:
        osversion.arches = arches
    if not name:
        name = unique_name(u'%s.%s-%%s' % (osmajor, osminor))
    distro = Distro.lazy_create(name=name, osversion=osversion)
    for tag in (tags or []):
        distro.add_tag(tag)
    # add distro wide install options, if any
    if osmajor_installopts:
        for arch in arches:
            io = OSMajorInstallOptions.lazy_create(osmajor_id=osmajor.id,
                                                   arch_id=Arch.by_name(arch).id)
            io.ks_meta = osmajor_installopts.get('ks_meta', '')
            io.kernel_options = osmajor_installopts.get('kernel_options', '')
            io.kernel_options_post = osmajor_installopts.get('kernel_options_post', '')

    log.debug('Created distro %r', distro)
    if harness_dir:
        harness_dir = os.path.join(turbogears.config.get('basepath.harness'), distro.osversion.osmajor.osmajor)
        if not os.path.exists(harness_dir):
            os.makedirs(harness_dir)
    return distro
예제 #5
0
 def test_concurrent_same_tree(self):
     distro_data = dict(self.distro_data)
     # ensure osmajor, osversion, and distro already exist
     with session.begin():
         osmajor = OSMajor.lazy_create(osmajor=distro_data["osmajor"])
         osversion = OSVersion.lazy_create(osmajor=osmajor, osminor=distro_data["osminor"])
         osversion.arches = [Arch.lazy_create(arch=arch) for arch in distro_data["arches"]]
         Distro.lazy_create(name=distro_data["name"], osversion=osversion)
     self.add_distro_trees_concurrently(distro_data, distro_data)
예제 #6
0
 def test_concurrent_new_distro(self):
     distro_data = dict(self.distro_data)
     # ensure osmajor and osversion already exist
     with session.begin():
         osmajor = OSMajor.lazy_create(osmajor=distro_data["osmajor"])
         osversion = OSVersion.lazy_create(osmajor=osmajor, osminor=distro_data["osminor"])
         osversion.arches = [Arch.lazy_create(arch=arch) for arch in distro_data["arches"]]
     # ... but distro is new
     distro_data["name"] = "concurrent-new-distro"
     self.add_distro_trees_concurrently(distro_data, distro_data)
예제 #7
0
 def test_concurrent_same_tree(self):
     distro_data = dict(self.distro_data)
     # ensure osmajor, osversion, and distro already exist
     with session.begin():
         osmajor = OSMajor.lazy_create(osmajor=distro_data['osmajor'])
         osversion = OSVersion.lazy_create(osmajor=osmajor,
                 osminor=distro_data['osminor'])
         osversion.arches = [Arch.lazy_create(arch=arch)
                 for arch in distro_data['arches']]
         Distro.lazy_create(name=distro_data['name'], osversion=osversion)
     self.add_distro_trees_concurrently(distro_data, distro_data)
예제 #8
0
 def edit(self, id=None, *args, **kw):
     try:
         osversion = OSVersion.by_id(id)
     except InvalidRequestError:
         flash(_(u"Invalid OSVersion ID %s" % id))
         redirect(".")
     return dict(title   = unicode(osversion),
                 value   = dict(id     = osversion.id,
                                arches = [arch.id for arch in osversion.arches]),
                 form    = self.osversion_form,
                 action  = "./save",
                 options = None)
예제 #9
0
 def test_concurrent_new_distro(self):
     distro_data = dict(self.distro_data)
     # ensure osmajor and osversion already exist
     with session.begin():
         osmajor = OSMajor.lazy_create(osmajor=distro_data['osmajor'])
         osversion = OSVersion.lazy_create(osmajor=osmajor,
                 osminor=distro_data['osminor'])
         osversion.arches = [Arch.lazy_create(arch=arch)
                 for arch in distro_data['arches']]
     # ... but distro is new
     distro_data['name'] = 'concurrent-new-distro'
     self.add_distro_trees_concurrently(distro_data, distro_data)
예제 #10
0
 def save(self, id=None, arches=None, *args, **kw):
     try:
         osversion = OSVersion.by_id(id)
     except InvalidRequestError:
         flash(_(u"Invalid OSVersion ID %s" % id))
         redirect(".")
     arch_objects = [Arch.by_id(arch) for arch in arches]
     if osversion.arches != arch_objects:
         osversion.arches = arch_objects
         flash(_(u"Changes Saved for %s" % osversion))
     else:
         flash(_(u"No Changes for %s" % osversion))
     redirect(".")
예제 #11
0
 def test_concurrent_different_trees(self):
     distro_data = dict(self.distro_data)
     # ensure osmajor, osversion, and distro already exist
     with session.begin():
         osmajor = OSMajor.lazy_create(osmajor=distro_data["osmajor"])
         osversion = OSVersion.lazy_create(osmajor=osmajor, osminor=distro_data["osminor"])
         osversion.arches = [Arch.lazy_create(arch=arch) for arch in distro_data["arches"]]
         Distro.lazy_create(name=distro_data["name"], osversion=osversion)
     # ensure two different trees
     distro_data["variant"] = u"Workstation"
     distro_data2 = dict(distro_data)
     distro_data2["variant"] = u"Server"
     self.add_distro_trees_concurrently(distro_data, distro_data2)
예제 #12
0
 def test_concurrent_different_trees(self):
     distro_data = dict(self.distro_data)
     # ensure osmajor, osversion, and distro already exist
     with session.begin():
         osmajor = OSMajor.lazy_create(osmajor=distro_data['osmajor'])
         osversion = OSVersion.lazy_create(osmajor=osmajor,
                 osminor=distro_data['osminor'])
         osversion.arches = [Arch.lazy_create(arch=arch)
                 for arch in distro_data['arches']]
         Distro.lazy_create(name=distro_data['name'], osversion=osversion)
     # ensure two different trees
     distro_data['variant'] = u'Workstation'
     distro_data2 = dict(distro_data)
     distro_data2['variant'] = u'Server'
     self.add_distro_trees_concurrently(distro_data, distro_data2)
예제 #13
0
 def test_concurrent_different_trees(self):
     distro_data = dict(self.distro_data)
     # ensure osmajor, osversion, and distro already exist
     with session.begin():
         osmajor = OSMajor.lazy_create(osmajor=distro_data['osmajor'])
         osversion = OSVersion.lazy_create(osmajor=osmajor,
                 osminor=distro_data['osminor'])
         osversion.arches = [Arch.lazy_create(arch=arch)
                 for arch in distro_data['arches']]
         Distro.lazy_create(name=distro_data['name'], osversion=osversion)
     # ensure two different trees
     distro_data['variant'] = u'Workstation'
     distro_data2 = dict(distro_data)
     distro_data2['variant'] = u'Server'
     self.add_distro_trees_concurrently(distro_data, distro_data2)
예제 #14
0
def create_distro(name=None, osmajor=u'DansAwesomeLinux6', osminor=u'9',
        arches=None, tags=None):
    osmajor = OSMajor.lazy_create(osmajor=osmajor)
    osversion = OSVersion.lazy_create(osmajor=osmajor, osminor=osminor)
    if arches:
        osversion.arches = arches
    if not name:
        name = unique_name(u'%s.%s-%%s' % (osmajor, osminor))
    distro = Distro.lazy_create(name=name, osversion=osversion)
    for tag in (tags or []):
        distro.add_tag(tag)
    log.debug('Created distro %r', distro)
    harness_dir = os.path.join(turbogears.config.get('basepath.harness'), distro.osversion.osmajor.osmajor)
    if not os.path.exists(harness_dir):
        os.makedirs(harness_dir)
    return distro
예제 #15
0
def create_distro(name=None, osmajor=u'DansAwesomeLinux6', osminor=u'9',
        arches=None, tags=None, harness_dir=True):
    osmajor = OSMajor.lazy_create(osmajor=osmajor)
    osversion = OSVersion.lazy_create(osmajor=osmajor, osminor=osminor)
    if arches:
        osversion.arches = arches
    if not name:
        name = unique_name(u'%s.%s-%%s' % (osmajor, osminor))
    distro = Distro.lazy_create(name=name, osversion=osversion)
    for tag in (tags or []):
        distro.add_tag(tag)
    log.debug('Created distro %r', distro)
    if harness_dir:
        harness_dir = os.path.join(turbogears.config.get('basepath.harness'), distro.osversion.osmajor.osmajor)
        if not os.path.exists(harness_dir):
            os.makedirs(harness_dir)
    return distro
예제 #16
0
파일: distro.py 프로젝트: xhernandez/beaker
    def edit_version(self, name, version):
        """
        Updates the version for all distros with the given name.

        :param name: name of distros to be updated, for example 
            'RHEL5.6-Server-20101110.0'
        :type name: string
        :param version: new version to be applied, for example 
            'RedHatEnterpriseLinuxServer5.6' or 'Fedora14'
        :type version: string
        """
        distros = Distro.query.filter(Distro.name.like(unicode(name)))
        edited = []

        os_major = version.split('.')[0]

        # Try and split OSMinor
        try:
            os_minor = version.split('.')[1]
        except IndexError:
            os_minor = '0'

        # Try and find OSMajor
        osmajor = OSMajor.lazy_create(osmajor=os_major)

        # Try and find OSVersion
        osversion = OSVersion.lazy_create(osmajor=osmajor, osminor=os_minor)

        # Check each Distro
        for distro in distros:
            if osversion != distro.osversion:
                edited.append('%s' % distro.name)
                distro.activity.append(
                    DistroActivity(user=identity.current.user,
                                   service=u'XMLRPC',
                                   field_name=u'osversion',
                                   action=u'Changed',
                                   old_value=unicode(distro.osversion),
                                   new_value=unicode(osversion)))
                distro.osversion = osversion
        return edited
예제 #17
0
def create_distro(name=None,
                  osmajor=u'DansAwesomeLinux6',
                  osminor=u'9',
                  arches=None,
                  tags=None,
                  harness_dir=True,
                  osmajor_installopts=None,
                  date_created=None):
    osmajor = OSMajor.lazy_create(osmajor=osmajor)
    osversion = OSVersion.lazy_create(osmajor=osmajor, osminor=osminor)
    if arches:
        # list arches may contains unicode name or instance
        # Comparing instance to attribute is prohibited in SQLAlchemy 1.1 and later
        osversion.arches = [
            Arch.by_name(arch.arch if isinstance(arch, Arch) else arch)
            for arch in arches
        ]
    if not name:
        name = unique_name(u'%s.%s-%%s' % (osmajor, osminor))
    distro = Distro.lazy_create(name=name, osversion=osversion)
    if date_created is not None:
        distro.date_created = date_created
    for tag in (tags or []):
        distro.add_tag(tag)
    # add distro wide install options, if any
    if osmajor_installopts:
        for arch in arches:
            io = OSMajorInstallOptions.lazy_create(
                osmajor_id=osmajor.id, arch_id=Arch.by_name(arch).id)
            io.ks_meta = osmajor_installopts.get('ks_meta', '')
            io.kernel_options = osmajor_installopts.get('kernel_options', '')
            io.kernel_options_post = osmajor_installopts.get(
                'kernel_options_post', '')

    log.debug('Created distro %r', distro)
    if harness_dir:
        harness_dir = os.path.join(turbogears.config.get('basepath.harness'),
                                   distro.osversion.osmajor.osmajor)
        if not os.path.exists(harness_dir):
            os.makedirs(harness_dir)
    return distro
예제 #18
0
파일: distro.py 프로젝트: ShaolongHu/beaker
    def edit_version(self, name, version):
        """
        Updates the version for all distros with the given name.

        :param name: name of distros to be updated, for example 
            'RHEL5.6-Server-20101110.0'
        :type name: string
        :param version: new version to be applied, for example 
            'RedHatEnterpriseLinuxServer5.6' or 'Fedora14'
        :type version: string
        """
        distros = Distro.query.filter(Distro.name.like(unicode(name)))
        edited = []

        os_major = version.split('.')[0]

        # Try and split OSMinor
        try:
            os_minor = version.split('.')[1]
        except IndexError:
            os_minor = '0'

        # Try and find OSMajor
        osmajor = OSMajor.lazy_create(osmajor=os_major)

        # Try and find OSVersion
        osversion = OSVersion.lazy_create(osmajor=osmajor, osminor=os_minor)

        # Check each Distro
        for distro in distros:
            if osversion != distro.osversion:
                edited.append('%s' % distro.name)
                distro.activity.append(DistroActivity(user=identity.current.user,
                        service=u'XMLRPC', field_name=u'osversion', action=u'Changed',
                        old_value=unicode(distro.osversion),
                        new_value=unicode(osversion)))
                distro.osversion = osversion
        return edited
예제 #19
0
    def _from_csv(cls,system,data,csv_type,log):
        """
        Import data from CSV file into System Objects
        """
        family = None
        update = None

        # Arch is required
        if 'arch' in data:
            try:
                arch = Arch.by_name(data['arch'])
            except ValueError:
                log.append("%s: Invalid arch %s" % (system.fqdn, data['arch']))
                return False
        else:
            log.append("%s: Error! Missing arch" % system.fqdn)
            return False

        # pull in update and family if present
        if 'family' in data:
            family = data['family']
            if family:
                try:
                    family = OSMajor.by_name(family)
                except InvalidRequestError:
                    log.append("%s: Error! Invalid family %s" % (system.fqdn,
                                                              data['family']))
                    return False
        if 'update' in data:
            update = data['update']
            if update:
                if not family:
                    log.append("%s: Error! You must specify Family along with Update" % system.fqdn)
                    return False
                try:
                    update = OSVersion.by_name(family, unicode(update))
                except InvalidRequestError:
                    log.append("%s: Error! Invalid update %s" % (system.fqdn,
                                                             data['update']))
                    return False

        #Import Update specific
        if update and family:
            if system.provisions.has_key(arch):
                system_arch = system.provisions[arch]
            else:
                system_arch = Provision(arch=arch)
                system.provisions[arch] = system_arch

            if system_arch.provision_families.has_key(family):
                system_provfam = system_arch.provision_families[family]
            else:
                system_provfam = ProvisionFamily(osmajor=family)
                system_arch.provision_families[family] = system_provfam

            if system_provfam.provision_family_updates.has_key(update):
                prov = system_provfam.provision_family_updates[update]
            else:
                prov = ProvisionFamilyUpdate(osversion=update)
                system_provfam.provision_family_updates[update] = prov
            installlog = '%s/%s' % (arch,update)
                       
        #Import Family specific
        if family and not update:
            if system.provisions.has_key(arch):
                system_arch = system.provisions[arch]
            else:
                system_arch = Provision(arch=arch)
                system.provisions[arch] = system_arch

            if system_arch.provision_families.has_key(family):
                prov = system_arch.provision_families[family]
            else:
                prov = ProvisionFamily(osmajor=family)
                system_arch.provision_families[family] = prov
            installlog = '%s/%s' % (arch,family)
                       
        #Import Arch specific
        if not family and not update:
            if system.provisions.has_key(arch):
                prov = system.provisions[arch]
            else:
                prov = Provision(arch=arch)
                system.provisions[arch] = prov
            installlog = '%s' % arch

        if 'ks_meta' in data and prov.ks_meta != data['ks_meta']:
            system.record_activity(user=identity.current.user, service=u'CSV',
                    action=u'Changed', field=u'InstallOption:ks_meta:%s' % installlog,
                    old=prov.ks_meta, new=data['ks_meta'])
            prov.ks_meta = data['ks_meta']
        if 'kernel_options' in data and prov.kernel_options != data['kernel_options']:
            system.record_activity(user=identity.current.user, service=u'CSV',
                    action=u'Changed', field=u'InstallOption:kernel_options:%s' % installlog,
                    old=prov.kernel_options, new=data['kernel_options'])
            prov.kernel_options = data['kernel_options']
        if 'kernel_options_post' in data and prov.kernel_options_post != data['kernel_options_post']:
            system.record_activity(user=identity.current.user, service=u'CSV',
                    action=u'Changed', field=u'InstallOption:kernel_options_post:%s' % installlog,
                    old=prov.kernel_options_post, new=data['kernel_options_post'])
            prov.kernel_options_post = data['kernel_options_post']

        return True
예제 #20
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
예제 #21
0
    def add_distro_tree(self, new_distro):
        lab_controller = identity.current.user.lab_controller

        # osmajor is required
        if 'osmajor' in new_distro:
            osmajor = OSMajor.lazy_create(osmajor=new_distro['osmajor'])
        else:
            return ''

        if 'osminor' in new_distro:
            osversion = OSVersion.lazy_create(osmajor=osmajor, osminor=new_distro['osminor'])
        else:
            return ''

        if 'arches' in new_distro:
            for arch_name in new_distro['arches']:
                try:
                   arch = Arch.by_name(arch_name)
                   if arch not in osversion.arches:
                       osversion.arches.append(arch)
                except NoResultFound:
                   pass

        distro = Distro.lazy_create(name=new_distro['name'], osversion=osversion)
        arch = Arch.lazy_create(arch=new_distro['arch'])
        variant = new_distro.get('variant')
        distro_tree = DistroTree.lazy_create(distro=distro,
                variant=variant, arch=arch)

        # Automatically tag the distro if tags exists
        if 'tags' in new_distro:
            for tag in new_distro['tags']:
                if tag not in distro.tags:
                    distro.tags.append(tag)

        if arch not in distro.osversion.arches:
            distro.osversion.arches.append(arch)
        distro_tree.date_created = datetime.utcfromtimestamp(float(new_distro['tree_build_time']))
        distro.date_created = datetime.utcfromtimestamp(float(new_distro['tree_build_time']))

        if 'repos' in new_distro:
            for repo in new_distro['repos']:
                dtr = distro_tree.repo_by_id(repo['repoid'])
                if dtr is None:
                    dtr = DistroTreeRepo(repo_id=repo['repoid'])
                    distro_tree.repos.append(dtr)
                dtr.repo_type = repo['type']
                dtr.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 NoResultFound:
                    continue # ignore
                dti = distro_tree.image_by_type(image_type, kernel_type)
                if dti is None:
                    dti = DistroTreeImage(image_type=image_type,
                                          kernel_type=kernel_type)
                    distro_tree.images.append(dti)
                dti.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
예제 #22
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
예제 #23
0
    def _from_csv(cls, system, data, csv_type, log):
        """
        Import data from CSV file into System Objects
        """
        family = None
        update = None

        # Arch is required
        if 'arch' in data:
            try:
                arch = Arch.by_name(data['arch'])
            except ValueError:
                log.append("%s: Invalid arch %s" % (system.fqdn, data['arch']))
                return False
        else:
            log.append("%s: Error! Missing arch" % system.fqdn)
            return False

        # pull in update and family if present
        if 'family' in data:
            family = data['family']
            if family:
                try:
                    family = OSMajor.by_name(family)
                except InvalidRequestError:
                    log.append("%s: Error! Invalid family %s" %
                               (system.fqdn, data['family']))
                    return False
        if 'update' in data:
            update = data['update']
            if update:
                if not family:
                    log.append(
                        "%s: Error! You must specify Family along with Update"
                        % system.fqdn)
                    return False
                try:
                    update = OSVersion.by_name(family, unicode(update))
                except InvalidRequestError:
                    log.append("%s: Error! Invalid update %s" %
                               (system.fqdn, data['update']))
                    return False

        #Import Update specific
        if update and family:
            if system.provisions.has_key(arch):
                system_arch = system.provisions[arch]
            else:
                system_arch = Provision(arch=arch)
                system.provisions[arch] = system_arch

            if system_arch.provision_families.has_key(family):
                system_provfam = system_arch.provision_families[family]
            else:
                system_provfam = ProvisionFamily(osmajor=family)
                system_arch.provision_families[family] = system_provfam

            if system_provfam.provision_family_updates.has_key(update):
                prov = system_provfam.provision_family_updates[update]
            else:
                prov = ProvisionFamilyUpdate(osversion=update)
                system_provfam.provision_family_updates[update] = prov
            installlog = '%s/%s' % (arch, update)

        #Import Family specific
        if family and not update:
            if system.provisions.has_key(arch):
                system_arch = system.provisions[arch]
            else:
                system_arch = Provision(arch=arch)
                system.provisions[arch] = system_arch

            if system_arch.provision_families.has_key(family):
                prov = system_arch.provision_families[family]
            else:
                prov = ProvisionFamily(osmajor=family)
                system_arch.provision_families[family] = prov
            installlog = '%s/%s' % (arch, family)

        #Import Arch specific
        if not family and not update:
            if system.provisions.has_key(arch):
                prov = system.provisions[arch]
            else:
                prov = Provision(arch=arch)
                system.provisions[arch] = prov
            installlog = '%s' % arch

        if 'ks_meta' in data and prov.ks_meta != data['ks_meta']:
            system.record_activity(user=identity.current.user,
                                   service=u'CSV',
                                   action=u'Changed',
                                   field=u'InstallOption:ks_meta:%s' %
                                   installlog,
                                   old=prov.ks_meta,
                                   new=data['ks_meta'])
            prov.ks_meta = data['ks_meta']
        if 'kernel_options' in data and prov.kernel_options != data[
                'kernel_options']:
            system.record_activity(user=identity.current.user,
                                   service=u'CSV',
                                   action=u'Changed',
                                   field=u'InstallOption:kernel_options:%s' %
                                   installlog,
                                   old=prov.kernel_options,
                                   new=data['kernel_options'])
            prov.kernel_options = data['kernel_options']
        if 'kernel_options_post' in data and prov.kernel_options_post != data[
                'kernel_options_post']:
            system.record_activity(
                user=identity.current.user,
                service=u'CSV',
                action=u'Changed',
                field=u'InstallOption:kernel_options_post:%s' % installlog,
                old=prov.kernel_options_post,
                new=data['kernel_options_post'])
            prov.kernel_options_post = data['kernel_options_post']

        return True