root / lib / client / gnt_backup.py @ 2c398e80
History | View | Annotate | Download (4.9 kB)
1 | 02266fe0 | Michael Hanselmann | #
|
---|---|---|---|
2 | dd4b1106 | Iustin Pop | #
|
3 | dd4b1106 | Iustin Pop | |
4 | 5ba392f9 | Iustin Pop | # Copyright (C) 2006, 2007, 2010, 2011, 2013 Google Inc.
|
5 | dd4b1106 | Iustin Pop | #
|
6 | dd4b1106 | Iustin Pop | # This program is free software; you can redistribute it and/or modify
|
7 | dd4b1106 | Iustin Pop | # it under the terms of the GNU General Public License as published by
|
8 | dd4b1106 | Iustin Pop | # the Free Software Foundation; either version 2 of the License, or
|
9 | dd4b1106 | Iustin Pop | # (at your option) any later version.
|
10 | dd4b1106 | Iustin Pop | #
|
11 | dd4b1106 | Iustin Pop | # This program is distributed in the hope that it will be useful, but
|
12 | dd4b1106 | Iustin Pop | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | dd4b1106 | Iustin Pop | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | dd4b1106 | Iustin Pop | # General Public License for more details.
|
15 | dd4b1106 | Iustin Pop | #
|
16 | dd4b1106 | Iustin Pop | # You should have received a copy of the GNU General Public License
|
17 | dd4b1106 | Iustin Pop | # along with this program; if not, write to the Free Software
|
18 | dd4b1106 | Iustin Pop | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 | dd4b1106 | Iustin Pop | # 02110-1301, USA.
|
20 | dd4b1106 | Iustin Pop | |
21 | 7260cfbe | Iustin Pop | """Backup related commands"""
|
22 | dd4b1106 | Iustin Pop | |
23 | b459a848 | Andrea Spadaccini | # pylint: disable=W0401,W0613,W0614,C0103
|
24 | 2f79bd34 | Iustin Pop | # W0401: Wildcard import ganeti.cli
|
25 | 2d54e29c | Iustin Pop | # W0613: Unused argument, since all functions follow the same API
|
26 | 2f79bd34 | Iustin Pop | # W0614: Unused import %s from wildcard import (since we need cli)
|
27 | 7260cfbe | Iustin Pop | # C0103: Invalid name gnt-backup
|
28 | 2f79bd34 | Iustin Pop | |
29 | dd4b1106 | Iustin Pop | from ganeti.cli import * |
30 | dd4b1106 | Iustin Pop | from ganeti import opcodes |
31 | dd4b1106 | Iustin Pop | from ganeti import constants |
32 | bc696589 | Michael Hanselmann | from ganeti import errors |
33 | 0fdf247d | Michael Hanselmann | from ganeti import qlang |
34 | 0fdf247d | Michael Hanselmann | |
35 | 0fdf247d | Michael Hanselmann | |
36 | 0fdf247d | Michael Hanselmann | _LIST_DEF_FIELDS = ["node", "export"] |
37 | dd4b1106 | Iustin Pop | |
38 | 7c0d6283 | Michael Hanselmann | |
39 | dd4b1106 | Iustin Pop | def PrintExportList(opts, args): |
40 | dd4b1106 | Iustin Pop | """Prints a list of all the exported system images.
|
41 | dd4b1106 | Iustin Pop |
|
42 | 48de3413 | Iustin Pop | @param opts: the command line options selected by the user
|
43 | 48de3413 | Iustin Pop | @type args: list
|
44 | 48de3413 | Iustin Pop | @param args: should be an empty list
|
45 | 48de3413 | Iustin Pop | @rtype: int
|
46 | 48de3413 | Iustin Pop | @return: the desired exit code
|
47 | dd4b1106 | Iustin Pop |
|
48 | dd4b1106 | Iustin Pop | """
|
49 | 0fdf247d | Michael Hanselmann | selected_fields = ParseFields(opts.output, _LIST_DEF_FIELDS) |
50 | 0fdf247d | Michael Hanselmann | |
51 | 0fdf247d | Michael Hanselmann | qfilter = qlang.MakeSimpleFilter("node", opts.nodes)
|
52 | 0fdf247d | Michael Hanselmann | |
53 | 5ba392f9 | Iustin Pop | cl = GetClient(query=True)
|
54 | 5ba392f9 | Iustin Pop | |
55 | 0fdf247d | Michael Hanselmann | return GenericList(constants.QR_EXPORT, selected_fields, None, opts.units, |
56 | 0fdf247d | Michael Hanselmann | opts.separator, not opts.no_headers,
|
57 | 5ba392f9 | Iustin Pop | verbose=opts.verbose, qfilter=qfilter, cl=cl) |
58 | 0fdf247d | Michael Hanselmann | |
59 | 0fdf247d | Michael Hanselmann | |
60 | 0fdf247d | Michael Hanselmann | def ListExportFields(opts, args): |
61 | 0fdf247d | Michael Hanselmann | """List export fields.
|
62 | 0fdf247d | Michael Hanselmann |
|
63 | 0fdf247d | Michael Hanselmann | @param opts: the command line options selected by the user
|
64 | 0fdf247d | Michael Hanselmann | @type args: list
|
65 | 0fdf247d | Michael Hanselmann | @param args: fields to list, or empty for all
|
66 | 0fdf247d | Michael Hanselmann | @rtype: int
|
67 | 0fdf247d | Michael Hanselmann | @return: the desired exit code
|
68 | 0fdf247d | Michael Hanselmann |
|
69 | 0fdf247d | Michael Hanselmann | """
|
70 | 5ba392f9 | Iustin Pop | cl = GetClient(query=True)
|
71 | 5ba392f9 | Iustin Pop | |
72 | 0fdf247d | Michael Hanselmann | return GenericListFields(constants.QR_EXPORT, args, opts.separator,
|
73 | 5ba392f9 | Iustin Pop | not opts.no_headers, cl=cl)
|
74 | dd4b1106 | Iustin Pop | |
75 | dd4b1106 | Iustin Pop | |
76 | dd4b1106 | Iustin Pop | def ExportInstance(opts, args): |
77 | dd4b1106 | Iustin Pop | """Export an instance to an image in the cluster.
|
78 | dd4b1106 | Iustin Pop |
|
79 | 48de3413 | Iustin Pop | @param opts: the command line options selected by the user
|
80 | 48de3413 | Iustin Pop | @type args: list
|
81 | 48de3413 | Iustin Pop | @param args: should contain only one element, the name
|
82 | 48de3413 | Iustin Pop | of the instance to be exported
|
83 | 48de3413 | Iustin Pop | @rtype: int
|
84 | 48de3413 | Iustin Pop | @return: the desired exit code
|
85 | dd4b1106 | Iustin Pop |
|
86 | dd4b1106 | Iustin Pop | """
|
87 | 8d8d650c | Michael Hanselmann | ignore_remove_failures = opts.ignore_remove_failures |
88 | 8d8d650c | Michael Hanselmann | |
89 | bc696589 | Michael Hanselmann | if not opts.node: |
90 | 5ec4b9d2 | Michael Hanselmann | raise errors.OpPrereqError("Target node must be specified", |
91 | 5ec4b9d2 | Michael Hanselmann | errors.ECODE_INVAL) |
92 | bc696589 | Michael Hanselmann | |
93 | 4ff922a2 | Iustin Pop | op = opcodes.OpBackupExport(instance_name=args[0],
|
94 | 4ff922a2 | Iustin Pop | target_node=opts.node, |
95 | 4ff922a2 | Iustin Pop | shutdown=opts.shutdown, |
96 | 4ff922a2 | Iustin Pop | shutdown_timeout=opts.shutdown_timeout, |
97 | 4ff922a2 | Iustin Pop | remove_instance=opts.remove_instance, |
98 | 4ff922a2 | Iustin Pop | ignore_remove_failures=ignore_remove_failures) |
99 | dd4b1106 | Iustin Pop | |
100 | f5c0c206 | Michael Hanselmann | SubmitOrSend(op, opts) |
101 | 44247302 | Iustin Pop | return 0 |
102 | 60d49723 | Michael Hanselmann | |
103 | 8d8d650c | Michael Hanselmann | |
104 | dd4b1106 | Iustin Pop | def ImportInstance(opts, args): |
105 | dd4b1106 | Iustin Pop | """Add an instance to the cluster.
|
106 | dd4b1106 | Iustin Pop |
|
107 | d77490c5 | Iustin Pop | This is just a wrapper over GenericInstanceCreate.
|
108 | dd4b1106 | Iustin Pop |
|
109 | dd4b1106 | Iustin Pop | """
|
110 | d77490c5 | Iustin Pop | return GenericInstanceCreate(constants.INSTANCE_IMPORT, opts, args)
|
111 | dd4b1106 | Iustin Pop | |
112 | dd4b1106 | Iustin Pop | |
113 | 9ac99fda | Guido Trotter | def RemoveExport(opts, args): |
114 | 9ac99fda | Guido Trotter | """Remove an export from the cluster.
|
115 | 9ac99fda | Guido Trotter |
|
116 | 48de3413 | Iustin Pop | @param opts: the command line options selected by the user
|
117 | 48de3413 | Iustin Pop | @type args: list
|
118 | 48de3413 | Iustin Pop | @param args: should contain only one element, the name of the
|
119 | 48de3413 | Iustin Pop | instance whose backup should be removed
|
120 | 48de3413 | Iustin Pop | @rtype: int
|
121 | 48de3413 | Iustin Pop | @return: the desired exit code
|
122 | 9ac99fda | Guido Trotter |
|
123 | 9ac99fda | Guido Trotter | """
|
124 | ca5890ad | Iustin Pop | op = opcodes.OpBackupRemove(instance_name=args[0])
|
125 | 9ac99fda | Guido Trotter | |
126 | f5c0c206 | Michael Hanselmann | SubmitOrSend(op, opts) |
127 | 9ac99fda | Guido Trotter | return 0 |
128 | 9ac99fda | Guido Trotter | |
129 | 9ac99fda | Guido Trotter | |
130 | dd4b1106 | Iustin Pop | # this is defined separately due to readability only
|
131 | dd4b1106 | Iustin Pop | import_opts = [ |
132 | e588764d | Iustin Pop | IDENTIFY_DEFAULTS_OPT, |
133 | df62e5db | Iustin Pop | SRC_DIR_OPT, |
134 | df62e5db | Iustin Pop | SRC_NODE_OPT, |
135 | 2a84b7d3 | René Nussbaumer | IGNORE_IPOLICY_OPT, |
136 | dd4b1106 | Iustin Pop | ] |
137 | dd4b1106 | Iustin Pop | |
138 | 8d8d650c | Michael Hanselmann | |
139 | dd4b1106 | Iustin Pop | commands = { |
140 | 3ccb3a64 | Michael Hanselmann | "list": (
|
141 | 6ea815cf | Iustin Pop | PrintExportList, ARGS_NONE, |
142 | 0fdf247d | Michael Hanselmann | [NODE_LIST_OPT, NOHDR_OPT, SEP_OPT, USEUNITS_OPT, FIELDS_OPT, VERBOSE_OPT], |
143 | 6ea815cf | Iustin Pop | "", "Lists instance exports available in the ganeti cluster"), |
144 | 0fdf247d | Michael Hanselmann | "list-fields": (
|
145 | 0fdf247d | Michael Hanselmann | ListExportFields, [ArgUnknown()], |
146 | 0fdf247d | Michael Hanselmann | [NOHDR_OPT, SEP_OPT], |
147 | 0fdf247d | Michael Hanselmann | "[fields...]",
|
148 | 0fdf247d | Michael Hanselmann | "Lists all available fields for exports"),
|
149 | 3ccb3a64 | Michael Hanselmann | "export": (
|
150 | 6ea815cf | Iustin Pop | ExportInstance, ARGS_ONE_INSTANCE, |
151 | 8d8d650c | Michael Hanselmann | [FORCE_OPT, SINGLE_NODE_OPT, NOSHUTDOWN_OPT, SHUTDOWN_TIMEOUT_OPT, |
152 | aa06f8c6 | Michael Hanselmann | REMOVE_INSTANCE_OPT, IGNORE_REMOVE_FAILURES_OPT, DRY_RUN_OPT, |
153 | f5c0c206 | Michael Hanselmann | PRIORITY_OPT, SUBMIT_OPT], |
154 | 6ea815cf | Iustin Pop | "-n <target_node> [opts...] <name>",
|
155 | 6ea815cf | Iustin Pop | "Exports an instance to an image"),
|
156 | 3ccb3a64 | Michael Hanselmann | "import": (
|
157 | eb28ecf6 | Guido Trotter | ImportInstance, ARGS_ONE_INSTANCE, COMMON_CREATE_OPTS + import_opts, |
158 | 6ea815cf | Iustin Pop | "[...] -t disk-type -n node[:secondary-node] <name>",
|
159 | 6ea815cf | Iustin Pop | "Imports an instance from an exported image"),
|
160 | 3ccb3a64 | Michael Hanselmann | "remove": (
|
161 | f5c0c206 | Michael Hanselmann | RemoveExport, [ArgUnknown(min=1, max=1)], |
162 | f5c0c206 | Michael Hanselmann | [DRY_RUN_OPT, PRIORITY_OPT, SUBMIT_OPT], |
163 | 6ea815cf | Iustin Pop | "<name>", "Remove exports of named instance from the filesystem."), |
164 | dd4b1106 | Iustin Pop | } |
165 | dd4b1106 | Iustin Pop | |
166 | a8005e17 | Michael Hanselmann | |
167 | 02266fe0 | Michael Hanselmann | def Main(): |
168 | 02266fe0 | Michael Hanselmann | return GenericMain(commands) |