[NEW PATCH] Use automake to build and install vdsm (via gerrit-bot)

Federico Simoncelli fsimonce at redhat.com
Wed Aug 3 12:28:26 UTC 2011


New patch submitted by Federico Simoncelli (fsimonce at redhat.com)

You can review this change at: http://gerrit.usersys.redhat.com/726

commit 58c429a800574307e31f45dc0f8ea84c42c639f4
Author: Federico Simoncelli <fsimonce at redhat.com>
Date:   Mon Jul 18 16:06:49 2011 +0000

    Use automake to build and install vdsm
    
    Autoconf is a tool for producing shell scripts that automatically
    configure software source code packages to adapt to many kinds of
    Posix-like systems.
    Automake aims to allow the programmer to write a makefile in a
    higher-level language, rather than having to write the whole makefile
    manually.
    In VDSM autoconf is used to configure paths and check for tools
    required both at build and run time. Automake is used to generate
    makefiles which already include features like recursion and standard
    targets like: all, dist, clean, distclean.
    
    Change-Id: I91fae2ca646f8f1db8c12708dee1ddd1ae96b38f

diff --git a/Makefile.am b/Makefile.am
new file mode 100644
index 0000000..70c42be
--- /dev/null
+++ b/Makefile.am
@@ -0,0 +1,37 @@
+# Copyright 2008 Red Hat, Inc. and/or its affiliates.
+#
+# Licensed to you under 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.  See the files README and
+# LICENSE_GPL_v2 which accompany this distribution.
+#
+
+SUBDIRS = vdsm vdsm_cli vds_bootstrap vdsm_reg vdsm_hooks
+EXTRA_DIST = vdsm.spec
+
+rpmversion = @PACKAGE_VERSION@
+rpmrelease = @PACKAGE_RELEASE@
+RPMTOP = $(PWD)/rpmtop
+
+TESTS = pyflakes
+
+test: pyflakes exceptions
+	echo $(rpmrelease) $(rpmversion)
+
+.PHONY: pyflakes exceptions
+exceptions:
+	python vdsm/storage/storage_exception.py | grep Collision && exit 1 || true
+
+pyflakes:
+	@git ls-files '*.py' | xargs pyflakes \
+	    || (echo "Pyflakes errors or pyflakes not found"; exit 1)
+
+.PHONY: srpm rpm
+srpm: dist
+	$(MKDIR_P) $(RPMTOP)/{RPMS,SRPMS,SOURCES,BUILD}
+	rpmbuild -ts \
+		--define="_topdir $(RPMTOP)" \
+		--define="_sourcedir $(PWD)" $(DIST_ARCHIVES)
+
+rpm: dist
+	rpmbuild --define="_topdir $(RPMTOP)" -ta $(DIST_ARCHIVES)
diff --git a/Makefile.in b/Makefile.in
deleted file mode 100644
index ac0b198..0000000
--- a/Makefile.in
+++ /dev/null
@@ -1,54 +0,0 @@
-# Copyright 2008 Red Hat, Inc. and/or its affiliates.
-#
-# Licensed to you under 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.  See the files README and
-# LICENSE_GPL_v2 which accompany this distribution.
-#
-SUBDIRS=vdsm_cli re vds_bootstrap vdsm vdsm_reg vdsm_hooks
-DOCS=COPYING README
-
-all: rpm
-
-rpmversion=@PACKAGE_VERSION@
-rpmrelease=@PACKAGE_RELEASE@
-RPMTOP=$(PWD)/rpmtop
-SPEC=vdsm.spec
-
-TARBALL=vdsm-$(rpmversion)-$(rpmrelease).tar.gz
-SRPM=$(RPMTOP)/SRPMS/vdsm-$(rpmversion)-$(rpmrelease).src.rpm
-
-TESTS=pyflakes
-
-test: pyflakes exceptions
-	echo $(rpmrelease) $(rpmversion)
-
-exceptions:
-	python vdsm/storage/storage_exception.py | grep Collision && exit 1 || true
-
-pyflakes:
-	@git ls-files '*.py' | xargs pyflakes \
-	    || (echo "Pyflakes errors or pyflakes not found"; exit 1)
-
-install:
-	for subdir in $(SUBDIRS); do make -C $$subdir $@; done
-
-.PHONY: tarball
-tarball: $(TARBALL)
-$(TARBALL): Makefile $(SUBDIRS) $(DOCS) $(TESTS)
-	tar zcf $(TARBALL) `git ls-files | grep -v /ut/` vdsm.spec configure
-
-.PHONY: srpm rpm
-srpm: $(SRPM)
-$(SRPM): $(TARBALL) vdsm.spec.in
-	mkdir -p $(RPMTOP)/{RPMS,SRPMS,SOURCES,BUILD}
-	rpmbuild -ts \
-	    --define="_topdir $(RPMTOP)" \
-	    --define="_sourcedir $(PWD)" $(TARBALL)
-
-rpm: $(SRPM)
-	rpmbuild --define="_topdir $(RPMTOP)" -ta $(TARBALL)
-
-clean:
-	$(RM) *~ *.pyc vdsm*.tar.gz $(SPEC)
-	$(RM) -r rpmtop
diff --git a/configure.ac b/configure.ac
index ea1cfaa..0533cd0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,5 +1,15 @@
+# Autoconf initialization
 AC_INIT([vdsm], [4.9], [vdsm-devel at lists.fedorahosted.org])
 AC_SUBST([PACKAGE_RELEASE], m4_esyscmd([./build-aux/release.sh]))
+AC_CONFIG_AUX_DIR([build-aux])
+
+# Automake initialization
+AM_INIT_AUTOMAKE([-Wno-portability])
+
+# Checking for build tools
+AC_PROG_CC
+AC_PROG_LN_S
+AM_PATH_PYTHON([2.6])
 
 # Users and groups
 AC_SUBST([VDSMUSER], [vdsm])
@@ -7,6 +17,23 @@ AC_SUBST([VDSMGROUP], [qemu])
 AC_SUBST([METADATAGROUP], [kvm])
 AC_SUBST([QEMUUSER], [qemu])
 
+# VDSM default paths
+AC_SUBST([vdsmdir], ['${datarootdir}/vdsm'])
+AC_SUBST([vdsmconfdir], ['${sysconfdir}/vdsm'])
+AC_SUBST([vdsmlogdir], ['${localstatedir}/log/vdsm'])
+AC_SUBST([vdsmrundir], ['${localstatedir}/run/vdsm'])
+AC_SUBST([vdsmlibdir], ['${localstatedir}/lib/vdsm'])
+AC_SUBST([vdsmpoolsdir], ['${vdsmrundir}/pools'])
+AC_SUBST([vdsmbackupdir], ['${vdsmlogdir}/backup'])
+AC_SUBST([vdsmexecdir], ['${libexecdir}/vdsm'])
+AC_SUBST([vdsmhooksdir], ['${vdsmexecdir}/hooks'])
+AC_SUBST([vdsmtsdir], ['${sysconfdir}/pki/vdsm'])
+
+# VDSM registration default paths
+AC_SUBST([vdsmregdir], ['${datarootdir}/vdsm-reg'])
+AC_SUBST([vdsmregconfdir], ['${sysconfdir}/vdsm-reg'])
+AC_SUBST([vdsmreglogdir], ['${localstatedir}/log/vdsm-reg'])
+
 # External programs (sorted, please keep in order)
 AC_PATH_PROG([BLOCKDEV_PATH], [blockdev], [/sbin/blockdev])
 AC_PATH_PROG([BRCTL_PATH], [brctl], [/usr/sbin/brctl])
@@ -62,9 +89,17 @@ AC_PATH_PROG([WGET_PATH], [wget], [/usr/bin/wget])
 AC_PATH_PROG([YUM_PATH], [yum], [/usr/bin/yum])
 
 AC_OUTPUT([
-	vdsm.spec
 	Makefile
+	vds_bootstrap/Makefile
+	vdsm_cli/Makefile
+	vdsm_hooks/faqemu/Makefile
+	vdsm_hooks/Makefile
+	vdsm_hooks/vhostmd/Makefile
 	vdsm/Makefile
+	vdsm_reg/Makefile
+	vdsm/storage/Makefile
+	vdsm/storage/protect/Makefile
+	vdsm.spec
 	vdsm/constants.py.in
 	vdsm/sudoers.vdsm.in
 	vdsm/mk_sysprep_floppy
diff --git a/vds_bootstrap/Makefile b/vds_bootstrap/Makefile
deleted file mode 100644
index 2c023ae..0000000
--- a/vds_bootstrap/Makefile
+++ /dev/null
@@ -1,25 +0,0 @@
-# Copyright 2008 Red Hat, Inc. and/or its affiliates.
-#
-# Licensed to you under 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.  See the files README and
-# LICENSE_GPL_v2 which accompany this distribution.
-#
-
-INSTALL      = install
-VDSMBOOTDIR  = /usr/share/vdsm-bootstrap
-PYSRCS       = vds_bootstrap.py vds_bootstrap_complete.py
-
-all: $(PYSRCS)
-
-install:
-	$(INSTALL) -Dd 755 $(DESTDIR)$(VDSMBOOTDIR)
-	$(INSTALL) -Dm 755 $(PYSRCS) $(DESTDIR)$(VDSMBOOTDIR)
-	$(INSTALL) -Dm 644 deployUtil.py $(DESTDIR)$(VDSMBOOTDIR)
-
-clean:
-	$(RM) *.pyc *.pyo  *~
-
-pyflakes:
-	find . -name "*.py" | xargs pyflakes
-
diff --git a/vds_bootstrap/Makefile.am b/vds_bootstrap/Makefile.am
new file mode 100644
index 0000000..8199cbf
--- /dev/null
+++ b/vds_bootstrap/Makefile.am
@@ -0,0 +1,14 @@
+# Copyright 2008 Red Hat, Inc. and/or its affiliates.
+#
+# Licensed to you under 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.  See the files README and
+# LICENSE_GPL_v2 which accompany this distribution.
+#
+
+vdsmbootstrapdir = $(datarootdir)/vdsm-bootstrap
+
+dist_vdsmbootstrap_DATA = \
+	deployUtil.py \
+	vds_bootstrap_complete.py \
+	vds_bootstrap.py
diff --git a/vdsm.spec.in b/vdsm.spec.in
index decb7aa..b4a4e8c 100644
--- a/vdsm.spec.in
+++ b/vdsm.spec.in
@@ -6,7 +6,7 @@
 
 Summary: Virtual Desktop Server Manager
 Name: vdsm
-Source: %{vdsm_name}-%{version}-%{vdsm_release}.tar.gz
+Source: %{vdsm_name}-%{version}.tar.gz
 # Url: no upstream project exists
 # tarball built from internal git repo with
 #       make tarball rpmversion=<version> rpmrelease=<release>
@@ -44,32 +44,15 @@ storage, memory and networks as well as virtual machine creation, other host
 administration tasks, statistics gathering, and log collection.
 
 %prep
-%setup -c -q
+%setup -q
 
 %build
 %configure
-make -C vdsm CFLAGS="$RPM_OPT_FLAGS"
-baserelease=`echo "%{release}" | sed 's/\([0-9]\+\(\.[0-9]\+\)\?\).*/\1/'`
-sed -i 's/^software_version =.*/software_version = "%{version}"/;s/software_revision =.*/software_revision = "'"$baserelease"'"/' re/dsaversion.py
-
+make
 
 %install
-rm -rf "%{buildroot}"
-mkdir -p "%{buildroot}"
-make DESTDIR="%{buildroot}" \
-     ETC=%{_sysconfdir} \
-     VDSMDIR=%{_datadir}/%{vdsm_name} \
-     VDSMLOGDIR=%{_localstatedir}/log/%{vdsm_name} \
-     TRUSTSTORE=%{_sysconfdir}/pki/%{vdsm_name} \
-     BINDIR=%{_bindir} \
-     LIBEXECDIR=%{_libexecdir}/%{vdsm_name} \
-     CONFDIR=%{_sysconfdir}/%{vdsm_name} \
-     REGCONFDIR=%{_sysconfdir}/%{vdsm_name}-reg \
-     VDSMRUNDIR=%{_localstatedir}/run/%{vdsm_name} \
-     VDSMLIBDIR=%{_localstatedir}/lib/%{vdsm_name} \
-     SOSPLUGINDIR=%{py_sitedir}/sos/plugins \
-     OVIRT_CONFIG_SETUP=%{py_sitedir}/ovirt_config_setup \
-     install
+rm -rf %{buildroot}
+make DESTDIR=%{buildroot} install
 
 # this is not commonplace, but we want /var/log/core to be a world-writable
 # dropbox for core dumps.
@@ -230,6 +213,7 @@ machines without running real guests.
 
 %files
 %defattr(-,root,root,-)
+%doc vdsm/vdsm.conf.sample
 %dir %{_libexecdir}/%{vdsm_name}
 %dir %{_datadir}/%{vdsm_name}
 %dir %{_datadir}/%{vdsm_name}/storage
@@ -253,7 +237,6 @@ machines without running real guests.
 %{_datadir}/%{vdsm_name}/mk_sysprep_floppy
 %{_datadir}/%{vdsm_name}/get-vm-pid
 %{_datadir}/%{vdsm_name}/prepare-vmchannel
-%doc vdsm/vdsm.conf.sample
 %config(noreplace) %{_sysconfdir}/%{vdsm_name}/logger.conf
 %config(noreplace) %{_sysconfdir}/logrotate.d/vdsm
 %config(noreplace) %{_sysconfdir}/rwtab.d/vdsm
diff --git a/vdsm/Makefile.am b/vdsm/Makefile.am
new file mode 100644
index 0000000..25bedd2
--- /dev/null
+++ b/vdsm/Makefile.am
@@ -0,0 +1,153 @@
+# Copyright 2008 Red Hat, Inc. and/or its affiliates.
+#
+# Licensed to you under 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.  See the files README and
+# LICENSE_GPL_v2 which accompany this distribution.
+#
+
+SUBDIRS = storage
+
+dist_vdsm_DATA = \
+	betterThreading.py \
+	caps.py \
+	clientIF.py \
+	configNetwork.py \
+	config.py \
+	constants.py \
+	define.py \
+	dsaversion.py \
+	guestIF.py \
+	hooking.py \
+	hooks.py \
+	kaxmlrpclib.py \
+	ksm.py \
+	libvirtconnection.py \
+	libvirtev.py \
+	libvirtvm.py \
+	logUtils.py \
+	neterrors.py \
+	netinfo.py \
+	pthread.py \
+	SecureXMLRPCServer.py \
+	supervdsm.py \
+	supervdsmServer.py \
+	utils.py \
+	vdsmDebugPlugin.py \
+	vm.py
+
+dist_vdsm_SCRIPTS = \
+	addNetwork \
+	delNetwork \
+	get-conf-item \
+	get-vm-pid \
+	logCollector.sh \
+	mk_sysprep_floppy \
+	prepare-vmchannel \
+	respawn \
+	set-conf-item \
+	vdsm \
+	vdsm-restore-net-config \
+	vdsm-store-net-config \
+	write-net-config
+
+dist_man8_MANS = \
+	vdsmd.8
+
+noinst_DATA = \
+	logger.conf \
+	sudoers.vdsm \
+	vdsm.conf.sample \
+	vdsmd \
+	vdsm-sosplugin.py
+
+vdsm_SUBST = \
+	$(noinst_DATA) \
+	constants.py \
+	vdsm-restore-net-config \
+	vdsm-store-net-config
+
+CLEANFILES = \
+	$(vdsm_SUBST)
+
+EXTRA_DIST = \
+	constants.py.in \
+	logger.conf.in \
+	mk_vdsm.conf.sample.py \
+	sudoers.vdsm.in \
+	vdsmd.in \
+	vdsm-logrotate \
+	vdsm-libvirt-logrotate \
+	vdsm-logrotate.conf \
+	vdsm-restore-net-config.in \
+	vdsm.rwtab \
+	vdsm-sosplugin.py.in \
+	vdsm-store-net-config.in
+
+# Reference:
+# http://www.gnu.org/software/automake/manual/html_node/Scripts.html
+do_subst = sed -e "s,[@]CONFDIR[@],$(vdsmconfdir),g" \
+	    -e "s,[@]VDSMLOGDIR[@],$(vdsmlogdir),g" \
+	    -e "s,[@]VDSMDIR[@],$(vdsmdir),g" \
+	    -e "s,[@]HOOKSDIR[@],$(vdsmhooksdir),g" \
+	    -e "s,[@]VDSMRUNDIR[@],$(vdsmrundir),g" \
+	    -e "s,[@]VDSMLIBDIR[@],$(vdsmlibdir),g" \
+	    -e "s,[@]POOLSDIR[@],$(vdsmpoolsdir),g" \
+	    -e "s,[@]BACKUPDIR[@],$(vdsmbackupdir),g" \
+	    -e "s,[@]LIBEXECDIR[@],$(vdsmexecdir),g" \
+	    -e "s,[@]TRUSTSTORE[@],$(vdsmtsdir),g"
+
+$(vdsm_SUBST): Makefile
+	$(do_subst) < $@.in > $@
+
+vdsm.conf.sample: config.py
+	python mk_vdsm.conf.sample.py > vdsm.conf.sample
+
+install-data-hook:
+	chmod 440 $(DESTDIR)$(sysconfdir)/sudoers.d/50_vdsm
+	chmod 775 $(DESTDIR)$(localstatedir)/lib/libvirt/qemu/channels
+
+install-data-local: install-data-init install-data-logger \
+		install-data-rwtab install-data-logrotate \
+		install-data-sudoers install-data-sosplugin
+	$(MKDIR_P) $(DESTDIR)$(vdsmtsdir)/keys
+	$(MKDIR_P) $(DESTDIR)$(vdsmtsdir)/certs
+	$(MKDIR_P) $(DESTDIR)$(vdsmlogdir)
+	$(MKDIR_P) $(DESTDIR)$(vdsmrundir)
+	$(MKDIR_P) $(DESTDIR)$(vdsmlibdir)/netconfback
+	$(MKDIR_P) $(DESTDIR)$(vdsmpoolsdir)
+	$(MKDIR_P) $(DESTDIR)$(vdsmbackupdir)
+	$(MKDIR_P) $(DESTDIR)$(localstatedir)/lib/libvirt/qemu/channels
+
+install-data-init: $(vdsm_SUBST)
+	$(MKDIR_P) $(DESTDIR)$(sysconfdir)/init.d
+	$(INSTALL_SCRIPT) vdsmd $(DESTDIR)$(sysconfdir)/init.d/vdsmd
+
+install-data-logger: $(vdsm_SUBST)
+	$(MKDIR_P) $(DESTDIR)$(vdsmconfdir)
+	$(INSTALL_DATA) logger.conf $(DESTDIR)$(vdsmconfdir)/logger.conf
+
+install-data-rwtab: $(vdsm_SUBST)
+	$(MKDIR_P) $(DESTDIR)$(sysconfdir)/rwtab.d
+	$(INSTALL_DATA) vdsm.rwtab $(DESTDIR)$(sysconfdir)/rwtab.d/vdsm
+
+install-data-logrotate: $(vdsm_SUBST)
+	$(MKDIR_P) $(DESTDIR)$(sysconfdir)/logrotate.d
+	$(INSTALL_DATA) vdsm-logrotate.conf \
+		$(DESTDIR)$(sysconfdir)/logrotate.d/vdsm
+	$(MKDIR_P) $(DESTDIR)$(sysconfdir)/cron.hourly
+	$(INSTALL_SCRIPT) vdsm-logrotate \
+		$(DESTDIR)$(sysconfdir)/cron.hourly/vdsm-logrotate
+	$(MKDIR_P) $(DESTDIR)$(sysconfdir)/cron.d
+	$(INSTALL_SCRIPT) vdsm-libvirt-logrotate \
+		$(DESTDIR)$(sysconfdir)/cron.d/vdsm-libvirt-logrotate
+
+install-data-sudoers: $(vdsm_SUBST)
+	$(MKDIR_P) $(DESTDIR)$(sysconfdir)/sudoers.d
+	$(INSTALL_DATA) sudoers.vdsm \
+		$(DESTDIR)$(sysconfdir)/sudoers.d/50_vdsm
+
+install-data-sosplugin: $(vdsm_SUBST)
+	$(MKDIR_P) $(DESTDIR)$(pythondir)/sos/plugins
+	$(INSTALL_DATA) vdsm-sosplugin.py \
+		$(DESTDIR)$(pythondir)/sos/plugins/vdsm.py
diff --git a/vdsm/Makefile.in b/vdsm/Makefile.in
deleted file mode 100644
index a188f27..0000000
--- a/vdsm/Makefile.in
+++ /dev/null
@@ -1,123 +0,0 @@
-# Copyright 2008 Red Hat, Inc. and/or its affiliates.
-#
-# Licensed to you under 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.  See the files README and
-# LICENSE_GPL_v2 which accompany this distribution.
-#
-
-INSTALL=install
-
-FILES=define.py utils.py constants.py \
-      vm.py libvirtvm.py libvirtev.py \
-      caps.py clientIF.py hooks.py hooking.py \
-      guestIF.py dsaversion.py \
-      configNetwork.py SecureXMLRPCServer.py ksm.py \
-      netinfo.py neterrors.py \
-      kaxmlrpclib.py config.py logUtils.py \
-      supervdsm.py supervdsmServer.py \
-      libvirtconnection.py vdsmDebugPlugin.py \
-      pthread.py betterThreading.py \
-
-SCRIPTFILES=vdsm logCollector.sh \
-            addNetwork delNetwork \
-            get-conf-item set-conf-item \
-            mk_sysprep_floppy \
-            write-net-config vdsm-restore-net-config \
-            vdsm-store-net-config \
-            get-vm-pid respawn \
-            prepare-vmchannel
-
-STORAGEFILES=storageConstants.py dispatcher.py storage_exception.py \
-             __init__.py \
-             sd.py sp.py blockSD.py fileSD.py hsm.py safelease.py spm.py \
-             image.py volume.py blockVolume.py fileVolume.py taskManager.py\
-             resourceManager.py storage_connection.py fileUtils.py misc.py hba.py \
-             lvm.py iscsi.py multipath.py threadPool.py task.py \
-             storage_mailbox.py sdc.py sdf.py persistentDict.py \
-             threadLocal.py nfsSD.py localFsSD.py resourceFactories.py \
-	     outOfProcess.py processPool.py devicemapper.py
-
-FILES_SUBSTITUTIONS = \
-	constants.py \
-	vdsm-sosplugin.py \
-	sudoers.vdsm \
-	logger.conf \
-	vdsmd \
-	vdsm-store-net-config \
-	vdsm-restore-net-config
-
-PROTECTFILES=spmprotect.sh spmstop.sh safelease
-
-prefix = @prefix@
-exec_prefix = @exec_prefix@
-VDSMDIR = @datarootdir@/vdsm
-VDSMLOGDIR = @localstatedir@/log/vdsm
-VDSMRUNDIR = @localstatedir@/run/vdsm
-VDSMLIBDIR = @localstatedir@/lib/vdsm
-LOGROTATEDIR = @sysconfdir@/logrotate.d
-SOSPLUGINDIR = @libdir@/python/site-packages/sos/plugins
-POOLSDATADIR = $(VDSMRUNDIR)/pools
-BACKUPDIR = $(VDSMLOGDIR)/backup
-LIBEXECDIR = @libexecdir@/vdsm
-HOOKSDIR = $(LIBEXECDIR)/hooks
-CONFDIR = $(VDSMDIR)
-TRUSTSTORE = $(VDSMRUNDIR)/ts
-MANDIR = @mandir@
-UDEVDIR = @sysconfdir@/udev/rules.d
-
-CFLAGS=-Wall -O
-
-all: storage/protect/safelease
-
-vdsm.conf.sample: config.py
-	python mk_vdsm.conf.sample.py > vdsm.conf.sample
-
-# Reference:
-# http://www.gnu.org/software/automake/manual/html_node/Scripts.html#Scripts
-do_subst = sed -e "s,[@]CONFDIR[@],$(CONFDIR),g" \
-	    -e "s,[@]VDSMLOGDIR[@],$(VDSMLOGDIR),g" \
-	    -e "s,[@]VDSMDIR[@],$(VDSMDIR),g" \
-	    -e "s,[@]HOOKSDIR[@],$(HOOKSDIR),g" \
-	    -e "s,[@]VDSMRUNDIR[@],$(VDSMRUNDIR),g" \
-	    -e "s,[@]VDSMLIBDIR[@],$(VDSMLIBDIR),g" \
-	    -e "s,[@]POOLSDIR[@],$(POOLSDATADIR),g" \
-	    -e "s,[@]BACKUPDIR[@],$(BACKUPDIR),g" \
-	    -e "s,[@]LIBEXECDIR[@],$(LIBEXECDIR),g" \
-	    -e "s,[@]TRUSTSTORE[@],$(TRUSTSTORE),g"
-
-$(FILES_SUBSTITUTIONS):
-	$(do_subst) < $@.in > $@
-
-install: $(FILES_SUBSTITUTIONS) vdsm.conf.sample
-	$(INSTALL) -Dd $(DESTDIR)$(VDSMDIR)/storage/protect
-	$(INSTALL) -Dd $(DESTDIR)$(TRUSTSTORE)/{certs,keys}
-	$(INSTALL) -Dd $(DESTDIR)$(VDSMLOGDIR)
-	$(INSTALL) -Dd $(DESTDIR)$(VDSMRUNDIR)
-	$(INSTALL) -Dd $(DESTDIR)$(VDSMLIBDIR)/netconfback
-	$(INSTALL) -Dd $(DESTDIR)$(POOLSDATADIR)
-	$(INSTALL) -Dd $(DESTDIR)$(BACKUPDIR)
-	$(INSTALL) -Dd $(DESTDIR)$(POOLDATADIR)
-	$(INSTALL) -Dd $(DESTDIR)$(LIBEXECDIR)
-	$(INSTALL) -Dd $(DESTDIR)/etc/init.d
-	$(INSTALL) -Dd $(DESTDIR)/etc/udev/rules.d
-	$(INSTALL) -Dd -m 775 $(DESTDIR)/var/lib/libvirt/qemu/channels
-	$(INSTALL) -Dm 644 $(FILES) $(DESTDIR)$(VDSMDIR)
-	$(INSTALL) -Dm 755 $(SCRIPTFILES) $(DESTDIR)$(VDSMDIR)
-	(cd storage; \
-	    $(INSTALL) -Dm 644 $(STORAGEFILES) $(DESTDIR)$(VDSMDIR)/storage)
-	(cd storage/protect; \
-	    $(INSTALL) -Dm 755 $(PROTECTFILES) $(DESTDIR)$(LIBEXECDIR))
-	$(INSTALL) -Dm 644 storage/12-vdsm-lvm.rules $(DESTDIR)$(UDEVDIR)
-	$(INSTALL) -Dm 644 logger.conf $(DESTDIR)$(CONFDIR)/logger.conf
-	$(INSTALL) -Dm 755 vdsmd $(DESTDIR)/etc/init.d/vdsmd
-	$(INSTALL) -Dm 440 sudoers.vdsm $(DESTDIR)/etc/sudoers.d/50_vdsm
-	$(INSTALL) -Dm 644 vdsm-logrotate.conf $(DESTDIR)/etc/logrotate.d/vdsm
-	$(INSTALL) -Dm 755 vdsm-logrotate $(DESTDIR)/etc/cron.hourly/vdsm-logrotate
-	$(INSTALL) -Dm 755 vdsm-libvirt-logrotate $(DESTDIR)/etc/cron.d/vdsm-libvirt-logrotate
-	$(INSTALL) -Dm 644 vdsm-sosplugin.py $(DESTDIR)$(SOSPLUGINDIR)/vdsm.py
-	$(INSTALL) -Dm 644 vdsmd.8 $(DESTDIR)$(MANDIR)/man8/vdsmd.8
-	$(INSTALL) -Dm 644 vdsm.rwtab $(DESTDIR)/etc/rwtab.d/vdsm
-
-clean:
-	$(RM) *~ *.pyc storage/protect/safelease vdsm.conf.sample
diff --git a/vdsm/storage/Makefile.am b/vdsm/storage/Makefile.am
new file mode 100644
index 0000000..d8bd81d
--- /dev/null
+++ b/vdsm/storage/Makefile.am
@@ -0,0 +1,57 @@
+# Copyright 2008 Red Hat, Inc. and/or its affiliates.
+#
+# Licensed to you under 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.  See the files README and
+# LICENSE_GPL_v2 which accompany this distribution.
+#
+
+SUBDIRS = protect
+
+vdsmstoragedir = $(vdsmdir)/storage
+dist_vdsmstorage_DATA = \
+	__init__.py \
+	blockSD.py \
+	blockVolume.py \
+	devicemapper.py \
+	dispatcher.py \
+	fileSD.py \
+	fileUtils.py \
+	fileVolume.py \
+	hba.py \
+	hsm.py \
+	image.py \
+	iscsi.py \
+	localFsSD.py \
+	lvm.py \
+	misc.py \
+	multipath.py \
+	nfsSD.py \
+	outOfProcess.py \
+	persistentDict.py \
+	processPool.py \
+	resourceFactories.py \
+	resourceManager.py \
+	safelease.py \
+	sdc.py \
+	sdf.py \
+	sd.py \
+	spm.py \
+	sp.py \
+	storage_connection.py \
+	storageConstants.py \
+	storage_exception.py \
+	storage_mailbox.py \
+	taskManager.py \
+	task.py \
+	threadLocal.py \
+	threadPool.py \
+	volume.py
+
+EXTRA_DIST = \
+	12-vdsm-lvm.rules
+
+install-data-local:
+	$(MKDIR_P) $(DESTDIR)$(sysconfdir)/udev/rules.d
+	$(INSTALL_DATA) 12-vdsm-lvm.rules \
+			$(DESTDIR)$(sysconfdir)/udev/rules.d/12-vdsm-lvm.rules
diff --git a/vdsm/storage/protect/Makefile.am b/vdsm/storage/protect/Makefile.am
new file mode 100644
index 0000000..feb40a9
--- /dev/null
+++ b/vdsm/storage/protect/Makefile.am
@@ -0,0 +1,16 @@
+# Copyright 2008 Red Hat, Inc. and/or its affiliates.
+#
+# Licensed to you under 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.  See the files README and
+# LICENSE_GPL_v2 which accompany this distribution.
+#
+
+vdsmexec_PROGRAMS = safelease
+
+dist_vdsmexec_SCRIPTS = \
+	spmprotect.sh  \
+	spmstop.sh
+
+safelease_SOURCES = \
+	safelease.c
diff --git a/vdsm_cli/Makefile b/vdsm_cli/Makefile
deleted file mode 100644
index 287284b..0000000
--- a/vdsm_cli/Makefile
+++ /dev/null
@@ -1,34 +0,0 @@
-# Copyright 2006 Red Hat, Inc. and/or its affiliates.
-#
-# Licensed to you under 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.  See the files README and
-# LICENSE_GPL_v2 which accompany this distribution.
-#
-
-INSTALL      = install
-
-VDSMDIR      = /usr/share/vdsm
-PYSRCS       = vdsClient.py vdscli.py dumpStorageTable.py
-CONFDIR      = /etc/vdsm
-BINDIR       = bin
-VDSMDIR      = /usr/share/vdsm
-COMPDIR      = /etc/bash_completion.d
-TRUSTSTORE   = /etc/pki/vdsm
-MANDIR	     = /usr/share/man
-
-all: rpm
-
-fixpaths:
-	sed -i "s:@VDSMDIR@:$(VDSMDIR):" vdsClient
-	sed -i "s:@TRUSTSTORE@:$(TRUSTSTORE):" vdscli.py
-
-install: fixpaths
-	$(INSTALL) -Dd $(DESTDIR)/$(VDSMDIR)
-	$(INSTALL) -Dm 644 $(PYSRCS) $(DESTDIR)/$(VDSMDIR)
-	$(INSTALL) -Dm 755 vdsClient $(DESTDIR)/$(BINDIR)/vdsClient
-	$(INSTALL) -Dm 644 vdsClient.completion $(DESTDIR)$(COMPDIR)/vdsClient
-	$(INSTALL) -Dm 644 vdsClient.1 $(DESTDIR)$(MANDIR)/man1/vdsClient.1
-
-clean:
-	$(RM) *~ *.pyc
diff --git a/vdsm_cli/Makefile.am b/vdsm_cli/Makefile.am
new file mode 100644
index 0000000..6da1ac3
--- /dev/null
+++ b/vdsm_cli/Makefile.am
@@ -0,0 +1,43 @@
+# Copyright 2006 Red Hat, Inc. and/or its affiliates.
+#
+# Licensed to you under 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.  See the files README and
+# LICENSE_GPL_v2 which accompany this distribution.
+#
+
+dist_bin_SCRIPTS = \
+	vdsClient
+
+dist_vdsm_DATA = \
+	dumpStorageTable.py \
+	vdsClient.py \
+	vdscli.py
+
+dist_man1_MANS = \
+	vdsClient.1
+
+vdsmcli_SUBST = \
+	vdsClient \
+	vdscli.py
+
+CLEANFILES = \
+	$(vdsmcli_SUBST)
+
+EXTRA_DIST = \
+	vdsClient.completion \
+	vdsClient.in \
+	vdscli.py.in
+
+# Reference:
+# http://www.gnu.org/software/automake/manual/html_node/Scripts.html
+do_subst = sed -e "s,[@]VDSMDIR[@],$(vdsmdir),g" \
+	    -e "s,[@]TRUSTSTORE[@],$(vdsmtsdir),g"
+
+$(vdsmcli_SUBST):
+	$(do_subst) < $@.in > $@
+
+install-data-local: $(vdsmcli_SUBST)
+	$(MKDIR_P) $(DESTDIR)$(sysconfdir)/bash_completion.d
+	$(INSTALL_DATA) vdsClient.completion \
+		$(DESTDIR)$(sysconfdir)/bash_completion.d/vdsClient
diff --git a/vdsm_cli/vdsClient b/vdsm_cli/vdsClient
deleted file mode 100755
index 7e306f9..0000000
--- a/vdsm_cli/vdsClient
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/bin/sh
-
-PYTHONPATH="@VDSMDIR@:$PYTHONPATH" python -m vdsClient "$@"
diff --git a/vdsm_cli/vdsClient.in b/vdsm_cli/vdsClient.in
new file mode 100755
index 0000000..7e306f9
--- /dev/null
+++ b/vdsm_cli/vdsClient.in
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+PYTHONPATH="@VDSMDIR@:$PYTHONPATH" python -m vdsClient "$@"
diff --git a/vdsm_cli/vdscli.py b/vdsm_cli/vdscli.py
deleted file mode 100644
index 4507fe1..0000000
--- a/vdsm_cli/vdscli.py
+++ /dev/null
@@ -1,103 +0,0 @@
-# vdscli: contact vdsm running on localhost over xmlrpc easily
-#
-# Copyright 2009-2010 Red Hat, Inc.
-#
-# Licensed to you under 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.
-
-import xmlrpclib
-import subprocess
-import os
-
-d_useSSL = False
-d_tsPath = '@TRUSTSTORE@'
-d_addr = '0'
-d_port = '54321'
-
-def __guessDefaults():
-    global d_useSSL, d_tsPath, d_addr, d_port
-    VDSM_CONF = '/etc/vdsm/vdsm.conf'
-    try:
-        try:
-            from config import config
-            config.read(VDSM_CONF)
-            d_useSSL = config.getboolean('vars', 'ssl')
-            d_tsPath = config.get('vars', 'trust_store_path')
-            d_port = config.get('addresses', 'management_port')
-            if d_useSSL:
-                d_addr = __getLocalVdsName(d_tsPath)
-            else:
-                if config.get('addresses', 'management_ip'):
-                    d_addr = config.get('addresses', 'management_ip')
-                else:
-                    import netinfo
-                    proposed_addr = netinfo.ifconfig()['rhevm']['addr']
-                    if proposed_addr:
-                        d_addr = proposed_addr
-        except:
-            pass
-        if os.name == 'nt':
-            def getRHEVMInstallPath():
-                import _winreg
-                key_path = 'SOFTWARE\\RedHat\\RHEVM Service'
-                root = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, key_path)
-                val, v_type = _winreg.QueryValueEx(root,"Location")
-                retval = os.path.dirname(os.path.dirname(val))
-                return str(retval)
-            d_tsPath = os.path.join(getRHEVMInstallPath(), "Service", "ca")
-    except:
-        pass
-
-def __getLocalVdsName(tsPath):
-    p = subprocess.Popen(['openssl', 'x509', '-noout', '-subject', '-in',
-            '%s/certs/vdsmcert.pem' % tsPath],
-            stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
-    out, err = p.communicate()
-    if p.returncode != 0:
-        return '0'
-    return out.split('=')[-1].strip()
-
-__guessDefaults()
-
-def cannonizeAddrPort(addrport=None):
-    if addrport is None or addrport == '0':
-        return d_addr + ':' + d_port
-    elif ':' in addrport:
-        return addrport
-    else:
-        return addrport + ':' + d_port
-
-def connect(addrport=None, useSSL=None, tsPath=None):
-    addrport = cannonizeAddrPort(addrport)
-    if useSSL is None: useSSL = d_useSSL
-    if tsPath is None: tsPath = d_tsPath
-    if useSSL:
-        from M2Crypto.m2xmlrpclib import SSL_Transport
-        from M2Crypto import SSL
-
-        if os.name == 'nt':
-            KEYFILE = tsPath + '\\keys\\rhevm.pem'
-            CERTFILE = tsPath + '\\certs\\rhevm.cer'
-            CACERT = tsPath + '\\certs\\ca.pem'
-        else:
-            KEYFILE = tsPath + '/keys/vdsmkey.pem'
-            CERTFILE = tsPath + '/certs/vdsmcert.pem'
-            CACERT = tsPath + '/certs/cacert.pem'
-
-        ctx = SSL.Context ('sslv3')
-
-        ctx.set_verify(SSL.verify_peer | SSL.verify_fail_if_no_peer_cert, 16)
-        ctx.load_verify_locations(CACERT)
-        ctx.load_cert(CERTFILE, KEYFILE, lambda v: "mypass")
-
-        server = xmlrpclib.Server('https://%s' % addrport,
-                                SSL_Transport(ctx))
-    else:
-        server = xmlrpclib.Server('http://%s' % addrport)
-    return server
-
-if __name__ == '__main__':
-    print 'connecting to %s:%s ssl %s ts %s' % (d_addr, d_port, d_useSSL, d_tsPath)
-    server = connect()
-    print server.getVdsCapabilities()
diff --git a/vdsm_cli/vdscli.py.in b/vdsm_cli/vdscli.py.in
new file mode 100644
index 0000000..4507fe1
--- /dev/null
+++ b/vdsm_cli/vdscli.py.in
@@ -0,0 +1,103 @@
+# vdscli: contact vdsm running on localhost over xmlrpc easily
+#
+# Copyright 2009-2010 Red Hat, Inc.
+#
+# Licensed to you under 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.
+
+import xmlrpclib
+import subprocess
+import os
+
+d_useSSL = False
+d_tsPath = '@TRUSTSTORE@'
+d_addr = '0'
+d_port = '54321'
+
+def __guessDefaults():
+    global d_useSSL, d_tsPath, d_addr, d_port
+    VDSM_CONF = '/etc/vdsm/vdsm.conf'
+    try:
+        try:
+            from config import config
+            config.read(VDSM_CONF)
+            d_useSSL = config.getboolean('vars', 'ssl')
+            d_tsPath = config.get('vars', 'trust_store_path')
+            d_port = config.get('addresses', 'management_port')
+            if d_useSSL:
+                d_addr = __getLocalVdsName(d_tsPath)
+            else:
+                if config.get('addresses', 'management_ip'):
+                    d_addr = config.get('addresses', 'management_ip')
+                else:
+                    import netinfo
+                    proposed_addr = netinfo.ifconfig()['rhevm']['addr']
+                    if proposed_addr:
+                        d_addr = proposed_addr
+        except:
+            pass
+        if os.name == 'nt':
+            def getRHEVMInstallPath():
+                import _winreg
+                key_path = 'SOFTWARE\\RedHat\\RHEVM Service'
+                root = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, key_path)
+                val, v_type = _winreg.QueryValueEx(root,"Location")
+                retval = os.path.dirname(os.path.dirname(val))
+                return str(retval)
+            d_tsPath = os.path.join(getRHEVMInstallPath(), "Service", "ca")
+    except:
+        pass
+
+def __getLocalVdsName(tsPath):
+    p = subprocess.Popen(['openssl', 'x509', '-noout', '-subject', '-in',
+            '%s/certs/vdsmcert.pem' % tsPath],
+            stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True)
+    out, err = p.communicate()
+    if p.returncode != 0:
+        return '0'
+    return out.split('=')[-1].strip()
+
+__guessDefaults()
+
+def cannonizeAddrPort(addrport=None):
+    if addrport is None or addrport == '0':
+        return d_addr + ':' + d_port
+    elif ':' in addrport:
+        return addrport
+    else:
+        return addrport + ':' + d_port
+
+def connect(addrport=None, useSSL=None, tsPath=None):
+    addrport = cannonizeAddrPort(addrport)
+    if useSSL is None: useSSL = d_useSSL
+    if tsPath is None: tsPath = d_tsPath
+    if useSSL:
+        from M2Crypto.m2xmlrpclib import SSL_Transport
+        from M2Crypto import SSL
+
+        if os.name == 'nt':
+            KEYFILE = tsPath + '\\keys\\rhevm.pem'
+            CERTFILE = tsPath + '\\certs\\rhevm.cer'
+            CACERT = tsPath + '\\certs\\ca.pem'
+        else:
+            KEYFILE = tsPath + '/keys/vdsmkey.pem'
+            CERTFILE = tsPath + '/certs/vdsmcert.pem'
+            CACERT = tsPath + '/certs/cacert.pem'
+
+        ctx = SSL.Context ('sslv3')
+
+        ctx.set_verify(SSL.verify_peer | SSL.verify_fail_if_no_peer_cert, 16)
+        ctx.load_verify_locations(CACERT)
+        ctx.load_cert(CERTFILE, KEYFILE, lambda v: "mypass")
+
+        server = xmlrpclib.Server('https://%s' % addrport,
+                                SSL_Transport(ctx))
+    else:
+        server = xmlrpclib.Server('http://%s' % addrport)
+    return server
+
+if __name__ == '__main__':
+    print 'connecting to %s:%s ssl %s ts %s' % (d_addr, d_port, d_useSSL, d_tsPath)
+    server = connect()
+    print server.getVdsCapabilities()
diff --git a/vdsm_hooks/Makefile b/vdsm_hooks/Makefile
deleted file mode 100644
index 9145f4a..0000000
--- a/vdsm_hooks/Makefile
+++ /dev/null
@@ -1,30 +0,0 @@
-# Copyright 2008 Red Hat, Inc. and/or its affiliates.
-#
-# Licensed to you under 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.  See the files README and
-# LICENSE_GPL_v2 which accompany this distribution.
-#
-
-INSTALL=install
-
-SUBDIRS=faqemu vhostmd
-
-HOOKS=before_vm_start after_vm_start before_vm_cont after_vm_cont \
-      before_vm_pause after_vm_pause \
-      before_vm_hibernate after_vm_hibernate \
-      before_vm_dehibernate after_vm_dehibernate \
-      before_vm_migrate_source after_vm_migrate_source \
-      before_vm_migrate_destination after_vm_migrate_destination \
-      after_vm_destroy \
-      before_vdsm_start after_vdsm_stop
-
-install:
-	(for hook in $(HOOKS); do \
-	    $(INSTALL) -Dd $(DESTDIR)$(LIBEXECDIR)/hooks/$$hook; \
-	done)
-	$(INSTALL) -Dm 755 persist-vdsm-hooks $(DESTDIR)$(LIBEXECDIR)/persist-vdsm-hooks
-	$(INSTALL) -Dm 755 unpersist-vdsm-hook $(DESTDIR)$(LIBEXECDIR)/unpersist-vdsm-hook
-	(for hook in $(SUBDIRS); do \
-	    make -C $$hook $@; \
-	done)
diff --git a/vdsm_hooks/Makefile.am b/vdsm_hooks/Makefile.am
new file mode 100644
index 0000000..83ca423
--- /dev/null
+++ b/vdsm_hooks/Makefile.am
@@ -0,0 +1,37 @@
+# Copyright 2008 Red Hat, Inc. and/or its affiliates.
+#
+# Licensed to you under 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.  See the files README and
+# LICENSE_GPL_v2 which accompany this distribution.
+#
+
+SUBDIRS = faqemu vhostmd
+
+dist_vdsmexec_SCRIPTS = \
+	persist-vdsm-hooks \
+	unpersist-vdsm-hook
+
+VDSMHOOKS = \
+	before_vm_start \
+	after_vm_start \
+	before_vm_cont \
+	after_vm_cont \
+	before_vm_pause \
+	after_vm_pause \
+	before_vm_hibernate \
+	after_vm_hibernate \
+	before_vm_dehibernate \
+	after_vm_dehibernate \
+	before_vm_migrate_source \
+	after_vm_migrate_source \
+	before_vm_migrate_destination \
+	after_vm_migrate_destination \
+	after_vm_destroy \
+	before_vdsm_start \
+	after_vdsm_stop
+
+install-data-local:
+	(for hook in $(VDSMHOOKS); do \
+	    $(MKDIR_P) $(DESTDIR)$(vdsmexecdir)/hooks/$$hook; \
+	done)
diff --git a/vdsm_hooks/faqemu/Makefile b/vdsm_hooks/faqemu/Makefile
deleted file mode 100644
index 0ec2515..0000000
--- a/vdsm_hooks/faqemu/Makefile
+++ /dev/null
@@ -1,13 +0,0 @@
-INSTALL=install
-LN_S=ln -s
-BINDIR=/usr/bin
-LIBEXECDIR=/usr/libexec/vdsm
-HOOKSDIR=$(LIBEXECDIR)/hooks
-
-install:
-	$(INSTALL) -Dm 755 qemu $(DESTDIR)$(BINDIR)/qemu
-	$(LN_S) qemu $(DESTDIR)$(BINDIR)/qemu-system-x86_64
-	$(INSTALL) -Dm 755 before_vm_start.py $(DESTDIR)$(HOOKSDIR)/before_vm_start/10_faqemu
-
-clean:
-	$(RM) *~ *.pyc
diff --git a/vdsm_hooks/faqemu/Makefile.am b/vdsm_hooks/faqemu/Makefile.am
new file mode 100644
index 0000000..0a04e25
--- /dev/null
+++ b/vdsm_hooks/faqemu/Makefile.am
@@ -0,0 +1,19 @@
+# Copyright 2008 Red Hat, Inc. and/or its affiliates.
+#
+# Licensed to you under 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.  See the files README and
+# LICENSE_GPL_v2 which accompany this distribution.
+#
+
+dist_bin_SCRIPTS = \
+	qemu
+
+EXTRA_DIST = \
+	before_vm_start.py
+
+install-data-local:
+	$(LN_S) qemu $(DESTDIR)$(bindir)/qemu-system-x86_64
+	$(MKDIR_P) $(DESTDIR)$(vdsmhooksdir)/before_vm_start
+	$(INSTALL_SCRIPT) before_vm_start.py \
+		$(DESTDIR)$(vdsmhooksdir)/before_vm_start/10_faqemu
diff --git a/vdsm_hooks/vhostmd/Makefile b/vdsm_hooks/vhostmd/Makefile
deleted file mode 100644
index 6f13033..0000000
--- a/vdsm_hooks/vhostmd/Makefile
+++ /dev/null
@@ -1,16 +0,0 @@
-INSTALL=install
-LN_S=ln -s
-LIBEXECDIR=/usr/libexec/vdsm
-HOOKSDIR=$(LIBEXECDIR)/hooks
-
-all:
-
-install:
-	$(INSTALL) -Dm 755 before_vm_start.py $(DESTDIR)$(HOOKSDIR)/before_vm_start/50_vhostmd
-	$(LN_S) ../before_vm_start/50_vhostmd $(DESTDIR)$(HOOKSDIR)/before_vm_migrate_destination/50_vhostmd
-	$(LN_S) ../before_vm_start/50_vhostmd $(DESTDIR)$(HOOKSDIR)/before_vm_dehibernate/50_vhostmd
-	$(INSTALL) -Dm 755 after_vm_destroy.py $(DESTDIR)$(HOOKSDIR)/after_vm_destroy/50_vhostmd
-	$(INSTALL) -Dm 440 sudoers.vdsm_hook_vhostmd $(DESTDIR)/etc/sudoers.d/50_vdsm_hook_vhostmd
-
-clean:
-	$(RM) *~ *.pyc
diff --git a/vdsm_hooks/vhostmd/Makefile.am b/vdsm_hooks/vhostmd/Makefile.am
new file mode 100644
index 0000000..2b9e499
--- /dev/null
+++ b/vdsm_hooks/vhostmd/Makefile.am
@@ -0,0 +1,34 @@
+# Copyright 2008 Red Hat, Inc. and/or its affiliates.
+#
+# Licensed to you under 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.  See the files README and
+# LICENSE_GPL_v2 which accompany this distribution.
+#
+
+EXTRA_DIST = \
+	after_vm_destroy.py \
+	before_vm_start.py \
+	sudoers.vdsm_hook_vhostmd
+
+install-data-hook:
+	chmod 440 $(DESTDIR)$(sysconfdir)/sudoers.d/50_vdsm_hook_vhostmd
+
+install-data-local: install-data-sudoers
+	$(MKDIR_P) $(DESTDIR)$(vdsmhooksdir)/before_vm_start
+	$(INSTALL_SCRIPT) before_vm_start.py \
+		$(DESTDIR)$(vdsmhooksdir)/before_vm_start/50_vhostmd
+	$(MKDIR_P) $(DESTDIR)$(vdsmhooksdir)/after_vm_destroy
+	$(INSTALL_SCRIPT) after_vm_destroy.py \
+		$(DESTDIR)$(vdsmhooksdir)/after_vm_destroy/50_vhostmd
+	$(MKDIR_P) $(DESTDIR)$(vdsmhooksdir)/before_vm_migrate_destination
+	$(LN_S) ../before_vm_start/50_vhostmd \
+		$(DESTDIR)$(vdsmhooksdir)/before_vm_migrate_destination/50_vhostmd
+	$(MKDIR_P) $(DESTDIR)$(vdsmhooksdir)/before_vm_dehibernate
+	$(LN_S) ../before_vm_start/50_vhostmd \
+		$(DESTDIR)$(vdsmhooksdir)/before_vm_dehibernate/50_vhostmd
+
+install-data-sudoers:
+	$(MKDIR_P) $(DESTDIR)$(sysconfdir)/sudoers.d
+	$(INSTALL_DATA) sudoers.vdsm_hook_vhostmd \
+		$(DESTDIR)$(sysconfdir)/sudoers.d/50_vdsm_hook_vhostmd
diff --git a/vdsm_reg/Makefile b/vdsm_reg/Makefile
deleted file mode 100644
index 035d45a..0000000
--- a/vdsm_reg/Makefile
+++ /dev/null
@@ -1,38 +0,0 @@
-INSTALL=install
-LN_S=ln -s
-VDSMREGDIR=/usr/share/vdsm-reg
-ETC=/etc
-REGCONFDIR=$(ETC)/vdsm-reg
-VDSMREGLOGDIR=/var/log/vdsm-reg
-VDSMRUNDIR=/var/run/vdsm
-MANDIR=/usr/share/man
-
-FILES=define.py config.py deployUtil.py createDaemon.py
-
-all:
-	@echo only \"make install\" is available
-	@false
-
-fixpaths:
-	sed -i "s:@VDSMRUNDIR@:$(VDSMRUNDIR):" vdsm-reg.conf
-
-install: fixpaths
-	$(INSTALL) -Dd $(DESTDIR)$(REGCONFDIR)
-	$(INSTALL) -Dd $(DESTDIR)$(VDSMREGDIR)
-	$(INSTALL) -Dd $(DESTDIR)$(VDSMREGLOGDIR)
-	$(INSTALL) -Dd $(DESTDIR)$(OVIRT_CONFIG_SETUP)
-	$(INSTALL) -Dm 755 vdsm-reg $(DESTDIR)$(ETC)/init.d/vdsm-reg
-	$(INSTALL) -Dm 644 logger.conf $(DESTDIR)$(REGCONFDIR)/logger.conf
-	$(INSTALL) -Dm 644 vdsm-reg.conf $(DESTDIR)$(REGCONFDIR)/vdsm-reg.conf
-	$(INSTALL) -Dm 644 $(FILES) $(DESTDIR)$(VDSMREGDIR)
-	$(INSTALL) -Dm 755 save-config $(DESTDIR)$(VDSMREGDIR)
-	$(INSTALL) -Dm 755 vdsm-reg-setup.py $(DESTDIR)$(VDSMREGDIR)/vdsm-reg-setup
-	$(INSTALL) -Dm 755 vdsm-gen-cert.py $(DESTDIR)$(VDSMREGDIR)/vdsm-gen-cert
-	$(INSTALL) -Dm 755 vdsm-complete.py $(DESTDIR)$(VDSMREGDIR)/vdsm-complete
-	$(INSTALL) -Dm 755 vdsm-upgrade.py $(DESTDIR)$(VDSMREGDIR)/vdsm-upgrade
-	$(INSTALL) -Dd $(DESTDIR)$(ETC)/ovirt-config-setup.d
-	$(INSTALL) -Dm 755 vdsm-config $(DESTDIR)$(ETC)/ovirt-config-boot.d/vdsm-config
-	$(INSTALL) -Dm 644 vdsm-reg-logrotate.conf $(DESTDIR)$(ETC)/logrotate.d/vdsm-reg
-	$(INSTALL) -Dm 755 vdsm-reg-logrotate $(DESTDIR)$(ETC)/cron.hourly
-	$(INSTALL) -Dm 644 vdsm-reg.8 $(DESTDIR)$(MANDIR)/man8/vdsm-reg.8
-	$(INSTALL) -Dm 644 rhevm.py $(DESTDIR)$(OVIRT_CONFIG_SETUP)/rhevm.py
diff --git a/vdsm_reg/Makefile.am b/vdsm_reg/Makefile.am
new file mode 100644
index 0000000..fb66848
--- /dev/null
+++ b/vdsm_reg/Makefile.am
@@ -0,0 +1,75 @@
+# Copyright 2008 Red Hat, Inc. and/or its affiliates.
+#
+# Licensed to you under 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.  See the files README and
+# LICENSE_GPL_v2 which accompany this distribution.
+#
+
+dist_vdsmreg_DATA = \
+	config.py \
+	createDaemon.py \
+	define.py \
+	deployUtil.py
+
+dist_vdsmreg_SCRIPTS = \
+	save-config \
+	vdsm-complete \
+	vdsm-gen-cert \
+	vdsm-reg-setup \
+	vdsm-upgrade
+
+dist_man8_MANS = \
+	vdsm-reg.8
+
+noinst_DATA = \
+	vdsm-reg.conf
+
+vdsmreg_SUBST = \
+	$(noinst_DATA)
+
+CLEANFILES = \
+	$(vdsmreg_SUBST)
+
+EXTRA_DIST = \
+	logger.conf \
+	rhevm.py \
+	vdsm-config \
+	vdsm-reg \
+	vdsm-reg.conf.in \
+	vdsm-reg-logrotate \
+	vdsm-reg-logrotate.conf
+
+# Reference:
+# http://www.gnu.org/software/automake/manual/html_node/Scripts.html
+do_subst = sed -e "s,[@]VDSMRUNDIR[@],$(vdsmrundir),g"
+
+$(vdsmreg_SUBST):
+	$(do_subst) < $@.in > $@
+
+install-data-local: install-data-init install-data-logger install-data-ovirt \
+		install-data-logrotate
+	$(MKDIR_P)  $(DESTDIR)$(vdsmreglogdir)
+
+install-data-init: $(vdsmreg_SUBST)
+	$(MKDIR_P) $(DESTDIR)$(sysconfdir)/init.d
+	$(INSTALL_SCRIPT) vdsm-reg $(DESTDIR)$(sysconfdir)/init.d/vdsm-reg
+
+install-data-logger: $(vdsmreg_SUBST)
+	$(MKDIR_P) $(DESTDIR)$(vdsmregconfdir)
+	$(INSTALL_DATA) logger.conf $(DESTDIR)$(vdsmregconfdir)/logger.conf
+	$(INSTALL_DATA) vdsm-reg.conf $(DESTDIR)$(vdsmregconfdir)/vdsm-reg.conf
+
+install-data-ovirt: $(vdsmreg_SUBST)
+	$(MKDIR_P) $(DESTDIR)$(sysconfdir)/ovirt-config-boot.d
+	$(INSTALL_SCRIPT) vdsm-config $(DESTDIR)$(sysconfdir)/ovirt-config-boot.d/vdsm-config
+	$(MKDIR_P) $(DESTDIR)$(pythondir)/ovirt_config_setup
+	$(INSTALL_DATA) rhevm.py $(DESTDIR)$(pythondir)/ovirt_config_setup/rhevm.py
+
+install-data-logrotate: $(vdsmreg_SUBST)
+	$(MKDIR_P) $(DESTDIR)$(sysconfdir)/logrotate.d
+	$(INSTALL_DATA) vdsm-reg-logrotate.conf \
+		$(DESTDIR)$(sysconfdir)/logrotate.d/vdsm-reg
+	$(MKDIR_P) $(DESTDIR)$(sysconfdir)/cron.hourly
+	$(INSTALL_SCRIPT) vdsm-reg-logrotate \
+		$(DESTDIR)$(sysconfdir)/cron.hourly/vdsm-reg-logrotate
diff --git a/vdsm_reg/vdsm-complete b/vdsm_reg/vdsm-complete
new file mode 100755
index 0000000..316925e
--- /dev/null
+++ b/vdsm_reg/vdsm-complete
@@ -0,0 +1,93 @@
+#!/usr/bin/python
+#
+# Copyright 2008 Red Hat, Inc. and/or its affiliates.
+#
+# Licensed to you under 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.  See the files README and
+# LICENSE_GPL_v2 which accompany this distribution.
+#
+
+import sys
+import getopt
+import logging
+import logging.config
+from time import strftime
+import deployUtil
+
+VDSM_CONF_FILE = '/etc/vdsm/vdsm.conf'
+log_filename = '/var/log/vdsm-reg/vds_bootstrap_complete.'+strftime("%Y%m%d_%H%M%S")+'.log'
+logging.basicConfig(level=logging.DEBUG,
+                    format='%(asctime)s %(levelname)-8s %(message)s',
+                    datefmt='%a, %d %b %Y %H:%M:%S',
+                    filename=log_filename,
+                    filemode='w')
+
+def reboot(act=1):
+    """ Reboot.
+    """
+    logging.debug("Reboot: started.")
+    action = 'Reboot'
+    message = 'Rebooting machine'
+
+    if (act==1):
+        deployUtil.reboot()
+    else:
+        action = 'Restart'
+        message = 'Restarting vdsmd service'
+        deployUtil.setService("vdsmd", "restart")
+
+    print "<BSTRAP component='" + action + "' status='OK' message='" + message + "' />"
+    sys.stdout.flush()
+    logging.debug("Reboot: ended.")
+
+def main():
+    """Usage: ovirt-vdsm-complete.py  [-c vds_config_str] <random_num> [reboot]"""
+    try:
+        vds_config_str = None
+        opts, args = getopt.getopt(sys.argv[1:], "c:")
+        for o,v in opts:
+            if o == "-c":
+                # it should looks like: 'ssl=true;ksm_nice=5;images=/images/irsd'
+                # without white spaces in it.
+                vds_config_str = v
+
+        rnum = args[0]
+    except:
+        print main.__doc__
+        return 0
+    try:
+        act = args[1]
+    except:
+        act = 1
+
+    fOK = True
+    try:
+        fOK = deployUtil.instCert(rnum, VDSM_CONF_FILE)
+        if fOK:
+            fOK = deployUtil.setCoreDumpPath()
+
+        if fOK:
+            fOK = deployUtil.cleanAll(rnum)
+
+        if fOK:
+            fOK = deployUtil.setVdsConf(vds_config_str, VDSM_CONF_FILE)
+
+        if fOK:
+            deployUtil.setService("vdsmd", "reconfigure")
+            reboot(act)
+    except:
+        fOK = False
+
+    if not fOK:
+        print "<BSTRAP component='RHEV_INSTALL' status='FAIL'/>"
+        logging.debug("<BSTRAP component='RHEV_INSTALL' status='FAIL'/>")
+
+    else:
+        print "<BSTRAP component='RHEV_INSTALL' status='OK'/>"
+        logging.debug("<BSTRAP component='RHEV_INSTALL' status='OK'/>")
+
+    sys.stdout.flush()
+
+if __name__ == "__main__":
+    sys.exit(main())
diff --git a/vdsm_reg/vdsm-complete.py b/vdsm_reg/vdsm-complete.py
deleted file mode 100755
index 316925e..0000000
--- a/vdsm_reg/vdsm-complete.py
+++ /dev/null
@@ -1,93 +0,0 @@
-#!/usr/bin/python
-#
-# Copyright 2008 Red Hat, Inc. and/or its affiliates.
-#
-# Licensed to you under 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.  See the files README and
-# LICENSE_GPL_v2 which accompany this distribution.
-#
-
-import sys
-import getopt
-import logging
-import logging.config
-from time import strftime
-import deployUtil
-
-VDSM_CONF_FILE = '/etc/vdsm/vdsm.conf'
-log_filename = '/var/log/vdsm-reg/vds_bootstrap_complete.'+strftime("%Y%m%d_%H%M%S")+'.log'
-logging.basicConfig(level=logging.DEBUG,
-                    format='%(asctime)s %(levelname)-8s %(message)s',
-                    datefmt='%a, %d %b %Y %H:%M:%S',
-                    filename=log_filename,
-                    filemode='w')
-
-def reboot(act=1):
-    """ Reboot.
-    """
-    logging.debug("Reboot: started.")
-    action = 'Reboot'
-    message = 'Rebooting machine'
-
-    if (act==1):
-        deployUtil.reboot()
-    else:
-        action = 'Restart'
-        message = 'Restarting vdsmd service'
-        deployUtil.setService("vdsmd", "restart")
-
-    print "<BSTRAP component='" + action + "' status='OK' message='" + message + "' />"
-    sys.stdout.flush()
-    logging.debug("Reboot: ended.")
-
-def main():
-    """Usage: ovirt-vdsm-complete.py  [-c vds_config_str] <random_num> [reboot]"""
-    try:
-        vds_config_str = None
-        opts, args = getopt.getopt(sys.argv[1:], "c:")
-        for o,v in opts:
-            if o == "-c":
-                # it should looks like: 'ssl=true;ksm_nice=5;images=/images/irsd'
-                # without white spaces in it.
-                vds_config_str = v
-
-        rnum = args[0]
-    except:
-        print main.__doc__
-        return 0
-    try:
-        act = args[1]
-    except:
-        act = 1
-
-    fOK = True
-    try:
-        fOK = deployUtil.instCert(rnum, VDSM_CONF_FILE)
-        if fOK:
-            fOK = deployUtil.setCoreDumpPath()
-
-        if fOK:
-            fOK = deployUtil.cleanAll(rnum)
-
-        if fOK:
-            fOK = deployUtil.setVdsConf(vds_config_str, VDSM_CONF_FILE)
-
-        if fOK:
-            deployUtil.setService("vdsmd", "reconfigure")
-            reboot(act)
-    except:
-        fOK = False
-
-    if not fOK:
-        print "<BSTRAP component='RHEV_INSTALL' status='FAIL'/>"
-        logging.debug("<BSTRAP component='RHEV_INSTALL' status='FAIL'/>")
-
-    else:
-        print "<BSTRAP component='RHEV_INSTALL' status='OK'/>"
-        logging.debug("<BSTRAP component='RHEV_INSTALL' status='OK'/>")
-
-    sys.stdout.flush()
-
-if __name__ == "__main__":
-    sys.exit(main())
diff --git a/vdsm_reg/vdsm-gen-cert b/vdsm_reg/vdsm-gen-cert
new file mode 100755
index 0000000..f41fe00
--- /dev/null
+++ b/vdsm_reg/vdsm-gen-cert
@@ -0,0 +1,102 @@
+#!/usr/bin/python
+# Script to complete vdsm installation.
+# Input: certificate subject + current random ID.
+# Output: stdout as XML format
+#
+# Steps to perform: Initiate Certificate Initalization
+#   a. Clean previous certificates / keys.
+#   b. Generate certificate and sign request
+#
+
+import sys
+import getopt
+#import pwd
+#import errno
+#from stat import *
+from time import strftime
+import logging
+import logging.config
+import traceback
+import random
+import ConfigParser
+import deployUtil
+
+rnum = random.randint(100,1000000).__repr__()
+log_filename = '/var/log/vdsm-reg/vds_bootstrap_gen.'+strftime("%Y%m%d_%H%M%S")+'.log'
+
+logging.basicConfig(level=logging.DEBUG,
+                    format='%(asctime)s %(levelname)-8s %(message)s',
+                    datefmt='%a, %d %b %Y %H:%M:%S',
+                    filename=log_filename,
+                    filemode='w')
+
+class CSR:
+    """
+        Makes sure that vdsmd has its Certificate in place
+    """
+    def __init__(self, sub='', num='', orgName='Red Hat, Inc.'):
+        self.orgName = orgName
+        self.subject = sub
+        self.random_num = num
+
+        # NOTE: /etc/vdsm/vdsm.conf must exist (Should exist after rpms are isntalled)
+        config = ConfigParser.ConfigParser()
+        config.read('/etc/vdsm/vdsm.conf')
+        try:
+            tsDir = config.get('vars', 'trust_store_path')
+        except:
+            tsDir = '/etc/pki/vdsm'
+
+        self.tsDir = tsDir
+        self.VDSMKEY = tsDir + "/keys/vdsmkey.pem"
+        self.VDSMCERT = tsDir + "/certs/vdsm-" + sub + "-cert.pem"
+        self.DHKEY = tsDir + '/keys/dh.pem'
+
+    def xmlOutput(self):
+        print "<BSTRAP component='Encryption setup' status='OK'/>"
+        logging.debug("<BSTRAP component='Encryption setup' status='OK'/>")
+        sys.stdout.flush()
+
+    def runTest(self):
+        deployUtil.pkiCleanup(self.VDSMKEY, self.VDSMCERT)
+        deployUtil.createCSR(self.orgName, self.subject, self.random_num, self.tsDir, self.VDSMKEY, self.DHKEY)
+        self.xmlOutput()
+
+def main():
+    """Usage: vdsm-gen-cert [-O organizationName] <subject> <random_num>"""
+    try:
+        orgName = 'Red Hat, Inc.'
+        opts, args = getopt.getopt(sys.argv[1:], "O:")
+        for o,v in opts:
+            if o == "-O":
+                orgName = v
+        subject = args[0]
+        random_num = args[1]
+    except:
+        print main.__doc__
+        return 0
+
+    try:
+        CSR(subject, random_num, orgName).runTest()
+        ret = True
+    except:
+        logging.error(traceback.format_exc())
+        logging.error(main.__doc__)
+        logging.debug("<BSTRAP component='RHEV_INSTALL' status='FAIL'/>")
+        print "<BSTRAP component='RHEV_INSTALL' status='FAIL'/>"
+
+        return 0
+    else:
+        if not ret:
+            print "<BSTRAP component='RHEV_INSTALL' status='FAIL'/>"
+            logging.debug("<BSTRAP component='RHEV_INSTALL' status='FAIL'/>")
+
+        else:
+            print "<BSTRAP component='RHEV_INSTALL' status='OK'/>"
+            logging.debug("<BSTRAP component='RHEV_INSTALL' status='OK'/>")
+
+    sys.stdout.flush()
+
+if __name__ == "__main__":
+    sys.exit(main())
+
diff --git a/vdsm_reg/vdsm-gen-cert.py b/vdsm_reg/vdsm-gen-cert.py
deleted file mode 100755
index f41fe00..0000000
--- a/vdsm_reg/vdsm-gen-cert.py
+++ /dev/null
@@ -1,102 +0,0 @@
-#!/usr/bin/python
-# Script to complete vdsm installation.
-# Input: certificate subject + current random ID.
-# Output: stdout as XML format
-#
-# Steps to perform: Initiate Certificate Initalization
-#   a. Clean previous certificates / keys.
-#   b. Generate certificate and sign request
-#
-
-import sys
-import getopt
-#import pwd
-#import errno
-#from stat import *
-from time import strftime
-import logging
-import logging.config
-import traceback
-import random
-import ConfigParser
-import deployUtil
-
-rnum = random.randint(100,1000000).__repr__()
-log_filename = '/var/log/vdsm-reg/vds_bootstrap_gen.'+strftime("%Y%m%d_%H%M%S")+'.log'
-
-logging.basicConfig(level=logging.DEBUG,
-                    format='%(asctime)s %(levelname)-8s %(message)s',
-                    datefmt='%a, %d %b %Y %H:%M:%S',
-                    filename=log_filename,
-                    filemode='w')
-
-class CSR:
-    """
-        Makes sure that vdsmd has its Certificate in place
-    """
-    def __init__(self, sub='', num='', orgName='Red Hat, Inc.'):
-        self.orgName = orgName
-        self.subject = sub
-        self.random_num = num
-
-        # NOTE: /etc/vdsm/vdsm.conf must exist (Should exist after rpms are isntalled)
-        config = ConfigParser.ConfigParser()
-        config.read('/etc/vdsm/vdsm.conf')
-        try:
-            tsDir = config.get('vars', 'trust_store_path')
-        except:
-            tsDir = '/etc/pki/vdsm'
-
-        self.tsDir = tsDir
-        self.VDSMKEY = tsDir + "/keys/vdsmkey.pem"
-        self.VDSMCERT = tsDir + "/certs/vdsm-" + sub + "-cert.pem"
-        self.DHKEY = tsDir + '/keys/dh.pem'
-
-    def xmlOutput(self):
-        print "<BSTRAP component='Encryption setup' status='OK'/>"
-        logging.debug("<BSTRAP component='Encryption setup' status='OK'/>")
-        sys.stdout.flush()
-
-    def runTest(self):
-        deployUtil.pkiCleanup(self.VDSMKEY, self.VDSMCERT)
-        deployUtil.createCSR(self.orgName, self.subject, self.random_num, self.tsDir, self.VDSMKEY, self.DHKEY)
-        self.xmlOutput()
-
-def main():
-    """Usage: vdsm-gen-cert [-O organizationName] <subject> <random_num>"""
-    try:
-        orgName = 'Red Hat, Inc.'
-        opts, args = getopt.getopt(sys.argv[1:], "O:")
-        for o,v in opts:
-            if o == "-O":
-                orgName = v
-        subject = args[0]
-        random_num = args[1]
-    except:
-        print main.__doc__
-        return 0
-
-    try:
-        CSR(subject, random_num, orgName).runTest()
-        ret = True
-    except:
-        logging.error(traceback.format_exc())
-        logging.error(main.__doc__)
-        logging.debug("<BSTRAP component='RHEV_INSTALL' status='FAIL'/>")
-        print "<BSTRAP component='RHEV_INSTALL' status='FAIL'/>"
-
-        return 0
-    else:
-        if not ret:
-            print "<BSTRAP component='RHEV_INSTALL' status='FAIL'/>"
-            logging.debug("<BSTRAP component='RHEV_INSTALL' status='FAIL'/>")
-
-        else:
-            print "<BSTRAP component='RHEV_INSTALL' status='OK'/>"
-            logging.debug("<BSTRAP component='RHEV_INSTALL' status='OK'/>")
-
-    sys.stdout.flush()
-
-if __name__ == "__main__":
-    sys.exit(main())
-
diff --git a/vdsm_reg/vdsm-reg-setup b/vdsm_reg/vdsm-reg-setup
new file mode 100755
index 0000000..b1015b8
--- /dev/null
+++ b/vdsm_reg/vdsm-reg-setup
@@ -0,0 +1,303 @@
+#!/usr/bin/python
+# Script to setup basic vdsm environment and register the VDSM with VDC.
+# Input: none.
+# Output: none.
+#
+# Steps to perform: Initiate Certificate Initalization
+#   a. Find menagement bridge and rename it to rhevm.
+#   b. Create .ssh directory and fetch authorized_keys
+#   c. Call VDC registration.
+#   d. Set time according to rhev-m time.
+
+import sys
+import getopt
+import os
+import socket
+import httplib
+import time
+import logging
+import logging.config
+import traceback
+import urllib
+import ssl
+from config import config
+import deployUtil
+import createDaemon
+
+DEFAULT_CONFIG_FILE="/etc/vdsm-reg/vdsm-reg.conf"
+VDSM_CONF="/etc/vdsm/vdsm.conf"
+SCRIPT_NAME_SAVE="vdsm-store-net-config"
+MGT_BRIDGE_NAME="rhevm"
+
+class Setup:
+    """
+    Makes sure that vdsmd has its Certificate in place
+    """
+    def __init__(self):
+        logging.debug("__init__ begin.")
+        self.registered = False
+        self.fInitOK = True
+        self.vdcURL = "None"
+        self.vdcName = config.get('vars', 'vdc_host_name')
+        if self.vdcName != "None":
+            try: self.vdcURL = socket.gethostbyname(self.vdcName)
+            except: self.vdcURL = "None"
+        else:
+            self.vdcURL = config.get('vars', 'vdc_host_ip')
+
+        self.vdsmDir = config.get('vars', 'vdsm_dir')
+        if self.vdcURL != "None":
+            self.ovirtURL = deployUtil.getMGTIP(self.vdsmDir, self.vdcName)
+            self.ovirtName = socket.getfqdn()
+            self.ovirtUID = deployUtil.getHostID()
+        else:
+            self.ovirtURL = "None"
+            self.ovirtName = "None"
+            self.ovirtUID = "None"
+
+        self.vdcPORT = config.get('vars', 'vdc_host_port')
+        self.vdcURI = config.get('vars', 'vdc_reg_uri')
+        self.vdcRegPort = config.get('vars', 'vdc_reg_port')
+        self.VDCTime = None
+        logging.debug("Setup::__init__ vars:" +
+            "\n\tself.vdcURL " + self.vdcURL +
+            "\n\tself.vdcPORT " + self.vdcPORT +
+            "\n\tself.vdcURI " + self.vdcURI +
+            "\n\tself.vdcRegPort " + self.vdcRegPort +
+            "\n\tself.ovirtURL " + self.ovirtURL +
+            "\n\tself.ovirtName " + self.ovirtName +
+            "\n\tself.ovirtUID " + self.ovirtUID +
+            "\n\tself.vdcName " + self.vdcName
+        )
+
+    def validateData(self):
+        logging.debug("validate start")
+        fReturn = True
+
+        if self.ovirtURL == None or self.ovirtURL == "" or self.ovirtURL == "None" or \
+           self.ovirtName  == None or self.ovirtName == "" or self.ovirtName == "None":
+            fReturn = False
+
+        logging.debug("validate end. return: " + str(fReturn))
+        return fReturn
+
+    def renameBridge(self):
+        """
+            Rename oVirt default bridge to rhevm bridge.
+        """
+        logging.debug("renameBridge begin.")
+        fReturn = True
+
+        #Rename existing bridge
+        fReturn = deployUtil.makeBridge(self.vdcName, self.vdsmDir)
+        if not fReturn:
+            logging.error("renameBridge Failed to rename existing bridge!")
+
+        #Persist changes
+        if fReturn:
+            try:
+                out, err, ret = deployUtil._logExec([os.path.join(self.vdsmDir, SCRIPT_NAME_SAVE)])
+                if ret:
+                    fReturn = False
+                    logging.error("renameBridge Failed to persist rhevm bridge changes. out=" + out + "\nerr=" + str(err) + "\nret=" + str(ret))
+            except:
+                fReturn = False
+                logging.error("renameBridge Failed to persist bridge changes. out=" + out + "\nerr=" + str(err) + "\nret=" + str(ret))
+
+        #Fix file permissions to relevant mask
+        if fReturn:
+            try:
+                os.chmod("/config/etc/sysconfig/network-scripts/ifcfg-" + MGT_BRIDGE_NAME, 0644)
+            except:
+                fReturn = False
+                logging.error("renameBridge: failed to chmod bridge file")
+
+        logging.debug("renameBridge return.")
+        return fReturn
+
+    def registerVDS(self):
+        logging.debug("registerVDS begin.")
+
+        strFullURI = (
+            self.vdcURI + "?vds_ip=" + urllib.quote(self.ovirtURL) +
+            "&vds_name=" + urllib.quote(self.ovirtName) +
+            "&vds_unique_id=" + urllib.quote(self.ovirtUID) +
+            "&port=" + urllib.quote(self.vdcRegPort) +
+            "&__VIEWSTATE="
+        )
+        logging.debug("registerVDS URI= " + strFullURI + "\n")
+        if self.ovirtUID == "None" and "localhost.localdomain" in self.ovirtName:
+            logging.warn("WARNING! registering RHEV-H with no UUID and no unique host-name!")
+
+        fReturn = True
+        res = None
+        nTimeout = int(config.get('vars', 'test_socket_timeout'))
+        old_timeout = socket.getdefaulttimeout()
+        socket.setdefaulttimeout(nTimeout)
+        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+
+        try:
+            sock.connect((self.vdcURL, int(self.vdcPORT)))
+            conn = httplib.HTTPSConnection(self.vdcURL + ":" + self.vdcPORT)
+            conn.sock = ssl.wrap_socket(sock)
+            conn.request("GET", strFullURI)
+            res = conn.getresponse()
+        except:
+           logging.debug("registerVDS failed in HTTPS. Retrying using HTTP.")
+           try:
+                conn = None
+                conn = httplib.HTTPConnection(self.vdcURL + ":" + self.vdcPORT)
+                conn.request("GET", strFullURI)
+                res = conn.getresponse()
+                logging.debug("registerVDS succeeded using HTTP.")
+           except:
+                fReturn = False
+                logging.error("registerVDS failed using HTTP!")
+                logging.error(traceback.format_exc())
+
+        else:
+            logging.debug("registerVDS status: " + str(res.status) +
+                " reason: " + res.reason
+            )
+
+        if res == None or res.status != 200:
+            if conn != None: conn.close()
+            fReturn = False
+
+        if fReturn:
+            try:
+                try:
+                    self.VDCTime = res.read()
+                    logging.debug("registerVDS time read: " + str(self.VDCTime))
+                except:
+                    fReturn = False
+                    logging.error(traceback.format_exc())
+            finally:
+                if conn != None: conn.close()
+
+        socket.setdefaulttimeout(old_timeout)
+        logging.debug("registerVDS end.")
+        return fReturn
+
+    def execute(self):
+        fOK = True
+        fOKNow = True
+        logging.debug("execute start.")
+        self.registered = False
+
+        if deployUtil.preventDuplicate():
+            logging.debug("execute: found existing management bridge. Skipping rename.")
+        else:
+            fOK = self.renameBridge()
+            logging.debug("execute: after renameBridge: " + str(fOK))
+
+        if fOK:
+            strKey = deployUtil.getAuthKeysFile(self.vdcURL, self.vdcPORT)
+            if strKey is not None:
+                fOKNow = deployUtil.handleSSHKey(strKey)
+            else:
+                fOKNow = False
+            fOK = fOK and fOKNow
+            logging.debug("execute: after getAuthKeysFile: " + str(fOK))
+
+        if fOK:
+            fOKNow = self.registerVDS()
+            fOK = fOK and fOKNow
+            logging.debug("execute: after registerVDS: " + str(fOK))
+
+        if fOK:
+            self.registered = True
+
+        logging.debug("Registration status:" +
+            str(self.registered)
+        )
+
+        # Utility settings. This will not fail the registration process.
+        if self.registered == True:
+            fOK = (fOK and deployUtil.setHostTime(self.VDCTime))
+            if fOK:
+                logging.debug("Node time in sync with RHEVM server")
+            else:
+                logging.warning("Node time failed to sync with RHEVM server. This may cause problems !")
+
+def run(confFile, daemonize):
+    #print "entered run(conf='%s', daemonize='%s')"%(confFile,str(daemonize))
+    import random
+
+    registered = False
+    log = None
+    pidfile = False
+    try:
+        try:
+            config.read([confFile])
+            loggerConf = config.get('vars','logger_conf')
+            vdsmDir = config.get('vars', 'vdsm_dir')
+            pidfile = config.get('vars','pidfile')
+            sleepTime = float(config.get('vars','reg_req_interval'))
+            sys.path.append(vdsmDir)
+
+            if daemonize:
+                createDaemon.createDaemon()
+            #set up logger
+            logging.config.fileConfig(loggerConf)
+            log = logging.getLogger('')
+            if daemonize:
+                log = logging.getLogger('vdsRegistrator')
+            if not daemonize:
+                log.handlers.append(logging.StreamHandler())
+
+            log.info("After daemonize - My pid is " + str(os.getpid()))
+            file(pidfile, 'w').write(str(os.getpid()) + "\n")
+            os.chmod(pidfile, 0664)
+
+            itr = 0
+            while daemonize and not registered:
+                oSetup = Setup()
+                if oSetup.validateData():
+                    oSetup.execute()
+                registered = oSetup.registered;
+                oSetup = None
+                itr += 1
+                nRandom = random.randint(1, 5)
+                if not registered:
+                    # wait random time, so multiple machines access randomly.
+                    time.sleep(sleepTime + nRandom)
+
+                log.debug("Total retry count: %d, waited: %d seconds." % (itr, sleepTime+nRandom))
+        except:
+            if log is not None:
+                log.error(traceback.format_exc())
+    finally:
+        if pidfile and os.path.exists(pidfile):
+            os.unlink(pidfile)
+        if log:
+            log.info("Exiting ....")
+
+def usage():
+    print "Usage: %s [-c <config_file>]"
+    print "    -c         - configuration file"
+    print "    -l         - run local (= no daemon)"
+    print "    -h,--help  - prints this usage"
+
+if __name__ == "__main__":
+    config_file = DEFAULT_CONFIG_FILE
+    daemonize = True
+    try:
+        opts,args = getopt.getopt(sys.argv[1:], "hc:l",["help"])
+        for o,v in opts:
+            if o == "-h" or o == "--help":
+                usage()
+                sys.exit(0)
+            elif o == "-c":
+                config_file = v
+                if not os.path.exists(config_file):
+                    print "ERROR: file %s does not exist"%(config_file)
+                    usage()
+                    sys.exit(1)
+            elif o == "-l":
+                daemonize = False
+    except getopt.GetoptError,e:
+        print "ERROR: '%s'"%(e.msg)
+        usage()
+        sys.exit(1)
+    run(config_file, daemonize)
diff --git a/vdsm_reg/vdsm-reg-setup.py b/vdsm_reg/vdsm-reg-setup.py
deleted file mode 100755
index b1015b8..0000000
--- a/vdsm_reg/vdsm-reg-setup.py
+++ /dev/null
@@ -1,303 +0,0 @@
-#!/usr/bin/python
-# Script to setup basic vdsm environment and register the VDSM with VDC.
-# Input: none.
-# Output: none.
-#
-# Steps to perform: Initiate Certificate Initalization
-#   a. Find menagement bridge and rename it to rhevm.
-#   b. Create .ssh directory and fetch authorized_keys
-#   c. Call VDC registration.
-#   d. Set time according to rhev-m time.
-
-import sys
-import getopt
-import os
-import socket
-import httplib
-import time
-import logging
-import logging.config
-import traceback
-import urllib
-import ssl
-from config import config
-import deployUtil
-import createDaemon
-
-DEFAULT_CONFIG_FILE="/etc/vdsm-reg/vdsm-reg.conf"
-VDSM_CONF="/etc/vdsm/vdsm.conf"
-SCRIPT_NAME_SAVE="vdsm-store-net-config"
-MGT_BRIDGE_NAME="rhevm"
-
-class Setup:
-    """
-    Makes sure that vdsmd has its Certificate in place
-    """
-    def __init__(self):
-        logging.debug("__init__ begin.")
-        self.registered = False
-        self.fInitOK = True
-        self.vdcURL = "None"
-        self.vdcName = config.get('vars', 'vdc_host_name')
-        if self.vdcName != "None":
-            try: self.vdcURL = socket.gethostbyname(self.vdcName)
-            except: self.vdcURL = "None"
-        else:
-            self.vdcURL = config.get('vars', 'vdc_host_ip')
-
-        self.vdsmDir = config.get('vars', 'vdsm_dir')
-        if self.vdcURL != "None":
-            self.ovirtURL = deployUtil.getMGTIP(self.vdsmDir, self.vdcName)
-            self.ovirtName = socket.getfqdn()
-            self.ovirtUID = deployUtil.getHostID()
-        else:
-            self.ovirtURL = "None"
-            self.ovirtName = "None"
-            self.ovirtUID = "None"
-
-        self.vdcPORT = config.get('vars', 'vdc_host_port')
-        self.vdcURI = config.get('vars', 'vdc_reg_uri')
-        self.vdcRegPort = config.get('vars', 'vdc_reg_port')
-        self.VDCTime = None
-        logging.debug("Setup::__init__ vars:" +
-            "\n\tself.vdcURL " + self.vdcURL +
-            "\n\tself.vdcPORT " + self.vdcPORT +
-            "\n\tself.vdcURI " + self.vdcURI +
-            "\n\tself.vdcRegPort " + self.vdcRegPort +
-            "\n\tself.ovirtURL " + self.ovirtURL +
-            "\n\tself.ovirtName " + self.ovirtName +
-            "\n\tself.ovirtUID " + self.ovirtUID +
-            "\n\tself.vdcName " + self.vdcName
-        )
-
-    def validateData(self):
-        logging.debug("validate start")
-        fReturn = True
-
-        if self.ovirtURL == None or self.ovirtURL == "" or self.ovirtURL == "None" or \
-           self.ovirtName  == None or self.ovirtName == "" or self.ovirtName == "None":
-            fReturn = False
-
-        logging.debug("validate end. return: " + str(fReturn))
-        return fReturn
-
-    def renameBridge(self):
-        """
-            Rename oVirt default bridge to rhevm bridge.
-        """
-        logging.debug("renameBridge begin.")
-        fReturn = True
-
-        #Rename existing bridge
-        fReturn = deployUtil.makeBridge(self.vdcName, self.vdsmDir)
-        if not fReturn:
-            logging.error("renameBridge Failed to rename existing bridge!")
-
-        #Persist changes
-        if fReturn:
-            try:
-                out, err, ret = deployUtil._logExec([os.path.join(self.vdsmDir, SCRIPT_NAME_SAVE)])
-                if ret:
-                    fReturn = False
-                    logging.error("renameBridge Failed to persist rhevm bridge changes. out=" + out + "\nerr=" + str(err) + "\nret=" + str(ret))
-            except:
-                fReturn = False
-                logging.error("renameBridge Failed to persist bridge changes. out=" + out + "\nerr=" + str(err) + "\nret=" + str(ret))
-
-        #Fix file permissions to relevant mask
-        if fReturn:
-            try:
-                os.chmod("/config/etc/sysconfig/network-scripts/ifcfg-" + MGT_BRIDGE_NAME, 0644)
-            except:
-                fReturn = False
-                logging.error("renameBridge: failed to chmod bridge file")
-
-        logging.debug("renameBridge return.")
-        return fReturn
-
-    def registerVDS(self):
-        logging.debug("registerVDS begin.")
-
-        strFullURI = (
-            self.vdcURI + "?vds_ip=" + urllib.quote(self.ovirtURL) +
-            "&vds_name=" + urllib.quote(self.ovirtName) +
-            "&vds_unique_id=" + urllib.quote(self.ovirtUID) +
-            "&port=" + urllib.quote(self.vdcRegPort) +
-            "&__VIEWSTATE="
-        )
-        logging.debug("registerVDS URI= " + strFullURI + "\n")
-        if self.ovirtUID == "None" and "localhost.localdomain" in self.ovirtName:
-            logging.warn("WARNING! registering RHEV-H with no UUID and no unique host-name!")
-
-        fReturn = True
-        res = None
-        nTimeout = int(config.get('vars', 'test_socket_timeout'))
-        old_timeout = socket.getdefaulttimeout()
-        socket.setdefaulttimeout(nTimeout)
-        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-
-        try:
-            sock.connect((self.vdcURL, int(self.vdcPORT)))
-            conn = httplib.HTTPSConnection(self.vdcURL + ":" + self.vdcPORT)
-            conn.sock = ssl.wrap_socket(sock)
-            conn.request("GET", strFullURI)
-            res = conn.getresponse()
-        except:
-           logging.debug("registerVDS failed in HTTPS. Retrying using HTTP.")
-           try:
-                conn = None
-                conn = httplib.HTTPConnection(self.vdcURL + ":" + self.vdcPORT)
-                conn.request("GET", strFullURI)
-                res = conn.getresponse()
-                logging.debug("registerVDS succeeded using HTTP.")
-           except:
-                fReturn = False
-                logging.error("registerVDS failed using HTTP!")
-                logging.error(traceback.format_exc())
-
-        else:
-            logging.debug("registerVDS status: " + str(res.status) +
-                " reason: " + res.reason
-            )
-
-        if res == None or res.status != 200:
-            if conn != None: conn.close()
-            fReturn = False
-
-        if fReturn:
-            try:
-                try:
-                    self.VDCTime = res.read()
-                    logging.debug("registerVDS time read: " + str(self.VDCTime))
-                except:
-                    fReturn = False
-                    logging.error(traceback.format_exc())
-            finally:
-                if conn != None: conn.close()
-
-        socket.setdefaulttimeout(old_timeout)
-        logging.debug("registerVDS end.")
-        return fReturn
-
-    def execute(self):
-        fOK = True
-        fOKNow = True
-        logging.debug("execute start.")
-        self.registered = False
-
-        if deployUtil.preventDuplicate():
-            logging.debug("execute: found existing management bridge. Skipping rename.")
-        else:
-            fOK = self.renameBridge()
-            logging.debug("execute: after renameBridge: " + str(fOK))
-
-        if fOK:
-            strKey = deployUtil.getAuthKeysFile(self.vdcURL, self.vdcPORT)
-            if strKey is not None:
-                fOKNow = deployUtil.handleSSHKey(strKey)
-            else:
-                fOKNow = False
-            fOK = fOK and fOKNow
-            logging.debug("execute: after getAuthKeysFile: " + str(fOK))
-
-        if fOK:
-            fOKNow = self.registerVDS()
-            fOK = fOK and fOKNow
-            logging.debug("execute: after registerVDS: " + str(fOK))
-
-        if fOK:
-            self.registered = True
-
-        logging.debug("Registration status:" +
-            str(self.registered)
-        )
-
-        # Utility settings. This will not fail the registration process.
-        if self.registered == True:
-            fOK = (fOK and deployUtil.setHostTime(self.VDCTime))
-            if fOK:
-                logging.debug("Node time in sync with RHEVM server")
-            else:
-                logging.warning("Node time failed to sync with RHEVM server. This may cause problems !")
-
-def run(confFile, daemonize):
-    #print "entered run(conf='%s', daemonize='%s')"%(confFile,str(daemonize))
-    import random
-
-    registered = False
-    log = None
-    pidfile = False
-    try:
-        try:
-            config.read([confFile])
-            loggerConf = config.get('vars','logger_conf')
-            vdsmDir = config.get('vars', 'vdsm_dir')
-            pidfile = config.get('vars','pidfile')
-            sleepTime = float(config.get('vars','reg_req_interval'))
-            sys.path.append(vdsmDir)
-
-            if daemonize:
-                createDaemon.createDaemon()
-            #set up logger
-            logging.config.fileConfig(loggerConf)
-            log = logging.getLogger('')
-            if daemonize:
-                log = logging.getLogger('vdsRegistrator')
-            if not daemonize:
-                log.handlers.append(logging.StreamHandler())
-
-            log.info("After daemonize - My pid is " + str(os.getpid()))
-            file(pidfile, 'w').write(str(os.getpid()) + "\n")
-            os.chmod(pidfile, 0664)
-
-            itr = 0
-            while daemonize and not registered:
-                oSetup = Setup()
-                if oSetup.validateData():
-                    oSetup.execute()
-                registered = oSetup.registered;
-                oSetup = None
-                itr += 1
-                nRandom = random.randint(1, 5)
-                if not registered:
-                    # wait random time, so multiple machines access randomly.
-                    time.sleep(sleepTime + nRandom)
-
-                log.debug("Total retry count: %d, waited: %d seconds." % (itr, sleepTime+nRandom))
-        except:
-            if log is not None:
-                log.error(traceback.format_exc())
-    finally:
-        if pidfile and os.path.exists(pidfile):
-            os.unlink(pidfile)
-        if log:
-            log.info("Exiting ....")
-
-def usage():
-    print "Usage: %s [-c <config_file>]"
-    print "    -c         - configuration file"
-    print "    -l         - run local (= no daemon)"
-    print "    -h,--help  - prints this usage"
-
-if __name__ == "__main__":
-    config_file = DEFAULT_CONFIG_FILE
-    daemonize = True
-    try:
-        opts,args = getopt.getopt(sys.argv[1:], "hc:l",["help"])
-        for o,v in opts:
-            if o == "-h" or o == "--help":
-                usage()
-                sys.exit(0)
-            elif o == "-c":
-                config_file = v
-                if not os.path.exists(config_file):
-                    print "ERROR: file %s does not exist"%(config_file)
-                    usage()
-                    sys.exit(1)
-            elif o == "-l":
-                daemonize = False
-    except getopt.GetoptError,e:
-        print "ERROR: '%s'"%(e.msg)
-        usage()
-        sys.exit(1)
-    run(config_file, daemonize)
diff --git a/vdsm_reg/vdsm-reg.conf b/vdsm_reg/vdsm-reg.conf
deleted file mode 100644
index f6942fc..0000000
--- a/vdsm_reg/vdsm-reg.conf
+++ /dev/null
@@ -1,20 +0,0 @@
-[vars]
-# time to wait (in seconds) for the next registration request when registration fails
-reg_req_interval = 5
-#The location of the vdsm conf file
-vdsm_conf_file=/etc/vdsm/vdsm.conf
-#The location of the pid file
-pidfile=/var/run/vdsm-reg.pid
-#The logger conf file
-logger_conf=/etc/vdsm-reg/logger.conf
-#The hostname of the vdc, should be verified each boot (look for DNS SRV record)
-vdc_host_name=None
-#The port of the RHEV Manager. Allows http or https connections.
-vdc_host_port=443
-#The ssh file uri
-vdc_authkeys_path=/rhevm.ssh.key.txt
-#The registrtion uri
-vdc_reg_uri=/RHEVManagerWeb/VdsAutoRegistration.aspx
-#Upgrade settings
-upgrade_iso_file=/data/updates/ovirt-node-image.iso
-upgrade_mount_point=@VDSMRUNDIR@/image-update
diff --git a/vdsm_reg/vdsm-reg.conf.in b/vdsm_reg/vdsm-reg.conf.in
new file mode 100644
index 0000000..f6942fc
--- /dev/null
+++ b/vdsm_reg/vdsm-reg.conf.in
@@ -0,0 +1,20 @@
+[vars]
+# time to wait (in seconds) for the next registration request when registration fails
+reg_req_interval = 5
+#The location of the vdsm conf file
+vdsm_conf_file=/etc/vdsm/vdsm.conf
+#The location of the pid file
+pidfile=/var/run/vdsm-reg.pid
+#The logger conf file
+logger_conf=/etc/vdsm-reg/logger.conf
+#The hostname of the vdc, should be verified each boot (look for DNS SRV record)
+vdc_host_name=None
+#The port of the RHEV Manager. Allows http or https connections.
+vdc_host_port=443
+#The ssh file uri
+vdc_authkeys_path=/rhevm.ssh.key.txt
+#The registrtion uri
+vdc_reg_uri=/RHEVManagerWeb/VdsAutoRegistration.aspx
+#Upgrade settings
+upgrade_iso_file=/data/updates/ovirt-node-image.iso
+upgrade_mount_point=@VDSMRUNDIR@/image-update
diff --git a/vdsm_reg/vdsm-upgrade b/vdsm_reg/vdsm-upgrade
new file mode 100755
index 0000000..061e492
--- /dev/null
+++ b/vdsm_reg/vdsm-upgrade
@@ -0,0 +1,185 @@
+#!/usr/bin/python
+#
+# Copyright 2008 Red Hat, Inc. and/or its affiliates.
+#
+# Licensed to you under 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.  See the files README and
+# LICENSE_GPL_v2 which accompany this distribution.
+#
+
+import errno
+import sys
+import os
+import logging
+import logging.config
+from time import strftime
+import ConfigParser
+import deployUtil
+
+VDSM_CONF_FILE = '/etc/vdsm/vdsm.conf'
+log_filename = '/var/log/vdsm-reg/vds_bootstrap_upgrade.'+strftime("%Y%m%d_%H%M%S")+'.log'
+
+try:
+    logging.basicConfig(level=logging.DEBUG,
+                        format='%(asctime)s %(levelname)-8s %(message)s',
+                        datefmt='%a, %d %b %Y %H:%M:%S',
+                        filename=log_filename,
+                        filemode='w')
+except:
+    log_filename = '/var/log/vds_bootstrap_upgrade.'+strftime("%Y%m%d_%H%M%S")+'.log'
+    logging.basicConfig(level=logging.DEBUG,
+                        format='%(asctime)s %(levelname)-8s %(message)s',
+                        datefmt='%a, %d %b %Y %H:%M:%S',
+                        filename=log_filename,
+                        filemode='w')
+
+def setMountPoint(config):
+    strFile = ""
+    try:
+        strFile = config.get('vars', 'upgrade_iso_file')
+    except:
+        strFile = '/data/updates/ovirt-node-image.iso'
+
+    try:
+        strMountPoint = config.get('vars', 'upgrade_mount_point')
+    except:
+        strMountPoint = '/var/vdsm/image-update'
+
+    try:
+        fOK = True
+        ret = None
+        err = ""
+        out = None
+
+        #First look for the upgrade file
+        if not os.path.exists(strFile):
+           fOK = False
+           msg = "<BSTRAP component='setMountPoint' status='FAIL' message='Upgrade file not found'/>"
+           logging.error(msg)
+           print (msg)
+
+        #Now, check if we need to create a mount-point dir.
+        if fOK and not os.path.exists(strMountPoint):
+           try: os.mkdir(strMountPoint)
+           except OSError, err:
+               if err.errno != errno.EEXIST:
+                   fOK = False
+
+        #Now, loop-mount the upgrade iso file.
+        if not fOK:
+           msg = "<BSTRAP component='setMountPoint' status='FAIL' message='Failed to create mount point: " + deployUtil.escapeXML(str(err)) + "'/>"
+           print (msg)
+           logging.error(msg)
+        else:
+           out, err, ret = deployUtil._logExec(["/bin/mount", "-o", "loop", strFile, strMountPoint])
+           fOK = (ret != None and ret == 0)
+
+        msg = ""
+        if fOK:
+           msg = "<BSTRAP component='setMountPoint' status='OK' message='Mount succeeded.'/>"
+           logging.debug(msg)
+        else:
+           msg = "<BSTRAP component='setMountPoint' status='FAIL' message='Failed to mount ISO file: " + deployUtil.escapeXML(str(err)) + "'/>"
+           logging.error(msg)
+        print msg
+    except Exception, e:
+        fOK = False
+        msg = "<BSTRAP component='setMountPoint' status='FAIL' message='setMountPoint exception: " + deployUtil.escapeXML(str(e)) + "'/>"
+        logging.error(msg)
+        print (msg)
+
+    return fOK
+
+def doUpgrade(config):
+    out = None
+    err = None
+    ret = None
+    fReturn = True
+
+    try:
+        strMountPoint = config.get('vars', 'upgrade_mount_point')
+    except:
+        strMountPoint = '/var/vdsm/image-update'
+
+    if os.path.exists("/usr/libexec/ovirt-config-boot"):
+        out, err, ret = deployUtil._logExec(["/usr/libexec/ovirt-config-boot", strMountPoint])
+    else:
+        err = "Can not find /usr/libexec/ovirt-config-boot !"
+
+    if ret == None or ret != 0:
+        msg = "<BSTRAP component='doUpgrade' status='FAIL' message='" + deployUtil.escapeXML(str(err)) + "'/>"
+        print (msg)
+        logging.error(msg)
+        fReturn = False
+    else:
+        msg = "<BSTRAP component='doUpgrade' status='OK' message='Upgrade Succeeded. Rebooting'/>"
+        print (msg)
+        logging.debug(msg)
+
+    return fReturn
+
+def umount(config, shouldReport=True):
+    out = None
+    err = None
+    ret = None
+    fReturn = True
+
+    try:
+        strMountPoint = config.get('vars', 'upgrade_mount_point')
+    except:
+        strMountPoint = '/var/vdsm/image-update'
+
+    if os.path.exists(strMountPoint):
+        out, err, ret = deployUtil._logExec(["/bin/umount", strMountPoint])
+        fReturn = (ret != None and ret == 0)
+
+    if fReturn:
+        msg = "<BSTRAP component='umount' status='OK' message='umount Succeeded'/>"
+    else:
+        msg = "<BSTRAP component='umount' status='FAIL' message=' " + deployUtil.escapeXML(str(err)) + "'/>"
+
+    if shouldReport:
+        print (msg)
+
+    logging.debug(msg)
+    return fReturn
+
+def main():
+    """Usage: vdsm-upgrade """
+    fOK = True
+    fMounted = False
+
+    try:
+        config = ConfigParser.ConfigParser()
+        config.read('/etc/vdsm-reg/vdsm-reg.conf')
+
+        #First, quietly try to clean any previous problems.
+        umount(config, False)
+
+        #Now: Try mounting
+        fOK = setMountPoint(config)
+        if fOK:
+            fMounted = True
+            fOK = doUpgrade(config)
+
+        #Finally, is possible umount current upgrade file.
+        if fMounted:
+            umount(config) #cleanup, may fail in some cases- device busy.
+    except:
+        fOK = False
+
+    if not fOK:
+        msg = "<BSTRAP component='RHEV_INSTALL' status='FAIL'/>"
+        logging.error("<BSTRAP component='RHEV_INSTALL' status='FAIL'/>")
+    else:
+        msg = "<BSTRAP component='RHEV_INSTALL' status='OK'/>"
+        logging.debug("<BSTRAP component='RHEV_INSTALL' status='OK'/>")
+    print (msg)
+
+    sys.stdout.flush()
+    return fOK
+
+if __name__ == "__main__":
+    sys.exit(main())
+
diff --git a/vdsm_reg/vdsm-upgrade.py b/vdsm_reg/vdsm-upgrade.py
deleted file mode 100755
index 061e492..0000000
--- a/vdsm_reg/vdsm-upgrade.py
+++ /dev/null
@@ -1,185 +0,0 @@
-#!/usr/bin/python
-#
-# Copyright 2008 Red Hat, Inc. and/or its affiliates.
-#
-# Licensed to you under 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.  See the files README and
-# LICENSE_GPL_v2 which accompany this distribution.
-#
-
-import errno
-import sys
-import os
-import logging
-import logging.config
-from time import strftime
-import ConfigParser
-import deployUtil
-
-VDSM_CONF_FILE = '/etc/vdsm/vdsm.conf'
-log_filename = '/var/log/vdsm-reg/vds_bootstrap_upgrade.'+strftime("%Y%m%d_%H%M%S")+'.log'
-
-try:
-    logging.basicConfig(level=logging.DEBUG,
-                        format='%(asctime)s %(levelname)-8s %(message)s',
-                        datefmt='%a, %d %b %Y %H:%M:%S',
-                        filename=log_filename,
-                        filemode='w')
-except:
-    log_filename = '/var/log/vds_bootstrap_upgrade.'+strftime("%Y%m%d_%H%M%S")+'.log'
-    logging.basicConfig(level=logging.DEBUG,
-                        format='%(asctime)s %(levelname)-8s %(message)s',
-                        datefmt='%a, %d %b %Y %H:%M:%S',
-                        filename=log_filename,
-                        filemode='w')
-
-def setMountPoint(config):
-    strFile = ""
-    try:
-        strFile = config.get('vars', 'upgrade_iso_file')
-    except:
-        strFile = '/data/updates/ovirt-node-image.iso'
-
-    try:
-        strMountPoint = config.get('vars', 'upgrade_mount_point')
-    except:
-        strMountPoint = '/var/vdsm/image-update'
-
-    try:
-        fOK = True
-        ret = None
-        err = ""
-        out = None
-
-        #First look for the upgrade file
-        if not os.path.exists(strFile):
-           fOK = False
-           msg = "<BSTRAP component='setMountPoint' status='FAIL' message='Upgrade file not found'/>"
-           logging.error(msg)
-           print (msg)
-
-        #Now, check if we need to create a mount-point dir.
-        if fOK and not os.path.exists(strMountPoint):
-           try: os.mkdir(strMountPoint)
-           except OSError, err:
-               if err.errno != errno.EEXIST:
-                   fOK = False
-
-        #Now, loop-mount the upgrade iso file.
-        if not fOK:
-           msg = "<BSTRAP component='setMountPoint' status='FAIL' message='Failed to create mount point: " + deployUtil.escapeXML(str(err)) + "'/>"
-           print (msg)
-           logging.error(msg)
-        else:
-           out, err, ret = deployUtil._logExec(["/bin/mount", "-o", "loop", strFile, strMountPoint])
-           fOK = (ret != None and ret == 0)
-
-        msg = ""
-        if fOK:
-           msg = "<BSTRAP component='setMountPoint' status='OK' message='Mount succeeded.'/>"
-           logging.debug(msg)
-        else:
-           msg = "<BSTRAP component='setMountPoint' status='FAIL' message='Failed to mount ISO file: " + deployUtil.escapeXML(str(err)) + "'/>"
-           logging.error(msg)
-        print msg
-    except Exception, e:
-        fOK = False
-        msg = "<BSTRAP component='setMountPoint' status='FAIL' message='setMountPoint exception: " + deployUtil.escapeXML(str(e)) + "'/>"
-        logging.error(msg)
-        print (msg)
-
-    return fOK
-
-def doUpgrade(config):
-    out = None
-    err = None
-    ret = None
-    fReturn = True
-
-    try:
-        strMountPoint = config.get('vars', 'upgrade_mount_point')
-    except:
-        strMountPoint = '/var/vdsm/image-update'
-
-    if os.path.exists("/usr/libexec/ovirt-config-boot"):
-        out, err, ret = deployUtil._logExec(["/usr/libexec/ovirt-config-boot", strMountPoint])
-    else:
-        err = "Can not find /usr/libexec/ovirt-config-boot !"
-
-    if ret == None or ret != 0:
-        msg = "<BSTRAP component='doUpgrade' status='FAIL' message='" + deployUtil.escapeXML(str(err)) + "'/>"
-        print (msg)
-        logging.error(msg)
-        fReturn = False
-    else:
-        msg = "<BSTRAP component='doUpgrade' status='OK' message='Upgrade Succeeded. Rebooting'/>"
-        print (msg)
-        logging.debug(msg)
-
-    return fReturn
-
-def umount(config, shouldReport=True):
-    out = None
-    err = None
-    ret = None
-    fReturn = True
-
-    try:
-        strMountPoint = config.get('vars', 'upgrade_mount_point')
-    except:
-        strMountPoint = '/var/vdsm/image-update'
-
-    if os.path.exists(strMountPoint):
-        out, err, ret = deployUtil._logExec(["/bin/umount", strMountPoint])
-        fReturn = (ret != None and ret == 0)
-
-    if fReturn:
-        msg = "<BSTRAP component='umount' status='OK' message='umount Succeeded'/>"
-    else:
-        msg = "<BSTRAP component='umount' status='FAIL' message=' " + deployUtil.escapeXML(str(err)) + "'/>"
-
-    if shouldReport:
-        print (msg)
-
-    logging.debug(msg)
-    return fReturn
-
-def main():
-    """Usage: vdsm-upgrade """
-    fOK = True
-    fMounted = False
-
-    try:
-        config = ConfigParser.ConfigParser()
-        config.read('/etc/vdsm-reg/vdsm-reg.conf')
-
-        #First, quietly try to clean any previous problems.
-        umount(config, False)
-
-        #Now: Try mounting
-        fOK = setMountPoint(config)
-        if fOK:
-            fMounted = True
-            fOK = doUpgrade(config)
-
-        #Finally, is possible umount current upgrade file.
-        if fMounted:
-            umount(config) #cleanup, may fail in some cases- device busy.
-    except:
-        fOK = False
-
-    if not fOK:
-        msg = "<BSTRAP component='RHEV_INSTALL' status='FAIL'/>"
-        logging.error("<BSTRAP component='RHEV_INSTALL' status='FAIL'/>")
-    else:
-        msg = "<BSTRAP component='RHEV_INSTALL' status='OK'/>"
-        logging.debug("<BSTRAP component='RHEV_INSTALL' status='OK'/>")
-    print (msg)
-
-    sys.stdout.flush()
-    return fOK
-
-if __name__ == "__main__":
-    sys.exit(main())
-




More information about the vdsm-patches mailing list