root / lib / client / gnt_backup.py @ 1fa2c40b
History | View | Annotate | Download (4.8 kB)
1 | 02266fe0 | Michael Hanselmann | #
|
---|---|---|---|
2 | dd4b1106 | Iustin Pop | #
|
3 | dd4b1106 | Iustin Pop | |
4 | 4ff922a2 | Iustin Pop | # Copyright (C) 2006, 2007, 2010, 2011 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 | 0fdf247d | Michael Hanselmann | return GenericList(constants.QR_EXPORT, selected_fields, None, opts.units, |
54 | 0fdf247d | Michael Hanselmann | opts.separator, not opts.no_headers,
|
55 | 0fdf247d | Michael Hanselmann | verbose=opts.verbose, qfilter=qfilter) |
56 | 0fdf247d | Michael Hanselmann | |
57 | 0fdf247d | Michael Hanselmann | |
58 | 0fdf247d | Michael Hanselmann | def ListExportFields(opts, args): |
59 | 0fdf247d | Michael Hanselmann | """List export fields.
|
60 | 0fdf247d | Michael Hanselmann |
|
61 | 0fdf247d | Michael Hanselmann | @param opts: the command line options selected by the user
|
62 | 0fdf247d | Michael Hanselmann | @type args: list
|
63 | 0fdf247d | Michael Hanselmann | @param args: fields to list, or empty for all
|
64 | 0fdf247d | Michael Hanselmann | @rtype: int
|
65 | 0fdf247d | Michael Hanselmann | @return: the desired exit code
|
66 | 0fdf247d | Michael Hanselmann |
|
67 | 0fdf247d | Michael Hanselmann | """
|
68 | 0fdf247d | Michael Hanselmann | return GenericListFields(constants.QR_EXPORT, args, opts.separator,
|
69 | 0fdf247d | Michael Hanselmann | not opts.no_headers)
|
70 | dd4b1106 | Iustin Pop | |
71 | dd4b1106 | Iustin Pop | |
72 | dd4b1106 | Iustin Pop | def ExportInstance(opts, args): |
73 | dd4b1106 | Iustin Pop | """Export an instance to an image in the cluster.
|
74 | dd4b1106 | Iustin Pop |
|
75 | 48de3413 | Iustin Pop | @param opts: the command line options selected by the user
|
76 | 48de3413 | Iustin Pop | @type args: list
|
77 | 48de3413 | Iustin Pop | @param args: should contain only one element, the name
|
78 | 48de3413 | Iustin Pop | of the instance to be exported
|
79 | 48de3413 | Iustin Pop | @rtype: int
|
80 | 48de3413 | Iustin Pop | @return: the desired exit code
|
81 | dd4b1106 | Iustin Pop |
|
82 | dd4b1106 | Iustin Pop | """
|
83 | 8d8d650c | Michael Hanselmann | ignore_remove_failures = opts.ignore_remove_failures |
84 | 8d8d650c | Michael Hanselmann | |
85 | bc696589 | Michael Hanselmann | if not opts.node: |
86 | 5ec4b9d2 | Michael Hanselmann | raise errors.OpPrereqError("Target node must be specified", |
87 | 5ec4b9d2 | Michael Hanselmann | errors.ECODE_INVAL) |
88 | bc696589 | Michael Hanselmann | |
89 | 4ff922a2 | Iustin Pop | op = opcodes.OpBackupExport(instance_name=args[0],
|
90 | 4ff922a2 | Iustin Pop | target_node=opts.node, |
91 | 4ff922a2 | Iustin Pop | shutdown=opts.shutdown, |
92 | 4ff922a2 | Iustin Pop | shutdown_timeout=opts.shutdown_timeout, |
93 | 4ff922a2 | Iustin Pop | remove_instance=opts.remove_instance, |
94 | 4ff922a2 | Iustin Pop | ignore_remove_failures=ignore_remove_failures) |
95 | dd4b1106 | Iustin Pop | |
96 | f5c0c206 | Michael Hanselmann | SubmitOrSend(op, opts) |
97 | 44247302 | Iustin Pop | return 0 |
98 | 60d49723 | Michael Hanselmann | |
99 | 8d8d650c | Michael Hanselmann | |
100 | dd4b1106 | Iustin Pop | def ImportInstance(opts, args): |
101 | dd4b1106 | Iustin Pop | """Add an instance to the cluster.
|
102 | dd4b1106 | Iustin Pop |
|
103 | d77490c5 | Iustin Pop | This is just a wrapper over GenericInstanceCreate.
|
104 | dd4b1106 | Iustin Pop |
|
105 | dd4b1106 | Iustin Pop | """
|
106 | d77490c5 | Iustin Pop | return GenericInstanceCreate(constants.INSTANCE_IMPORT, opts, args)
|
107 | dd4b1106 | Iustin Pop | |
108 | dd4b1106 | Iustin Pop | |
109 | 9ac99fda | Guido Trotter | def RemoveExport(opts, args): |
110 | 9ac99fda | Guido Trotter | """Remove an export from the cluster.
|
111 | 9ac99fda | Guido Trotter |
|
112 | 48de3413 | Iustin Pop | @param opts: the command line options selected by the user
|
113 | 48de3413 | Iustin Pop | @type args: list
|
114 | 48de3413 | Iustin Pop | @param args: should contain only one element, the name of the
|
115 | 48de3413 | Iustin Pop | instance whose backup should be removed
|
116 | 48de3413 | Iustin Pop | @rtype: int
|
117 | 48de3413 | Iustin Pop | @return: the desired exit code
|
118 | 9ac99fda | Guido Trotter |
|
119 | 9ac99fda | Guido Trotter | """
|
120 | ca5890ad | Iustin Pop | op = opcodes.OpBackupRemove(instance_name=args[0])
|
121 | 9ac99fda | Guido Trotter | |
122 | f5c0c206 | Michael Hanselmann | SubmitOrSend(op, opts) |
123 | 9ac99fda | Guido Trotter | return 0 |
124 | 9ac99fda | Guido Trotter | |
125 | 9ac99fda | Guido Trotter | |
126 | dd4b1106 | Iustin Pop | # this is defined separately due to readability only
|
127 | dd4b1106 | Iustin Pop | import_opts = [ |
128 | e588764d | Iustin Pop | IDENTIFY_DEFAULTS_OPT, |
129 | df62e5db | Iustin Pop | SRC_DIR_OPT, |
130 | df62e5db | Iustin Pop | SRC_NODE_OPT, |
131 | 2a84b7d3 | René Nussbaumer | IGNORE_IPOLICY_OPT, |
132 | dd4b1106 | Iustin Pop | ] |
133 | dd4b1106 | Iustin Pop | |
134 | 8d8d650c | Michael Hanselmann | |
135 | dd4b1106 | Iustin Pop | commands = { |
136 | 3ccb3a64 | Michael Hanselmann | "list": (
|
137 | 6ea815cf | Iustin Pop | PrintExportList, ARGS_NONE, |
138 | 0fdf247d | Michael Hanselmann | [NODE_LIST_OPT, NOHDR_OPT, SEP_OPT, USEUNITS_OPT, FIELDS_OPT, VERBOSE_OPT], |
139 | 6ea815cf | Iustin Pop | "", "Lists instance exports available in the ganeti cluster"), |
140 | 0fdf247d | Michael Hanselmann | "list-fields": (
|
141 | 0fdf247d | Michael Hanselmann | ListExportFields, [ArgUnknown()], |
142 | 0fdf247d | Michael Hanselmann | [NOHDR_OPT, SEP_OPT], |
143 | 0fdf247d | Michael Hanselmann | "[fields...]",
|
144 | 0fdf247d | Michael Hanselmann | "Lists all available fields for exports"),
|
145 | 3ccb3a64 | Michael Hanselmann | "export": (
|
146 | 6ea815cf | Iustin Pop | ExportInstance, ARGS_ONE_INSTANCE, |
147 | 8d8d650c | Michael Hanselmann | [FORCE_OPT, SINGLE_NODE_OPT, NOSHUTDOWN_OPT, SHUTDOWN_TIMEOUT_OPT, |
148 | aa06f8c6 | Michael Hanselmann | REMOVE_INSTANCE_OPT, IGNORE_REMOVE_FAILURES_OPT, DRY_RUN_OPT, |
149 | f5c0c206 | Michael Hanselmann | PRIORITY_OPT, SUBMIT_OPT], |
150 | 6ea815cf | Iustin Pop | "-n <target_node> [opts...] <name>",
|
151 | 6ea815cf | Iustin Pop | "Exports an instance to an image"),
|
152 | 3ccb3a64 | Michael Hanselmann | "import": (
|
153 | eb28ecf6 | Guido Trotter | ImportInstance, ARGS_ONE_INSTANCE, COMMON_CREATE_OPTS + import_opts, |
154 | 6ea815cf | Iustin Pop | "[...] -t disk-type -n node[:secondary-node] <name>",
|
155 | 6ea815cf | Iustin Pop | "Imports an instance from an exported image"),
|
156 | 3ccb3a64 | Michael Hanselmann | "remove": (
|
157 | f5c0c206 | Michael Hanselmann | RemoveExport, [ArgUnknown(min=1, max=1)], |
158 | f5c0c206 | Michael Hanselmann | [DRY_RUN_OPT, PRIORITY_OPT, SUBMIT_OPT], |
159 | 6ea815cf | Iustin Pop | "<name>", "Remove exports of named instance from the filesystem."), |
160 | dd4b1106 | Iustin Pop | } |
161 | dd4b1106 | Iustin Pop | |
162 | a8005e17 | Michael Hanselmann | |
163 | 02266fe0 | Michael Hanselmann | def Main(): |
164 | 02266fe0 | Michael Hanselmann | return GenericMain(commands) |