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()))
"""
parent_bdev = _RecursiveFindBD(parent_cdev)
if parent_bdev is None:
- logging.error("Can't find parent device")
- return False
+ msg = "Can't find parent device %s" % str(parent_cdev)
+ logging.error("BlockdevAddchildren: %s", msg)
+ return (False, msg)
new_bdevs = [_RecursiveFindBD(disk) for disk in new_cdevs]
if new_bdevs.count(None) > 0:
- logging.error("Can't find new device(s) to add: %s:%s",
- new_bdevs, new_cdevs)
- return False
+ msg = "Can't find new device(s) to add: %s:%s" % (new_bdevs, new_cdevs)
+ logging.error(msg)
+ return (False, msg)
parent_bdev.AddChildren(new_bdevs)
- return True
+ return (True, None)
def BlockdevRemovechildren(parent_cdev, new_cdevs):
"""
if not os.path.isabs(file_name):
- logging.error("Filename passed to UploadFile is not absolute: '%s'",
- file_name)
- return False
+ err = "Filename passed to UploadFile is not absolute: '%s'" % file_name
+ logging.error(err)
+ return (False, err)
- allowed_files = [
+ allowed_files = set([
constants.CLUSTER_CONF_FILE,
constants.ETC_HOSTS,
constants.SSH_KNOWN_HOSTS_FILE,
constants.VNC_PASSWORD_FILE,
- ]
+ constants.RAPI_CERT_FILE,
+ constants.RAPI_USERS_FILE,
+ ])
+
+ for hv_name in constants.HYPER_TYPES:
+ hv_class = hypervisor.GetHypervisor(hv_name)
+ allowed_files.update(hv_class.GetAncillaryFiles())
if file_name not in allowed_files:
- logging.error("Filename passed to UploadFile not in allowed"
- " upload targets: '%s'", file_name)
- return False
+ err = "Filename passed to UploadFile not in allowed upload targets: '%s'" \
+ % file_name
+ logging.error(err)
+ return (False, err)
raw_data = _Decompress(data)
utils.WriteFile(file_name, data=raw_data, mode=mode, uid=uid, gid=gid,
atime=atime, mtime=mtime)
- return True
+ return (True, "success")
def WriteSsconfFiles(values):
@return: True if all renames succeeded, False otherwise
"""
+ msgs = []
result = True
for disk, unique_id in devlist:
dev = _RecursiveFindBD(disk)
if dev is None:
+ msgs.append("Can't find device %s in rename" % str(disk))
result = False
continue
try:
# cache? for now, we only lose lvm data when we rename, which
# is less critical than DRBD or MD
except errors.BlockDeviceError, err:
+ msgs.append("Can't rename device '%s' to '%s': %s" %
+ (dev, unique_id, err))
logging.exception("Can't rename device '%s' to '%s'", dev, unique_id)
result = False
- return result
+ return (result, "; ".join(msgs))
def _TransformFileStorageDir(file_storage_dir):
return (not failure, (alldone, min_resync))
+def PowercycleNode(hypervisor_type):
+ """Hard-powercycle the node.
+
+ Because we need to return first, and schedule the powercycle in the
+ background, we won't be able to report failures nicely.
+
+ """
+ hyper = hypervisor.GetHypervisor(hypervisor_type)
+ try:
+ pid = os.fork()
+ except OSError, err:
+ # if we can't fork, we'll pretend that we're in the child process
+ pid = 0
+ if pid > 0:
+ return (True, "Reboot scheduled in 5 seconds")
+ time.sleep(5)
+ hyper.PowercycleNode()
+
+
class HooksRunner(object):
"""Hook runner.