[Kimchi-devel] [PATCH 4/5] Add a monitor to change iso ownership

Aline Manera alinefm at linux.vnet.ibm.com
Wed Jun 11 17:03:32 UTC 2014


On 06/10/2014 07:06 AM, lvroyce at linux.vnet.ibm.com wrote:
> From: Royce Lv <lvroyce at linux.vnet.ibm.com>
>
> Add a threaded monitor to change file ownership.
> Also its pynotify dependecy is added.
>
> Signed-off-by: Royce Lv <lvroyce at linux.vnet.ibm.com>
> ---
>   docs/README.md           |  6 ++++--
>   src/kimchi/isomonitor.py | 33 +++++++++++++++++++++++++++++++++
>   2 files changed, 37 insertions(+), 2 deletions(-)
>   create mode 100644 src/kimchi/isomonitor.py
>
> diff --git a/docs/README.md b/docs/README.md
> index 63ac760..9f059ca 100644
> --- a/docs/README.md
> +++ b/docs/README.md
> @@ -53,7 +53,8 @@ Install Dependencies
>                           PyPAM m2crypto python-jsonschema rpm-build \
>                           qemu-kvm python-psutil python-ethtool sos \
>                           python-ipaddr python-lxml nfs-utils \
> -                        iscsi-initiator-utils libxslt pyparted nginx
> +                        iscsi-initiator-utils libxslt pyparted nginx \
> +                        python-inotify
>        # If using RHEL6, install the following additional packages:
>        $ sudo yum install python-unittest2 python-ordereddict
>        # Restart libvirt to allow configuration changes to take effect
> @@ -75,7 +76,8 @@ for more information on how to configure your system to access this repository.
>                              python-pam python-m2crypto python-jsonschema \
>                              qemu-kvm libtool python-psutil python-ethtool \
>                              sosreport python-ipaddr python-lxml nfs-common \
> -                           open-iscsi lvm2 xsltproc python-parted nginx
> +                           open-iscsi lvm2 xsltproc python-parted nginx \
> +                           python-pyinotify
>
>       Packages version requirement:
>           python-jsonschema >= 1.3.0
> diff --git a/src/kimchi/isomonitor.py b/src/kimchi/isomonitor.py
> new file mode 100644
> index 0000000..c20d71a
> --- /dev/null
> +++ b/src/kimchi/isomonitor.py

You need to add the license header for new files

> @@ -0,0 +1,33 @@
> +import os
> +import pyinotify
> +
> +
> +from kimchi.utils import get_qemu_owner
> +
> +
> +class EventHandler(pyinotify.ProcessEvent):
> +    def process_IN_CREATE(self, event):
> +        uid, gid = get_qemu_owner()
> +        os.chown(event.pathname, uid, gid)
> +
> +
> +class pathMonitor(object):
> +    def __init__(self):
> +        self.wm = pyinotify.WatchManager()
> +        self.notifier = pyinotify.ThreadedNotifier(self.wm, EventHandler())
> +        self.handlers = dict()
> +
> +        self.notifier.start()
> +
> +    def add_monitor_path(self, path):
> +        mask = pyinotify.IN_DELETE | pyinotify.IN_CREATE # watched events
> +        self.handlers[path] = self.wm.add_watch(path, mask, rec=True)
> +
> +    def rm_monitor_path(self, path):
> +        self.wm.rm_watch(self.handlers.pop(path).values())
> +
> +    def stop_monitor(self):
> +        for path in self.handlers.iterkeys():
> +            self.rm_monitor_path(path)
> +        self.notifier.stop()
> +




More information about the Kimchi-devel mailing list