Vinzenz Feenstra has uploaded a new change for review. Change subject: Implement default configuration values ......................................................................
Implement default configuration values When adding new config values to the configuration files, it's possible that due to the installation the configuration files won't get updated, when they are modified by an user/administrator on that given system. By using defaults, we can override this problem and ensure a proper application start, when config values are missing which are mandatory, to the functionality. Change-Id: I5ce9d457e826448aad205ce4abda5dc4b0210804 Signed-off-by: Vinzenz Feenstra <[email protected]> Bug-Url: https://bugzilla.redhat.com/1100249 --- M ovirt-guest-agent/OVirtGuestService.py A ovirt-guest-agent/config.py M ovirt-guest-agent/ovirt-guest-agent.py 3 files changed, 98 insertions(+), 5 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-guest-agent refs/changes/45/28045/1 diff --git a/ovirt-guest-agent/OVirtGuestService.py b/ovirt-guest-agent/OVirtGuestService.py index 3206e8a..e9e97f9 100644 --- a/ovirt-guest-agent/OVirtGuestService.py +++ b/ovirt-guest-agent/OVirtGuestService.py @@ -8,9 +8,9 @@ import logging import logging.config import servicemanager -import ConfigParser import os import _winreg +from config import config AGENT_CONFIG = 'ovirt-guest-agent.ini' @@ -62,7 +62,6 @@ self.ReportEvent(servicemanager.PYS_SERVICE_STARTED) logging.info("Starting OVirt Guest Agent service") - config = ConfigParser.ConfigParser() config.read(AGENT_CONFIG) self.vdsAgent = WinVdsAgent(config) diff --git a/ovirt-guest-agent/config.py b/ovirt-guest-agent/config.py new file mode 100644 index 0000000..2065de8 --- /dev/null +++ b/ovirt-guest-agent/config.py @@ -0,0 +1,96 @@ +#! /usr/bin/env python +# -*- coding: utf-8 -*- +# vim:fenc=utf-8 +# Copyright 2014 Vinzenz Feenstra, Red Hat, Inc. and/or its affiliates. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Refer to the README and COPYING files for full details of the license. +# + +import ConfigParser +import platform + + +_IS_WINDOWS = platform.system() in ['Windows', 'Microsoft'] + + +def _get_platform_app_list(): + if _IS_WINDOWS: + return '' + return ' '.join([ + 'kernel', + 'ovirt-guest-agent', + 'ovirt-guest-agent-common' + 'xorg-x11-drv-qxl', + 'linux-image', + 'xserver-xorg-video-qxl', + 'xf86-video-qxl', + 'kernel-desktop', + 'kernel-default', + 'kernel-trace', + 'kernel-vanilla,' + 'kernel-debug', + 'kernel-ec2', + 'kernel-xen', + ]) + + +def _get_platform_ignored_fs_list(): + if _IS_WINDOWS: + return '' + return ' '.join(( + 'rootfs', + 'tmpfs', + 'autofs', + 'cgroup', + 'selinuxfs', + 'udev', + 'mqueue', + 'nfsd', + 'proc', + 'sysfs', + 'devtmpfs', + 'hugetlbfs', + 'rpc_pipefs', + 'devpts', + 'securityfs', + 'debugfs', + 'binfmt_misc', + 'fuse.gvfsd-fuse', + 'fuse.gvfs-fuse-daemon', + 'fusectl usbfs', + )) + + +_default_config = ( + ('general', ( + ('heart_beat_rate', 5), + ('report_user_rate', 10), + ('report_num_cpu_rate', 60), + ('report_application_rate', 120), + ('report_disk_usage', 300), + ('applications_list', _get_platform_app_list()), + ('ignored_fs', _get_platform_ignored_fs_list()) + )) +) + + +def _get_default_config(): + config = ConfigParser.ConfigParser() + for section, entries in _default_config: + for key, value in entries: + config.set(section, key, value) + return config + +config = _get_default_config() diff --git a/ovirt-guest-agent/ovirt-guest-agent.py b/ovirt-guest-agent/ovirt-guest-agent.py index c7d60c8..d32ec9c 100644 --- a/ovirt-guest-agent/ovirt-guest-agent.py +++ b/ovirt-guest-agent/ovirt-guest-agent.py @@ -21,7 +21,7 @@ import signal import sys import getopt -import ConfigParser +from config import config from GuestAgentLinux2 import LinuxVdsAgent AGENT_CONFIG = '/etc/ovirt-guest-agent.conf' @@ -35,8 +35,6 @@ def run(self, daemon, pidfile): logging.info("Starting oVirt guest agent") - - config = ConfigParser.ConfigParser() config.read(AGENT_CONFIG) self.agent = LinuxVdsAgent(config) -- To view, visit http://gerrit.ovirt.org/28045 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I5ce9d457e826448aad205ce4abda5dc4b0210804 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-guest-agent Gerrit-Branch: master Gerrit-Owner: Vinzenz Feenstra <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
