示例#1
0
文件: beadm.py 项目: nxmirrors/onnv
def createSnapshot(be):
    """Create a snapshot."""

    be_name, snap_name = be.trgt_be_name_or_snapshot[0].split("@")

    rc = lb.beCreateSnapshot(be_name, snap_name)[0]

    if rc == 0:
        return 0

    be.msg_buf["0"] = be.trgt_be_name_or_snapshot[0]
    if rc == msg.Msgs.BE_ERR_BE_NOENT:
        be.msg_buf["1"] = msg.getMsg(msg.Msgs.BEADM_ERR_BE_DOES_NOT_EXIST, be_name)
    elif rc == msg.Msgs.BE_ERR_SS_EXISTS:
        be.msg_buf["1"] = msg.getMsg(msg.Msgs.BEADM_ERR_SNAP_EXISTS, be.trgt_be_name_or_snapshot[0])
    elif rc == msg.Msgs.BE_ERR_PERM or rc == msg.Msgs.BE_ERR_ACCESS:
        be.msg_buf["1"] = msg.getMsg(msg.Msgs.BEADM_ERR_PERMISSIONS, rc)
        msg.printMsg(msg.Msgs.BEADM_ERR_CREATE, be.msg_buf, -1)
        return 1
    else:
        be.msg_buf["1"] = lb.beGetErrDesc(rc)
        if be.msg_buf["1"] == None:
            be.msg_buf["1"] = msg.getMsg(msg.Msgs.BEADM_ERR_NO_MSG, rc)

    msg.printMsg(msg.Msgs.BEADM_ERR_CREATE, be.msg_buf, -1)

    return 1
示例#2
0
def createSnapshot(be):
    """Create a snapshot."""

    be_name, snap_name = be.trgt_be_name_or_snapshot[0].split("@")

    rc = lb.beCreateSnapshot(be_name, snap_name)[0]

    if rc == 0:
        return 0

    be.msg_buf["0"] = be.trgt_be_name_or_snapshot[0]
    if rc == msg.Msgs.BE_ERR_BE_NOENT:
        be.msg_buf["1"] = \
            msg.getMsg(msg.Msgs.BEADM_ERR_BE_DOES_NOT_EXIST,
            be_name)
    elif rc == msg.Msgs.BE_ERR_SS_EXISTS:
        be.msg_buf["1"] = msg.getMsg(msg.Msgs.BEADM_ERR_SNAP_EXISTS,
            be.trgt_be_name_or_snapshot[0])
    elif rc == msg.Msgs.BE_ERR_PERM or rc == msg.Msgs.BE_ERR_ACCESS:
        be.msg_buf["1"] = msg.getMsg(msg.Msgs.BEADM_ERR_PERMISSIONS, rc)
        msg.printMsg(msg.Msgs.BEADM_ERR_CREATE, be.msg_buf, -1)
        return 1
    else:
        be.msg_buf["1"] = lb.beGetErrDesc(rc)
        if be.msg_buf["1"] == None:
            be.msg_buf["1"] = \
                msg.getMsg(msg.Msgs.BEADM_ERR_NO_MSG, rc)

    msg.printMsg(msg.Msgs.BEADM_ERR_CREATE, be.msg_buf, -1)

    return 1
示例#3
0
    def __init__(self, img, progress_tracker=None):
        self.be_name = None
        self.dataset = None
        self.be_name_clone = None
        self.be_name_clone_uuid = None
        self.clone_dir = None
        self.img = img
        self.is_live_BE = False
        self.is_valid = False
        self.snapshot_name = None
        self.progress_tracker = progress_tracker

        # record current location of image root so we can remember
        # original source BE if we clone existing image
        self.root = self.img.get_root()
        rc = 0

        assert self.root != None

        # Need to find the name of the BE we're operating on in order
        # to create a snapshot and/or a clone of the BE.
        self.beList = self.get_be_list(raise_error=True)

        for i, beVals in enumerate(self.beList):
            # pkg(1) expects a directory as the target of an
            # operation. BootEnv needs to determine if this target
            # directory maps to a BE. If a bogus directory is
            # provided to pkg(1) via -R, then pkg(1) just updates
            # '/' which also causes BootEnv to manage '/' as well.
            # This should be fixed before this class is ever
            # instantiated.

            be_name = beVals.get("orig_be_name")

            # If we're not looking at a boot env entry or an
            # entry that is not mounted then continue.
            if not be_name or not beVals.get("mounted"):
                continue

            # Check if we're operating on the live BE.
            # If so it must also be active. If we are not
            # operating on the live BE, then verify
            # that the mountpoint of the BE matches
            # the -R argument passed in by the user.
            if self.root == '/':
                if not beVals.get("active"):
                    continue
                else:
                    self.is_live_BE = True
            else:
                if beVals.get("mountpoint") != self.root:
                    continue

            # Set the needed BE components so snapshots
            # and clones can be managed.
            self.be_name = be_name

            self.dataset = beVals.get("dataset")

            # Let libbe provide the snapshot name
            err, snapshot_name = be.beCreateSnapshot(self.be_name)
            self.clone_dir = tempfile.mkdtemp()

            # Check first field for failure.
            # 2nd field is the returned snapshot name
            if err == 0:
                self.snapshot_name = snapshot_name
                # we require BootEnv to be initialised within
                # the context of a history operation, i.e.
                # after img.history.operation_name has been set.
                img.history.operation_snapshot = snapshot_name
            else:
                logger.error(
                    _("pkg: unable to create an auto "
                      "snapshot. pkg recovery is disabled."))
                raise RuntimeError("recoveryDisabled")
            self.is_valid = True
            break

        else:
            # We will get here if we don't find find any BE's. e.g
            # if were are on UFS.
            raise RuntimeError("recoveryDisabled")
示例#4
0
    def __init__(self, root):
        self.be_name = None
        self.dataset = None
        self.be_name_clone = None
        self.clone_dir = None
        self.img = None
        self.is_live_BE = False
        self.is_valid = False
        self.snapshot_name = None
        self.root = root
        rc = 0

        assert root != None

        # Check for the old beList() API since pkg(1) can be
        # back published and live on a system without the latest libbe.
        beVals = be.beList()
        if isinstance(beVals[0], int):
            rc, self.beList = beVals
        else:
            self.beList = beVals

        # Happens e.g. in zones (at least, for now)
        if not self.beList or rc != 0:
            raise RuntimeError, "nobootenvironments"

        # Need to find the name of the BE we're operating on in order
        # to create a snapshot and/or a clone of the BE.

        for i, beVals in enumerate(self.beList):
            # pkg(1) expects a directory as the target of an
            # operation. BootEnv needs to determine if this target
            # directory maps to a BE. If a bogus directory is
            # provided to pkg(1) via -R, then pkg(1) just updates
            # '/' which also causes BootEnv to manage '/' as well.
            # This should be fixed before this class is ever
            # instantiated.

            be_name = beVals.get("orig_be_name")

            # If we're not looking at a boot env entry or an
            # entry that is not mounted then continue.
            if not be_name or not beVals.get("mounted"):
                continue

            # Check if we're operating on the live BE.
            # If so it must also be active. If we are not
            # operating on the live BE, then verify
            # that the mountpoint of the BE matches
            # the -R argument passed in by the user.
            if root == '/':
                if not beVals.get("active"):
                    continue
                else:
                    self.is_live_BE = True
            else:
                if beVals.get("mountpoint") != root:
                    continue

            # Set the needed BE components so snapshots
            # and clones can be managed.
            self.be_name = be_name

            self.dataset = beVals.get("dataset")

            # Let libbe provide the snapshot name
            err, snapshot_name = be.beCreateSnapshot(self.be_name)
            self.clone_dir = tempfile.mkdtemp()

            # Check first field for failure.
            # 2nd field is the returned snapshot name
            if err == 0:
                self.snapshot_name = snapshot_name
            else:
                logger.error(
                    _("pkg: unable to create an auto "
                      "snapshot. pkg recovery is disabled."))
                raise RuntimeError, "recoveryDisabled"
            self.is_valid = True
            break

        else:
            # We will get here if we don't find find any BE's. e.g
            # if were are on UFS.
            raise RuntimeError, "recoveryDisabled"
        def __init__(self, root):
                self.be_name = None
                self.dataset = None
                self.be_name_clone = None
                self.clone_dir = None
                self.img = None
                self.is_live_BE = False
                self.is_valid = False
                self.snapshot_name = None
                self.root = root
                rc = 0

                assert root != None

                # Check for the old beList() API since pkg(1) can be
                # back published and live on a system without the latest libbe.
                beVals = be.beList()
                if isinstance(beVals[0], int):
                        rc, self.beList = beVals
                else:
                        self.beList = beVals

                # Happens e.g. in zones (at least, for now)
                if not self.beList or rc != 0:
                        raise RuntimeError, "nobootenvironments"

                # Need to find the name of the BE we're operating on in order
                # to create a snapshot and/or a clone of the BE.

                for i, beVals in enumerate(self.beList):
                        # pkg(1) expects a directory as the target of an
                        # operation. BootEnv needs to determine if this target
                        # directory maps to a BE. If a bogus directory is
                        # provided to pkg(1) via -R, then pkg(1) just updates
                        # '/' which also causes BootEnv to manage '/' as well.
                        # This should be fixed before this class is ever
                        # instantiated.

                        be_name = beVals.get("orig_be_name")

                        # If we're not looking at a boot env entry or an
                        # entry that is not mounted then continue.
                        if not be_name or not beVals.get("mounted"):
                                continue

                        # Check if we're operating on the live BE.
                        # If so it must also be active. If we are not
                        # operating on the live BE, then verify
                        # that the mountpoint of the BE matches
                        # the -R argument passed in by the user.
                        if root == '/':
                                if not beVals.get("active"):
                                        continue
                                else:
                                        self.is_live_BE = True
                        else:
                                if beVals.get("mountpoint") != root:
                                        continue

                        # Set the needed BE components so snapshots
                        # and clones can be managed.
                        self.be_name = be_name

                        self.dataset = beVals.get("dataset")

                        # Let libbe provide the snapshot name
                        err, snapshot_name = be.beCreateSnapshot(self.be_name)
                        self.clone_dir = tempfile.mkdtemp()

                        # Check first field for failure.
                        # 2nd field is the returned snapshot name
                        if err == 0:
                                self.snapshot_name = snapshot_name
                        else:
                                logger.error(_("pkg: unable to create an auto "
                                    "snapshot. pkg recovery is disabled."))
                                raise RuntimeError, "recoveryDisabled"
                        self.is_valid = True
                        break

                else:
                        # We will get here if we don't find find any BE's. e.g
                        # if were are on UFS.
                        raise RuntimeError, "recoveryDisabled"