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 Google Inc. 
  5  # 
  6  # This program is free software; you can redistribute it and/or modify 
  7  # it under the terms of the GNU General Public License as published by 
  8  # the Free Software Foundation; either version 2 of the License, or 
  9  # (at your option) any later version. 
 10  # 
 11  # This program is distributed in the hope that it will be useful, but 
 12  # WITHOUT ANY WARRANTY; without even the implied warranty of 
 13  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
 14  # General Public License for more details. 
 15  # 
 16  # You should have received a copy of the GNU General Public License 
 17  # along with this program; if not, write to the Free Software 
 18  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
 19  # 02110-1301, USA. 
 20   
 21  """Backup related commands""" 
 22   
 23  # pylint: disable-msg=W0401,W0613,W0614,C0103 
 24  # W0401: Wildcard import ganeti.cli 
 25  # W0613: Unused argument, since all functions follow the same API 
 26  # W0614: Unused import %s from wildcard import (since we need cli) 
 27  # C0103: Invalid name gnt-backup 
 28   
 29  from ganeti.cli import * 
 30  from ganeti import opcodes 
 31  from ganeti import constants 
 32  from ganeti import errors 
 33   
 34   
35 -def PrintExportList(opts, args):
36 """Prints a list of all the exported system images. 37 38 @param opts: the command line options selected by the user 39 @type args: list 40 @param args: should be an empty list 41 @rtype: int 42 @return: the desired exit code 43 44 """ 45 exports = GetClient().QueryExports(opts.nodes, False) 46 retcode = 0 47 for node in exports: 48 ToStdout("Node: %s", node) 49 ToStdout("Exports:") 50 if isinstance(exports[node], list): 51 for instance_name in exports[node]: 52 ToStdout("\t%s", instance_name) 53 else: 54 ToStdout(" Could not get exports list") 55 retcode = 1 56 return retcode
57 58
59 -def ExportInstance(opts, args):
60 """Export an instance to an image in the cluster. 61 62 @param opts: the command line options selected by the user 63 @type args: list 64 @param args: should contain only one element, the name 65 of the instance to be exported 66 @rtype: int 67 @return: the desired exit code 68 69 """ 70 ignore_remove_failures = opts.ignore_remove_failures 71 72 if not opts.node: 73 raise errors.OpPrereqError("Target node must be specified", 74 errors.ECODE_INVAL) 75 76 op = opcodes.OpBackupExport(instance_name=args[0], 77 target_node=opts.node, 78 shutdown=opts.shutdown, 79 shutdown_timeout=opts.shutdown_timeout, 80 remove_instance=opts.remove_instance, 81 ignore_remove_failures=ignore_remove_failures) 82 83 SubmitOpCode(op, opts=opts) 84 return 0
85 86
87 -def ImportInstance(opts, args):
88 """Add an instance to the cluster. 89 90 This is just a wrapper over GenericInstanceCreate. 91 92 """ 93 return GenericInstanceCreate(constants.INSTANCE_IMPORT, opts, args)
94 95
96 -def RemoveExport(opts, args):
97 """Remove an export from the cluster. 98 99 @param opts: the command line options selected by the user 100 @type args: list 101 @param args: should contain only one element, the name of the 102 instance whose backup should be removed 103 @rtype: int 104 @return: the desired exit code 105 106 """ 107 op = opcodes.OpBackupRemove(instance_name=args[0]) 108 109 SubmitOpCode(op, opts=opts) 110 return 0
111 112 113 # this is defined separately due to readability only 114 import_opts = [ 115 IDENTIFY_DEFAULTS_OPT, 116 SRC_DIR_OPT, 117 SRC_NODE_OPT, 118 ] 119 120 121 commands = { 122 'list': ( 123 PrintExportList, ARGS_NONE, 124 [NODE_LIST_OPT], 125 "", "Lists instance exports available in the ganeti cluster"), 126 'export': ( 127 ExportInstance, ARGS_ONE_INSTANCE, 128 [FORCE_OPT, SINGLE_NODE_OPT, NOSHUTDOWN_OPT, SHUTDOWN_TIMEOUT_OPT, 129 REMOVE_INSTANCE_OPT, IGNORE_REMOVE_FAILURES_OPT, DRY_RUN_OPT, 130 PRIORITY_OPT], 131 "-n <target_node> [opts...] <name>", 132 "Exports an instance to an image"), 133 'import': ( 134 ImportInstance, ARGS_ONE_INSTANCE, COMMON_CREATE_OPTS + import_opts, 135 "[...] -t disk-type -n node[:secondary-node] <name>", 136 "Imports an instance from an exported image"), 137 'remove': ( 138 RemoveExport, [ArgUnknown(min=1, max=1)], [DRY_RUN_OPT, PRIORITY_OPT], 139 "<name>", "Remove exports of named instance from the filesystem."), 140 } 141 142
143 -def Main():
144 return GenericMain(commands)
145