Using a minimal validation, figure out whether the command should be sent to a monitor or an osd. We do this before even asking for the 'real' set of command signatures, so we can ask the right daemon. Returns ('osd', osdid), ('pg', pgid), ('mgr', '') or ('mon', '')
(childargs: List[str])
| 1433 | |
| 1434 | |
| 1435 | def find_cmd_target(childargs: List[str]) -> Tuple[str, Optional[str]]: |
| 1436 | """ |
| 1437 | Using a minimal validation, figure out whether the command |
| 1438 | should be sent to a monitor or an osd. We do this before even |
| 1439 | asking for the 'real' set of command signatures, so we can ask the |
| 1440 | right daemon. |
| 1441 | Returns ('osd', osdid), ('pg', pgid), ('mgr', '') or ('mon', '') |
| 1442 | """ |
| 1443 | sig = parse_funcsig(['tell', {'name': 'target', 'type': 'CephName'}]) |
| 1444 | try: |
| 1445 | valid_dict = validate(childargs, sig, partial=True) |
| 1446 | except ArgumentError: |
| 1447 | pass |
| 1448 | else: |
| 1449 | if len(valid_dict) == 2: |
| 1450 | # revalidate to isolate type and id |
| 1451 | name = CephName() |
| 1452 | # if this fails, something is horribly wrong, as it just |
| 1453 | # validated successfully above |
| 1454 | name.valid(valid_dict['target']) |
| 1455 | assert name.nametype is not None |
| 1456 | return name.nametype, name.nameid |
| 1457 | |
| 1458 | sig = parse_funcsig(['tell', {'name': 'pgid', 'type': 'CephPgid'}]) |
| 1459 | try: |
| 1460 | valid_dict = validate(childargs, sig, partial=True) |
| 1461 | except ArgumentError: |
| 1462 | pass |
| 1463 | else: |
| 1464 | if len(valid_dict) == 2: |
| 1465 | # pg doesn't need revalidation; the string is fine |
| 1466 | pgid = valid_dict['pgid'] |
| 1467 | assert isinstance(pgid, str) |
| 1468 | return 'pg', pgid |
| 1469 | |
| 1470 | # If we reached this far it must mean that so far we've been unable to |
| 1471 | # obtain a proper target from childargs. This may mean that we are not |
| 1472 | # dealing with a 'tell' command, or that the specified target is invalid. |
| 1473 | # If the latter, we likely were unable to catch it because we were not |
| 1474 | # really looking for it: first we tried to parse a 'CephName' (osd, mon, |
| 1475 | # mds, followed by and id); given our failure to parse, we tried to parse |
| 1476 | # a 'CephPgid' instead (e.g., 0.4a). Considering we got this far though |
| 1477 | # we were unable to do so. |
| 1478 | # |
| 1479 | # We will now check if this is a tell and, if so, forcefully validate the |
| 1480 | # target as a 'CephName'. This must be so because otherwise we will end |
| 1481 | # up sending garbage to a monitor, which is the default target when a |
| 1482 | # target is not explicitly specified. |
| 1483 | # e.g., |
| 1484 | # 'ceph status' -> target is any one monitor |
| 1485 | # 'ceph tell mon.* status -> target is all monitors |
| 1486 | # 'ceph tell foo status -> target is invalid! |
| 1487 | if len(childargs) > 1 and childargs[0] == 'tell': |
| 1488 | name = CephName() |
| 1489 | # CephName.valid() raises on validation error; find_cmd_target()'s |
| 1490 | # caller should handle them |
| 1491 | name.valid(childargs[1]) |
| 1492 | assert name.nametype is not None |
nothing calls this directly
no test coverage detected