Ejemplo n.º 1
0
 def _mount_command(self, image, fs, mountpoint):
     command = ['imagemount', '-f', image, '-d', self.device, '-m', mountpoint, '-t', fs, '-r', '-D']
     self._runner = Execute(command)
     self._runner.run()
     status = self._runner.poll()
     if not self._unmounting and status != 0:
         raise MountException("Mounting returned exit code different than 0")
Ejemplo n.º 2
0
 def _mount_command(self, image, fs, mountpoint):
     command = ["imagemount", "-f", image, "-d", self.device, "-m", mountpoint, "-t", fs, "-r", "-D"]
     self._runner = Execute(command)
     self._runner.run()
     status = self._runner.poll()
     if not self._unmounting and status != 0:
         raise MountException("Mounting returned exit code different than 0")
Ejemplo n.º 3
0
class DiskIOUtilisationPlugin(ThreadedMetricPlugin):
    """
    This plugin collects the disk I/O utilisation, it does represent the average I/O
    usage of the backup disk over the interval period in percents.
    """
    NAME = 'Disk_IO_Utilisation'
    COMMAND = [
        'iostat', '-x', '-d',
        str(ConfigHelper.config['node']['backup_disk'])
    ]

    def _run(self):
        self._thread = Thread(target=self._collect_metric, daemon=True)
        self._thread.start()

    @property
    def value(self):
        """
        Checks whether a new value is available and returns the up to date value of the metric.
        :return: numerical value representing the percentage of the I/O utilisation.
        """
        with self._lock:
            output = self._runner.output()
            if output:
                self._value = output
            return float(self._value)

    def _collect_metric(self):
        self.COMMAND.append(str(self.interval))
        self._runner = Execute(self.COMMAND,
                               output_parser=_IOStatParser(),
                               use_pty=True)
        self._runner.run()

    def stop(self):
        """
        Stops the command that is executed in the background to collect the metric.
        :return: None
        """
        self._stop = True
        self._runner.kill()
        self._thread.join()
Ejemplo n.º 4
0
 def unmount(self):
     """
     Unmounts the previously mounted image file.
     :return: None
     """
     if self._thread.isAlive():
         self._unmounting = True
         self._runner.kill()
         self._thread.join()
         self._unmounting = False
     command = ['umount', self.mountpoint]
     Execute(command).run()
Ejemplo n.º 5
0
class DiskIOUtilisationPlugin(ThreadedMetricPlugin):
    """
    This plugin collects the disk I/O utilisation, it does represent the average I/O
    usage of the backup disk over the interval period in percents.
    """
    NAME = 'Disk_IO_Utilisation'
    COMMAND = ['iostat', '-x', '-d', str(ConfigHelper.config['node']['backup_disk'])]

    def _run(self):
        self._thread = Thread(target=self._collect_metric, daemon=True)
        self._thread.start()

    @property
    def value(self):
        """
        Checks whether a new value is available and returns the up to date value of the metric.
        :return: numerical value representing the percentage of the I/O utilisation.
        """
        with self._lock:
            output = self._runner.output()
            if output:
                self._value = output
            return float(self._value)

    def _collect_metric(self):
        self.COMMAND.append(str(self.interval))
        self._runner = Execute(self.COMMAND, output_parser=_IOStatParser(), use_pty=True)
        self._runner.run()

    def stop(self):
        """
        Stops the command that is executed in the background to collect the metric.
        :return: None
        """
        self._stop = True
        self._runner.kill()
        self._thread.join()
Ejemplo n.º 6
0
class NBDNode:
    """
    This class wraps NBD devices provided by the Linux kernel and allows mounting of
    the partclone images with the use of the ImageMount command.
    """

    def __init__(self, device):
        self.device = device
        self.mountpoint = ""
        self.error = False
        self._runner = None
        self._thread = None
        self._unmounting = False

    def mount(self, image, fs, mountpoint):
        """
        Mounts the specified image file at the given mountpoint.
        :param image: path to the image file to be mounted.
        :param fs: file system of the imaged partition.
        :param mountpoint: directory to be used for mounting.
        :return: None
        """
        self.mountpoint = mountpoint
        self._thread = ExtendedThread(exception_callback=self._exception_callback,
                                      target=self._mount_command, args=(image, fs, mountpoint),
                                      daemon=True)
        self._thread.start()
        self._wait_and_set_status()

    def _wait_and_set_status(self):
        """
        Waits until the image is mounted and checks whether the mount procedure
        was successful or not.
        :return: None
        """
        while self._runner.poll() is Execute.PROCESS_NOT_STARTED:
            sleep(constants.BUSY_WAIT_INTERVAL)
        if self._runner.poll() is not Execute.PROCESS_RUNNING:
            self.error = True

    def _mount_command(self, image, fs, mountpoint):
        command = ['imagemount', '-f', image, '-d', self.device, '-m', mountpoint, '-t', fs, '-r', '-D']
        self._runner = Execute(command)
        self._runner.run()
        status = self._runner.poll()
        if not self._unmounting and status != 0:
            raise MountException("Mounting returned exit code different than 0")

    def _exception_callback(self, source, e):
        self.error = True

    def unmount(self):
        """
        Unmounts the previously mounted image file.
        :return: None
        """
        if self._thread.isAlive():
            self._unmounting = True
            self._runner.kill()
            self._thread.join()
            self._unmounting = False
        command = ['umount', self.mountpoint]
        Execute(command).run()

    def reset(self):
        """
        Resets the node so that it can be used again for mounting another image.
        :return: None
        """
        self.unmount()
        self._runner = None
        self._thread = None
        self.error = False
Ejemplo n.º 7
0
class NBDNode:
    """
    This class wraps NBD devices provided by the Linux kernel and allows mounting of
    the partclone images with the use of the ImageMount command.
    """

    def __init__(self, device):
        self.device = device
        self.mountpoint = ""
        self.error = False
        self._runner = None
        self._thread = None
        self._unmounting = False

    def mount(self, image, fs, mountpoint):
        """
        Mounts the specified image file at the given mountpoint.
        :param image: path to the image file to be mounted.
        :param fs: file system of the imaged partition.
        :param mountpoint: directory to be used for mounting.
        :return: None
        """
        self.mountpoint = mountpoint
        self._thread = ExtendedThread(
            exception_callback=self._exception_callback,
            target=self._mount_command,
            args=(image, fs, mountpoint),
            daemon=True,
        )
        self._thread.start()
        self._wait_and_set_status()

    def _wait_and_set_status(self):
        """
        Waits until the image is mounted and checks whether the mount procedure
        was successful or not.
        :return: None
        """
        while self._runner.poll() is Execute.PROCESS_NOT_STARTED:
            sleep(constants.BUSY_WAIT_INTERVAL)
        if self._runner.poll() is not Execute.PROCESS_RUNNING:
            self.error = True

    def _mount_command(self, image, fs, mountpoint):
        command = ["imagemount", "-f", image, "-d", self.device, "-m", mountpoint, "-t", fs, "-r", "-D"]
        self._runner = Execute(command)
        self._runner.run()
        status = self._runner.poll()
        if not self._unmounting and status != 0:
            raise MountException("Mounting returned exit code different than 0")

    def _exception_callback(self, source, e):
        self.error = True

    def unmount(self):
        """
        Unmounts the previously mounted image file.
        :return: None
        """
        if self._thread.isAlive():
            self._unmounting = True
            self._runner.kill()
            self._thread.join()
            self._unmounting = False
        command = ["umount", self.mountpoint]
        Execute(command).run()

    def reset(self):
        """
        Resets the node so that it can be used again for mounting another image.
        :return: None
        """
        self.unmount()
        self._runner = None
        self._thread = None
        self.error = False
Ejemplo n.º 8
0
 def _collect_metric(self):
     self.COMMAND.append(str(self.interval))
     self._runner = Execute(self.COMMAND,
                            output_parser=_IOStatParser(),
                            use_pty=True)
     self._runner.run()
Ejemplo n.º 9
0
 def _collect_metric(self):
     self.COMMAND.append(str(self.interval))
     self._runner = Execute(self.COMMAND, output_parser=_IOStatParser(), use_pty=True)
     self._runner.run()