Change in vdsm[master]: wip: Adding the verb run_vdsmd_with_new_conf
ybronhei at redhat.com
ybronhei at redhat.com
Tue Jan 20 09:25:06 UTC 2015
Yaniv Bronhaim has uploaded a new change for review.
Change subject: wip: Adding the verb run_vdsmd_with_new_conf
......................................................................
wip: Adding the verb run_vdsmd_with_new_conf
This patch is part of www.ovirt.org/Features/HostConfiguration
Change-Id: Ieb7077978c367ec5730a704a3252dbd928e03c30
Signed-off-by: Yaniv Bronhaim <ybronhei at redhat.com>
---
M debian/vdsm-python.install
M lib/vdsm/tool/Makefile.am
A lib/vdsm/tool/run_vdsmd_with_new_conf.py.in
M vdsm.spec.in
4 files changed, 74 insertions(+), 0 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/19/37119/1
diff --git a/debian/vdsm-python.install b/debian/vdsm-python.install
index f633e54..7e7984d 100644
--- a/debian/vdsm-python.install
+++ b/debian/vdsm-python.install
@@ -25,6 +25,7 @@
./usr/lib/python2.7/dist-packages/vdsm/tool/nwfilter.py
./usr/lib/python2.7/dist-packages/vdsm/tool/passwd.py
./usr/lib/python2.7/dist-packages/vdsm/tool/restore_nets.py
+./usr/lib/python2.7/dist-packages/vdsm/tool/run_vdsmd_with_new_conf.py
./usr/lib/python2.7/dist-packages/vdsm/tool/service.py
./usr/lib/python2.7/dist-packages/vdsm/tool/transient.py
./usr/lib/python2.7/dist-packages/vdsm/tool/unified_persistence.py
diff --git a/lib/vdsm/tool/Makefile.am b/lib/vdsm/tool/Makefile.am
index 562a995..5dbfe0e 100644
--- a/lib/vdsm/tool/Makefile.am
+++ b/lib/vdsm/tool/Makefile.am
@@ -29,11 +29,13 @@
EXTRA_DIST = \
load_needed_modules.py.in \
+ run_vdsmd_with_new_conf.py.in \
validate_ovirt_certs.py.in \
$(NULL)
nodist_vdsmtool_PYTHON = \
load_needed_modules.py \
+ run_vdsmd_with_new_conf.py \
validate_ovirt_certs.py \
$(NULL)
diff --git a/lib/vdsm/tool/run_vdsmd_with_new_conf.py.in b/lib/vdsm/tool/run_vdsmd_with_new_conf.py.in
new file mode 100644
index 0000000..fbc2de0
--- /dev/null
+++ b/lib/vdsm/tool/run_vdsmd_with_new_conf.py.in
@@ -0,0 +1,70 @@
+# 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
+#
+
+import errno
+import sys
+import os
+import time
+import shutil
+from . import expose, UsageError, ExtraArgsError, service
+
+
+ at expose("run_vdsmd_with_new_conf")
+def run_vdsmd_with_new_conf(*args):
+ """
+ vdsmd_with_new_conf
+ The command gets as parameter a path to vdsm.conf file and replace the
+ current one with its content and restart vdsmd. If vdsmd fails to start
+ we fallback to recent conf file and start again.
+ """
+ sys.stdout.write('Warning: This command attempt to restart vdsmd\n')
+ if len(args) < 2:
+ raise UsageError("Path to config file is required")
+
+ if len(args) > 2:
+ raise ExtraArgsError()
+
+ new_config_path = args[1]
+ path = '@CONFDIR@/vdsm.conf'
+ if os.path.exists(path):
+ backup = path + '.' + time.strftime("%Y%m%d%H%M")
+ shutil.copyfile(path, backup)
+ sys.stdout.write('Saved backup file %s\n' % backup)
+
+ try:
+ new_content = None
+ with open(new_config_path, 'r') as f:
+ new_content = f.read()
+
+ sys.stdout.write('Replacing content with file %s\n' % new_config_path)
+
+ with open(path, 'w') as f:
+ f.write(new_content)
+
+ except IOError as e:
+ if e.errno == errno.ENOENT:
+ return
+ raise
+
+ sys.stdout.write('Starting vdsmd service\n')
+ rc = service.service_restart('vdsmd')
+ if rc != 0:
+ sys.stdout.write('Failed to start - Falling back to backup file\n')
+ shutil.copyfile(backup, path)
+ service.service_restart('vdsmd')
diff --git a/vdsm.spec.in b/vdsm.spec.in
index f48b40e..c02e08c 100644
--- a/vdsm.spec.in
+++ b/vdsm.spec.in
@@ -1329,6 +1329,7 @@
%{python_sitelib}/%{vdsm_name}/tool/configurators/multipath.py*
%{python_sitelib}/%{vdsm_name}/tool/passwd.py*
%{python_sitelib}/%{vdsm_name}/tool/restore_nets.py*
+%{python_sitelib}/%{vdsm_name}/tool/run_vdsmd_with_new_conf.py*
%{python_sitelib}/%{vdsm_name}/tool/service.py*
%{python_sitelib}/%{vdsm_name}/tool/transient.py*
%{python_sitelib}/%{vdsm_name}/tool/unified_persistence.py*
--
To view, visit http://gerrit.ovirt.org/37119
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ieb7077978c367ec5730a704a3252dbd928e03c30
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