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