'state': state,
'time': times,
}
- if name in output and output[name] != value:
- raise errors.HypervisorError("Instance %s running duplicate"
- " with different parameters" % name)
+ if name in output:
+ # we only check static parameters, like memory and vcpus,
+ # and not state and time which can change between the
+ # invocations of the different hypervisors
+ for key in 'memory', 'vcpus':
+ if value[key] != output[name][key]:
+ raise errors.HypervisorError("Instance %s is running twice"
+ " with different parameters" % name)
output[name] = value
return output
-def InstanceOsAdd(instance):
+def InstanceOsAdd(instance, reinstall):
"""Add an OS to an instance.
@type instance: L{objects.Instance}
@param instance: Instance whose OS is to be installed
+ @type reinstall: boolean
+ @param reinstall: whether this is an instance reinstall
@rtype: boolean
@return: the success of the operation
(os_name, os_dir, os_err))
create_env = OSEnvironment(instance)
+ if reinstall:
+ create_env['INSTANCE_REINSTALL'] = "1"
logfile = "%s/add-%s-%s-%d.log" % (constants.LOG_OS_DIR, instance.os,
instance.name, int(time.time()))
return block_devices
-def StartInstance(instance, extra_args):
+def StartInstance(instance):
"""Start an instance.
@type instance: L{objects.Instance}
try:
block_devices = _GatherAndLinkBlockDevs(instance)
hyper = hypervisor.GetHypervisor(instance.hypervisor)
- hyper.StartInstance(instance, block_devices, extra_args)
+ hyper.StartInstance(instance, block_devices)
except errors.BlockDeviceError, err:
logging.exception("Failed to start instance")
return (False, "Block device error: %s" % str(err))
return (True, "Instance has been shutdown successfully")
-def InstanceReboot(instance, reboot_type, extra_args):
+def InstanceReboot(instance, reboot_type):
"""Reboot an instance.
@type instance: L{objects.Instance}
return (False, msg)
elif reboot_type == constants.INSTANCE_REBOOT_HARD:
try:
- InstanceShutdown(instance)
- StartInstance(instance, extra_args)
+ stop_result = InstanceShutdown(instance)
+ if not stop_result[0]:
+ return stop_result
+ return StartInstance(instance)
except errors.HypervisorError, err:
msg = "Failed to hard reboot instance %s: %s" % (instance.name, err)
logging.error(msg)