예제 #1
0
 def testWellFormed(self):
     self.assertEqual(utils.ParseMultiCpuMask(""), [])
     self.assertEqual(utils.ParseMultiCpuMask("1"), [[1]])
     self.assertEqual(utils.ParseMultiCpuMask("0-2,4,5-5"),
                      [[0, 1, 2, 4, 5]])
     self.assertEqual(utils.ParseMultiCpuMask("all"), [[-1]])
     self.assertEqual(utils.ParseMultiCpuMask("0-2:all:4,6-8"),
                      [[0, 1, 2], [-1], [4, 6, 7, 8]])
예제 #2
0
파일: hv_xen.py 프로젝트: badp/ganeti
def _CreateConfigCpus(cpu_mask):
  """Create a CPU config string for Xen's config file.

  """
  # Convert the string CPU mask to a list of list of int's
  cpu_list = utils.ParseMultiCpuMask(cpu_mask)

  if len(cpu_list) == 1:
    all_cpu_mapping = cpu_list[0]
    if all_cpu_mapping == constants.CPU_PINNING_OFF:
      # If CPU pinning has 1 entry that's "all", then remove the
      # parameter from the config file
      return None
    else:
      # If CPU pinning has one non-all entry, mapping all vCPUS (the entire
      # VM) to one physical CPU, using format 'cpu = "C"'
      return "cpu = \"%s\"" % ",".join(map(str, all_cpu_mapping))
  else:

    def _GetCPUMap(vcpu):
      if vcpu[0] == constants.CPU_PINNING_ALL_VAL:
        cpu_map = constants.CPU_PINNING_ALL_XEN
      else:
        cpu_map = ",".join(map(str, vcpu))
      return "\"%s\"" % cpu_map

    # build the result string in format 'cpus = [ "c", "c", "c" ]',
    # where each c is a physical CPU number, a range, a list, or any
    # combination
    return "cpus = [ %s ]" % ", ".join(map(_GetCPUMap, cpu_list))
예제 #3
0
def _IsMultiCpuMaskWellFormed(cpu_mask):
  """Verifies if the given multiple CPU mask is valid

  A valid multiple CPU mask is in the form "a:b:c:d", where each
  letter is a single CPU mask.

  """
  try:
    utils.ParseMultiCpuMask(cpu_mask)
  except errors.ParseError, _:
    return False