Change in vdsm[master]: Adding remove\disable verbs to vdsm-tool for admin usages
ybronhei at redhat.com
ybronhei at redhat.com
Wed Nov 27 11:25:56 UTC 2013
Yaniv Bronhaim has uploaded a new change for review.
Change subject: Adding remove\disable verbs to vdsm-tool for admin usages
......................................................................
Adding remove\disable verbs to vdsm-tool for admin usages
The spec will be modified separately to use vdsm-tool instead of hard-coded
operations
Change-Id: Ie7f2c031436a6d202f856c24d9c9420c8bfdf6df
Signed-off-by: Yaniv Bronhaim <ybronhei at redhat.com>
---
M lib/vdsm/constants.py.in
M lib/vdsm/tool/configurator.py
M lib/vdsm/tool/passwd.py
M lib/vdsm/tool/seboolsetup.py
4 files changed, 118 insertions(+), 3 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/72/21772/1
diff --git a/lib/vdsm/constants.py.in b/lib/vdsm/constants.py.in
index 790a3a0..43e13da 100644
--- a/lib/vdsm/constants.py.in
+++ b/lib/vdsm/constants.py.in
@@ -80,6 +80,15 @@
P_VDSM_EXEC = '@LIBEXECDIR@'
#
+# Configuration file definitions
+#
+SYSCONF_PATH = '@sysconfdir@'
+P_SYSTEMCTL_CONF = SYSCONF_PATH + '/sysctl.d/vdsm'
+P_VDSM_LCONF = SYSCONF_PATH + '/libvirt/libvirtd.conf'
+P_VDSM_LDCONF = SYSCONF_PATH + '/sysconfig/libvirtd'
+P_VDSM_QCONF = SYSCONF_PATH + '/libvirt/qemu.conf'
+
+#
# External programs (sorted, please keep in order).
#
EXT_BLKID = '@BLKID_PATH@'
diff --git a/lib/vdsm/tool/configurator.py b/lib/vdsm/tool/configurator.py
index 51eda80..a30827a 100644
--- a/lib/vdsm/tool/configurator.py
+++ b/lib/vdsm/tool/configurator.py
@@ -21,11 +21,13 @@
import sys
import grp
import argparse
+import tempfile
+import shutil
from .. import utils
from . import service, expose
-from ..constants import P_VDSM_EXEC, DISKIMAGE_GROUP
-from ..constants import QEMU_PROCESS_GROUP, VDSM_GROUP
+from ..constants import P_VDSM_EXEC, DISKIMAGE_GROUP, QEMU_PROCESS_GROUP, \
+ VDSM_GROUP, P_VDSM_LCONF, P_VDSM_QCONF, P_VDSM_LDCONF, P_SYSTEMCTL_CONF
class _ModuleConfigure(object):
@@ -47,6 +49,35 @@
def isconfigured(self):
return True
+ def removeConf(self, filename, beginField=None, endField=None):
+ newfile = []
+ if not beginField and not endField:
+ return
+ else:
+ with open(filename, 'r') as f:
+ skip = False
+ for line in f.readlines():
+ if beginField and endField:
+ if skip:
+ if line.startswith(endField):
+ skip = False
+ continue
+ if line.startswith(beginField):
+ skip = True
+ continue
+ elif beginField:
+ if line.startswith(beginField):
+ continue
+ else:
+ if line.endswith('%s\n' % endField):
+ continue
+ newfile.append(line)
+ tmp_file = tempfile.NamedTemporaryFile(delete=False)
+ tname = tmp_file.name
+ tmp_file.writelines(newfile)
+ tmp_file.close()
+ shutil.move(tname, filename)
+
class LibvirtModuleConfigure(_ModuleConfigure):
def __init__(self):
@@ -57,6 +88,28 @@
def getServices(self):
return ["supervdsmd", "vdsmd", "libvirtd"]
+
+ def removeConf(self):
+ vdsm_ver = '-4.9.10'
+ conf_prefix = '## beginning of configuration section by vdsm' + \
+ vdsm_ver
+ conf_suffix = '## end of configuration section by vdsm' + vdsm_ver
+
+ conf_paths = [
+ P_VDSM_LCONF,
+ P_VDSM_QCONF,
+ P_VDSM_LDCONF,
+ ]
+ for path in conf_paths:
+ try:
+ super(LibvirtModuleConfigure, self).removeConf(path,
+ conf_prefix,
+ conf_suffix)
+ except OSError, e:
+ if e.errno != os.errno.EEXIST:
+ raise
+
+ utils.rmFile(P_SYSTEMCTL_CONF)
def _exec_libvirt_configure(self, action):
"""
@@ -113,6 +166,9 @@
def getServices(self):
return ['sanlock']
+
+ def removeConf(self):
+ pass
def configure(self):
"""
@@ -257,6 +313,25 @@
raise RuntimeError("Config is not valid. Check conf files")
+ at expose("remove-config")
+def remove_config(*args):
+ """
+ Remove vdsm configuration from conf files
+ """
+ args = _parse_args('remove-config')
+ m = [
+ c.getName() for c in __configurers
+ if c.getName() in args.modules and not c.removeConf()
+ ]
+ if m:
+ sys.stdout.write(
+ "Could not remove configuration for modules %s\n" % ','.join(m),
+ )
+ ret = False
+ if not ret:
+ raise RuntimeError("Remove configuration failed")
+
+
def _parse_args(action):
parser = argparse.ArgumentParser('vdsm-tool %s' % (action))
allModules = [n.getName() for n in __configurers]
diff --git a/lib/vdsm/tool/passwd.py b/lib/vdsm/tool/passwd.py
index 0b127c8..4e40948 100644
--- a/lib/vdsm/tool/passwd.py
+++ b/lib/vdsm/tool/passwd.py
@@ -43,4 +43,17 @@
stderr=subprocess.PIPE, close_fds=True)
output, err = p.communicate()
if p.returncode != 0:
- raise Exception("Set password failed: %s" % (err, ))
+ raise RuntimeError("Set password failed: %s" % (err, ))
+
+
+ at expose("remove-saslpasswd")
+def remove_saslpasswd():
+ """
+ Remove vdsm password for libvirt connection
+ """
+ script = ['/usr/sbin/saslpasswd2', '-p', '-a', 'libvirt', '-d',
+ constants.SASL_USERNAME]
+ p = subprocess.Popen(script)
+ output, err = p.communicate()
+ if p.returncode != 0:
+ raise RuntimeError("Remove password failed: %s" % (err, ))
diff --git a/lib/vdsm/tool/seboolsetup.py b/lib/vdsm/tool/seboolsetup.py
index f664ecd..7c1effa 100644
--- a/lib/vdsm/tool/seboolsetup.py
+++ b/lib/vdsm/tool/seboolsetup.py
@@ -18,6 +18,7 @@
# Refer to the README and COPYING files for full details of the license
#
+import selinux
from . import expose
SEBOOL_ENABLED = "on"
@@ -63,3 +64,20 @@
def sebool_unconfig():
"""Disable the required selinux booleans"""
setup_booleans(False)
+
+
+ at expose("clear-selinux-policy")
+def clear_selinux_policy():
+ """
+ Clear the changes of selinux policy
+ """
+ selinux_policys = [
+ 'virt_use_nfs',
+ 'virt_use_sanlock',
+ 'sanlock_use_nfs',
+ ]
+
+ if selinux.is_selinux_enabled():
+ for policy in selinux_policys:
+ selinux.security_set_boolean(policy, 0)
+ selinux.security_commit_booleans()
--
To view, visit http://gerrit.ovirt.org/21772
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie7f2c031436a6d202f856c24d9c9420c8bfdf6df
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Yaniv Bronhaim <ybronhei at redhat.com>
More information about the vdsm-patches
mailing list