Package ganeti :: Package client :: Module gnt_backup
[hide private]
[frames] | no frames]

Source Code for Module ganeti.client.gnt_backup

  1  # 
  2  # 
  3   
  4  # Copyright (C) 2006, 2007, 2010, 2011, 2013 Google Inc. 
  5  # All rights reserved. 
  6  # 
  7  # Redistribution and use in source and binary forms, with or without 
  8  # modification, are permitted provided that the following conditions are 
  9  # met: 
 10  # 
 11  # 1. Redistributions of source code must retain the above copyright notice, 
 12  # this list of conditions and the following disclaimer. 
 13  # 
 14  # 2. Redistributions in binary form must reproduce the above copyright 
 15  # notice, this list of conditions and the following disclaimer in the 
 16  # documentation and/or other materials provided with the distribution. 
 17  # 
 18  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 
 19  # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 
 20  # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
 21  # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
 22  # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
 23  # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
 24  # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
 25  # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
 26  # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
 27  # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
 28  # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
 29   
 30  """Backup related commands""" 
 31   
 32  # pylint: disable=W0401,W0613,W0614,C0103 
 33  # W0401: Wildcard import ganeti.cli 
 34  # W0613: Unused argument, since all functions follow the same API 
 35  # W0614: Unused import %s from wildcard import (since we need cli) 
 36  # C0103: Invalid name gnt-backup 
 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   
48 -def PrintExportList(opts, args):
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
69 -def ListExportFields(opts, args):
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
85 -def ExportInstance(opts, args):
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 compress=opts.transport_compression, 105 shutdown=opts.shutdown, 106 shutdown_timeout=opts.shutdown_timeout, 107 remove_instance=opts.remove_instance, 108 ignore_remove_failures=ignore_remove_failures) 109 110 SubmitOrSend(op, opts) 111 return 0
112 113
114 -def ImportInstance(opts, args):
115 """Add an instance to the cluster. 116 117 This is just a wrapper over GenericInstanceCreate. 118 119 """ 120 return GenericInstanceCreate(constants.INSTANCE_IMPORT, opts, args)
121 122
123 -def RemoveExport(opts, args):
124 """Remove an export from the cluster. 125 126 @param opts: the command line options selected by the user 127 @type args: list 128 @param args: should contain only one element, the name of the 129 instance whose backup should be removed 130 @rtype: int 131 @return: the desired exit code 132 133 """ 134 op = opcodes.OpBackupRemove(instance_name=args[0]) 135 136 SubmitOrSend(op, opts) 137 return 0
138 139 140 # this is defined separately due to readability only 141 import_opts = [ 142 IDENTIFY_DEFAULTS_OPT, 143 SRC_DIR_OPT, 144 SRC_NODE_OPT, 145 COMPRESS_OPT, 146 IGNORE_IPOLICY_OPT, 147 ] 148 149 150 commands = { 151 "list": ( 152 PrintExportList, ARGS_NONE, 153 [NODE_LIST_OPT, NOHDR_OPT, SEP_OPT, USEUNITS_OPT, FIELDS_OPT, VERBOSE_OPT], 154 "", "Lists instance exports available in the ganeti cluster"), 155 "list-fields": ( 156 ListExportFields, [ArgUnknown()], 157 [NOHDR_OPT, SEP_OPT], 158 "[fields...]", 159 "Lists all available fields for exports"), 160 "export": ( 161 ExportInstance, ARGS_ONE_INSTANCE, 162 [FORCE_OPT, SINGLE_NODE_OPT, TRANSPORT_COMPRESSION_OPT, NOSHUTDOWN_OPT, 163 SHUTDOWN_TIMEOUT_OPT, REMOVE_INSTANCE_OPT, IGNORE_REMOVE_FAILURES_OPT, 164 DRY_RUN_OPT, PRIORITY_OPT] + SUBMIT_OPTS, 165 "-n <target_node> [opts...] <name>", 166 "Exports an instance to an image"), 167 "import": ( 168 ImportInstance, ARGS_ONE_INSTANCE, COMMON_CREATE_OPTS + import_opts, 169 "[...] -t disk-type -n node[:secondary-node] <name>", 170 "Imports an instance from an exported image"), 171 "remove": ( 172 RemoveExport, [ArgUnknown(min=1, max=1)], 173 [DRY_RUN_OPT, PRIORITY_OPT] + SUBMIT_OPTS, 174 "<name>", "Remove exports of named instance from the filesystem."), 175 } 176 177
178 -def Main():
179 return GenericMain(commands)
180