Commit 007a2f3e authored by Alexander Schreiber's avatar Alexander Schreiber
Browse files

Patch series for reboot feature, part 1

This patch series implements the reboot command for gnt-instance. It
supports three types of reboot: soft (hypervisor reboot), hard (instance
config rebuild and reboot) and full (full instance shutdown and startup
again).

This patch contains the backend and rpc part of the patch.


Reviewed-by: iustinp
parent fafa5990
......@@ -324,6 +324,16 @@ class ServerObject(pb.Avatar):
extra_args = params[1]
return backend.StartInstance(instance, extra_args)
@staticmethod
def perspective_instance_reboot(params):
"""Reboot an instance.
"""
instance = objects.Instance.FromDict(params[0])
reboot_type = params[1]
extra_args = params[2]
return backend.RebootInstance(instance, reboot_type, extra_args)
@staticmethod
def perspective_instance_info(params):
"""Query instance information.
......
......@@ -585,6 +585,41 @@ def ShutdownInstance(instance):
return True
def RebootInstance(instance, reboot_type, extra_args):
"""Reboot an instance.
Args:
instance - name of instance to reboot
reboot_type - how to reboot [soft,hard,full]
"""
running_instances = GetInstanceList()
if instance.name not in running_instances:
logger.Error("Cannot reboot instance that is not running")
return False
hyper = hypervisor.GetHypervisor()
if reboot_type == constants.INSTANCE_REBOOT_SOFT:
try:
hyper.RebootInstance(instance)
except errors.HypervisorError, err:
logger.Error("Failed to soft reboot instance: %s" % err)
return False
elif reboot_type == constants.INSTANCE_REBOOT_HARD:
try:
ShutdownInstance(instance)
StartInstance(instance, extra_args)
except errors.HypervisorError, err:
logger.Error("Failed to hard reboot instance: %s" % err)
return False
else:
raise errors.ParameterError("reboot_type invalid")
return True
def CreateBlockDevice(disk, size, on_primary, info):
"""Creates a block device for an instance.
......
......@@ -117,3 +117,8 @@ SSH_HOST_DSA_PRIV = SSH_CONFIG_DIR + "ssh_host_dsa_key"
SSH_HOST_DSA_PUB = SSH_HOST_DSA_PRIV + ".pub"
SSH_HOST_RSA_PRIV = SSH_CONFIG_DIR + "ssh_host_rsa_key"
SSH_HOST_RSA_PUB = SSH_HOST_RSA_PRIV + ".pub"
# reboot types
INSTANCE_REBOOT_SOFT = "soft"
INSTANCE_REBOOT_HARD = "hard"
INSTANCE_REBOOT_FULL = "full"
......@@ -311,6 +311,18 @@ def call_instance_shutdown(node, instance):
return c.getresult().get(node, False)
def call_instance_reboot(node, instance, reboot_type, extra_args):
"""Reboots an instance.
This is a single-node call.
"""
c = Client("instance_reboot", [instance.ToDict(), reboot_type, extra_args])
c.connect(node)
c.run()
return c.getresult().get(node, False)
def call_instance_os_add(node, inst, osdev, swapdev):
"""Installs an OS on the given instance.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment