import sys
import os
from optparse import make_option
-import textwrap
from cStringIO import StringIO
from ganeti.cli import *
"oper_state": "Status", "admin_ram": "Configured_memory",
"oper_ram": "Memory", "disk_template": "Disk_template",
"ip": "IP Address", "mac": "MAC Address",
- "bridge": "Bridge"}
+ "bridge": "Bridge",
+ "sda_size": "Disk/0", "sdb_size": "Disk/1"}
else:
headers = None
if opts.human_readable:
- unitfields = ["admin_ram", "oper_ram"]
+ unitfields = ["admin_ram", "oper_ram", "sda_size", "sdb_size"]
else:
unitfields = None
- numfields = ["admin_ram", "oper_ram"]
+ numfields = ["admin_ram", "oper_ram", "sda_size", "sdb_size"]
- OutputTable(separator=opts.separator, headers=headers,
- fields=selected_fields, unitfields=unitfields,
- numfields=numfields, data=output)
+ data = GenerateTable(separator=opts.separator, headers=headers,
+ fields=selected_fields, unitfields=unitfields,
+ numfields=numfields, data=output)
+
+ for line in data:
+ logger.ToStdout(line)
return 0
node - node to run new instance on
"""
-
instance = args[0]
op = opcodes.OpCreateInstance(instance_name=instance, mem_size=opts.mem,
return 0
+def ReinstallInstance(opts, args):
+ """Reinstall an instance.
+
+ Args:
+ opts - class with options as members
+ args - list containing a single element, the instance name
+
+ """
+ instance_name = args[0]
+
+ if not opts.force:
+ usertext = ("This will reinstall the instance %s and remove "
+ "all data. Continue?") % instance_name
+ if not opts._ask_user(usertext):
+ return 1
+
+ op = opcodes.OpReinstallInstance(instance_name=instance_name,
+ os_type=opts.os)
+ SubmitOpCode(op)
+
+ return 0
+
+
def RemoveInstance(opts, args):
"""Remove an instance.
def RemoveMDDRBDComponent(opts, args):
- """Connect to the console of an instance
+ """Remove a component from a remote_raid1 disk.
Args:
opts - class with options as members
usertext = ("Failover will happen to image %s."
" This requires a shutdown of the instance. Continue?" %
(instance_name,))
- usertext = textwrap.fill(usertext)
if not opts._ask_user(usertext):
return 1
instance_name = args[0]
op = opcodes.OpConnectConsole(instance_name=instance_name)
- node, console_cmd = SubmitOpCode(op)
+ cmd, argv = SubmitOpCode(op)
# drop lock and exec so other commands can run while we have console
utils.Unlock("cmd")
try:
- os.execv("/usr/bin/ssh", ["ssh", "-qt", node, console_cmd])
+ os.execvp(cmd, argv)
finally:
- sys.stderr.write("Can't run console command %s on node %s" %
- (console_cmd, node))
+ sys.stderr.write("Can't run console command %s with arguments:\n'%s'" %
+ (cmd, " ".join(argv)))
os._exit(1)
"""Compute instance run-time status.
"""
-
retcode = 0
op = opcodes.OpQueryInstanceData(instances=args)
result = SubmitOpCode(op)
# options used in more than one cmd
node_opt = make_option("-n", "--node", dest="node", help="Target node",
metavar="<node>")
-force_opt = make_option("-f", "--force", dest="force", action="store_true",
- default=False, help="Force the operation")
+
+os_opt = cli_option("-o", "--os-type", dest="os", help="What OS to run",
+ metavar="<os>")
# this is defined separately due to readability only
add_opts = [
DEBUG_OPT,
node_opt,
- cli_option("-s", "--os-size", dest="size", help="Disk size",
+ cli_option("-s", "--os-size", dest="size", help="Disk size, in MiB unless"
+ " a suffix is used",
default=20 * 1024, type="unit", metavar="<size>"),
- cli_option("--swap-size", dest="swap", help="Swap size",
+ cli_option("--swap-size", dest="swap", help="Swap size, in MiB unless a"
+ " suffix is used",
default=4 * 1024, type="unit", metavar="<size>"),
- cli_option("-o", "--os-type", dest="os", help="What OS to run",
- metavar="<os>"),
- cli_option("-m", "--memory", dest="mem", help="Memory size",
+ os_opt,
+ cli_option("-m", "--memory", dest="mem", help="Memory size (in MiB)",
default=128, type="unit", metavar="<mem>"),
make_option("-p", "--cpu", dest="vcpus", help="Number of virtual CPUs",
default=1, type="int", metavar="<PROC>"),
default=None, metavar="<bridge>")
]
-
commands = {
'add': (AddInstance, ARGS_ONE, add_opts,
"[opts...] <name>",
"<instance>",
"Opens a console on the specified instance"),
'failover': (FailoverInstance, ARGS_ONE,
- [DEBUG_OPT, force_opt,
+ [DEBUG_OPT, FORCE_OPT,
make_option("--ignore-consistency", dest="ignore_consistency",
action="store_true", default=False,
help="Ignore the consistency of the disks on"
'list': (ListInstances, ARGS_NONE,
[DEBUG_OPT, NOHDR_OPT, SEP_OPT, USEUNITS_OPT, FIELDS_OPT],
"", "Lists the instances and their status"),
- 'remove': (RemoveInstance, ARGS_ONE, [DEBUG_OPT, force_opt],
+ 'reinstall': (ReinstallInstance, ARGS_ONE, [DEBUG_OPT, FORCE_OPT, os_opt],
+ "[-f] <instance>", "Reinstall the instance"),
+ 'remove': (RemoveInstance, ARGS_ONE, [DEBUG_OPT, FORCE_OPT],
"[-f] <instance>", "Shuts down the instance and removes it"),
'remove-mirror': (RemoveMDDRBDComponent, ARGS_ONE,
[DEBUG_OPT, node_opt,
" change the secondary)"))],
"[-n NODE] <instance>",
"Replaces all disks for the instance"),
-
'modify': (SetInstanceParms, ARGS_ONE,
- [DEBUG_OPT, force_opt,
+ [DEBUG_OPT, FORCE_OPT,
cli_option("-m", "--memory", dest="mem",
help="Memory size",
default=None, type="unit", metavar="<mem>"),
'shutdown': (ShutdownInstance, ARGS_ONE, [DEBUG_OPT],
"<instance>", "Stops an instance"),
'startup': (StartupInstance, ARGS_ONE,
- [DEBUG_OPT, force_opt,
+ [DEBUG_OPT, FORCE_OPT,
make_option("-e", "--extra", dest="extra_args",
help="Extra arguments for the instance's kernel",
default=None, type="string", metavar="<PARAMS>"),
}
if __name__ == '__main__':
- retcode = GenericMain(commands)
- sys.exit(retcode)
+ sys.exit(GenericMain(commands))