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