1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 """Backup related commands"""
31
32
33
34
35
36
37
38 from ganeti.cli import *
39 from ganeti import opcodes
40 from ganeti import constants
41 from ganeti import errors
42 from ganeti import qlang
43
44
45 _LIST_DEF_FIELDS = ["node", "export"]
46
47
49 """Prints a list of all the exported system images.
50
51 @param opts: the command line options selected by the user
52 @type args: list
53 @param args: should be an empty list
54 @rtype: int
55 @return: the desired exit code
56
57 """
58 selected_fields = ParseFields(opts.output, _LIST_DEF_FIELDS)
59
60 qfilter = qlang.MakeSimpleFilter("node", opts.nodes)
61
62 cl = GetClient(query=True)
63
64 return GenericList(constants.QR_EXPORT, selected_fields, None, opts.units,
65 opts.separator, not opts.no_headers,
66 verbose=opts.verbose, qfilter=qfilter, cl=cl)
67
68
70 """List export fields.
71
72 @param opts: the command line options selected by the user
73 @type args: list
74 @param args: fields to list, or empty for all
75 @rtype: int
76 @return: the desired exit code
77
78 """
79 cl = GetClient(query=True)
80
81 return GenericListFields(constants.QR_EXPORT, args, opts.separator,
82 not opts.no_headers, cl=cl)
83
84
86 """Export an instance to an image in the cluster.
87
88 @param opts: the command line options selected by the user
89 @type args: list
90 @param args: should contain only one element, the name
91 of the instance to be exported
92 @rtype: int
93 @return: the desired exit code
94
95 """
96 ignore_remove_failures = opts.ignore_remove_failures
97
98 if not opts.node:
99 raise errors.OpPrereqError("Target node must be specified",
100 errors.ECODE_INVAL)
101
102 op = opcodes.OpBackupExport(instance_name=args[0],
103 target_node=opts.node,
104 shutdown=opts.shutdown,
105 shutdown_timeout=opts.shutdown_timeout,
106 remove_instance=opts.remove_instance,
107 ignore_remove_failures=ignore_remove_failures)
108
109 SubmitOrSend(op, opts)
110 return 0
111
112
120
121
123 """Remove an export from the cluster.
124
125 @param opts: the command line options selected by the user
126 @type args: list
127 @param args: should contain only one element, the name of the
128 instance whose backup should be removed
129 @rtype: int
130 @return: the desired exit code
131
132 """
133 op = opcodes.OpBackupRemove(instance_name=args[0])
134
135 SubmitOrSend(op, opts)
136 return 0
137
138
139
140 import_opts = [
141 IDENTIFY_DEFAULTS_OPT,
142 SRC_DIR_OPT,
143 SRC_NODE_OPT,
144 IGNORE_IPOLICY_OPT,
145 ]
146
147
148 commands = {
149 "list": (
150 PrintExportList, ARGS_NONE,
151 [NODE_LIST_OPT, NOHDR_OPT, SEP_OPT, USEUNITS_OPT, FIELDS_OPT, VERBOSE_OPT],
152 "", "Lists instance exports available in the ganeti cluster"),
153 "list-fields": (
154 ListExportFields, [ArgUnknown()],
155 [NOHDR_OPT, SEP_OPT],
156 "[fields...]",
157 "Lists all available fields for exports"),
158 "export": (
159 ExportInstance, ARGS_ONE_INSTANCE,
160 [FORCE_OPT, SINGLE_NODE_OPT, NOSHUTDOWN_OPT, SHUTDOWN_TIMEOUT_OPT,
161 REMOVE_INSTANCE_OPT, IGNORE_REMOVE_FAILURES_OPT, DRY_RUN_OPT,
162 PRIORITY_OPT] + SUBMIT_OPTS,
163 "-n <target_node> [opts...] <name>",
164 "Exports an instance to an image"),
165 "import": (
166 ImportInstance, ARGS_ONE_INSTANCE, COMMON_CREATE_OPTS + import_opts,
167 "[...] -t disk-type -n node[:secondary-node] <name>",
168 "Imports an instance from an exported image"),
169 "remove": (
170 RemoveExport, [ArgUnknown(min=1, max=1)],
171 [DRY_RUN_OPT, PRIORITY_OPT] + SUBMIT_OPTS,
172 "<name>", "Remove exports of named instance from the filesystem."),
173 }
174
175
178