def configure(): """ Set up the multipath daemon configuration to the known and supported state. The original configuration, if any, is saved """ if os.path.exists(_CONF_FILE): backup = _CONF_FILE + '.' + time.strftime("%Y%m%d%H%M") shutil.copyfile(_CONF_FILE, backup) sys.stdout.write("Backup previous multipath.conf to %r\n" % backup) with tempfile.NamedTemporaryFile( mode="wb", prefix=os.path.basename(_CONF_FILE) + ".tmp", dir=os.path.dirname(_CONF_FILE), delete=False) as f: try: f.write(_CONF_DATA) f.flush() selinux.restorecon(f.name) os.chmod(f.name, 0o644) os.rename(f.name, _CONF_FILE) except: os.unlink(f.name) raise # Flush all unused multipath device maps commands.execCmd([constants.EXT_MULTIPATH, "-F"]) try: service.service_reload("multipathd") except service.ServiceOperationError: status = service.service_status("multipathd", False) if status == 0: raise
def configure(): """ Set up the multipath daemon configuration to the known and supported state. The original configuration, if any, is saved """ if os.path.exists(_CONF_FILE): backup = _CONF_FILE + '.' + time.strftime("%Y%m%d%H%M") shutil.copyfile(_CONF_FILE, backup) sys.stdout.write("Backup previous multipath.conf to %r\n" % backup) utils.persist(backup) with tempfile.NamedTemporaryFile( mode="wb", prefix=os.path.basename(_CONF_FILE) + ".tmp", dir=os.path.dirname(_CONF_FILE), delete=False) as f: try: f.write(_CONF_DATA) f.flush() if selinux.is_selinux_enabled(): selinux.restorecon(f.name) os.chmod(f.name, 0o644) # On ovirt node multipath.conf is a bind mount and rename will fail # if we do not unpersist first, making this non-atomic. utils.unpersist(_CONF_FILE) os.rename(f.name, _CONF_FILE) except: os.unlink(f.name) raise utils.persist(_CONF_FILE) # Flush all unused multipath device maps commands.execCmd([constants.EXT_MULTIPATH, "-F"]) try: service.service_reload("multipathd") except service.ServiceOperationError: status = service.service_status("multipathd", False) if status == 0: raise
def configure(): """ Set up the multipath daemon configuration to the known and supported state. The original configuration, if any, is saved """ if os.path.exists(_CONF_FILE): backup = _CONF_FILE + '.' + time.strftime("%Y%m%d%H%M") shutil.copyfile(_CONF_FILE, backup) sys.stdout.write("Backup previous multipath.conf to %r\n" % backup) with tempfile.NamedTemporaryFile( mode="wb", prefix=os.path.basename(_CONF_FILE) + ".tmp", dir=os.path.dirname(_CONF_FILE), delete=False) as f: try: f.write(_CONF_DATA) f.flush() selinux.restorecon(f.name) os.chmod(f.name, 0o644) os.rename(f.name, _CONF_FILE) except: os.unlink(f.name) raise # Flush all unused multipath device maps. 'multipath' # returns 1 if any of the devices is in use and unable to flush. try: commands.run([constants.EXT_MULTIPATH, "-F"]) except cmdutils.Error: pass try: service.service_reload("multipathd") except service.ServiceOperationError: status = service.service_status("multipathd", False) if status == 0: raise