]>
Commit | Line | Data |
---|---|---|
31f18b77 FG |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | /* | |
4 | * Ceph - scalable distributed file system | |
5 | * | |
6 | * Copyright (C) 2017 Red Hat | |
7 | * | |
8 | * This is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU Lesser General Public | |
10 | * License version 2.1, as published by the Free Software | |
11 | * Foundation. See file COPYING. | |
12 | * | |
13 | */ | |
14 | ||
15 | #ifndef CEPH_ADMIN_SOCKET_OUTPUT_H | |
16 | #define CEPH_ADMIN_SOCKET_OUTPUT_H | |
17 | ||
18 | #include <string> | |
19 | #include <map> | |
20 | #include <set> | |
21 | #include <vector> | |
22 | ||
23 | #include <boost/filesystem/path.hpp> // For path | |
24 | #include <boost/filesystem/operations.hpp> // For exists, is_directory | |
25 | ||
26 | namespace bfs = boost::filesystem; | |
27 | ||
28 | using socket_results = std::map<std::string, std::string>; | |
29 | using test_functions = | |
30 | std::vector<std::pair<std::string, bool (*)(std::string &)>>; | |
31 | ||
32 | class AdminSocketClient; | |
33 | ||
34 | class AdminSocketOutput { | |
35 | public: | |
36 | AdminSocketOutput() {} | |
37 | ||
38 | void add_target(const std::string &target); | |
39 | void add_command(const std::string &target, const std::string &command); | |
40 | void add_test(const std::string &target, const std::string &command, | |
41 | bool (*test)(std::string &)); | |
42 | void postpone(const std::string &target, const std::string &command); | |
43 | ||
44 | void exec(); | |
45 | ||
46 | void mod_for_vstart() { | |
47 | socketdir = "./out"; | |
48 | prefix = ""; | |
49 | } | |
50 | ||
51 | private: | |
52 | bool init_directories() const { | |
53 | std::cout << "Checking " << socketdir << std::endl; | |
54 | return exists(socketdir) && is_directory(socketdir); | |
55 | } | |
56 | ||
57 | bool init_sockets(); | |
58 | bool gather_socket_output(); | |
59 | std::string get_result(const std::string target, const std::string command) const; | |
60 | ||
61 | std::pair<std::string, std::string> | |
62 | run_command(AdminSocketClient &client, const std::string raw_command, | |
63 | bool send_untouched = false); | |
64 | ||
65 | bool run_tests() const; | |
66 | ||
67 | std::set<std::string> targets; | |
68 | std::map<std::string, std::string> sockets; | |
69 | std::map<std::string, socket_results> results; | |
70 | std::map<std::string, std::vector<std::string>> custom_commands; | |
71 | std::map<std::string, std::vector<std::string>> postponed_commands; | |
72 | std::map<std::string, test_functions> tests; | |
73 | ||
74 | std::string prefix = "ceph-"; | |
75 | bfs::path socketdir = "/var/run/ceph"; | |
76 | }; | |
77 | ||
78 | #endif // CEPH_ADMIN_SOCKET_OUTPUT_H |