Exemplo n.º 1
0
 def get(self):
     for cdrom in ifilter(lambda x:x.startswith('/sys/block/sr'),
                  listDirectory('/sys/block',fullPath=True)):
         if getUdevDeviceInfo(path=cdrom).get('ID_CDROM','') == "1":
             return "on"
     else:
         return "off"
Exemplo n.º 2
0
 def set(self,value):
     """
     If device in calculate3.env dev_from not exists set ''
     """
     if value:
         value = getUdevDeviceInfo(name=value).get('DEVNAME',value)
     if value in self.Get('os_disk_dev'):
         return value
     else:
         return ""
Exemplo n.º 3
0
 def get(self):
     """Root filesystem device"""
     record = readFile('/proc/cmdline').strip()
     re_resRealRoot=re.search('(?:^|\s)real_root=(\S+)(\s|$)',record)
     re_resFakeRoot=re.search('(?:^|\s)root=(\S+)(\s|$)',record)
     # param real_root priority that root
     re_res = re_resRealRoot or re_resFakeRoot
     if re_res:
         rootparam=re_res.group(1)
         # check root for /dev/sd view
         if re.match("^\/dev\/[a-z]+.*$", rootparam):
             return getUdevDeviceInfo(
                name=rootparam.strip()).get('DEVNAME',rootparam)
         # check root set by uuid
         if re.match("^UUID=.*$",rootparam):
             uuid = rootparam[5:].strip("\"'")
             blkidProcess = process('/sbin/blkid','-c','/dev/null','-U',
                                 uuid)
             if blkidProcess.success():
                 return getUdevDeviceInfo(
                    name=blkidProcess.read().strip()).get('DEVNAME','')
         # check root set by label
         if re.match("^LABEL=.*$",rootparam):
             uuid = rootparam[6:].strip("\"'")
             blkidProcess = process('/sbin/blkid','-c','/dev/null','-L',
                                 uuid)
             if blkidProcess.success():
                 return getUdevDeviceInfo(
                    name=blkidProcess.read().strip()).get('DEVNAME','')
     # get device mounted to root
     dfProcess = process('df','/',envdict={'LANG':'C'})
     if dfProcess.failed():
         return ""
     dfLines = dfProcess.readlines()
     if len(dfLines)>1:
         root_dev = dfLines[1].split(" ")[0].strip()
         if root_dev:
             return {'none':'/dev/ram0'}.get(root_dev,root_dev)
     return ""
Exemplo n.º 4
0
    def setupSystem(self,variables):
        self.initVars(variables)
        target = None
        setupType = self.clVars.Get('cl_setup',humanreadable=True)

        if setupType:
            self.startTask((_("%s are being configured")%
                           setupType).capitalize(),progress=True)
        else:
            self.startTask(_("System configuration"),progress=True)
        refreshLVM()
        res = self.applyTemplatesStartup()
        self.endTask()
        if setupType and self.clVars.Get('cl_setup') == 'network':
            pass
        if not setupType or self.clVars.Get('cl_setup') == 'video':
            self.setupVideo()
        if setupType and self.clVars.Get('cl_setup') == 'users':
            pass
        if self.clVars.Get('cl_setup') == 'boot' and \
            self.clVars.Get('os_root_type') != 'livecd':
            target = self.clVars.Get('cl_image')
            if self.clVars.Get('os_install_mbr'):
                self.startTask(_("Installing the bootloader"))
                self.prepareBoot(target)
                self.endTask()
            root_dev = self.clVars.Select('os_disk_parent',
                                   where='os_disk_mount',
                                   eq='/',limit=1)
            if root_dev:
                self.startTask(_("Changing the I/O scheduler"))
                try:
                    schedpath = ("/sys%s/queue/scheduler"%
                      (getUdevDeviceInfo(name=root_dev).get('DEVPATH','')))
                    if path.exists(schedpath):
                        open(schedpath,'w').write(
                            self.clVars.Get('os_install_kernel_scheduler'))
                    self.endTask()
                except:
                    self.printERROR(_("Unable to change the I/O scheduler"))
                    pass
        return True
Exemplo n.º 5
0
    def setActivePartition(self,partition):
        """Change partition id, specified by systemid,set active"""
        deviceName = detectDeviceForPartition(partition)
        if deviceName is None:
            raise DistributiveError(
                _("Failed to determine the parent device for %s")%partition)
        # device hasn't any partition
        elif deviceName == "":
            return True
        fdiskProg, gdiskProg, partedProg = checkUtils('/sbin/fdisk',
                    '/usr/sbin/gdisk','/usr/sbin/parted')

        disk = self.clVars.Select('os_install_disk_parent',
                                  where='os_install_disk_dev',eq=partition,
                                  limit=1)
        parttable = self.clVars.Select('os_device_table',where='os_device_dev',
                                  eq=disk,limit=1)
        partitionNumber = \
            getUdevDeviceInfo(name=partition).get('ID_PART_ENTRY_NUMBER','') or \
            getUdevDeviceInfo(name=partition).get('UDISKS_PARTITION_NUMBER','')

        devicePartitionCount = countPartitions(deviceName)
        if deviceName and not partitionNumber:
            raise DistributiveError(
                _("Failed to determine the partition number for %s")%partition)
        bootFlag = "boot" if parttable == "dos" else "legacy_boot"
        if parttable == "dos":
            fdisk = process(fdiskProg, "-l",deviceName)
            DEVICENUM,AFLAG = 0,1
            changeActive = \
                map(lambda x:x[DEVICENUM],
                filter(lambda x:x[DEVICENUM] != partitionNumber and \
                                x[AFLAG] == "*" or \
                                x[DEVICENUM] == partitionNumber and \
                                not x[AFLAG] == "*",
                list(map(lambda x:[str(x[0]),x[1][1].strip()],
                # enumerate partitions
                enumerate(filter(None,
                map(lambda x:x.split()[:2],
                # drop string before information about partitions
                dropwhile(lambda x:not x.lstrip().startswith("Device"),
                fdisk.readlines()))))))[1:]))
        else:
            parted = process(partedProg, "-m",deviceName,"print")
            DEVICENUM,FLAGS = 0,6
            changeActive = \
                map(lambda x:x[DEVICENUM],
                filter(lambda x:x[DEVICENUM] != partitionNumber and \
                                bootFlag in x[FLAGS].strip(';').split(', ') or \
                                x[DEVICENUM] == partitionNumber and \
                                not bootFlag in x[FLAGS].strip(';').split(', '),
                filter(lambda x:len(x)>=7,
                map(lambda x:x.split(':'),
                parted.readlines()[2:]))))
        if not changeActive:
            return True
        if parttable == "dos":
            pipe = Popen([fdiskProg,deviceName],
                stdin=PIPE, stdout=PIPE,stderr=PIPE)
            for partnum in changeActive:
                pipe.stdin.write("a\n%s\n"%partnum)
            pipe.stdin.write("w\n")
            pipe.stdin.close()
            pipe.wait()
        elif parttable == "gpt":
            pipe = Popen([gdiskProg,deviceName],
                stdin=PIPE, stdout=PIPE,stderr=PIPE)
            if devicePartitionCount > 1:
                pipe.stdin.write("x\n")
                for partnum in changeActive:
                    pipe.stdin.write("a\n%s\n2\n\n"%partnum)
                pipe.stdin.write("w\nY\n")
            else:
                pipe.stdin.write("x\na\n2\n\nw\nY\n")
            pipe.stdin.close()
            pipe.wait()
        for waittime in (0.1,0.2,0.5,1,2,4):
            if path.exists(partition):
                return True
            else:
                sleep(waittime)
        raise InstallError(
            _("Failed to find partition %s after changing the activity")%
                partition)