root / scripts / gnt-backup @ 2ec08468
History | View | Annotate | Download (5.5 kB)
1 | dd4b1106 | Iustin Pop | #!/usr/bin/python |
---|---|---|---|
2 | dd4b1106 | Iustin Pop | # |
3 | dd4b1106 | Iustin Pop | |
4 | dd4b1106 | Iustin Pop | # Copyright (C) 2006, 2007 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 | dd4b1106 | Iustin Pop | |
22 | dd4b1106 | Iustin Pop | import sys |
23 | dd4b1106 | Iustin Pop | from optparse import make_option |
24 | dd4b1106 | Iustin Pop | |
25 | dd4b1106 | Iustin Pop | from ganeti.cli import * |
26 | dd4b1106 | Iustin Pop | from ganeti import cmdlib |
27 | dd4b1106 | Iustin Pop | from ganeti import opcodes |
28 | dd4b1106 | Iustin Pop | from ganeti import constants |
29 | dd4b1106 | Iustin Pop | |
30 | dd4b1106 | Iustin Pop | def PrintExportList(opts, args): |
31 | dd4b1106 | Iustin Pop | """Prints a list of all the exported system images. |
32 | dd4b1106 | Iustin Pop | |
33 | dd4b1106 | Iustin Pop | Args: |
34 | dd4b1106 | Iustin Pop | opts - class with options as members (should be empty) |
35 | dd4b1106 | Iustin Pop | args - should be empty |
36 | dd4b1106 | Iustin Pop | |
37 | dd4b1106 | Iustin Pop | Returns: |
38 | dd4b1106 | Iustin Pop | nothing |
39 | dd4b1106 | Iustin Pop | |
40 | dd4b1106 | Iustin Pop | """ |
41 | dd4b1106 | Iustin Pop | op = opcodes.OpQueryExports(nodes=opts.nodes) |
42 | dd4b1106 | Iustin Pop | exports = SubmitOpCode(op) |
43 | dd4b1106 | Iustin Pop | for node in exports: |
44 | dd4b1106 | Iustin Pop | print ("Node: %s" % node) |
45 | dd4b1106 | Iustin Pop | print ("Exports:") |
46 | dd4b1106 | Iustin Pop | for instance_name in exports[node]: |
47 | dd4b1106 | Iustin Pop | print ("\t%s" % instance_name) |
48 | dd4b1106 | Iustin Pop | |
49 | dd4b1106 | Iustin Pop | |
50 | dd4b1106 | Iustin Pop | def ExportInstance(opts, args): |
51 | dd4b1106 | Iustin Pop | """Export an instance to an image in the cluster. |
52 | dd4b1106 | Iustin Pop | |
53 | dd4b1106 | Iustin Pop | Args: |
54 | dd4b1106 | Iustin Pop | opts - class with options as members |
55 | dd4b1106 | Iustin Pop | args - list with a single element, the instance name |
56 | dd4b1106 | Iustin Pop | |
57 | dd4b1106 | Iustin Pop | Returns: |
58 | dd4b1106 | Iustin Pop | 1 in case of error, 0 otherwise |
59 | dd4b1106 | Iustin Pop | |
60 | dd4b1106 | Iustin Pop | """ |
61 | dd4b1106 | Iustin Pop | op = opcodes.OpExportInstance(instance_name=args[0], |
62 | dd4b1106 | Iustin Pop | target_node=opts.node, |
63 | dd4b1106 | Iustin Pop | shutdown=opts.shutdown) |
64 | dd4b1106 | Iustin Pop | |
65 | dd4b1106 | Iustin Pop | SubmitOpCode(op) |
66 | dd4b1106 | Iustin Pop | |
67 | dd4b1106 | Iustin Pop | def ImportInstance(opts, args): |
68 | dd4b1106 | Iustin Pop | """Add an instance to the cluster. |
69 | dd4b1106 | Iustin Pop | |
70 | dd4b1106 | Iustin Pop | Args: |
71 | dd4b1106 | Iustin Pop | opts - class with options as members |
72 | dd4b1106 | Iustin Pop | args - list with a single element, the new instance name |
73 | dd4b1106 | Iustin Pop | Opts used: |
74 | dd4b1106 | Iustin Pop | memory - amount of memory to allocate to instance (MiB) |
75 | dd4b1106 | Iustin Pop | size - amount of disk space to allocate to instance (MiB) |
76 | dd4b1106 | Iustin Pop | os - which OS to run on instance |
77 | dd4b1106 | Iustin Pop | node - node to run new instance on |
78 | dd4b1106 | Iustin Pop | src_node - node containing the export |
79 | dd4b1106 | Iustin Pop | src_dir - directory on the old node with the export in it |
80 | dd4b1106 | Iustin Pop | |
81 | dd4b1106 | Iustin Pop | Returns: |
82 | dd4b1106 | Iustin Pop | 1 in case of error, 0 otherwise |
83 | dd4b1106 | Iustin Pop | |
84 | dd4b1106 | Iustin Pop | """ |
85 | dd4b1106 | Iustin Pop | instance = args[0] |
86 | dd4b1106 | Iustin Pop | |
87 | dd4b1106 | Iustin Pop | op = opcodes.OpCreateInstance(instance_name=instance, mem_size=opts.mem, |
88 | dd4b1106 | Iustin Pop | disk_size=opts.size, swap_size=opts.swap, |
89 | dd4b1106 | Iustin Pop | disk_template=opts.disk_template, |
90 | 098c0958 | Michael Hanselmann | mode=constants.INSTANCE_IMPORT, |
91 | 098c0958 | Michael Hanselmann | pnode=opts.node, snode=opts.snode, |
92 | 098c0958 | Michael Hanselmann | vcpus=opts.vcpus, |
93 | dd4b1106 | Iustin Pop | ip=opts.ip, bridge=opts.bridge, start=False, |
94 | dd4b1106 | Iustin Pop | src_node=opts.src_node, src_path=opts.src_dir, |
95 | dd4b1106 | Iustin Pop | wait_for_sync=opts.wait_for_sync) |
96 | dd4b1106 | Iustin Pop | SubmitOpCode(op) |
97 | dd4b1106 | Iustin Pop | return 0 |
98 | dd4b1106 | Iustin Pop | |
99 | dd4b1106 | Iustin Pop | |
100 | dd4b1106 | Iustin Pop | # options used in more than one cmd |
101 | dd4b1106 | Iustin Pop | node_opt = make_option("-n", "--node", dest="node", help="Target node", |
102 | dd4b1106 | Iustin Pop | metavar="<node>") |
103 | dd4b1106 | Iustin Pop | |
104 | dd4b1106 | Iustin Pop | # this is defined separately due to readability only |
105 | dd4b1106 | Iustin Pop | import_opts = [ |
106 | dd4b1106 | Iustin Pop | DEBUG_OPT, |
107 | dd4b1106 | Iustin Pop | node_opt, |
108 | dd4b1106 | Iustin Pop | cli_option("-s", "--os-size", dest="size", help="Disk size", |
109 | dd4b1106 | Iustin Pop | default=20 * 1024, type="unit", metavar="<size>"), |
110 | dd4b1106 | Iustin Pop | cli_option("--swap-size", dest="swap", help="Swap size", |
111 | dd4b1106 | Iustin Pop | default=4 * 1024, type="unit", metavar="<size>"), |
112 | dd4b1106 | Iustin Pop | cli_option("-m", "--memory", dest="mem", help="Memory size", |
113 | dd4b1106 | Iustin Pop | default=128, type="unit", metavar="<mem>"), |
114 | dd4b1106 | Iustin Pop | make_option("-p", "--cpu", dest="vcpus", help="Number of virtual CPUs", |
115 | dd4b1106 | Iustin Pop | default=1, type="int", metavar="<PROC>"), |
116 | dd4b1106 | Iustin Pop | make_option("-t", "--disk-template", dest="disk_template", |
117 | dd4b1106 | Iustin Pop | help="Custom disk setup (diskless, plain, local_raid1 or" |
118 | dd4b1106 | Iustin Pop | " remote_raid1)", default=None, metavar="TEMPL"), |
119 | dd4b1106 | Iustin Pop | make_option("-i", "--ip", dest="ip", |
120 | dd4b1106 | Iustin Pop | help="IP address ('none' [default], 'auto', or specify address)", |
121 | dd4b1106 | Iustin Pop | default='none', type="string", metavar="<ADDRESS>"), |
122 | dd4b1106 | Iustin Pop | make_option("--no-wait-for-sync", dest="wait_for_sync", default=True, |
123 | dd4b1106 | Iustin Pop | action="store_false", help="Don't wait for sync (DANGEROUS!)"), |
124 | dd4b1106 | Iustin Pop | make_option("--secondary-node", dest="snode", |
125 | dd4b1106 | Iustin Pop | help="Secondary node for remote_raid1 disk layout", |
126 | dd4b1106 | Iustin Pop | metavar="<node>"), |
127 | dd4b1106 | Iustin Pop | make_option("-b", "--bridge", dest="bridge", |
128 | dd4b1106 | Iustin Pop | help="Bridge to connect this instance to", |
129 | dd4b1106 | Iustin Pop | default=None, metavar="<bridge>"), |
130 | dd4b1106 | Iustin Pop | make_option("--src-node", dest="src_node", help="Source node", |
131 | dd4b1106 | Iustin Pop | metavar="<node>"), |
132 | dd4b1106 | Iustin Pop | make_option("--src-dir", dest="src_dir", help="Source directory", |
133 | dd4b1106 | Iustin Pop | metavar="<dir>"), |
134 | dd4b1106 | Iustin Pop | ] |
135 | dd4b1106 | Iustin Pop | |
136 | dd4b1106 | Iustin Pop | commands = { |
137 | dd4b1106 | Iustin Pop | 'list': (PrintExportList, ARGS_NONE, |
138 | dd4b1106 | Iustin Pop | [DEBUG_OPT, |
139 | dd4b1106 | Iustin Pop | make_option("--nodes", dest="nodes", default=[], action="append", |
140 | dd4b1106 | Iustin Pop | help="List only backups stored on these nodes"), |
141 | dd4b1106 | Iustin Pop | ], |
142 | dd4b1106 | Iustin Pop | "", "Lists instance exports available in the ganeti cluster"), |
143 | dd4b1106 | Iustin Pop | 'export': (ExportInstance, ARGS_ONE, |
144 | fe7b0351 | Michael Hanselmann | [node_opt, DEBUG_OPT, FORCE_OPT, |
145 | dd4b1106 | Iustin Pop | make_option("","--noshutdown", dest="shutdown", |
146 | dd4b1106 | Iustin Pop | action="store_false", default=True, |
147 | dd4b1106 | Iustin Pop | help="Don't shutdown the instance (unsafe)"), ], |
148 | dd4b1106 | Iustin Pop | "[opts...] <name>", |
149 | dd4b1106 | Iustin Pop | "Exports an instance to an image"), |
150 | dd4b1106 | Iustin Pop | 'import': (ImportInstance, ARGS_ONE, import_opts, "[opts...] <name>", |
151 | dd4b1106 | Iustin Pop | "Imports an instance from an exported image"), |
152 | dd4b1106 | Iustin Pop | } |
153 | dd4b1106 | Iustin Pop | |
154 | dd4b1106 | Iustin Pop | if __name__ == '__main__': |
155 | 3ecf6786 | Iustin Pop | sys.exit(GenericMain(commands)) |