Serialize a command and up a JSON command and send it with send_command() above. Prefix may be supplied separately or in argdict. Any bulk input data comes in inbuf. If target is osd.N, send command to that osd (except for pgid cmds) :param cluster: ``rados.Rados`` instance
(cluster,
target: Tuple[str, Optional[str]] = ('mon', ''),
prefix: Optional[str] = None,
argdict: Optional[ValidatedArgs] = None,
inbuf: Optional[bytes] = b'',
timeout: Optional[int] = 0,
verbose: Optional[bool] = False)
| 1671 | |
| 1672 | |
| 1673 | def json_command(cluster, |
| 1674 | target: Tuple[str, Optional[str]] = ('mon', ''), |
| 1675 | prefix: Optional[str] = None, |
| 1676 | argdict: Optional[ValidatedArgs] = None, |
| 1677 | inbuf: Optional[bytes] = b'', |
| 1678 | timeout: Optional[int] = 0, |
| 1679 | verbose: Optional[bool] = False) -> Tuple[int, bytes, str]: |
| 1680 | """ |
| 1681 | Serialize a command and up a JSON command and send it with send_command() above. |
| 1682 | Prefix may be supplied separately or in argdict. Any bulk input |
| 1683 | data comes in inbuf. |
| 1684 | |
| 1685 | If target is osd.N, send command to that osd (except for pgid cmds) |
| 1686 | |
| 1687 | :param cluster: ``rados.Rados`` instance |
| 1688 | :param prefix: String to inject into command arguments as 'prefix' |
| 1689 | :param argdict: Command arguments |
| 1690 | """ |
| 1691 | cmddict: ValidatedArgs = {} |
| 1692 | if prefix: |
| 1693 | cmddict.update({'prefix': prefix}) |
| 1694 | |
| 1695 | if argdict: |
| 1696 | cmddict.update(argdict) |
| 1697 | if 'target' in argdict: |
| 1698 | target = cast(Tuple[str, str], argdict['target']) |
| 1699 | |
| 1700 | try: |
| 1701 | if target[0] == 'osd': |
| 1702 | osdtarg = CephName() |
| 1703 | osdtarget = '{0}.{1}'.format(*target) |
| 1704 | # prefer target from cmddict if present and valid |
| 1705 | if 'target' in cmddict: |
| 1706 | osdtarget = cast(str, cmddict.pop('target')) |
| 1707 | try: |
| 1708 | osdtarg.valid(osdtarget) |
| 1709 | target = ('osd', osdtarg.nameid) |
| 1710 | except: |
| 1711 | # use the target we were originally given |
| 1712 | pass |
| 1713 | ret, outbuf, outs = send_command_retry(cluster, |
| 1714 | target, json.dumps(cmddict), |
| 1715 | inbuf, timeout, verbose) |
| 1716 | |
| 1717 | except Exception as e: |
| 1718 | if not isinstance(e, ArgumentError): |
| 1719 | raise RuntimeError('"{0}": exception {1}'.format(argdict, e)) |
| 1720 | else: |
| 1721 | raise |
| 1722 | |
| 1723 | return ret, outbuf, outs |
no test coverage detected