MCPcopy Create free account
hub / github.com/ceph/ceph / parse_json_funcsigs

Function parse_json_funcsigs

src/pybind/ceph_argparse.py:970–1020  ·  view source on GitHub ↗

A function signature is mostly an array of argdesc; it's represented in JSON as { "cmd001": {"sig":[ "type": type, "name": name, "n": num, "req":true|false ], "help":helptext, "module":modulename, "perm":perms, "avail":availability} . . . ]

(s: str,
                        consumer: str)

Source from the content-addressed store, hash-verified

968
969
970def parse_json_funcsigs(s: str,
971 consumer: str) -> Dict[str, Dict[str, List[argdesc]]]:
972 """
973 A function signature is mostly an array of argdesc; it's represented
974 in JSON as
975 {
976 "cmd001": {"sig":[ "type": type, "name": name, "n": num, "req":true|false <other param>], "help":helptext, "module":modulename, "perm":perms, "avail":availability}
977 .
978 .
979 .
980 ]
981
982 A set of sigs is in an dict mapped by a unique number:
983 {
984 "cmd1": {
985 "sig": ["type.. ], "help":helptext...
986 }
987 "cmd2"{
988 "sig": [.. ], "help":helptext...
989 }
990 }
991
992 Parse the string s and return a dict of dicts, keyed by opcode;
993 each dict contains 'sig' with the array of descriptors, and 'help'
994 with the helptext, 'module' with the module name, 'perm' with a
995 string representing required permissions in that module to execute
996 this command (and also whether it is a read or write command from
997 the cluster state perspective), and 'avail' as a hint for
998 whether the command should be advertised by CLI, REST, or both.
999 If avail does not contain 'consumer', don&#x27;t include the command
1000 in the returned dict.
1001 """
1002 try:
1003 overall = json.loads(s)
1004 except Exception as e:
1005 print("Couldn't parse JSON {0}: {1}".format(s, e), file=sys.stderr)
1006 raise e
1007 sigdict = {}
1008 for cmdtag, cmd in overall.items():
1009 if 'sig' not in cmd:
1010 s = "JSON descriptor {0} has no 'sig'".format(cmdtag)
1011 raise JsonFormat(s)
1012 # check 'avail' and possibly ignore this command
1013 if 'avail' in cmd:
1014 if consumer not in cmd['avail']:
1015 continue
1016 # rewrite the 'sig' item with the argdesc-ized version, and...
1017 cmd['sig'] = parse_funcsig(cmd['sig'])
1018 # just take everything else as given
1019 sigdict[cmdtag] = cmd
1020 return sigdict
1021
1022
1023ArgValT = Union[bool, int, float, str, Tuple[str, str]]

Callers 3

admin_socketFunction · 0.90

Calls 5

printFunction · 0.85
JsonFormatClass · 0.85
parse_funcsigFunction · 0.85
formatMethod · 0.45
itemsMethod · 0.45

Tested by 1