Пример #1
0
    def export(self):
        """
        Before importing check the device_path does not reference a dataset, if it does then retry on parent zpool
        block device.

        We can only export the zpool if it's already imported so check before exporting.

        :return: None for success meaning the zpool has been exported
        """
        self._initialize_modules()

        try:
            self._assert_zpool('export')
        except NotZpoolException:
            blockdevice = BlockDevice(self._supported_device_types[0],
                                      self._device_path.split('/')[0])

            return blockdevice.export()

        with ZfsDevice(self._device_path, False) as zfs_device:
            result = zfs_device.export()

            if result is not None and 'no such pool' in result:
                # Already not imported, nothing to do
                return None

            return result
Пример #2
0
    def export(self):
        """
        Before importing check the device_path does not reference a dataset, if it does then retry on parent zpool
        block device.

        We can only export the zpool if it's already imported so check before exporting.

        :return: None for success meaning the zpool has been exported
        """
        self._check_module()

        try:
            self._assert_zpool('export')
        except NotZpoolException:
            blockdevice = BlockDevice(self._supported_device_types[0],
                                      self._device_path.split('/')[0])

            return blockdevice.export()

        result = Shell.run_canned_error_message(
            ['zpool', 'export', self._device_path])

        if result is not None and 'no such pool' in result:
            # Already not imported, nothing to do
            return None

        return result
Пример #3
0
    def failmode(self, value):
        self._check_module()

        try:
            self._assert_zpool("failmode")
        except NotZpoolException:
            blockdevice = BlockDevice(self._supported_device_types[0], self._device_path.split("/")[0])

            blockdevice.failmode = value
        else:
            Shell.try_run(["zpool", "set", "failmode=%s" % value, self._device_path])
Пример #4
0
    def failmode(self, value):
        try:
            self._assert_zpool('failmode')
        except NotZpoolException:
            blockdevice = BlockDevice(self._supported_device_types[0],
                                      self._device_path.split('/')[0])

            blockdevice.failmode = value
        else:
            with ZfsDevice(self._device_path, False):
                shell.Shell.try_run(
                    ["zpool", "set",
                     "failmode=%s" % value, self._device_path])
Пример #5
0
    def import_(self, pacemaker_ha_operation):
        """
        Before importing check the device_path does not reference a dataset, if it does then retry on parent zpool
        block device.

        We can only import the zpool if it's not already imported so check before importing.

        :param pacemaker_ha_operation: This import is at the request of pacemaker. In HA operations the device may
               often have not have been cleanly exported because the previous mounted node failed in operation.
        :return: None for success meaning the zpool is imported
        """
        self._initialize_modules()

        try:
            self._assert_zpool('import_')
        except NotZpoolException:
            blockdevice = BlockDevice(self._supported_device_types[0],
                                      self._device_path.split('/')[0])

            return blockdevice.import_(pacemaker_ha_operation)

        with ZfsDevice(self._device_path, False) as zfs_device:
            result = zfs_device.import_(pacemaker_ha_operation, False)

            if result is not None and 'a pool with that name already exists' in result:

                if self.zpool_properties(True).get('readonly') == 'on':
                    # Zpool is already imported readonly. Export and re-import writeable.
                    result = self.export()

                    if result is not None:
                        return "zpool was imported readonly, and failed to export: '%s'" % result

                    result = self.import_(pacemaker_ha_operation)

                    if (result is None) and (
                            self.zpool_properties(True).get('readonly')
                            == 'on'):
                        return 'zfs pool %s can only be imported readonly, is it in use?' % self._device_path

                else:
                    # zpool is already imported and writable, nothing to do.
                    return None

            return result
Пример #6
0
    def import_(self, pacemaker_ha_operation):
        """
        Before importing check the device_path does not reference a dataset, if it does then retry on parent zpool
        block device.

        We can only import the zpool if it's not already imported so check before importing.

        :param pacemaker_ha_operation: This import is at the request of pacemaker. In HA operations the device may
               often have not have been cleanly exported because the previous mounted node failed in operation.
        :return: None for success meaning the zpool is imported
        """
        self._check_module()

        try:
            self._assert_zpool("import_")
        except NotZpoolException:
            blockdevice = BlockDevice(self._supported_device_types[0], self._device_path.split("/")[0])

            return blockdevice.import_(pacemaker_ha_operation)

        result = Shell.run_canned_error_message(
            ["zpool", "import"] + (["-f"] if pacemaker_ha_operation else []) + [self._device_path]
        )

        if result is not None and "a pool with that name already exists" in result:

            if self.zpool_properties(True).get("readonly") == "on":
                # Zpool is already imported readonly. Export and re-import writeable.
                result = self.export()

                if result is not None:
                    return "zpool was imported readonly, and failed to export: '%s'" % result

                result = self.import_(pacemaker_ha_operation)

                if (result is None) and (self.zpool_properties(True).get("readonly") == "on"):
                    return "zfs pool %s can only be imported readonly, is it in use?" % self._device_path

            else:
                # zpool is already imported and writable, nothing to do.
                return None

        return result
Пример #7
0
    def failmode(self):
        self._check_module()

        try:
            self._assert_zpool("failmode")
        except NotZpoolException:
            blockdevice = BlockDevice(self._supported_device_types[0], self._device_path.split("/")[0])

            return blockdevice.failmode
        else:
            return Shell.try_run(["zpool", "get", "-Hp", "failmode", self._device_path]).split()[2]
Пример #8
0
    def failmode(self):
        try:
            self._assert_zpool('failmode')
        except NotZpoolException:
            blockdevice = BlockDevice(self._supported_device_types[0],
                                      self._device_path.split('/')[0])

            return blockdevice.failmode
        else:
            with ZfsDevice(self._device_path, False):
                return shell.Shell.try_run(
                    ["zpool", "get", "-Hp", "failmode",
                     self._device_path]).split()[2]
Пример #9
0
from fsck import Fsck
from blockdevice import BlockDevice
from datatosend import dataToSend
from datatoreceive import dataToReceive

fsimg = "minixfs.img"

myDataToReceive = dataToReceive()

while True:
    try:
        mode = int(
            raw_input(
                "Enter 0 to access a local FS and 1 to access a remote FS:\n"))
        if mode == 0:
            myBlockDevice = BlockDevice(fsimg, 1024, 20, mode, None)
            break
        elif mode == 1:
            # Creation of the socket
            mySocket = socket.socket()

            # Get informations about the server
            IP = raw_input("Remote IP address:\n")
            PORT = int(raw_input("Remote listening port number:\n"))

            # Prepare the message to send
            myDataToSend = dataToSend()
            myDataToSend.send(IP, PORT, 20, 1024, mySocket)
            myDataToReceive.receive(20, mySocket)

            # Creation of the Blockdevice object