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 return GenericList(constants.QR_EXPORT, selected_fields, None, opts.units,
54 opts.separator, not opts.no_headers,
55 verbose=opts.verbose, qfilter=qfilter)
56
57
59 """List export fields.
60
61 @param opts: the command line options selected by the user
62 @type args: list
63 @param args: fields to list, or empty for all
64 @rtype: int
65 @return: the desired exit code
66
67 """
68 return GenericListFields(constants.QR_EXPORT, args, opts.separator,
69 not opts.no_headers)
70
71
73 """Export an instance to an image in the cluster.
74
75 @param opts: the command line options selected by the user
76 @type args: list
77 @param args: should contain only one element, the name
78 of the instance to be exported
79 @rtype: int
80 @return: the desired exit code
81
82 """
83 ignore_remove_failures = opts.ignore_remove_failures
84
85 if not opts.node:
86 raise errors.OpPrereqError("Target node must be specified",
87 errors.ECODE_INVAL)
88
89 op = opcodes.OpBackupExport(instance_name=args[0],
90 target_node=opts.node,
91 shutdown=opts.shutdown,
92 shutdown_timeout=opts.shutdown_timeout,
93 remove_instance=opts.remove_instance,
94 ignore_remove_failures=ignore_remove_failures)
95
96 SubmitOrSend(op, opts)
97 return 0
98
99
107
108
110 """Remove an export from the cluster.
111
112 @param opts: the command line options selected by the user
113 @type args: list
114 @param args: should contain only one element, the name of the
115 instance whose backup should be removed
116 @rtype: int
117 @return: the desired exit code
118
119 """
120 op = opcodes.OpBackupRemove(instance_name=args[0])
121
122 SubmitOrSend(op, opts)
123 return 0
124
125
126
127 import_opts = [
128 IDENTIFY_DEFAULTS_OPT,
129 SRC_DIR_OPT,
130 SRC_NODE_OPT,
131 IGNORE_IPOLICY_OPT,
132 ]
133
134
135 commands = {
136 "list": (
137 PrintExportList, ARGS_NONE,
138 [NODE_LIST_OPT, NOHDR_OPT, SEP_OPT, USEUNITS_OPT, FIELDS_OPT, VERBOSE_OPT],
139 "", "Lists instance exports available in the ganeti cluster"),
140 "list-fields": (
141 ListExportFields, [ArgUnknown()],
142 [NOHDR_OPT, SEP_OPT],
143 "[fields...]",
144 "Lists all available fields for exports"),
145 "export": (
146 ExportInstance, ARGS_ONE_INSTANCE,
147 [FORCE_OPT, SINGLE_NODE_OPT, NOSHUTDOWN_OPT, SHUTDOWN_TIMEOUT_OPT,
148 REMOVE_INSTANCE_OPT, IGNORE_REMOVE_FAILURES_OPT, DRY_RUN_OPT,
149 PRIORITY_OPT, SUBMIT_OPT],
150 "-n <target_node> [opts...] <name>",
151 "Exports an instance to an image"),
152 "import": (
153 ImportInstance, ARGS_ONE_INSTANCE, COMMON_CREATE_OPTS + import_opts,
154 "[...] -t disk-type -n node[:secondary-node] <name>",
155 "Imports an instance from an exported image"),
156 "remove": (
157 RemoveExport, [ArgUnknown(min=1, max=1)],
158 [DRY_RUN_OPT, PRIORITY_OPT, SUBMIT_OPT],
159 "<name>", "Remove exports of named instance from the filesystem."),
160 }
161
162
165