functions: added autodetection of format to cpulist_unpack
Now CPUs starting with 0x are taken as hexmask. As cpulist_unpack
is used as preprocessor of CPU list for other built-in functions
this also works with other functions (e.g. cpulist_invert).
Example:
[variables]
cpus = ${f:cpulist_invert:1-2,0x8}
On four CPU machines (CPUs 0-3) it expands to '0'.
Signed-off-by: Jaroslav Škarvada <jskarvad@redhat.com>
This commit is contained in:
parent
957922d3d7
commit
dfdbd88e67
2 changed files with 12 additions and 9 deletions
|
|
@ -16,4 +16,4 @@ class hex2cpulist(base.Function):
|
|||
def execute(self, args):
|
||||
if not super(self.__class__, self).execute(args):
|
||||
return None
|
||||
return ",".join(self._cmd.hex2cpulist(args[0]))
|
||||
return ",".join(str(v) for v in self._cmd.hex2cpulist(args[0]))
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@ class commands:
|
|||
return []
|
||||
while m > 0:
|
||||
if m & 1:
|
||||
cpus.append(str(cpu))
|
||||
cpus.append(cpu)
|
||||
m >>= 1
|
||||
cpu += 1
|
||||
return cpus
|
||||
|
|
@ -143,13 +143,16 @@ class commands:
|
|||
ll = str(l).split(",")
|
||||
for v in ll:
|
||||
vl = v.split("-")
|
||||
try:
|
||||
if len(vl) > 1:
|
||||
rl += range(int(vl[0]), int(vl[1]) + 1)
|
||||
else:
|
||||
rl.append(int(vl[0]))
|
||||
except ValueError:
|
||||
return None
|
||||
if v[0:2].lower() == "0x":
|
||||
rl += self.hex2cpulist(v)
|
||||
else:
|
||||
try:
|
||||
if len(vl) > 1:
|
||||
rl += range(int(vl[0]), int(vl[1]) + 1)
|
||||
else:
|
||||
rl.append(int(vl[0]))
|
||||
except ValueError:
|
||||
return []
|
||||
return sorted(list(set(rl)))
|
||||
|
||||
# Converts CPU list to hexadecimal CPU mask
|
||||
|
|
|
|||
Loading…
Reference in a new issue