ShaoHe Feng has uploaded a new change for review. Change subject: move get-conf-item to vdsm-tool ......................................................................
move get-conf-item to vdsm-tool many items in init scripts and spec file. move the complexity from out of the init scripts and spec file and into vdsm-tool Change-Id: I5c64de097bbaea6a8cf862b43243377e10e00391 Signed-off-by: ShaoHe Feng <[email protected]> --- M vdsm-tool/Makefile.am A vdsm-tool/vdsm_conf_item.py.in M vdsm.spec.in M vdsm/vdsmd.init.in 4 files changed, 86 insertions(+), 11 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/95/7695/1 diff --git a/vdsm-tool/Makefile.am b/vdsm-tool/Makefile.am index 6ec0198..dcbf7e1 100644 --- a/vdsm-tool/Makefile.am +++ b/vdsm-tool/Makefile.am @@ -23,9 +23,11 @@ vdsm-tool EXTRA_DIST = \ - validate_ovirt_certs.py.in + validate_ovirt_certs.py.in \ + vdsm_conf_item.py.in dist_vdsmtool_DATA = \ __init__.py \ passwd.py \ - validate_ovirt_certs.py \ No newline at end of file + validate_ovirt_certs.py \ + vdsm_conf_item.py diff --git a/vdsm-tool/vdsm_conf_item.py.in b/vdsm-tool/vdsm_conf_item.py.in new file mode 100644 index 0000000..ed268ff --- /dev/null +++ b/vdsm-tool/vdsm_conf_item.py.in @@ -0,0 +1,72 @@ +# Copyright 2012 IBM, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# +# Refer to the README and COPYING files for full details of the license +# + +# Access python's config files from bash. +# Usage: get-conf-itemname + +from vdsm.tool import expose +try: + from vdsm.config import config + vdsmconf = config +except: + import ConfigParser + vdsmconf = ConfigParser.ConfigParser() +from functools import partial + + +CONF_FILE = "@CONFDIR@/vdsm.conf" + + +def _get_conf_item(file, section, item, default): + vdsmconf.read(file) + try: + return vdsmconf.get(section, item) + except: + return default + + +def print_conf_item(file, section, item, default): + val = _get_conf_item(file, section, item, default) + if (val.lower() == "false" or val.lower() == "true"): + print val.lower() + else: + print val + + +# there are so many item in vdsm.conf so list all the item +# then iterate the list and expose every item in list +# item in tuple: (file, section, value, default) +get_item_list = ( + (CONF_FILE, 'addresses', 'management_port', ''), + (CONF_FILE, 'addresses', 'management_ip', '0.0.0.0'), + (CONF_FILE, 'irs', 'repository', '/rhev/'), + (CONF_FILE, 'irs', 'vdsm_nice', '-5'), + (CONF_FILE, 'vars', 'core_dump_enable', 'false'), + (CONF_FILE, 'vars', 'ssl', 'true'), + (CONF_FILE, 'vars', 'libvirt_log_filters', '1:libvirt 1:remote'), + (CONF_FILE, 'vars', 'libvirt_log_outputs', + '1:file:/var/log/vdsm/libvirt.log'), + (CONF_FILE, 'vars', 'trust_store_path', '/etc/pki/vdsm')) + +for item in get_item_list: + f, s, v, d = item + alias = "get-conf-" + v + globals()[alias] = partial(print_conf_item, f, s, v, d) + globals()[alias].__doc__ = " get %s from vdsm configure file" % v + expose(alias)(globals()[alias]) diff --git a/vdsm.spec.in b/vdsm.spec.in index 0d1b195..e161a93 100644 --- a/vdsm.spec.in +++ b/vdsm.spec.in @@ -720,6 +720,7 @@ %{python_sitearch}/%{vdsm_name}/tool/__init__.py* %{python_sitearch}/%{vdsm_name}/tool/passwd.py* %{python_sitearch}/%{vdsm_name}/tool/validate_ovirt_certs.py* +%{python_sitearch}/%{vdsm_name}/tool/vdsm_conf_item.py* %files tests %doc %{_datadir}/%{vdsm_name}/tests/README diff --git a/vdsm/vdsmd.init.in b/vdsm/vdsmd.init.in index 860e301..b33e1be 100755 --- a/vdsm/vdsmd.init.in +++ b/vdsm/vdsmd.init.in @@ -40,7 +40,7 @@ LDCONF=/etc/sysconfig/libvirtd QLCONF=/etc/libvirt/qemu-sanlock.conf -is_coredump=`$GETCONFITEM $CONF_FILE vars core_dump_enable false | tr A-Z a-z` +is_coredump=`/usr/bin/vdsm-tool get-conf-core_dump_enable` [ $is_coredump != true ] && is_coredump=false SYSTEMCTL_SKIP_REDIRECT=true @@ -52,12 +52,12 @@ check_port_taken() { local MANAGEMENT_PORT MANAGEMENT_IP - MANAGEMENT_PORT=`$GETCONFITEM $CONF_FILE addresses management_port ""` + MANAGEMENT_PORT=`/usr/bin/vdsm-tool get-conf-management_port` if [ -z "$MANAGEMENT_PORT" ]; then log_failure_msg "$prog: management_port not found in $CONF_FILE" return 1 fi - MANAGEMENT_IP=`$GETCONFITEM $CONF_FILE addresses management_ip 0.0.0.0` + MANAGEMENT_IP=`/usr/bin/vdsm-tool get-conf-management_ip` netstat -ntl | grep -q "$MANAGEMENT_IP:$MANAGEMENT_PORT" RETVAL=$? if [ "$RETVAL" -eq 0 ]; then @@ -69,7 +69,7 @@ mk_data_center() { local dc - dc=`$GETCONFITEM $CONF_FILE irs repository /rhev/` + dc=`/usr/bin/vdsm-tool get-conf-repository` /bin/mkdir -p "$dc" /bin/chown vdsm.kvm "$dc" } @@ -110,7 +110,7 @@ test_conflicting_conf() { local listen_tcp auth_tcp ssl - ssl=`$GETCONFITEM $CONF_FILE vars ssl true | tr A-Z a-z` + ssl=`/usr/bin/vdsm-tool get-conf-ssl` [ "$ssl" == true ] && return 0 listen_tcp="`get_libvirt_conf_item $LCONF listen_tcp`" @@ -276,7 +276,7 @@ fi local lconf qconf ldconf - local ssl=`$GETCONFITEM $CONF_FILE vars ssl true | tr A-Z a-z` + local ssl=`/usr/bin/vdsm-tool get-conf-ssl` lconf="$2" qconf="$3" @@ -511,10 +511,10 @@ fi echo $"Starting up vdsm daemon: " - local vdsm_nice=`$GETCONFITEM $CONF_FILE vars vdsm_nice -5` + local vdsm_nice=`/usr/bin/vdsm-tool get-conf-vdsm_nice` - LIBVIRT_LOG_FILTERS=`$GETCONFITEM $CONF_FILE vars libvirt_log_filters "1:libvirt 1:remote"` \ - LIBVIRT_LOG_OUTPUTS=`$GETCONFITEM $CONF_FILE vars libvirt_log_outputs "1:file:/var/log/vdsm/libvirt.log"` \ + LIBVIRT_LOG_FILTERS=`/usr/bin/vdsm-tool get-conf-libvirt_log_filters` \ + LIBVIRT_LOG_OUTPUTS=`/usr/bin/vdsm-tool get-conf-libvirt_log_outputs` \ LC_ALL=C NICELEVEL=$vdsm_nice daemon --user=vdsm @VDSMDIR@/respawn --minlifetime 10 --daemon --masterpid $RESPAWNPIDFILE $VDSM_BIN RETVAL=$? [ "$RETVAL" -eq 0 ] && log_success_msg $"$prog start" || log_failure_msg $"$prog start" -- To view, visit http://gerrit.ovirt.org/7695 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I5c64de097bbaea6a8cf862b43243377e10e00391 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: ShaoHe Feng <[email protected]> _______________________________________________ vdsm-patches mailing list [email protected] https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
