]>
Commit | Line | Data |
---|---|---|
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- | |
2 | // vim: ts=8 sw=2 smarttab | |
3 | ||
4 | #ifndef CEPH_RBD_ARGUMENT_TYPES_H | |
5 | #define CEPH_RBD_ARGUMENT_TYPES_H | |
6 | ||
7 | #include "include/int_types.h" | |
8 | #include <set> | |
9 | #include <string> | |
10 | #include <vector> | |
11 | #include <boost/any.hpp> | |
12 | #include <boost/program_options.hpp> | |
13 | #include <boost/shared_ptr.hpp> | |
14 | ||
15 | namespace ceph { class Formatter; } | |
16 | ||
17 | namespace rbd { | |
18 | namespace argument_types { | |
19 | ||
20 | enum ArgumentModifier { | |
21 | ARGUMENT_MODIFIER_NONE, | |
22 | ARGUMENT_MODIFIER_SOURCE, | |
23 | ARGUMENT_MODIFIER_DEST | |
24 | }; | |
25 | ||
26 | enum SpecFormat { | |
27 | SPEC_FORMAT_IMAGE, | |
28 | SPEC_FORMAT_SNAPSHOT, | |
29 | SPEC_FORMAT_IMAGE_OR_SNAPSHOT | |
30 | }; | |
31 | ||
32 | static const std::string SOURCE_PREFIX("source-"); | |
33 | static const std::string DEST_PREFIX("dest-"); | |
34 | ||
35 | // positional arguments | |
36 | static const std::string POSITIONAL_COMMAND_SPEC("positional-command-spec"); | |
37 | static const std::string POSITIONAL_ARGUMENTS("positional-arguments"); | |
38 | static const std::string IMAGE_SPEC("image-spec"); | |
39 | static const std::string GROUP_SPEC("group-spec"); | |
40 | static const std::string SNAPSHOT_SPEC("snap-spec"); | |
41 | static const std::string IMAGE_OR_SNAPSHOT_SPEC("image-or-snap-spec"); | |
42 | static const std::string JOURNAL_SPEC("journal-spec"); | |
43 | static const std::string PATH_NAME("path-name"); | |
44 | static const std::string IMAGE_ID("image-id"); | |
45 | ||
46 | // optional arguments | |
47 | static const std::string CONFIG_PATH("conf"); | |
48 | static const std::string POOL_NAME("pool"); | |
49 | static const std::string DEST_POOL_NAME("dest-pool"); | |
50 | static const std::string IMAGE_NAME("image"); | |
51 | static const std::string DEST_IMAGE_NAME("dest"); | |
52 | static const std::string GROUP_NAME("group"); | |
53 | static const std::string DEST_GROUP_NAME("dest-group"); | |
54 | static const std::string SNAPSHOT_NAME("snap"); | |
55 | static const std::string DEST_SNAPSHOT_NAME("dest-snap"); | |
56 | static const std::string JOURNAL_NAME("journal"); | |
57 | static const std::string DEST_JOURNAL_NAME("dest-journal"); | |
58 | static const std::string PATH("path"); | |
59 | static const std::string FROM_SNAPSHOT_NAME("from-snap"); | |
60 | static const std::string WHOLE_OBJECT("whole-object"); | |
61 | ||
62 | static const std::string IMAGE_FORMAT("image-format"); | |
63 | static const std::string IMAGE_NEW_FORMAT("new-format"); | |
64 | static const std::string IMAGE_ORDER("order"); | |
65 | static const std::string IMAGE_OBJECT_SIZE("object-size"); | |
66 | static const std::string IMAGE_FEATURES("image-feature"); | |
67 | static const std::string IMAGE_SHARED("image-shared"); | |
68 | static const std::string IMAGE_SIZE("size"); | |
69 | static const std::string IMAGE_STRIPE_UNIT("stripe-unit"); | |
70 | static const std::string IMAGE_STRIPE_COUNT("stripe-count"); | |
71 | static const std::string IMAGE_DATA_POOL("data-pool"); | |
72 | static const std::string IMAGE_SPARSE_SIZE("sparse-size"); | |
73 | ||
74 | static const std::string JOURNAL_OBJECT_SIZE("journal-object-size"); | |
75 | static const std::string JOURNAL_SPLAY_WIDTH("journal-splay-width"); | |
76 | static const std::string JOURNAL_POOL("journal-pool"); | |
77 | ||
78 | static const std::string NO_PROGRESS("no-progress"); | |
79 | static const std::string FORMAT("format"); | |
80 | static const std::string PRETTY_FORMAT("pretty-format"); | |
81 | static const std::string VERBOSE("verbose"); | |
82 | static const std::string NO_ERROR("no-error"); | |
83 | ||
84 | static const std::string DELAY("delay"); | |
85 | ||
86 | static const std::string LIMIT("limit"); | |
87 | ||
88 | static const std::set<std::string> SWITCH_ARGUMENTS = { | |
89 | WHOLE_OBJECT, NO_PROGRESS, PRETTY_FORMAT, VERBOSE, NO_ERROR}; | |
90 | ||
91 | struct ImageSize {}; | |
92 | struct ImageOrder {}; | |
93 | struct ImageObjectSize {}; | |
94 | struct ImageFormat {}; | |
95 | struct ImageNewFormat {}; | |
96 | ||
97 | struct ImageFeatures { | |
98 | static const std::map<uint64_t, std::string> FEATURE_MAPPING; | |
99 | ||
100 | uint64_t features; | |
101 | }; | |
102 | ||
103 | template <typename T> | |
104 | struct TypedValue { | |
105 | T value; | |
106 | TypedValue(const T& t) : value(t) {} | |
107 | }; | |
108 | ||
109 | struct Format : public TypedValue<std::string> { | |
110 | typedef boost::shared_ptr<ceph::Formatter> Formatter; | |
111 | ||
112 | Format(const std::string &format) : TypedValue<std::string>(format) {} | |
113 | ||
114 | Formatter create_formatter(bool pretty) const; | |
115 | }; | |
116 | ||
117 | struct JournalObjectSize {}; | |
118 | ||
119 | struct ExportFormat {}; | |
120 | ||
121 | struct Secret {}; | |
122 | ||
123 | void add_export_format_option(boost::program_options::options_description *opt); | |
124 | ||
125 | std::string get_name_prefix(ArgumentModifier modifier); | |
126 | std::string get_description_prefix(ArgumentModifier modifier); | |
127 | ||
128 | ||
129 | void add_special_pool_option(boost::program_options::options_description *opt, | |
130 | std::string prefix); | |
131 | ||
132 | void add_pool_option(boost::program_options::options_description *opt, | |
133 | ArgumentModifier modifier, | |
134 | const std::string &desc_suffix = ""); | |
135 | ||
136 | void add_image_option(boost::program_options::options_description *opt, | |
137 | ArgumentModifier modifier, | |
138 | const std::string &desc_suffix = ""); | |
139 | ||
140 | void add_image_id_option(boost::program_options::options_description *opt, | |
141 | const std::string &desc_suffix = ""); | |
142 | ||
143 | void add_group_option(boost::program_options::options_description *opt, | |
144 | ArgumentModifier modifier, | |
145 | const std::string &desc_suffix = ""); | |
146 | ||
147 | void add_snap_option(boost::program_options::options_description *opt, | |
148 | ArgumentModifier modifier); | |
149 | ||
150 | void add_journal_option(boost::program_options::options_description *opt, | |
151 | ArgumentModifier modifier, | |
152 | const std::string &desc_suffix = ""); | |
153 | ||
154 | void add_pool_options(boost::program_options::options_description *pos, | |
155 | boost::program_options::options_description *opt); | |
156 | ||
157 | void add_image_spec_options(boost::program_options::options_description *pos, | |
158 | boost::program_options::options_description *opt, | |
159 | ArgumentModifier modifier); | |
160 | ||
161 | void add_group_spec_options(boost::program_options::options_description *pos, | |
162 | boost::program_options::options_description *opt, | |
163 | ArgumentModifier modifier); | |
164 | ||
165 | void add_snap_spec_options(boost::program_options::options_description *pos, | |
166 | boost::program_options::options_description *opt, | |
167 | ArgumentModifier modifier); | |
168 | ||
169 | void add_image_or_snap_spec_options( | |
170 | boost::program_options::options_description *pos, | |
171 | boost::program_options::options_description *opt, | |
172 | ArgumentModifier modifier); | |
173 | ||
174 | void add_journal_spec_options( | |
175 | boost::program_options::options_description *pos, | |
176 | boost::program_options::options_description *opt, | |
177 | ArgumentModifier modifier); | |
178 | ||
179 | void add_create_image_options(boost::program_options::options_description *opt, | |
180 | bool include_format); | |
181 | ||
182 | void add_create_journal_options( | |
183 | boost::program_options::options_description *opt); | |
184 | ||
185 | void add_size_option(boost::program_options::options_description *opt); | |
186 | ||
187 | void add_sparse_size_option(boost::program_options::options_description *opt); | |
188 | ||
189 | void add_path_options(boost::program_options::options_description *pos, | |
190 | boost::program_options::options_description *opt, | |
191 | const std::string &description); | |
192 | ||
193 | void add_limit_option(boost::program_options::options_description *opt); | |
194 | ||
195 | void add_no_progress_option(boost::program_options::options_description *opt); | |
196 | ||
197 | void add_format_options(boost::program_options::options_description *opt); | |
198 | ||
199 | void add_verbose_option(boost::program_options::options_description *opt); | |
200 | ||
201 | void add_no_error_option(boost::program_options::options_description *opt); | |
202 | ||
203 | std::string get_short_features_help(bool append_suffix); | |
204 | std::string get_long_features_help(); | |
205 | ||
206 | void validate(boost::any& v, const std::vector<std::string>& values, | |
207 | ExportFormat *target_type, int); | |
208 | void validate(boost::any& v, const std::vector<std::string>& values, | |
209 | ImageSize *target_type, int); | |
210 | void validate(boost::any& v, const std::vector<std::string>& values, | |
211 | ImageOrder *target_type, int); | |
212 | void validate(boost::any& v, const std::vector<std::string>& values, | |
213 | ImageObjectSize *target_type, int); | |
214 | void validate(boost::any& v, const std::vector<std::string>& values, | |
215 | ImageFormat *target_type, int); | |
216 | void validate(boost::any& v, const std::vector<std::string>& values, | |
217 | ImageNewFormat *target_type, int); | |
218 | void validate(boost::any& v, const std::vector<std::string>& values, | |
219 | ImageFeatures *target_type, int); | |
220 | void validate(boost::any& v, const std::vector<std::string>& values, | |
221 | Format *target_type, int); | |
222 | void validate(boost::any& v, const std::vector<std::string>& values, | |
223 | JournalObjectSize *target_type, int); | |
224 | void validate(boost::any& v, const std::vector<std::string>& values, | |
225 | Secret *target_type, int); | |
226 | ||
227 | ||
228 | std::ostream &operator<<(std::ostream &os, const ImageFeatures &features); | |
229 | ||
230 | } // namespace argument_types | |
231 | } // namespace rbd | |
232 | ||
233 | #endif // CEPH_RBD_ARGUMENT_TYPES_H |