Exemple #1
0
 def obtainSystemConstants(cls):
     # expect qhost output is in the form:
     # HOSTNAME                ARCH         NCPU NSOC NCOR NTHR NLOAD  MEMTOT  MEMUSE  SWAPTO  SWAPUS
     # ----------------------------------------------------------------------------------------------
     # global                  -               -    -    -    -     -       -       -       -       -
     # compute-1-1             lx-amd64       72    2   36   72  0.49  188.8G   79.6G   92.7G   19.2G
     # compute-1-10            lx-amd64       72    2   36   72  0.22  188.8G   51.1G   92.7G    2.8G
     lines = call_command(["qhost"]).strip().split('\n')
     items = lines[0].strip().split()
     num_columns = len(items)
     cpu_index = None
     mem_index = None
     for i in range(num_columns):
         if items[i] == 'NCPU':
             cpu_index = i
         elif items[i] == 'MEMTOT':
             mem_index = i
     if cpu_index is None or mem_index is None:
         raise RuntimeError(
             'qhost command does not return NCPU or MEMTOT columns')
     maxCPU = 0
     maxMEM = MemoryString("0")
     for line in lines[2:]:
         items = line.strip().split()
         if len(items) < num_columns:
             raise RuntimeError(
                 'qhost output has a varying number of columns')
         if items[cpu_index] != '-' and int(items[cpu_index]) > maxCPU:
             maxCPU = int(items[cpu_index])
         if items[mem_index] != '-' and MemoryString(
                 items[mem_index]) > maxMEM:
             maxMEM = MemoryString(items[mem_index])
     if maxCPU is 0 or maxMEM is 0:
         raise RuntimeError('qhost returned null NCPU or MEMTOT info')
     return maxCPU, maxMEM
Exemple #2
0
 def obtainSystemConstants(cls):
     def byteStrip(s):
         return s.encode('utf-8').strip()
     lines = [_f for _f in map(byteStrip, subprocess.check_output(["qhost"]).decode('utf-8').split('\n')) if _f]
     line = lines[0]
     items = line.strip().split()
     num_columns = len(items)
     cpu_index = None
     mem_index = None
     for i in range(num_columns):
         if items[i] == 'NCPU':
             cpu_index = i
         elif items[i] == 'MEMTOT':
             mem_index = i
     if cpu_index is None or mem_index is None:
         RuntimeError('qhost command does not return NCPU or MEMTOT columns')
     maxCPU = 0
     maxMEM = MemoryString("0")
     for line in lines[2:]:
         items = line.strip().split()
         if len(items) < num_columns:
             RuntimeError('qhost output has a varying number of columns')
         if items[cpu_index] != '-' and items[cpu_index] > maxCPU:
             maxCPU = items[cpu_index]
         if items[mem_index] != '-' and MemoryString(items[mem_index]) > maxMEM:
             maxMEM = MemoryString(items[mem_index])
     if maxCPU is 0 or maxMEM is 0:
         RuntimeError('qhost returned null NCPU or MEMTOT info')
     return maxCPU, maxMEM
Exemple #3
0
    def obtainSystemConstants(self):
        p = subprocess.Popen(["lshosts"], stdout = subprocess.PIPE, stderr = subprocess.STDOUT)

        line = p.stdout.readline()
        items = line.strip().split()
        num_columns = len(items)
        cpu_index = None
        mem_index = None
        for i in range(num_columns):
                if items[i] == 'ncpus':
                        cpu_index = i
                elif items[i] == 'maxmem':
                        mem_index = i

        if cpu_index is None or mem_index is None:
                RuntimeError("lshosts command does not return ncpus or maxmem columns")

        p.stdout.readline()

        self.maxCPU = 0
        self.maxMEM = MemoryString("0")
        for line in p.stdout:
                items = line.strip().split()
                if len(items) < num_columns:
                        RuntimeError("lshosts output has a varying number of columns")
                if items[cpu_index] != '-' and items[cpu_index] > self.maxCPU:
                        self.maxCPU = items[cpu_index]
                if items[mem_index] != '-' and MemoryString(items[mem_index]) > self.maxMEM:
                        self.maxMEM = MemoryString(items[mem_index])

        if self.maxCPU is 0 or self.maxMEM is 0:
                RuntimeError("lshosts returns null ncpus or maxmem info")
        logger.debug("Got the maxCPU: %s" % (self.maxMEM))
Exemple #4
0
    def obtainSystemConstants(cls):

        maxCPU = 0
        maxMEM = MemoryString("0K")

        # parse XML output from pbsnodes
        root = ET.fromstring(subprocess.check_output(["pbsnodes", "-x"]))

        # for each node, grab status line
        for node in root.findall('./Node/status'):
            # then split up the status line by comma and iterate
            status = {}
            for state in node.text.split(","):
                statusType, statusState = state.split("=")
                status[statusType] = statusState
            if status['ncpus'] is None or status['totmem'] is None:
                RuntimeError(
                    "pbsnodes command does not return ncpus or totmem columns")
            if status['ncpus'] > maxCPU:
                maxCPU = status['ncpus']
            if MemoryString(status['totmem']) > maxMEM:
                maxMEM = MemoryString(status['totmem'])

        if maxCPU is 0 or maxMEM is MemoryString("0K"):
            RuntimeError('pbsnodes returned null ncpus or totmem info')
        else:
            logger.info("Got maxCPU: %s and maxMEM: %s" % (
                maxCPU,
                maxMEM,
            ))

        return maxCPU, maxMEM
Exemple #5
0
    def obtainSystemConstants(cls):
        p = subprocess.Popen(["lshosts"],
                             stdout=subprocess.PIPE,
                             stderr=subprocess.STDOUT)

        line = p.stdout.readline().decode('utf-8')
        items = line.strip().split()
        num_columns = len(items)
        cpu_index = None
        mem_index = None
        for i in range(num_columns):
            if items[i] == 'ncpus':
                cpu_index = i
            elif items[i] == 'maxmem':
                mem_index = i

        if cpu_index is None or mem_index is None:
            RuntimeError("lshosts command does not return ncpus or maxmem "
                         "columns")

        # p.stdout.readline().decode('utf-8')

        maxCPU = 0
        maxMEM = MemoryString("0")
        for line in p.stdout:
            split_items = line.strip().split()
            items = [
                item.decode('utf-8') for item in split_items
                if isinstance(item, bytes)
            ]
            if len(items) < num_columns:
                RuntimeError("lshosts output has a varying number of "
                             "columns")
            if items[cpu_index] != '-' and int(items[cpu_index]) > int(maxCPU):
                maxCPU = items[cpu_index]
            if (items[mem_index] != '-'
                    and MemoryString(items[mem_index]) > maxMEM):
                maxMEM = MemoryString(items[mem_index])

        if maxCPU is 0 or maxMEM is 0:
            RuntimeError("lshosts returns null ncpus or maxmem info")
        logger.debug("Got the maxMEM: {}".format(maxMEM))
        logger.debug("Got the maxCPU: {}".format(maxCPU))

        return maxCPU, maxMEM
Exemple #6
0
 def obtainSystemConstants(cls):
     # sinfo -Ne --format '%m,%c'
     # sinfo arguments:
     # -N for node-oriented
     # -h for no header
     # -e for exact values (e.g. don't return 32+)
     # --format to get memory, cpu
     max_cpu = 0
     max_mem = MemoryString('0')
     lines = subprocess.check_output(['sinfo', '-Nhe', '--format', '%m %c']).split('\n')
     for line in lines:
         values = line.split()
         if len(values) < 2:
             continue
         mem, cpu = values
         max_cpu = max(max_cpu, int(cpu))
         max_mem = max(max_mem, MemoryString(mem + 'M'))
     if max_cpu == 0 or max_mem.byteVal() == 0:
         RuntimeError('sinfo did not return memory or cpu info')
     return max_cpu, max_mem
Exemple #7
0
 def obtainSystemConstants():
     # sinfo -Ne --format '%m,%c'
     # sinfo arguments:
     # -N for node-oriented
     # -h for no header
     # -e for exact values (e.g. don't return 32+)
     # --format to get memory, cpu
     max_cpu = 0
     max_mem = MemoryString('0')
     lines = subprocess.check_output(['sinfo', '-Nhe', '--format', '%m %c']).split('\n')
     for line in lines:
         values = line.split()
         if len(values) < 2:
             continue
         mem, cpu = values
         max_cpu = max(max_cpu, int(cpu))
         max_mem = max(max_mem, MemoryString(mem + 'M'))
     if max_cpu == 0 or max_mem.byteVal() == 0:
         RuntimeError('sinfo did not return memory or cpu info')
     return max_cpu, max_mem
Exemple #8
0
    def obtainSystemConstants(cls):
        stdout = call_command(["lshosts"])
        line = stdout.split('\n')[0]
        items = line.strip().split()
        num_columns = len(items)
        cpu_index = None
        mem_index = None
        for i in range(num_columns):
            if items[i] == 'ncpus':
                cpu_index = i
            elif items[i] == 'maxmem':
                mem_index = i

        if cpu_index is None or mem_index is None:
            raise RuntimeError(
                "lshosts command does not return ncpus or maxmem columns")

        maxCPU = 0
        maxMEM = MemoryString("0")
        for line in stdout.split('\n')[1:]:
            items = line.strip().split()
            if items:
                if len(items) < num_columns:
                    raise RuntimeError(
                        "lshosts output has a varying number of columns")
                if items[cpu_index] != '-' and int(
                        items[cpu_index]) > int(maxCPU):
                    maxCPU = int(items[cpu_index])
                if items[mem_index] != '-' and MemoryString(
                        items[mem_index]) > maxMEM:
                    maxMEM = MemoryString(items[mem_index])

        if maxCPU == 0 or maxMEM == MemoryString("0"):
            raise RuntimeError("lshosts returns null ncpus or maxmem info")

        logger.debug("Got the maxMEM: {}".format(maxMEM))
        logger.debug("Got the maxCPU: {}".format(maxCPU))

        return maxCPU, maxMEM