def configure(): script = (str(_SASLPASSWD2), '-p', '-a', 'libvirt', SASL_USERNAME) rc, _, err = commands.execCmd(script, data=libvirt_password()) if rc != 0: raise RuntimeError("Set password failed: %s" % (err,)) if utils.isOvirtNode(): # It seems that all /etc/libvirt folder is persisted in node, # but better to persist the db file explicitly utils.persist(_LIBVIRT_SASLDB)
def rotateFiles(directory, prefixName, gen, cp=False, persist=False): log.debug("dir: %s, prefixName: %s, versions: %s" % (directory, prefixName, gen)) gen = int(gen) files = os.listdir(directory) files = glob.glob("%s*" % prefixName) fd = {} for fname in files: name = fname.rsplit('.', 1) try: ind = int(name[1]) except ValueError: name[0] = fname ind = 0 except IndexError: ind = 0 except: continue if ind < gen: fd[ind] = {'old': fname, 'new': name[0] + '.' + str(ind + 1)} keys = fd.keys() keys.sort(reverse=True) log.debug("versions found: %s" % (keys)) for key in keys: oldName = os.path.join(directory, fd[key]['old']) newName = os.path.join(directory, fd[key]['new']) if utils.isOvirtNode() and persist and not cp: try: utils.unpersist(oldName) utils.unpersist(newName) except: pass try: if cp: execCmd([constants.EXT_CP, oldName, newName], sudo=True) if (utils.isOvirtNode() and persist and not os.path.exists(newName)): utils.persist(newName) else: os.rename(oldName, newName) except: pass if utils.isOvirtNode() and persist and not cp: try: utils.persist(newName) except: pass
def _configure(interface, custom_params): """ Enable FCoE on specified interface by coping default configuration Change parameters specified in custom_params argument """ # Map parameters to configuration mane # Check man fcoe-utils to add more parameters filename = _get_config_name(interface) config = _parse_config(_custom_parameter_to_config(custom_params)) with open(filename, 'w') as outfile: outfile.write(CONFFILE_HEADER + "\n") for name, value in six.iteritems(config): outfile.write('%s="%s"\n' % (name, value)) utils.persist(filename)
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) 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