root / scripts / gnt-instance @ 1f05af2b
History | View | Annotate | Download (38.8 kB)
1 | a8083063 | Iustin Pop | #!/usr/bin/python |
---|---|---|---|
2 | a8083063 | Iustin Pop | # |
3 | a8083063 | Iustin Pop | |
4 | a8083063 | Iustin Pop | # Copyright (C) 2006, 2007 Google Inc. |
5 | a8083063 | Iustin Pop | # |
6 | a8083063 | Iustin Pop | # This program is free software; you can redistribute it and/or modify |
7 | a8083063 | Iustin Pop | # it under the terms of the GNU General Public License as published by |
8 | a8083063 | Iustin Pop | # the Free Software Foundation; either version 2 of the License, or |
9 | a8083063 | Iustin Pop | # (at your option) any later version. |
10 | a8083063 | Iustin Pop | # |
11 | a8083063 | Iustin Pop | # This program is distributed in the hope that it will be useful, but |
12 | a8083063 | Iustin Pop | # WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | a8083063 | Iustin Pop | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | a8083063 | Iustin Pop | # General Public License for more details. |
15 | a8083063 | Iustin Pop | # |
16 | a8083063 | Iustin Pop | # You should have received a copy of the GNU General Public License |
17 | a8083063 | Iustin Pop | # along with this program; if not, write to the Free Software |
18 | a8083063 | Iustin Pop | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
19 | a8083063 | Iustin Pop | # 02110-1301, USA. |
20 | a8083063 | Iustin Pop | |
21 | a8083063 | Iustin Pop | |
22 | a8083063 | Iustin Pop | import sys |
23 | a8083063 | Iustin Pop | import os |
24 | 312ac745 | Iustin Pop | import itertools |
25 | a8083063 | Iustin Pop | from optparse import make_option |
26 | a8083063 | Iustin Pop | from cStringIO import StringIO |
27 | a8083063 | Iustin Pop | |
28 | a8083063 | Iustin Pop | from ganeti.cli import * |
29 | a8083063 | Iustin Pop | from ganeti import opcodes |
30 | a8083063 | Iustin Pop | from ganeti import logger |
31 | a8083063 | Iustin Pop | from ganeti import constants |
32 | a8083063 | Iustin Pop | from ganeti import utils |
33 | 312ac745 | Iustin Pop | from ganeti import errors |
34 | 312ac745 | Iustin Pop | |
35 | 312ac745 | Iustin Pop | |
36 | 312ac745 | Iustin Pop | _SHUTDOWN_CLUSTER = "cluster" |
37 | 312ac745 | Iustin Pop | _SHUTDOWN_NODES_BOTH = "nodes" |
38 | 312ac745 | Iustin Pop | _SHUTDOWN_NODES_PRI = "nodes-pri" |
39 | 312ac745 | Iustin Pop | _SHUTDOWN_NODES_SEC = "nodes-sec" |
40 | 312ac745 | Iustin Pop | _SHUTDOWN_INSTANCES = "instances" |
41 | 312ac745 | Iustin Pop | |
42 | 7c0d6283 | Michael Hanselmann | |
43 | 31a853d2 | Iustin Pop | _VALUE_TRUE = "true" |
44 | 31a853d2 | Iustin Pop | |
45 | 48c4dfa8 | Iustin Pop | _LIST_DEF_FIELDS = [ |
46 | 48c4dfa8 | Iustin Pop | "name", "os", "pnode", "status", "oper_ram", |
47 | 48c4dfa8 | Iustin Pop | ] |
48 | 48c4dfa8 | Iustin Pop | |
49 | bdb7d4e8 | Michael Hanselmann | |
50 | 312ac745 | Iustin Pop | def _ExpandMultiNames(mode, names): |
51 | 312ac745 | Iustin Pop | """Expand the given names using the passed mode. |
52 | 312ac745 | Iustin Pop | |
53 | 312ac745 | Iustin Pop | Args: |
54 | 312ac745 | Iustin Pop | - mode, which can be one of _SHUTDOWN_CLUSTER, _SHUTDOWN_NODES_BOTH, |
55 | 312ac745 | Iustin Pop | _SHUTDOWN_NODES_PRI, _SHUTDOWN_NODES_SEC or _SHUTDOWN_INSTANCES |
56 | 312ac745 | Iustin Pop | - names, which is a list of names; for cluster, it must be empty, |
57 | 312ac745 | Iustin Pop | and for node and instance it must be a list of valid item |
58 | 312ac745 | Iustin Pop | names (short names are valid as usual, e.g. node1 instead of |
59 | 312ac745 | Iustin Pop | node1.example.com) |
60 | 312ac745 | Iustin Pop | |
61 | 312ac745 | Iustin Pop | For _SHUTDOWN_CLUSTER, all instances will be returned. For |
62 | 312ac745 | Iustin Pop | _SHUTDOWN_NODES_PRI/SEC, all instances having those nodes as |
63 | 312ac745 | Iustin Pop | primary/secondary will be shutdown. For _SHUTDOWN_NODES_BOTH, all |
64 | 312ac745 | Iustin Pop | instances having those nodes as either primary or secondary will be |
65 | 312ac745 | Iustin Pop | returned. For _SHUTDOWN_INSTANCES, the given instances will be |
66 | 312ac745 | Iustin Pop | returned. |
67 | 312ac745 | Iustin Pop | |
68 | 312ac745 | Iustin Pop | """ |
69 | 312ac745 | Iustin Pop | if mode == _SHUTDOWN_CLUSTER: |
70 | 312ac745 | Iustin Pop | if names: |
71 | 312ac745 | Iustin Pop | raise errors.OpPrereqError("Cluster filter mode takes no arguments") |
72 | 312ac745 | Iustin Pop | op = opcodes.OpQueryInstances(output_fields=["name"], names=[]) |
73 | 312ac745 | Iustin Pop | idata = SubmitOpCode(op) |
74 | 312ac745 | Iustin Pop | inames = [row[0] for row in idata] |
75 | 312ac745 | Iustin Pop | |
76 | 312ac745 | Iustin Pop | elif mode in (_SHUTDOWN_NODES_BOTH, |
77 | 312ac745 | Iustin Pop | _SHUTDOWN_NODES_PRI, |
78 | 312ac745 | Iustin Pop | _SHUTDOWN_NODES_SEC): |
79 | 312ac745 | Iustin Pop | if not names: |
80 | 312ac745 | Iustin Pop | raise errors.OpPrereqError("No node names passed") |
81 | 312ac745 | Iustin Pop | op = opcodes.OpQueryNodes(output_fields=["name", "pinst_list", |
82 | 312ac745 | Iustin Pop | "sinst_list"], names=names) |
83 | 312ac745 | Iustin Pop | ndata = SubmitOpCode(op) |
84 | 312ac745 | Iustin Pop | ipri = [row[1] for row in ndata] |
85 | 312ac745 | Iustin Pop | pri_names = list(itertools.chain(*ipri)) |
86 | 312ac745 | Iustin Pop | isec = [row[2] for row in ndata] |
87 | 312ac745 | Iustin Pop | sec_names = list(itertools.chain(*isec)) |
88 | 312ac745 | Iustin Pop | if mode == _SHUTDOWN_NODES_BOTH: |
89 | 312ac745 | Iustin Pop | inames = pri_names + sec_names |
90 | 312ac745 | Iustin Pop | elif mode == _SHUTDOWN_NODES_PRI: |
91 | 312ac745 | Iustin Pop | inames = pri_names |
92 | 312ac745 | Iustin Pop | elif mode == _SHUTDOWN_NODES_SEC: |
93 | 312ac745 | Iustin Pop | inames = sec_names |
94 | 312ac745 | Iustin Pop | else: |
95 | 312ac745 | Iustin Pop | raise errors.ProgrammerError("Unhandled shutdown type") |
96 | 312ac745 | Iustin Pop | |
97 | 312ac745 | Iustin Pop | elif mode == _SHUTDOWN_INSTANCES: |
98 | 312ac745 | Iustin Pop | if not names: |
99 | 312ac745 | Iustin Pop | raise errors.OpPrereqError("No instance names passed") |
100 | 312ac745 | Iustin Pop | op = opcodes.OpQueryInstances(output_fields=["name"], names=names) |
101 | 312ac745 | Iustin Pop | idata = SubmitOpCode(op) |
102 | 312ac745 | Iustin Pop | inames = [row[0] for row in idata] |
103 | 312ac745 | Iustin Pop | |
104 | 312ac745 | Iustin Pop | else: |
105 | 312ac745 | Iustin Pop | raise errors.OpPrereqError("Unknown mode '%s'" % mode) |
106 | 312ac745 | Iustin Pop | |
107 | 312ac745 | Iustin Pop | return inames |
108 | a8083063 | Iustin Pop | |
109 | a8083063 | Iustin Pop | |
110 | 804a1e8e | Iustin Pop | def _ConfirmOperation(inames, text): |
111 | 804a1e8e | Iustin Pop | """Ask the user to confirm an operation on a list of instances. |
112 | 804a1e8e | Iustin Pop | |
113 | 804a1e8e | Iustin Pop | This function is used to request confirmation for doing an operation |
114 | 804a1e8e | Iustin Pop | on a given list of instances. |
115 | 804a1e8e | Iustin Pop | |
116 | 804a1e8e | Iustin Pop | The inames argument is what the selection algorithm computed, and |
117 | 804a1e8e | Iustin Pop | the text argument is the operation we should tell the user to |
118 | 804a1e8e | Iustin Pop | confirm (e.g. 'shutdown' or 'startup'). |
119 | 804a1e8e | Iustin Pop | |
120 | 804a1e8e | Iustin Pop | Returns: boolean depending on user's confirmation. |
121 | 804a1e8e | Iustin Pop | |
122 | 804a1e8e | Iustin Pop | """ |
123 | 804a1e8e | Iustin Pop | count = len(inames) |
124 | 804a1e8e | Iustin Pop | msg = ("The %s will operate on %d instances.\n" |
125 | 804a1e8e | Iustin Pop | "Do you want to continue?" % (text, count)) |
126 | 804a1e8e | Iustin Pop | affected = ("\nAffected instances:\n" + |
127 | 804a1e8e | Iustin Pop | "\n".join([" %s" % name for name in inames])) |
128 | 804a1e8e | Iustin Pop | |
129 | 804a1e8e | Iustin Pop | choices = [('y', True, 'Yes, execute the %s' % text), |
130 | 804a1e8e | Iustin Pop | ('n', False, 'No, abort the %s' % text)] |
131 | 804a1e8e | Iustin Pop | |
132 | 804a1e8e | Iustin Pop | if count > 20: |
133 | 804a1e8e | Iustin Pop | choices.insert(1, ('v', 'v', 'View the list of affected instances')) |
134 | 804a1e8e | Iustin Pop | ask = msg |
135 | 804a1e8e | Iustin Pop | else: |
136 | 804a1e8e | Iustin Pop | ask = msg + affected |
137 | 804a1e8e | Iustin Pop | |
138 | 804a1e8e | Iustin Pop | choice = AskUser(ask, choices) |
139 | 804a1e8e | Iustin Pop | if choice == 'v': |
140 | 804a1e8e | Iustin Pop | choices.pop(1) |
141 | 5e66b7e6 | Iustin Pop | choice = AskUser(msg + affected, choices) |
142 | 804a1e8e | Iustin Pop | return choice |
143 | 804a1e8e | Iustin Pop | |
144 | 804a1e8e | Iustin Pop | |
145 | 973d7867 | Iustin Pop | def _TransformPath(user_input): |
146 | 973d7867 | Iustin Pop | """Transform a user path into a canonical value. |
147 | 973d7867 | Iustin Pop | |
148 | 973d7867 | Iustin Pop | This function transforms the a path passed as textual information |
149 | 973d7867 | Iustin Pop | into the constants that the LU code expects. |
150 | 973d7867 | Iustin Pop | |
151 | 973d7867 | Iustin Pop | """ |
152 | 973d7867 | Iustin Pop | if user_input: |
153 | 973d7867 | Iustin Pop | if user_input.lower() == "default": |
154 | 973d7867 | Iustin Pop | result_path = constants.VALUE_DEFAULT |
155 | 973d7867 | Iustin Pop | elif user_input.lower() == "none": |
156 | 973d7867 | Iustin Pop | result_path = constants.VALUE_NONE |
157 | 973d7867 | Iustin Pop | else: |
158 | 973d7867 | Iustin Pop | if not os.path.isabs(user_input): |
159 | 973d7867 | Iustin Pop | raise errors.OpPrereqError("Path '%s' is not an absolute filename" % |
160 | 973d7867 | Iustin Pop | user_input) |
161 | 973d7867 | Iustin Pop | result_path = user_input |
162 | 973d7867 | Iustin Pop | else: |
163 | 973d7867 | Iustin Pop | result_path = constants.VALUE_DEFAULT |
164 | 973d7867 | Iustin Pop | |
165 | 973d7867 | Iustin Pop | return result_path |
166 | 973d7867 | Iustin Pop | |
167 | 973d7867 | Iustin Pop | |
168 | a8083063 | Iustin Pop | def ListInstances(opts, args): |
169 | f5abe9bd | Oleksiy Mishchenko | """List instances and their properties. |
170 | a8083063 | Iustin Pop | |
171 | a8083063 | Iustin Pop | """ |
172 | a8083063 | Iustin Pop | if opts.output is None: |
173 | 48c4dfa8 | Iustin Pop | selected_fields = _LIST_DEF_FIELDS |
174 | 48c4dfa8 | Iustin Pop | elif opts.output.startswith("+"): |
175 | 48c4dfa8 | Iustin Pop | selected_fields = _LIST_DEF_FIELDS + opts.output[1:].split(",") |
176 | a8083063 | Iustin Pop | else: |
177 | a8083063 | Iustin Pop | selected_fields = opts.output.split(",") |
178 | a8083063 | Iustin Pop | |
179 | 1f05af2b | Michael Hanselmann | output = GetClient().QueryInstances([], selected_fields) |
180 | a8083063 | Iustin Pop | |
181 | a8083063 | Iustin Pop | if not opts.no_headers: |
182 | d8052456 | Iustin Pop | headers = { |
183 | d8052456 | Iustin Pop | "name": "Instance", "os": "OS", "pnode": "Primary_node", |
184 | d8052456 | Iustin Pop | "snodes": "Secondary_Nodes", "admin_state": "Autostart", |
185 | d8052456 | Iustin Pop | "oper_state": "Running", "admin_ram": "Configured_memory", |
186 | d8052456 | Iustin Pop | "oper_ram": "Memory", "disk_template": "Disk_template", |
187 | d8052456 | Iustin Pop | "ip": "IP Address", "mac": "MAC Address", |
188 | d8052456 | Iustin Pop | "bridge": "Bridge", "vcpus": "VCPUs", |
189 | d8052456 | Iustin Pop | "sda_size": "Disk/0", "sdb_size": "Disk/1", |
190 | 130a6a6f | Iustin Pop | "status": "Status", "tags": "Tags", |
191 | d8052456 | Iustin Pop | } |
192 | 137161c9 | Michael Hanselmann | else: |
193 | 137161c9 | Michael Hanselmann | headers = None |
194 | 137161c9 | Michael Hanselmann | |
195 | 137161c9 | Michael Hanselmann | if opts.human_readable: |
196 | 644eeef9 | Iustin Pop | unitfields = ["admin_ram", "oper_ram", "sda_size", "sdb_size"] |
197 | 137161c9 | Michael Hanselmann | else: |
198 | 137161c9 | Michael Hanselmann | unitfields = None |
199 | 137161c9 | Michael Hanselmann | |
200 | d6d415e8 | Iustin Pop | numfields = ["admin_ram", "oper_ram", "sda_size", "sdb_size", "vcpus"] |
201 | 137161c9 | Michael Hanselmann | |
202 | 130a6a6f | Iustin Pop | list_type_fields = ("tags",) |
203 | 8a23d2d3 | Iustin Pop | # change raw values to nicer strings |
204 | 8a23d2d3 | Iustin Pop | for row in output: |
205 | 8a23d2d3 | Iustin Pop | for idx, field in enumerate(selected_fields): |
206 | 8a23d2d3 | Iustin Pop | val = row[idx] |
207 | 8a23d2d3 | Iustin Pop | if field == "snodes": |
208 | 8a23d2d3 | Iustin Pop | val = ",".join(val) or "-" |
209 | 8a23d2d3 | Iustin Pop | elif field == "admin_state": |
210 | 8a23d2d3 | Iustin Pop | if val: |
211 | 8a23d2d3 | Iustin Pop | val = "yes" |
212 | 8a23d2d3 | Iustin Pop | else: |
213 | 8a23d2d3 | Iustin Pop | val = "no" |
214 | 8a23d2d3 | Iustin Pop | elif field == "oper_state": |
215 | 8a23d2d3 | Iustin Pop | if val is None: |
216 | 8a23d2d3 | Iustin Pop | val = "(node down)" |
217 | 8a23d2d3 | Iustin Pop | elif val: # True |
218 | 8a23d2d3 | Iustin Pop | val = "running" |
219 | 8a23d2d3 | Iustin Pop | else: |
220 | 8a23d2d3 | Iustin Pop | val = "stopped" |
221 | 8a23d2d3 | Iustin Pop | elif field == "oper_ram": |
222 | 8a23d2d3 | Iustin Pop | if val is None: |
223 | 8a23d2d3 | Iustin Pop | val = "(node down)" |
224 | 8a23d2d3 | Iustin Pop | elif field == "sda_size" or field == "sdb_size": |
225 | 8a23d2d3 | Iustin Pop | if val is None: |
226 | 8a23d2d3 | Iustin Pop | val = "N/A" |
227 | 130a6a6f | Iustin Pop | elif field in list_type_fields: |
228 | 130a6a6f | Iustin Pop | val = ",".join(val) |
229 | 8a23d2d3 | Iustin Pop | row[idx] = str(val) |
230 | 8a23d2d3 | Iustin Pop | |
231 | 16be8703 | Iustin Pop | data = GenerateTable(separator=opts.separator, headers=headers, |
232 | 16be8703 | Iustin Pop | fields=selected_fields, unitfields=unitfields, |
233 | 16be8703 | Iustin Pop | numfields=numfields, data=output) |
234 | 16be8703 | Iustin Pop | |
235 | 16be8703 | Iustin Pop | for line in data: |
236 | 16be8703 | Iustin Pop | logger.ToStdout(line) |
237 | a8083063 | Iustin Pop | |
238 | a8083063 | Iustin Pop | return 0 |
239 | a8083063 | Iustin Pop | |
240 | a8083063 | Iustin Pop | |
241 | a8083063 | Iustin Pop | def AddInstance(opts, args): |
242 | a8083063 | Iustin Pop | """Add an instance to the cluster. |
243 | a8083063 | Iustin Pop | |
244 | a8083063 | Iustin Pop | Args: |
245 | a8083063 | Iustin Pop | opts - class with options as members |
246 | a8083063 | Iustin Pop | args - list with a single element, the instance name |
247 | a8083063 | Iustin Pop | Opts used: |
248 | a8083063 | Iustin Pop | mem - amount of memory to allocate to instance (MiB) |
249 | a8083063 | Iustin Pop | size - amount of disk space to allocate to instance (MiB) |
250 | a8083063 | Iustin Pop | os - which OS to run on instance |
251 | a8083063 | Iustin Pop | node - node to run new instance on |
252 | a8083063 | Iustin Pop | |
253 | a8083063 | Iustin Pop | """ |
254 | a8083063 | Iustin Pop | instance = args[0] |
255 | a8083063 | Iustin Pop | |
256 | 60d49723 | Michael Hanselmann | (pnode, snode) = SplitNodeOption(opts.node) |
257 | 60d49723 | Michael Hanselmann | |
258 | 3b6d8c9b | Iustin Pop | kernel_path = _TransformPath(opts.kernel_path) |
259 | 3b6d8c9b | Iustin Pop | initrd_path = _TransformPath(opts.initrd_path) |
260 | 3b6d8c9b | Iustin Pop | |
261 | 31a853d2 | Iustin Pop | hvm_acpi = opts.hvm_acpi == _VALUE_TRUE |
262 | 31a853d2 | Iustin Pop | hvm_pae = opts.hvm_pae == _VALUE_TRUE |
263 | 31a853d2 | Iustin Pop | |
264 | 31a853d2 | Iustin Pop | if ((opts.hvm_cdrom_image_path is not None) and |
265 | 31a853d2 | Iustin Pop | (opts.hvm_cdrom_image_path.lower() == constants.VALUE_NONE)): |
266 | 31a853d2 | Iustin Pop | hvm_cdrom_image_path = None |
267 | 31a853d2 | Iustin Pop | else: |
268 | 31a853d2 | Iustin Pop | hvm_cdrom_image_path = opts.hvm_cdrom_image_path |
269 | 31a853d2 | Iustin Pop | |
270 | a8083063 | Iustin Pop | op = opcodes.OpCreateInstance(instance_name=instance, mem_size=opts.mem, |
271 | a8083063 | Iustin Pop | disk_size=opts.size, swap_size=opts.swap, |
272 | a8083063 | Iustin Pop | disk_template=opts.disk_template, |
273 | a8083063 | Iustin Pop | mode=constants.INSTANCE_CREATE, |
274 | 60d49723 | Michael Hanselmann | os_type=opts.os, pnode=pnode, |
275 | 60d49723 | Michael Hanselmann | snode=snode, vcpus=opts.vcpus, |
276 | bdd55f71 | Iustin Pop | ip=opts.ip, bridge=opts.bridge, |
277 | bdd55f71 | Iustin Pop | start=opts.start, ip_check=opts.ip_check, |
278 | 3b6d8c9b | Iustin Pop | wait_for_sync=opts.wait_for_sync, |
279 | 3b6d8c9b | Iustin Pop | mac=opts.mac, |
280 | 3b6d8c9b | Iustin Pop | kernel_path=kernel_path, |
281 | 25c5878d | Alexander Schreiber | initrd_path=initrd_path, |
282 | 31a853d2 | Iustin Pop | iallocator=opts.iallocator, |
283 | 45873083 | Manuel Franceschini | hvm_boot_order=opts.hvm_boot_order, |
284 | 35a0d128 | Iustin Pop | file_storage_dir=opts.file_storage_dir, |
285 | 35a0d128 | Iustin Pop | file_driver=opts.file_driver, |
286 | 31a853d2 | Iustin Pop | hvm_acpi=hvm_acpi, hvm_pae=hvm_pae, |
287 | 31a853d2 | Iustin Pop | hvm_cdrom_image_path=hvm_cdrom_image_path, |
288 | 31a853d2 | Iustin Pop | vnc_bind_address=opts.vnc_bind_address) |
289 | 31a853d2 | Iustin Pop | |
290 | a8083063 | Iustin Pop | SubmitOpCode(op) |
291 | a8083063 | Iustin Pop | return 0 |
292 | a8083063 | Iustin Pop | |
293 | a8083063 | Iustin Pop | |
294 | fe7b0351 | Michael Hanselmann | def ReinstallInstance(opts, args): |
295 | fe7b0351 | Michael Hanselmann | """Reinstall an instance. |
296 | fe7b0351 | Michael Hanselmann | |
297 | fe7b0351 | Michael Hanselmann | Args: |
298 | fe7b0351 | Michael Hanselmann | opts - class with options as members |
299 | fe7b0351 | Michael Hanselmann | args - list containing a single element, the instance name |
300 | fe7b0351 | Michael Hanselmann | |
301 | fe7b0351 | Michael Hanselmann | """ |
302 | fe7b0351 | Michael Hanselmann | instance_name = args[0] |
303 | fe7b0351 | Michael Hanselmann | |
304 | fe7b0351 | Michael Hanselmann | if not opts.force: |
305 | f4bc1f2c | Michael Hanselmann | usertext = ("This will reinstall the instance %s and remove" |
306 | f4bc1f2c | Michael Hanselmann | " all data. Continue?") % instance_name |
307 | 47988778 | Iustin Pop | if not AskUser(usertext): |
308 | fe7b0351 | Michael Hanselmann | return 1 |
309 | fe7b0351 | Michael Hanselmann | |
310 | d0834de3 | Michael Hanselmann | op = opcodes.OpReinstallInstance(instance_name=instance_name, |
311 | d0834de3 | Michael Hanselmann | os_type=opts.os) |
312 | fe7b0351 | Michael Hanselmann | SubmitOpCode(op) |
313 | fe7b0351 | Michael Hanselmann | |
314 | fe7b0351 | Michael Hanselmann | return 0 |
315 | fe7b0351 | Michael Hanselmann | |
316 | fe7b0351 | Michael Hanselmann | |
317 | a8083063 | Iustin Pop | def RemoveInstance(opts, args): |
318 | a8083063 | Iustin Pop | """Remove an instance. |
319 | a8083063 | Iustin Pop | |
320 | a8083063 | Iustin Pop | Args: |
321 | a8083063 | Iustin Pop | opts - class with options as members |
322 | a8083063 | Iustin Pop | args - list containing a single element, the instance name |
323 | a8083063 | Iustin Pop | |
324 | a8083063 | Iustin Pop | """ |
325 | a8083063 | Iustin Pop | instance_name = args[0] |
326 | a8083063 | Iustin Pop | force = opts.force |
327 | a8083063 | Iustin Pop | |
328 | a8083063 | Iustin Pop | if not force: |
329 | a8083063 | Iustin Pop | usertext = ("This will remove the volumes of the instance %s" |
330 | a8083063 | Iustin Pop | " (including mirrors), thus removing all the data" |
331 | a8083063 | Iustin Pop | " of the instance. Continue?") % instance_name |
332 | 47988778 | Iustin Pop | if not AskUser(usertext): |
333 | a8083063 | Iustin Pop | return 1 |
334 | a8083063 | Iustin Pop | |
335 | 1d67656e | Iustin Pop | op = opcodes.OpRemoveInstance(instance_name=instance_name, |
336 | 1d67656e | Iustin Pop | ignore_failures=opts.ignore_failures) |
337 | a8083063 | Iustin Pop | SubmitOpCode(op) |
338 | a8083063 | Iustin Pop | return 0 |
339 | a8083063 | Iustin Pop | |
340 | a8083063 | Iustin Pop | |
341 | decd5f45 | Iustin Pop | def RenameInstance(opts, args): |
342 | 4ab0b9e3 | Guido Trotter | """Rename an instance. |
343 | decd5f45 | Iustin Pop | |
344 | decd5f45 | Iustin Pop | Args: |
345 | decd5f45 | Iustin Pop | opts - class with options as members |
346 | decd5f45 | Iustin Pop | args - list containing two elements, the instance name and the new name |
347 | decd5f45 | Iustin Pop | |
348 | decd5f45 | Iustin Pop | """ |
349 | decd5f45 | Iustin Pop | op = opcodes.OpRenameInstance(instance_name=args[0], |
350 | decd5f45 | Iustin Pop | new_name=args[1], |
351 | decd5f45 | Iustin Pop | ignore_ip=opts.ignore_ip) |
352 | decd5f45 | Iustin Pop | SubmitOpCode(op) |
353 | decd5f45 | Iustin Pop | |
354 | decd5f45 | Iustin Pop | return 0 |
355 | decd5f45 | Iustin Pop | |
356 | decd5f45 | Iustin Pop | |
357 | a8083063 | Iustin Pop | def ActivateDisks(opts, args): |
358 | a8083063 | Iustin Pop | """Activate an instance's disks. |
359 | a8083063 | Iustin Pop | |
360 | a8083063 | Iustin Pop | This serves two purposes: |
361 | a8083063 | Iustin Pop | - it allows one (as long as the instance is not running) to mount |
362 | a8083063 | Iustin Pop | the disks and modify them from the node |
363 | a8083063 | Iustin Pop | - it repairs inactive secondary drbds |
364 | a8083063 | Iustin Pop | |
365 | a8083063 | Iustin Pop | """ |
366 | a8083063 | Iustin Pop | instance_name = args[0] |
367 | a8083063 | Iustin Pop | op = opcodes.OpActivateInstanceDisks(instance_name=instance_name) |
368 | a8083063 | Iustin Pop | disks_info = SubmitOpCode(op) |
369 | a8083063 | Iustin Pop | for host, iname, nname in disks_info: |
370 | a8083063 | Iustin Pop | print "%s:%s:%s" % (host, iname, nname) |
371 | a8083063 | Iustin Pop | return 0 |
372 | a8083063 | Iustin Pop | |
373 | a8083063 | Iustin Pop | |
374 | a8083063 | Iustin Pop | def DeactivateDisks(opts, args): |
375 | a8083063 | Iustin Pop | """Command-line interface for _ShutdownInstanceBlockDevices. |
376 | a8083063 | Iustin Pop | |
377 | a8083063 | Iustin Pop | This function takes the instance name, looks for its primary node |
378 | a8083063 | Iustin Pop | and the tries to shutdown its block devices on that node. |
379 | a8083063 | Iustin Pop | |
380 | a8083063 | Iustin Pop | """ |
381 | a8083063 | Iustin Pop | instance_name = args[0] |
382 | a8083063 | Iustin Pop | op = opcodes.OpDeactivateInstanceDisks(instance_name=instance_name) |
383 | a8083063 | Iustin Pop | SubmitOpCode(op) |
384 | a8083063 | Iustin Pop | return 0 |
385 | a8083063 | Iustin Pop | |
386 | a8083063 | Iustin Pop | |
387 | c6e911bc | Iustin Pop | def GrowDisk(opts, args): |
388 | c6e911bc | Iustin Pop | """Command-line interface for _ShutdownInstanceBlockDevices. |
389 | c6e911bc | Iustin Pop | |
390 | c6e911bc | Iustin Pop | This function takes the instance name, looks for its primary node |
391 | c6e911bc | Iustin Pop | and the tries to shutdown its block devices on that node. |
392 | c6e911bc | Iustin Pop | |
393 | c6e911bc | Iustin Pop | """ |
394 | c6e911bc | Iustin Pop | instance = args[0] |
395 | c6e911bc | Iustin Pop | disk = args[1] |
396 | c6e911bc | Iustin Pop | amount = utils.ParseUnit(args[2]) |
397 | c6e911bc | Iustin Pop | op = opcodes.OpGrowDisk(instance_name=instance, disk=disk, amount=amount) |
398 | c6e911bc | Iustin Pop | SubmitOpCode(op) |
399 | c6e911bc | Iustin Pop | return 0 |
400 | c6e911bc | Iustin Pop | |
401 | c6e911bc | Iustin Pop | |
402 | a8083063 | Iustin Pop | def StartupInstance(opts, args): |
403 | decd5f45 | Iustin Pop | """Startup an instance. |
404 | a8083063 | Iustin Pop | |
405 | a8083063 | Iustin Pop | Args: |
406 | a8083063 | Iustin Pop | opts - class with options as members |
407 | a8083063 | Iustin Pop | args - list containing a single element, the instance name |
408 | a8083063 | Iustin Pop | |
409 | a8083063 | Iustin Pop | """ |
410 | 312ac745 | Iustin Pop | if opts.multi_mode is None: |
411 | 312ac745 | Iustin Pop | opts.multi_mode = _SHUTDOWN_INSTANCES |
412 | 312ac745 | Iustin Pop | inames = _ExpandMultiNames(opts.multi_mode, args) |
413 | bcee9cb4 | Iustin Pop | if not inames: |
414 | bcee9cb4 | Iustin Pop | raise errors.OpPrereqError("Selection filter does not match any instances") |
415 | 804a1e8e | Iustin Pop | multi_on = opts.multi_mode != _SHUTDOWN_INSTANCES or len(inames) > 1 |
416 | 804a1e8e | Iustin Pop | if not (opts.force_multi or not multi_on |
417 | 804a1e8e | Iustin Pop | or _ConfirmOperation(inames, "startup")): |
418 | 804a1e8e | Iustin Pop | return 1 |
419 | 312ac745 | Iustin Pop | for name in inames: |
420 | 312ac745 | Iustin Pop | op = opcodes.OpStartupInstance(instance_name=name, |
421 | 312ac745 | Iustin Pop | force=opts.force, |
422 | 312ac745 | Iustin Pop | extra_args=opts.extra_args) |
423 | 312ac745 | Iustin Pop | if multi_on: |
424 | 312ac745 | Iustin Pop | logger.ToStdout("Starting up %s" % name) |
425 | 312ac745 | Iustin Pop | SubmitOpCode(op) |
426 | a8083063 | Iustin Pop | return 0 |
427 | a8083063 | Iustin Pop | |
428 | 7c0d6283 | Michael Hanselmann | |
429 | 579d4337 | Alexander Schreiber | def RebootInstance(opts, args): |
430 | 579d4337 | Alexander Schreiber | """Reboot an instance |
431 | 579d4337 | Alexander Schreiber | |
432 | 579d4337 | Alexander Schreiber | Args: |
433 | 579d4337 | Alexander Schreiber | opts - class with options as members |
434 | 579d4337 | Alexander Schreiber | args - list containing a single element, the instance name |
435 | 579d4337 | Alexander Schreiber | |
436 | 579d4337 | Alexander Schreiber | """ |
437 | 579d4337 | Alexander Schreiber | if opts.multi_mode is None: |
438 | 579d4337 | Alexander Schreiber | opts.multi_mode = _SHUTDOWN_INSTANCES |
439 | 579d4337 | Alexander Schreiber | inames = _ExpandMultiNames(opts.multi_mode, args) |
440 | bcee9cb4 | Iustin Pop | if not inames: |
441 | bcee9cb4 | Iustin Pop | raise errors.OpPrereqError("Selection filter does not match any instances") |
442 | 579d4337 | Alexander Schreiber | multi_on = opts.multi_mode != _SHUTDOWN_INSTANCES or len(inames) > 1 |
443 | 579d4337 | Alexander Schreiber | if not (opts.force_multi or not multi_on |
444 | 579d4337 | Alexander Schreiber | or _ConfirmOperation(inames, "reboot")): |
445 | 579d4337 | Alexander Schreiber | return 1 |
446 | 579d4337 | Alexander Schreiber | for name in inames: |
447 | 579d4337 | Alexander Schreiber | op = opcodes.OpRebootInstance(instance_name=name, |
448 | 579d4337 | Alexander Schreiber | reboot_type=opts.reboot_type, |
449 | 579d4337 | Alexander Schreiber | ignore_secondaries=opts.ignore_secondaries) |
450 | 579d4337 | Alexander Schreiber | |
451 | 579d4337 | Alexander Schreiber | SubmitOpCode(op) |
452 | 579d4337 | Alexander Schreiber | return 0 |
453 | a8083063 | Iustin Pop | |
454 | 7c0d6283 | Michael Hanselmann | |
455 | a8083063 | Iustin Pop | def ShutdownInstance(opts, args): |
456 | a8083063 | Iustin Pop | """Shutdown an instance. |
457 | a8083063 | Iustin Pop | |
458 | a8083063 | Iustin Pop | Args: |
459 | a8083063 | Iustin Pop | opts - class with options as members |
460 | a8083063 | Iustin Pop | args - list containing a single element, the instance name |
461 | a8083063 | Iustin Pop | |
462 | a8083063 | Iustin Pop | """ |
463 | 312ac745 | Iustin Pop | if opts.multi_mode is None: |
464 | 312ac745 | Iustin Pop | opts.multi_mode = _SHUTDOWN_INSTANCES |
465 | 312ac745 | Iustin Pop | inames = _ExpandMultiNames(opts.multi_mode, args) |
466 | bcee9cb4 | Iustin Pop | if not inames: |
467 | bcee9cb4 | Iustin Pop | raise errors.OpPrereqError("Selection filter does not match any instances") |
468 | 804a1e8e | Iustin Pop | multi_on = opts.multi_mode != _SHUTDOWN_INSTANCES or len(inames) > 1 |
469 | 804a1e8e | Iustin Pop | if not (opts.force_multi or not multi_on |
470 | 804a1e8e | Iustin Pop | or _ConfirmOperation(inames, "shutdown")): |
471 | 804a1e8e | Iustin Pop | return 1 |
472 | 312ac745 | Iustin Pop | for name in inames: |
473 | 312ac745 | Iustin Pop | op = opcodes.OpShutdownInstance(instance_name=name) |
474 | 312ac745 | Iustin Pop | if multi_on: |
475 | 312ac745 | Iustin Pop | logger.ToStdout("Shutting down %s" % name) |
476 | 312ac745 | Iustin Pop | SubmitOpCode(op) |
477 | a8083063 | Iustin Pop | return 0 |
478 | a8083063 | Iustin Pop | |
479 | a8083063 | Iustin Pop | |
480 | a8083063 | Iustin Pop | def ReplaceDisks(opts, args): |
481 | a8083063 | Iustin Pop | """Replace the disks of an instance |
482 | a8083063 | Iustin Pop | |
483 | a8083063 | Iustin Pop | Args: |
484 | a8083063 | Iustin Pop | opts - class with options as members |
485 | a8083063 | Iustin Pop | args - list with a single element, the instance name |
486 | a8083063 | Iustin Pop | |
487 | a8083063 | Iustin Pop | """ |
488 | a8083063 | Iustin Pop | instance_name = args[0] |
489 | a9e0c397 | Iustin Pop | new_2ndary = opts.new_secondary |
490 | b6e82a65 | Iustin Pop | iallocator = opts.iallocator |
491 | a9e0c397 | Iustin Pop | if opts.disks is None: |
492 | a9e0c397 | Iustin Pop | disks = ["sda", "sdb"] |
493 | a9e0c397 | Iustin Pop | else: |
494 | a9e0c397 | Iustin Pop | disks = opts.disks.split(",") |
495 | a9e0c397 | Iustin Pop | if opts.on_primary == opts.on_secondary: # no -p or -s passed, or both passed |
496 | a9e0c397 | Iustin Pop | mode = constants.REPLACE_DISK_ALL |
497 | a9e0c397 | Iustin Pop | elif opts.on_primary: # only on primary: |
498 | a9e0c397 | Iustin Pop | mode = constants.REPLACE_DISK_PRI |
499 | b6e82a65 | Iustin Pop | if new_2ndary is not None or iallocator is not None: |
500 | a9e0c397 | Iustin Pop | raise errors.OpPrereqError("Can't change secondary node on primary disk" |
501 | a9e0c397 | Iustin Pop | " replacement") |
502 | b6e82a65 | Iustin Pop | elif opts.on_secondary is not None or iallocator is not None: |
503 | b6e82a65 | Iustin Pop | # only on secondary |
504 | a9e0c397 | Iustin Pop | mode = constants.REPLACE_DISK_SEC |
505 | a9e0c397 | Iustin Pop | |
506 | a9e0c397 | Iustin Pop | op = opcodes.OpReplaceDisks(instance_name=args[0], disks=disks, |
507 | b6e82a65 | Iustin Pop | remote_node=new_2ndary, mode=mode, |
508 | b6e82a65 | Iustin Pop | iallocator=iallocator) |
509 | a8083063 | Iustin Pop | SubmitOpCode(op) |
510 | a8083063 | Iustin Pop | return 0 |
511 | a8083063 | Iustin Pop | |
512 | a8083063 | Iustin Pop | |
513 | a8083063 | Iustin Pop | def FailoverInstance(opts, args): |
514 | a8083063 | Iustin Pop | """Failover an instance. |
515 | a8083063 | Iustin Pop | |
516 | a8083063 | Iustin Pop | The failover is done by shutting it down on its present node and |
517 | a8083063 | Iustin Pop | starting it on the secondary. |
518 | a8083063 | Iustin Pop | |
519 | a8083063 | Iustin Pop | Args: |
520 | a8083063 | Iustin Pop | opts - class with options as members |
521 | a8083063 | Iustin Pop | args - list with a single element, the instance name |
522 | a8083063 | Iustin Pop | Opts used: |
523 | a8083063 | Iustin Pop | force - whether to failover without asking questions. |
524 | a8083063 | Iustin Pop | |
525 | a8083063 | Iustin Pop | """ |
526 | 80de0e3f | Iustin Pop | instance_name = args[0] |
527 | 80de0e3f | Iustin Pop | force = opts.force |
528 | a8083063 | Iustin Pop | |
529 | 80de0e3f | Iustin Pop | if not force: |
530 | 80de0e3f | Iustin Pop | usertext = ("Failover will happen to image %s." |
531 | 80de0e3f | Iustin Pop | " This requires a shutdown of the instance. Continue?" % |
532 | 80de0e3f | Iustin Pop | (instance_name,)) |
533 | 80de0e3f | Iustin Pop | if not AskUser(usertext): |
534 | 80de0e3f | Iustin Pop | return 1 |
535 | a8083063 | Iustin Pop | |
536 | 80de0e3f | Iustin Pop | op = opcodes.OpFailoverInstance(instance_name=instance_name, |
537 | 80de0e3f | Iustin Pop | ignore_consistency=opts.ignore_consistency) |
538 | 80de0e3f | Iustin Pop | SubmitOpCode(op) |
539 | 80de0e3f | Iustin Pop | return 0 |
540 | a8083063 | Iustin Pop | |
541 | a8083063 | Iustin Pop | |
542 | a8083063 | Iustin Pop | def ConnectToInstanceConsole(opts, args): |
543 | a8083063 | Iustin Pop | """Connect to the console of an instance. |
544 | a8083063 | Iustin Pop | |
545 | a8083063 | Iustin Pop | Args: |
546 | a8083063 | Iustin Pop | opts - class with options as members |
547 | a8083063 | Iustin Pop | args - list with a single element, the instance name |
548 | a8083063 | Iustin Pop | |
549 | a8083063 | Iustin Pop | """ |
550 | a8083063 | Iustin Pop | instance_name = args[0] |
551 | a8083063 | Iustin Pop | |
552 | a8083063 | Iustin Pop | op = opcodes.OpConnectConsole(instance_name=instance_name) |
553 | 0a80a26f | Michael Hanselmann | cmd = SubmitOpCode(op) |
554 | 51c6e7b5 | Michael Hanselmann | |
555 | 51c6e7b5 | Michael Hanselmann | if opts.show_command: |
556 | 51c6e7b5 | Michael Hanselmann | print utils.ShellQuoteArgs(cmd) |
557 | 51c6e7b5 | Michael Hanselmann | else: |
558 | 51c6e7b5 | Michael Hanselmann | try: |
559 | 51c6e7b5 | Michael Hanselmann | os.execvp(cmd[0], cmd) |
560 | 51c6e7b5 | Michael Hanselmann | finally: |
561 | 51c6e7b5 | Michael Hanselmann | sys.stderr.write("Can't run console command %s with arguments:\n'%s'" % |
562 | 51c6e7b5 | Michael Hanselmann | (cmd, " ".join(argv))) |
563 | 51c6e7b5 | Michael Hanselmann | os._exit(1) |
564 | a8083063 | Iustin Pop | |
565 | a8083063 | Iustin Pop | |
566 | a8083063 | Iustin Pop | def _FormatBlockDevInfo(buf, dev, indent_level): |
567 | a8083063 | Iustin Pop | """Show block device information. |
568 | a8083063 | Iustin Pop | |
569 | a8083063 | Iustin Pop | This is only used by ShowInstanceConfig(), but it's too big to be |
570 | a8083063 | Iustin Pop | left for an inline definition. |
571 | a8083063 | Iustin Pop | |
572 | a8083063 | Iustin Pop | """ |
573 | a8083063 | Iustin Pop | def helper(buf, dtype, status): |
574 | f2e9e0e8 | Alexander Schreiber | """Format one line for physical device status.""" |
575 | a8083063 | Iustin Pop | if not status: |
576 | a8083063 | Iustin Pop | buf.write("not active\n") |
577 | a8083063 | Iustin Pop | else: |
578 | 0834c866 | Iustin Pop | (path, major, minor, syncp, estt, degr, ldisk) = status |
579 | fd38ef95 | Manuel Franceschini | if major is None: |
580 | fd38ef95 | Manuel Franceschini | major_string = "N/A" |
581 | fd38ef95 | Manuel Franceschini | else: |
582 | fd38ef95 | Manuel Franceschini | major_string = str(major) |
583 | fd38ef95 | Manuel Franceschini | |
584 | fd38ef95 | Manuel Franceschini | if minor is None: |
585 | fd38ef95 | Manuel Franceschini | minor_string = "N/A" |
586 | fd38ef95 | Manuel Franceschini | else: |
587 | fd38ef95 | Manuel Franceschini | minor_string = str(minor) |
588 | fd38ef95 | Manuel Franceschini | |
589 | fd38ef95 | Manuel Franceschini | buf.write("%s (%s:%s)" % (path, major_string, minor_string)) |
590 | 00fb8246 | Michael Hanselmann | if dtype in (constants.LD_DRBD8, ): |
591 | a8083063 | Iustin Pop | if syncp is not None: |
592 | a8083063 | Iustin Pop | sync_text = "*RECOVERING* %5.2f%%," % syncp |
593 | a8083063 | Iustin Pop | if estt: |
594 | a8083063 | Iustin Pop | sync_text += " ETA %ds" % estt |
595 | a8083063 | Iustin Pop | else: |
596 | a8083063 | Iustin Pop | sync_text += " ETA unknown" |
597 | a8083063 | Iustin Pop | else: |
598 | a8083063 | Iustin Pop | sync_text = "in sync" |
599 | a8083063 | Iustin Pop | if degr: |
600 | a8083063 | Iustin Pop | degr_text = "*DEGRADED*" |
601 | a8083063 | Iustin Pop | else: |
602 | a8083063 | Iustin Pop | degr_text = "ok" |
603 | 0834c866 | Iustin Pop | if ldisk: |
604 | 0834c866 | Iustin Pop | ldisk_text = " *MISSING DISK*" |
605 | 0834c866 | Iustin Pop | else: |
606 | 0834c866 | Iustin Pop | ldisk_text = "" |
607 | 0834c866 | Iustin Pop | buf.write(" %s, status %s%s" % (sync_text, degr_text, ldisk_text)) |
608 | 9db6dbce | Iustin Pop | elif dtype == constants.LD_LV: |
609 | 0834c866 | Iustin Pop | if ldisk: |
610 | 0834c866 | Iustin Pop | ldisk_text = " *FAILED* (failed drive?)" |
611 | 9db6dbce | Iustin Pop | else: |
612 | 0834c866 | Iustin Pop | ldisk_text = "" |
613 | 0834c866 | Iustin Pop | buf.write(ldisk_text) |
614 | a8083063 | Iustin Pop | buf.write("\n") |
615 | a8083063 | Iustin Pop | |
616 | a8083063 | Iustin Pop | if dev["iv_name"] is not None: |
617 | a8083063 | Iustin Pop | data = " - %s, " % dev["iv_name"] |
618 | a8083063 | Iustin Pop | else: |
619 | a8083063 | Iustin Pop | data = " - " |
620 | a8083063 | Iustin Pop | data += "type: %s" % dev["dev_type"] |
621 | a8083063 | Iustin Pop | if dev["logical_id"] is not None: |
622 | a8083063 | Iustin Pop | data += ", logical_id: %s" % (dev["logical_id"],) |
623 | a8083063 | Iustin Pop | elif dev["physical_id"] is not None: |
624 | a8083063 | Iustin Pop | data += ", physical_id: %s" % (dev["physical_id"],) |
625 | a8083063 | Iustin Pop | buf.write("%*s%s\n" % (2*indent_level, "", data)) |
626 | a8083063 | Iustin Pop | buf.write("%*s primary: " % (2*indent_level, "")) |
627 | a8083063 | Iustin Pop | helper(buf, dev["dev_type"], dev["pstatus"]) |
628 | a8083063 | Iustin Pop | |
629 | a8083063 | Iustin Pop | if dev["sstatus"]: |
630 | a8083063 | Iustin Pop | buf.write("%*s secondary: " % (2*indent_level, "")) |
631 | a8083063 | Iustin Pop | helper(buf, dev["dev_type"], dev["sstatus"]) |
632 | a8083063 | Iustin Pop | |
633 | a8083063 | Iustin Pop | if dev["children"]: |
634 | a8083063 | Iustin Pop | for child in dev["children"]: |
635 | a8083063 | Iustin Pop | _FormatBlockDevInfo(buf, child, indent_level+1) |
636 | a8083063 | Iustin Pop | |
637 | a8083063 | Iustin Pop | |
638 | a8083063 | Iustin Pop | def ShowInstanceConfig(opts, args): |
639 | a8083063 | Iustin Pop | """Compute instance run-time status. |
640 | a8083063 | Iustin Pop | |
641 | a8083063 | Iustin Pop | """ |
642 | a8083063 | Iustin Pop | retcode = 0 |
643 | a8083063 | Iustin Pop | op = opcodes.OpQueryInstanceData(instances=args) |
644 | a8083063 | Iustin Pop | result = SubmitOpCode(op) |
645 | a8340917 | Iustin Pop | hvm_parameters = ("hvm_acpi", "hvm_pae", "hvm_cdrom_image_path", |
646 | a8340917 | Iustin Pop | "hvm_boot_order") |
647 | a8340917 | Iustin Pop | |
648 | a8340917 | Iustin Pop | pvm_parameters = ("kernel_path", "initrd_path") |
649 | a8083063 | Iustin Pop | |
650 | a8083063 | Iustin Pop | if not result: |
651 | a8083063 | Iustin Pop | logger.ToStdout("No instances.") |
652 | a8083063 | Iustin Pop | return 1 |
653 | a8083063 | Iustin Pop | |
654 | a8083063 | Iustin Pop | buf = StringIO() |
655 | a8083063 | Iustin Pop | retcode = 0 |
656 | a8083063 | Iustin Pop | for instance_name in result: |
657 | a8083063 | Iustin Pop | instance = result[instance_name] |
658 | a8083063 | Iustin Pop | buf.write("Instance name: %s\n" % instance["name"]) |
659 | a8083063 | Iustin Pop | buf.write("State: configured to be %s, actual state is %s\n" % |
660 | a8083063 | Iustin Pop | (instance["config_state"], instance["run_state"])) |
661 | a8083063 | Iustin Pop | buf.write(" Nodes:\n") |
662 | a8083063 | Iustin Pop | buf.write(" - primary: %s\n" % instance["pnode"]) |
663 | a8083063 | Iustin Pop | buf.write(" - secondaries: %s\n" % ", ".join(instance["snodes"])) |
664 | a8083063 | Iustin Pop | buf.write(" Operating system: %s\n" % instance["os"]) |
665 | a8340917 | Iustin Pop | if instance.has_key("network_port"): |
666 | a8340917 | Iustin Pop | buf.write(" Allocated network port: %s\n" % instance["network_port"]) |
667 | a8340917 | Iustin Pop | if False not in map(instance.has_key, pvm_parameters): |
668 | a8340917 | Iustin Pop | if instance["kernel_path"] in (None, constants.VALUE_DEFAULT): |
669 | a8340917 | Iustin Pop | kpath = "(default: %s)" % constants.XEN_KERNEL |
670 | a8340917 | Iustin Pop | else: |
671 | a8340917 | Iustin Pop | kpath = instance["kernel_path"] |
672 | a8340917 | Iustin Pop | buf.write(" Kernel path: %s\n" % kpath) |
673 | a8340917 | Iustin Pop | if instance["initrd_path"] in (None, constants.VALUE_DEFAULT): |
674 | a8340917 | Iustin Pop | initrd = "(default: %s)" % constants.XEN_INITRD |
675 | a8340917 | Iustin Pop | elif instance["initrd_path"] == constants.VALUE_NONE: |
676 | a8340917 | Iustin Pop | initrd = "(none)" |
677 | a8340917 | Iustin Pop | else: |
678 | a8340917 | Iustin Pop | initrd = instance["initrd_path"] |
679 | a8340917 | Iustin Pop | buf.write(" initrd: %s\n" % initrd) |
680 | a8340917 | Iustin Pop | if False not in map(instance.has_key, hvm_parameters): |
681 | a8340917 | Iustin Pop | buf.write(" HVM:\n") |
682 | a8340917 | Iustin Pop | buf.write(" - boot order: %s\n" % instance["hvm_boot_order"]) |
683 | a8340917 | Iustin Pop | buf.write(" - ACPI support: %s\n" % instance["hvm_acpi"]) |
684 | a8340917 | Iustin Pop | buf.write(" - PAE support: %s\n" % instance["hvm_pae"]) |
685 | a8340917 | Iustin Pop | buf.write(" - virtual CDROM: %s\n" % instance["hvm_cdrom_image_path"]) |
686 | a8340917 | Iustin Pop | if instance.has_key("vnc_bind_address"): |
687 | a8340917 | Iustin Pop | buf.write(" VNC bind address: %s\n" % instance["vnc_bind_address"]) |
688 | a8083063 | Iustin Pop | buf.write(" Hardware:\n") |
689 | f55ff7ec | Iustin Pop | buf.write(" - VCPUs: %d\n" % instance["vcpus"]) |
690 | a8083063 | Iustin Pop | buf.write(" - memory: %dMiB\n" % instance["memory"]) |
691 | a8083063 | Iustin Pop | buf.write(" - NICs: %s\n" % |
692 | a8083063 | Iustin Pop | ", ".join(["{MAC: %s, IP: %s, bridge: %s}" % |
693 | a8083063 | Iustin Pop | (mac, ip, bridge) |
694 | a8083063 | Iustin Pop | for mac, ip, bridge in instance["nics"]])) |
695 | a8083063 | Iustin Pop | buf.write(" Block devices:\n") |
696 | a8083063 | Iustin Pop | |
697 | a8083063 | Iustin Pop | for device in instance["disks"]: |
698 | a8083063 | Iustin Pop | _FormatBlockDevInfo(buf, device, 1) |
699 | a8083063 | Iustin Pop | |
700 | a8083063 | Iustin Pop | logger.ToStdout(buf.getvalue().rstrip('\n')) |
701 | a8083063 | Iustin Pop | return retcode |
702 | a8083063 | Iustin Pop | |
703 | a8083063 | Iustin Pop | |
704 | 7767bbf5 | Manuel Franceschini | def SetInstanceParams(opts, args): |
705 | a8083063 | Iustin Pop | """Modifies an instance. |
706 | a8083063 | Iustin Pop | |
707 | a8083063 | Iustin Pop | All parameters take effect only at the next restart of the instance. |
708 | a8083063 | Iustin Pop | |
709 | a8083063 | Iustin Pop | Args: |
710 | a8083063 | Iustin Pop | opts - class with options as members |
711 | a8083063 | Iustin Pop | args - list with a single element, the instance name |
712 | a8083063 | Iustin Pop | Opts used: |
713 | a8083063 | Iustin Pop | memory - the new memory size |
714 | a8083063 | Iustin Pop | vcpus - the new number of cpus |
715 | 1862d460 | Alexander Schreiber | mac - the new MAC address of the instance |
716 | a8083063 | Iustin Pop | |
717 | a8083063 | Iustin Pop | """ |
718 | 973d7867 | Iustin Pop | if not (opts.mem or opts.vcpus or opts.ip or opts.bridge or opts.mac or |
719 | 31a853d2 | Iustin Pop | opts.kernel_path or opts.initrd_path or opts.hvm_boot_order or |
720 | 917f91d5 | Iustin Pop | opts.hvm_acpi or opts.hvm_pae or opts.hvm_cdrom_image_path or |
721 | 31a853d2 | Iustin Pop | opts.vnc_bind_address): |
722 | a8083063 | Iustin Pop | logger.ToStdout("Please give at least one of the parameters.") |
723 | a8083063 | Iustin Pop | return 1 |
724 | a8083063 | Iustin Pop | |
725 | 973d7867 | Iustin Pop | kernel_path = _TransformPath(opts.kernel_path) |
726 | 973d7867 | Iustin Pop | initrd_path = _TransformPath(opts.initrd_path) |
727 | 40cece88 | Iustin Pop | if opts.hvm_boot_order == 'default': |
728 | 25c5878d | Alexander Schreiber | hvm_boot_order = constants.VALUE_DEFAULT |
729 | 25c5878d | Alexander Schreiber | else: |
730 | 25c5878d | Alexander Schreiber | hvm_boot_order = opts.hvm_boot_order |
731 | 973d7867 | Iustin Pop | |
732 | 31a853d2 | Iustin Pop | hvm_acpi = opts.hvm_acpi == _VALUE_TRUE |
733 | 31a853d2 | Iustin Pop | hvm_pae = opts.hvm_pae == _VALUE_TRUE |
734 | 31a853d2 | Iustin Pop | |
735 | 31a853d2 | Iustin Pop | if ((opts.hvm_cdrom_image_path is not None) and |
736 | 31a853d2 | Iustin Pop | (opts.hvm_cdrom_image_path.lower() == constants.VALUE_NONE)): |
737 | 31a853d2 | Iustin Pop | hvm_cdrom_image_path = None |
738 | 31a853d2 | Iustin Pop | else: |
739 | 31a853d2 | Iustin Pop | hvm_cdrom_image_path = opts.hvm_cdrom_image_path |
740 | 31a853d2 | Iustin Pop | |
741 | 7767bbf5 | Manuel Franceschini | op = opcodes.OpSetInstanceParams(instance_name=args[0], mem=opts.mem, |
742 | 7767bbf5 | Manuel Franceschini | vcpus=opts.vcpus, ip=opts.ip, |
743 | 7767bbf5 | Manuel Franceschini | bridge=opts.bridge, mac=opts.mac, |
744 | 7767bbf5 | Manuel Franceschini | kernel_path=opts.kernel_path, |
745 | 7767bbf5 | Manuel Franceschini | initrd_path=opts.initrd_path, |
746 | 31a853d2 | Iustin Pop | hvm_boot_order=hvm_boot_order, |
747 | 31a853d2 | Iustin Pop | hvm_acpi=hvm_acpi, hvm_pae=hvm_pae, |
748 | 31a853d2 | Iustin Pop | hvm_cdrom_image_path=hvm_cdrom_image_path, |
749 | 31a853d2 | Iustin Pop | vnc_bind_address=opts.vnc_bind_address) |
750 | 31a853d2 | Iustin Pop | |
751 | a8083063 | Iustin Pop | result = SubmitOpCode(op) |
752 | a8083063 | Iustin Pop | |
753 | a8083063 | Iustin Pop | if result: |
754 | a8083063 | Iustin Pop | logger.ToStdout("Modified instance %s" % args[0]) |
755 | a8083063 | Iustin Pop | for param, data in result: |
756 | a8083063 | Iustin Pop | logger.ToStdout(" - %-5s -> %s" % (param, data)) |
757 | a8083063 | Iustin Pop | logger.ToStdout("Please don't forget that these parameters take effect" |
758 | a8083063 | Iustin Pop | " only at the next start of the instance.") |
759 | a8083063 | Iustin Pop | return 0 |
760 | a8083063 | Iustin Pop | |
761 | a8083063 | Iustin Pop | |
762 | a8083063 | Iustin Pop | # options used in more than one cmd |
763 | a8083063 | Iustin Pop | node_opt = make_option("-n", "--node", dest="node", help="Target node", |
764 | a8083063 | Iustin Pop | metavar="<node>") |
765 | a8083063 | Iustin Pop | |
766 | d0834de3 | Michael Hanselmann | os_opt = cli_option("-o", "--os-type", dest="os", help="What OS to run", |
767 | 739ecd56 | Michael Hanselmann | metavar="<os>") |
768 | d0834de3 | Michael Hanselmann | |
769 | 312ac745 | Iustin Pop | # multi-instance selection options |
770 | 804a1e8e | Iustin Pop | m_force_multi = make_option("--force-multiple", dest="force_multi", |
771 | 804a1e8e | Iustin Pop | help="Do not ask for confirmation when more than" |
772 | 804a1e8e | Iustin Pop | " one instance is affected", |
773 | 804a1e8e | Iustin Pop | action="store_true", default=False) |
774 | 804a1e8e | Iustin Pop | |
775 | 312ac745 | Iustin Pop | m_pri_node_opt = make_option("--primary", dest="multi_mode", |
776 | 312ac745 | Iustin Pop | help="Filter by nodes (primary only)", |
777 | 312ac745 | Iustin Pop | const=_SHUTDOWN_NODES_PRI, action="store_const") |
778 | 312ac745 | Iustin Pop | |
779 | 312ac745 | Iustin Pop | m_sec_node_opt = make_option("--secondary", dest="multi_mode", |
780 | 312ac745 | Iustin Pop | help="Filter by nodes (secondary only)", |
781 | 312ac745 | Iustin Pop | const=_SHUTDOWN_NODES_SEC, action="store_const") |
782 | 312ac745 | Iustin Pop | |
783 | 312ac745 | Iustin Pop | m_node_opt = make_option("--node", dest="multi_mode", |
784 | 312ac745 | Iustin Pop | help="Filter by nodes (primary and secondary)", |
785 | 312ac745 | Iustin Pop | const=_SHUTDOWN_NODES_BOTH, action="store_const") |
786 | 312ac745 | Iustin Pop | |
787 | 312ac745 | Iustin Pop | m_clust_opt = make_option("--all", dest="multi_mode", |
788 | 312ac745 | Iustin Pop | help="Select all instances in the cluster", |
789 | 312ac745 | Iustin Pop | const=_SHUTDOWN_CLUSTER, action="store_const") |
790 | 312ac745 | Iustin Pop | |
791 | 312ac745 | Iustin Pop | m_inst_opt = make_option("--instance", dest="multi_mode", |
792 | 312ac745 | Iustin Pop | help="Filter by instance name [default]", |
793 | 312ac745 | Iustin Pop | const=_SHUTDOWN_INSTANCES, action="store_const") |
794 | 312ac745 | Iustin Pop | |
795 | 312ac745 | Iustin Pop | |
796 | a8083063 | Iustin Pop | # this is defined separately due to readability only |
797 | a8083063 | Iustin Pop | add_opts = [ |
798 | a8083063 | Iustin Pop | DEBUG_OPT, |
799 | 60d49723 | Michael Hanselmann | make_option("-n", "--node", dest="node", |
800 | 60d49723 | Michael Hanselmann | help="Target node and optional secondary node", |
801 | 60d49723 | Michael Hanselmann | metavar="<pnode>[:<snode>]"), |
802 | b9ac33e9 | Iustin Pop | cli_option("-s", "--os-size", dest="size", help="Disk size, in MiB unless" |
803 | b9ac33e9 | Iustin Pop | " a suffix is used", |
804 | a8083063 | Iustin Pop | default=20 * 1024, type="unit", metavar="<size>"), |
805 | b9ac33e9 | Iustin Pop | cli_option("--swap-size", dest="swap", help="Swap size, in MiB unless a" |
806 | b9ac33e9 | Iustin Pop | " suffix is used", |
807 | a8083063 | Iustin Pop | default=4 * 1024, type="unit", metavar="<size>"), |
808 | d0834de3 | Michael Hanselmann | os_opt, |
809 | b9ac33e9 | Iustin Pop | cli_option("-m", "--memory", dest="mem", help="Memory size (in MiB)", |
810 | a8083063 | Iustin Pop | default=128, type="unit", metavar="<mem>"), |
811 | a8083063 | Iustin Pop | make_option("-p", "--cpu", dest="vcpus", help="Number of virtual CPUs", |
812 | a8083063 | Iustin Pop | default=1, type="int", metavar="<PROC>"), |
813 | a8083063 | Iustin Pop | make_option("-t", "--disk-template", dest="disk_template", |
814 | 45873083 | Manuel Franceschini | help="Custom disk setup (diskless, file, plain or drbd)", |
815 | f9193417 | Iustin Pop | default=None, metavar="TEMPL"), |
816 | a8083063 | Iustin Pop | make_option("-i", "--ip", dest="ip", |
817 | a8083063 | Iustin Pop | help="IP address ('none' [default], 'auto', or specify address)", |
818 | a8083063 | Iustin Pop | default='none', type="string", metavar="<ADDRESS>"), |
819 | 1862d460 | Alexander Schreiber | make_option("--mac", dest="mac", |
820 | 1862d460 | Alexander Schreiber | help="MAC address ('auto' [default], or specify address)", |
821 | 1862d460 | Alexander Schreiber | default='auto', type="string", metavar="<MACADDRESS>"), |
822 | a8083063 | Iustin Pop | make_option("--no-wait-for-sync", dest="wait_for_sync", default=True, |
823 | a8083063 | Iustin Pop | action="store_false", help="Don't wait for sync (DANGEROUS!)"), |
824 | a8083063 | Iustin Pop | make_option("-b", "--bridge", dest="bridge", |
825 | a8083063 | Iustin Pop | help="Bridge to connect this instance to", |
826 | bdd55f71 | Iustin Pop | default=None, metavar="<bridge>"), |
827 | bdd55f71 | Iustin Pop | make_option("--no-start", dest="start", default=True, |
828 | bdd55f71 | Iustin Pop | action="store_false", help="Don't start the instance after" |
829 | bdd55f71 | Iustin Pop | " creation"), |
830 | bdd55f71 | Iustin Pop | make_option("--no-ip-check", dest="ip_check", default=True, |
831 | bdd55f71 | Iustin Pop | action="store_false", help="Don't check that the instance's IP" |
832 | bdd55f71 | Iustin Pop | " is alive (only valid with --no-start)"), |
833 | 3b6d8c9b | Iustin Pop | make_option("--kernel", dest="kernel_path", |
834 | 3b6d8c9b | Iustin Pop | help="Path to the instances' kernel (or 'default')", |
835 | 3b6d8c9b | Iustin Pop | default=None, |
836 | 3b6d8c9b | Iustin Pop | type="string", metavar="<FILENAME>"), |
837 | 3b6d8c9b | Iustin Pop | make_option("--initrd", dest="initrd_path", |
838 | 3b6d8c9b | Iustin Pop | help="Path to the instances' initrd (or 'none', or 'default')", |
839 | 3b6d8c9b | Iustin Pop | default=None, |
840 | 3b6d8c9b | Iustin Pop | type="string", metavar="<FILENAME>"), |
841 | 25c5878d | Alexander Schreiber | make_option("--hvm-boot-order", dest="hvm_boot_order", |
842 | 538475ca | Iustin Pop | help="Boot device order for HVM (one or more of [acdn])", |
843 | 25c5878d | Alexander Schreiber | default=None, type="string", metavar="<BOOTORDER>"), |
844 | 45873083 | Manuel Franceschini | make_option("--file-storage-dir", dest="file_storage_dir", |
845 | 45873083 | Manuel Franceschini | help="Relative path under default cluster-wide file storage dir" |
846 | 45873083 | Manuel Franceschini | " to store file-based disks", default=None, |
847 | 45873083 | Manuel Franceschini | metavar="<DIR>"), |
848 | 45873083 | Manuel Franceschini | make_option("--file-driver", dest="file_driver", help="Driver to use" |
849 | 538475ca | Iustin Pop | " for image files", default="loop", metavar="<DRIVER>"), |
850 | 538475ca | Iustin Pop | make_option("--iallocator", metavar="<NAME>", |
851 | 538475ca | Iustin Pop | help="Select nodes for the instance automatically using the" |
852 | 538475ca | Iustin Pop | " <NAME> iallocator plugin", default=None, type="string"), |
853 | 31a853d2 | Iustin Pop | make_option("--hvm-acpi", dest="hvm_acpi", |
854 | 31a853d2 | Iustin Pop | help="ACPI support for HVM (true|false)", |
855 | 31a853d2 | Iustin Pop | metavar="<BOOL>", choices=["true", "false"]), |
856 | 31a853d2 | Iustin Pop | make_option("--hvm-pae", dest="hvm_pae", |
857 | 31a853d2 | Iustin Pop | help="PAE support for HVM (true|false)", |
858 | 31a853d2 | Iustin Pop | metavar="<BOOL>", choices=["true", "false"]), |
859 | 31a853d2 | Iustin Pop | make_option("--hvm-cdrom-image-path", dest="hvm_cdrom_image_path", |
860 | 31a853d2 | Iustin Pop | help="CDROM image path for HVM (absolute path or None)", |
861 | 31a853d2 | Iustin Pop | default=None, type="string", metavar="<CDROMIMAGE>"), |
862 | 31a853d2 | Iustin Pop | make_option("--vnc-bind-address", dest="vnc_bind_address", |
863 | 31a853d2 | Iustin Pop | help="bind address for VNC (IP address)", |
864 | 31a853d2 | Iustin Pop | default=None, type="string", metavar="<VNCADDRESS>"), |
865 | a8083063 | Iustin Pop | ] |
866 | a8083063 | Iustin Pop | |
867 | a8083063 | Iustin Pop | commands = { |
868 | a8083063 | Iustin Pop | 'add': (AddInstance, ARGS_ONE, add_opts, |
869 | bdb7d4e8 | Michael Hanselmann | "[...] -t disk-type -n node[:secondary-node] -o os-type <name>", |
870 | a8083063 | Iustin Pop | "Creates and adds a new instance to the cluster"), |
871 | 51c6e7b5 | Michael Hanselmann | 'console': (ConnectToInstanceConsole, ARGS_ONE, |
872 | 51c6e7b5 | Michael Hanselmann | [DEBUG_OPT, |
873 | 51c6e7b5 | Michael Hanselmann | make_option("--show-cmd", dest="show_command", |
874 | 51c6e7b5 | Michael Hanselmann | action="store_true", default=False, |
875 | 51c6e7b5 | Michael Hanselmann | help=("Show command instead of executing it"))], |
876 | 9a033156 | Iustin Pop | "[--show-cmd] <instance>", |
877 | a8083063 | Iustin Pop | "Opens a console on the specified instance"), |
878 | 80de0e3f | Iustin Pop | 'failover': (FailoverInstance, ARGS_ONE, |
879 | fe7b0351 | Michael Hanselmann | [DEBUG_OPT, FORCE_OPT, |
880 | a8083063 | Iustin Pop | make_option("--ignore-consistency", dest="ignore_consistency", |
881 | a8083063 | Iustin Pop | action="store_true", default=False, |
882 | a8083063 | Iustin Pop | help="Ignore the consistency of the disks on" |
883 | a8083063 | Iustin Pop | " the secondary"), |
884 | a8083063 | Iustin Pop | ], |
885 | 9a033156 | Iustin Pop | "[-f] <instance>", |
886 | a8083063 | Iustin Pop | "Stops the instance and starts it on the backup node, using" |
887 | 99e2be3b | Guido Trotter | " the remote mirror (only for instances of type drbd)"), |
888 | 9a033156 | Iustin Pop | 'info': (ShowInstanceConfig, ARGS_ANY, [DEBUG_OPT], "[<instance>...]", |
889 | a8083063 | Iustin Pop | "Show information on the specified instance"), |
890 | a8083063 | Iustin Pop | 'list': (ListInstances, ARGS_NONE, |
891 | 9a033156 | Iustin Pop | [DEBUG_OPT, NOHDR_OPT, SEP_OPT, USEUNITS_OPT, FIELDS_OPT], "", |
892 | d8052456 | Iustin Pop | "Lists the instances and their status. The available fields are" |
893 | d8052456 | Iustin Pop | " (see the man page for details): status, oper_state, oper_ram," |
894 | d8a4b51d | Iustin Pop | " name, os, pnode, snodes, admin_state, admin_ram, disk_template," |
895 | d8a4b51d | Iustin Pop | " ip, mac, bridge, sda_size, sdb_size, vcpus. The default field" |
896 | 48c4dfa8 | Iustin Pop | " list is (in order): %s." % ", ".join(_LIST_DEF_FIELDS), |
897 | 48c4dfa8 | Iustin Pop | ), |
898 | d0834de3 | Michael Hanselmann | 'reinstall': (ReinstallInstance, ARGS_ONE, [DEBUG_OPT, FORCE_OPT, os_opt], |
899 | 9a033156 | Iustin Pop | "[-f] <instance>", "Reinstall a stopped instance"), |
900 | 1d67656e | Iustin Pop | 'remove': (RemoveInstance, ARGS_ONE, |
901 | 1d67656e | Iustin Pop | [DEBUG_OPT, FORCE_OPT, |
902 | 1d67656e | Iustin Pop | make_option("--ignore-failures", dest="ignore_failures", |
903 | 1d67656e | Iustin Pop | action="store_true", default=False, |
904 | 1d67656e | Iustin Pop | help=("Remove the instance from the cluster even" |
905 | 1d67656e | Iustin Pop | " if there are failures during the removal" |
906 | 1d67656e | Iustin Pop | " process (shutdown, disk removal, etc.)")), |
907 | 1d67656e | Iustin Pop | ], |
908 | 9a033156 | Iustin Pop | "[-f] <instance>", "Shuts down the instance and removes it"), |
909 | decd5f45 | Iustin Pop | 'rename': (RenameInstance, ARGS_FIXED(2), |
910 | decd5f45 | Iustin Pop | [DEBUG_OPT, |
911 | decd5f45 | Iustin Pop | make_option("--no-ip-check", dest="ignore_ip", |
912 | decd5f45 | Iustin Pop | help="Do not check that the IP of the new name" |
913 | decd5f45 | Iustin Pop | " is alive", |
914 | decd5f45 | Iustin Pop | default=False, action="store_true"), |
915 | decd5f45 | Iustin Pop | ], |
916 | 9a033156 | Iustin Pop | "<instance> <new_name>", "Rename the instance"), |
917 | a8083063 | Iustin Pop | 'replace-disks': (ReplaceDisks, ARGS_ONE, |
918 | a8083063 | Iustin Pop | [DEBUG_OPT, |
919 | a8083063 | Iustin Pop | make_option("-n", "--new-secondary", dest="new_secondary", |
920 | a9e0c397 | Iustin Pop | help=("New secondary node (for secondary" |
921 | a9e0c397 | Iustin Pop | " node change)"), metavar="NODE"), |
922 | a9e0c397 | Iustin Pop | make_option("-p", "--on-primary", dest="on_primary", |
923 | a9e0c397 | Iustin Pop | default=False, action="store_true", |
924 | a9e0c397 | Iustin Pop | help=("Replace the disk(s) on the primary" |
925 | 12c3449a | Michael Hanselmann | " node (only for the drbd template)")), |
926 | a9e0c397 | Iustin Pop | make_option("-s", "--on-secondary", dest="on_secondary", |
927 | a9e0c397 | Iustin Pop | default=False, action="store_true", |
928 | a9e0c397 | Iustin Pop | help=("Replace the disk(s) on the secondary" |
929 | 12c3449a | Michael Hanselmann | " node (only for the drbd template)")), |
930 | a9e0c397 | Iustin Pop | make_option("--disks", dest="disks", default=None, |
931 | a9e0c397 | Iustin Pop | help=("Comma-separated list of disks" |
932 | a9e0c397 | Iustin Pop | " to replace (e.g. sda) (optional," |
933 | a9e0c397 | Iustin Pop | " defaults to all disks")), |
934 | b6e82a65 | Iustin Pop | make_option("--iallocator", metavar="<NAME>", |
935 | b6e82a65 | Iustin Pop | help="Select new secondary for the instance" |
936 | b6e82a65 | Iustin Pop | " automatically using the" |
937 | b6e82a65 | Iustin Pop | " <NAME> iallocator plugin (enables" |
938 | b6e82a65 | Iustin Pop | " secondary node replacement)", |
939 | b6e82a65 | Iustin Pop | default=None, type="string"), |
940 | a9e0c397 | Iustin Pop | ], |
941 | 9a033156 | Iustin Pop | "[-s|-p|-n NODE] <instance>", |
942 | a8083063 | Iustin Pop | "Replaces all disks for the instance"), |
943 | 7767bbf5 | Manuel Franceschini | 'modify': (SetInstanceParams, ARGS_ONE, |
944 | fe7b0351 | Michael Hanselmann | [DEBUG_OPT, FORCE_OPT, |
945 | a8083063 | Iustin Pop | cli_option("-m", "--memory", dest="mem", |
946 | a8083063 | Iustin Pop | help="Memory size", |
947 | a8083063 | Iustin Pop | default=None, type="unit", metavar="<mem>"), |
948 | a8083063 | Iustin Pop | make_option("-p", "--cpu", dest="vcpus", |
949 | a8083063 | Iustin Pop | help="Number of virtual CPUs", |
950 | a8083063 | Iustin Pop | default=None, type="int", metavar="<PROC>"), |
951 | a8083063 | Iustin Pop | make_option("-i", "--ip", dest="ip", |
952 | a8083063 | Iustin Pop | help="IP address ('none' or numeric IP)", |
953 | a8083063 | Iustin Pop | default=None, type="string", metavar="<ADDRESS>"), |
954 | a8083063 | Iustin Pop | make_option("-b", "--bridge", dest="bridge", |
955 | a8083063 | Iustin Pop | help="Bridge to connect this instance to", |
956 | decd5f45 | Iustin Pop | default=None, type="string", metavar="<bridge>"), |
957 | 1862d460 | Alexander Schreiber | make_option("--mac", dest="mac", |
958 | 1862d460 | Alexander Schreiber | help="MAC address", default=None, |
959 | 1862d460 | Alexander Schreiber | type="string", metavar="<MACADDRESS>"), |
960 | 973d7867 | Iustin Pop | make_option("--kernel", dest="kernel_path", |
961 | 973d7867 | Iustin Pop | help="Path to the instances' kernel (or" |
962 | 973d7867 | Iustin Pop | " 'default')", default=None, |
963 | 973d7867 | Iustin Pop | type="string", metavar="<FILENAME>"), |
964 | 973d7867 | Iustin Pop | make_option("--initrd", dest="initrd_path", |
965 | 973d7867 | Iustin Pop | help="Path to the instances' initrd (or 'none', or" |
966 | 973d7867 | Iustin Pop | " 'default')", default=None, |
967 | 973d7867 | Iustin Pop | type="string", metavar="<FILENAME>"), |
968 | 25c5878d | Alexander Schreiber | make_option("--hvm-boot-order", dest="hvm_boot_order", |
969 | 25c5878d | Alexander Schreiber | help="boot device order for HVM" |
970 | 25c5878d | Alexander Schreiber | "(either one or more of [acdn] or 'default')", |
971 | 25c5878d | Alexander Schreiber | default=None, type="string", metavar="<BOOTORDER>"), |
972 | 31a853d2 | Iustin Pop | make_option("--hvm-acpi", dest="hvm_acpi", |
973 | 31a853d2 | Iustin Pop | help="ACPI support for HVM (true|false)", |
974 | 31a853d2 | Iustin Pop | metavar="<BOOL>", choices=["true", "false"]), |
975 | 31a853d2 | Iustin Pop | make_option("--hvm-pae", dest="hvm_pae", |
976 | 31a853d2 | Iustin Pop | help="PAE support for HVM (true|false)", |
977 | 31a853d2 | Iustin Pop | metavar="<BOOL>", choices=["true", "false"]), |
978 | 31a853d2 | Iustin Pop | make_option("--hvm-cdrom-image-path", |
979 | 31a853d2 | Iustin Pop | dest="hvm_cdrom_image_path", |
980 | 31a853d2 | Iustin Pop | help="CDROM image path for HVM" |
981 | 31a853d2 | Iustin Pop | "(absolute path or None)", |
982 | 31a853d2 | Iustin Pop | default=None, type="string", metavar="<CDROMIMAGE>"), |
983 | 31a853d2 | Iustin Pop | make_option("--vnc-bind-address", dest="vnc_bind_address", |
984 | 31a853d2 | Iustin Pop | help="bind address for VNC (IP address)", |
985 | 31a853d2 | Iustin Pop | default=None, type="string", metavar="<VNCADDRESS>"), |
986 | a8083063 | Iustin Pop | ], |
987 | 9a033156 | Iustin Pop | "<instance>", "Alters the parameters of an instance"), |
988 | 312ac745 | Iustin Pop | 'shutdown': (ShutdownInstance, ARGS_ANY, |
989 | 312ac745 | Iustin Pop | [DEBUG_OPT, m_node_opt, m_pri_node_opt, m_sec_node_opt, |
990 | 804a1e8e | Iustin Pop | m_clust_opt, m_inst_opt, m_force_multi], |
991 | 9a033156 | Iustin Pop | "<instance>", "Stops an instance"), |
992 | 312ac745 | Iustin Pop | 'startup': (StartupInstance, ARGS_ANY, |
993 | 804a1e8e | Iustin Pop | [DEBUG_OPT, FORCE_OPT, m_force_multi, |
994 | a8083063 | Iustin Pop | make_option("-e", "--extra", dest="extra_args", |
995 | a8083063 | Iustin Pop | help="Extra arguments for the instance's kernel", |
996 | a8083063 | Iustin Pop | default=None, type="string", metavar="<PARAMS>"), |
997 | 312ac745 | Iustin Pop | m_node_opt, m_pri_node_opt, m_sec_node_opt, |
998 | 312ac745 | Iustin Pop | m_clust_opt, m_inst_opt, |
999 | a8083063 | Iustin Pop | ], |
1000 | 9a033156 | Iustin Pop | "<instance>", "Starts an instance"), |
1001 | 579d4337 | Alexander Schreiber | |
1002 | 579d4337 | Alexander Schreiber | 'reboot': (RebootInstance, ARGS_ANY, |
1003 | 579d4337 | Alexander Schreiber | [DEBUG_OPT, m_force_multi, |
1004 | 579d4337 | Alexander Schreiber | make_option("-e", "--extra", dest="extra_args", |
1005 | 579d4337 | Alexander Schreiber | help="Extra arguments for the instance's kernel", |
1006 | 579d4337 | Alexander Schreiber | default=None, type="string", metavar="<PARAMS>"), |
1007 | 579d4337 | Alexander Schreiber | make_option("-t", "--type", dest="reboot_type", |
1008 | 579d4337 | Alexander Schreiber | help="Type of reboot: soft/hard/full", |
1009 | 579d4337 | Alexander Schreiber | default=constants.INSTANCE_REBOOT_SOFT, |
1010 | 579d4337 | Alexander Schreiber | type="string", metavar="<REBOOT>"), |
1011 | 579d4337 | Alexander Schreiber | make_option("--ignore-secondaries", dest="ignore_secondaries", |
1012 | 579d4337 | Alexander Schreiber | default=False, action="store_true", |
1013 | 579d4337 | Alexander Schreiber | help="Ignore errors from secondaries"), |
1014 | 579d4337 | Alexander Schreiber | m_node_opt, m_pri_node_opt, m_sec_node_opt, |
1015 | 579d4337 | Alexander Schreiber | m_clust_opt, m_inst_opt, |
1016 | 579d4337 | Alexander Schreiber | ], |
1017 | 9a033156 | Iustin Pop | "<instance>", "Reboots an instance"), |
1018 | a8083063 | Iustin Pop | 'activate-disks': (ActivateDisks, ARGS_ONE, [DEBUG_OPT], |
1019 | 9a033156 | Iustin Pop | "<instance>", |
1020 | a8083063 | Iustin Pop | "Activate an instance's disks"), |
1021 | a8083063 | Iustin Pop | 'deactivate-disks': (DeactivateDisks, ARGS_ONE, [DEBUG_OPT], |
1022 | 9a033156 | Iustin Pop | "<instance>", |
1023 | a8083063 | Iustin Pop | "Deactivate an instance's disks"), |
1024 | c6e911bc | Iustin Pop | 'grow-disk': (GrowDisk, ARGS_FIXED(3), [DEBUG_OPT], |
1025 | c6e911bc | Iustin Pop | "<instance> <disk> <size>", "Grow an instance's disk"), |
1026 | 846baef9 | Iustin Pop | 'list-tags': (ListTags, ARGS_ONE, [DEBUG_OPT], |
1027 | 9a033156 | Iustin Pop | "<node_name>", "List the tags of the given instance"), |
1028 | 810c50b7 | Iustin Pop | 'add-tags': (AddTags, ARGS_ATLEAST(1), [DEBUG_OPT, TAG_SRC_OPT], |
1029 | 9a033156 | Iustin Pop | "<node_name> tag...", "Add tags to the given instance"), |
1030 | 810c50b7 | Iustin Pop | 'remove-tags': (RemoveTags, ARGS_ATLEAST(1), [DEBUG_OPT, TAG_SRC_OPT], |
1031 | 9a033156 | Iustin Pop | "<node_name> tag...", "Remove tags from given instance"), |
1032 | a8083063 | Iustin Pop | } |
1033 | a8083063 | Iustin Pop | |
1034 | dbfd89dd | Guido Trotter | aliases = { |
1035 | dbfd89dd | Guido Trotter | 'activate_block_devs': 'activate-disks', |
1036 | 00ce8b29 | Guido Trotter | 'replace_disks': 'replace-disks', |
1037 | 536fda25 | Guido Trotter | 'start': 'startup', |
1038 | 536fda25 | Guido Trotter | 'stop': 'shutdown', |
1039 | dbfd89dd | Guido Trotter | } |
1040 | dbfd89dd | Guido Trotter | |
1041 | a8083063 | Iustin Pop | if __name__ == '__main__': |
1042 | dbfd89dd | Guido Trotter | sys.exit(GenericMain(commands, aliases=aliases, |
1043 | 846baef9 | Iustin Pop | override={"tag_type": constants.TAG_INSTANCE})) |