Revision 31155d60 lib/utils.py
b/lib/utils.py | ||
---|---|---|
1299 | 1299 |
return value |
1300 | 1300 |
|
1301 | 1301 |
|
1302 |
def ParseCpuMask(cpu_mask): |
|
1303 |
"""Parse a CPU mask definition and return the list of CPU IDs. |
|
1304 |
|
|
1305 |
CPU mask format: comma-separated list of CPU IDs |
|
1306 |
or dash-separated ID ranges |
|
1307 |
Example: "0-2,5" -> "0,1,2,5" |
|
1308 |
|
|
1309 |
@type cpu_mask: str |
|
1310 |
@param cpu_mask: CPU mask definition |
|
1311 |
@rtype: list of int |
|
1312 |
@return: list of CPU IDs |
|
1313 |
|
|
1314 |
""" |
|
1315 |
if not cpu_mask: |
|
1316 |
return [] |
|
1317 |
cpu_list = [] |
|
1318 |
for range_def in cpu_mask.split(","): |
|
1319 |
boundaries = range_def.split("-") |
|
1320 |
n_elements = len(boundaries) |
|
1321 |
if n_elements > 2: |
|
1322 |
raise errors.ParseError("Invalid CPU ID range definition" |
|
1323 |
" (only one hyphen allowed): %s" % range_def) |
|
1324 |
try: |
|
1325 |
lower = int(boundaries[0]) |
|
1326 |
except (ValueError, TypeError), err: |
|
1327 |
raise errors.ParseError("Invalid CPU ID value for lower boundary of" |
|
1328 |
" CPU ID range: %s" % str(err)) |
|
1329 |
try: |
|
1330 |
higher = int(boundaries[-1]) |
|
1331 |
except (ValueError, TypeError), err: |
|
1332 |
raise errors.ParseError("Invalid CPU ID value for higher boundary of" |
|
1333 |
" CPU ID range: %s" % str(err)) |
|
1334 |
if lower > higher: |
|
1335 |
raise errors.ParseError("Invalid CPU ID range definition" |
|
1336 |
" (%d > %d): %s" % (lower, higher, range_def)) |
|
1337 |
cpu_list.extend(range(lower, higher + 1)) |
|
1338 |
return cpu_list |
|
1339 |
|
|
1340 |
|
|
1302 | 1341 |
def AddAuthorizedKey(file_name, key): |
1303 | 1342 |
"""Adds an SSH public key to an authorized_keys file. |
1304 | 1343 |
|
Also available in: Unified diff