| 1558 | } |
| 1559 | |
| 1560 | bool DaemonServer::_handle_command( |
| 1561 | std::shared_ptr<CommandContext>& cmdctx) |
| 1562 | { |
| 1563 | MessageRef m; |
| 1564 | bool admin_socket_cmd = false; |
| 1565 | if (cmdctx->m_tell) { |
| 1566 | m = cmdctx->m_tell; |
| 1567 | // a blank fsid in MCommand signals a legacy client sending a "mon-mgr" CLI |
| 1568 | // command. |
| 1569 | admin_socket_cmd = (cmdctx->m_tell->fsid != uuid_d()); |
| 1570 | } else { |
| 1571 | m = cmdctx->m_mgr; |
| 1572 | } |
| 1573 | auto priv = m->get_connection()->get_priv(); |
| 1574 | auto session = static_cast<MgrSession*>(priv.get()); |
| 1575 | if (!session) { |
| 1576 | return true; |
| 1577 | } |
| 1578 | if (session->inst.name == entity_name_t()) { |
| 1579 | session->inst.name = m->get_source(); |
| 1580 | } |
| 1581 | |
| 1582 | std::map<string,string> param_str_map; |
| 1583 | std::stringstream ss; |
| 1584 | int r = 0; |
| 1585 | |
| 1586 | if (!cmdmap_from_json(cmdctx->cmd, &(cmdctx->cmdmap), ss)) { |
| 1587 | cmdctx->reply(-EINVAL, ss); |
| 1588 | return true; |
| 1589 | } |
| 1590 | |
| 1591 | string prefix; |
| 1592 | cmd_getval(cmdctx->cmdmap, "prefix", prefix); |
| 1593 | dout(10) << "decoded-size=" << cmdctx->cmdmap.size() << " prefix=" << prefix << dendl; |
| 1594 | |
| 1595 | boost::scoped_ptr<Formatter> f; |
| 1596 | { |
| 1597 | std::string format; |
| 1598 | if (boost::algorithm::ends_with(prefix, "_json")) { |
| 1599 | format = "json"; |
| 1600 | } else { |
| 1601 | format = cmd_getval_or<string>(cmdctx->cmdmap, "format", "plain"); |
| 1602 | } |
| 1603 | f.reset(Formatter::create(format)); |
| 1604 | } |
| 1605 | |
| 1606 | // this is just for mgr commands - admin socket commands will fall |
| 1607 | // through and use the admin socket version of |
| 1608 | // get_command_descriptions |
| 1609 | if (prefix == "get_command_descriptions" && !admin_socket_cmd) { |
| 1610 | dout(10) << "reading commands from python modules" << dendl; |
| 1611 | const auto py_commands = py_modules.get_commands(); |
| 1612 | |
| 1613 | int cmdnum = 0; |
| 1614 | JSONFormatter f; |
| 1615 | f.open_object_section("command_descriptions"); |
| 1616 | |
| 1617 | auto dump_cmd = [&cmdnum, &f, m](const MonCommand &mc){ |
nothing calls this directly
no test coverage detected