Beispiel #1
0
        def check_be_name(be_name):
                try:
                        if be_name is None:
                                return

                        if be.beVerifyBEName(be_name) != 0:
                                raise api_errors.InvalidBENameException(be_name)

                        # 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, beList = beVals
                        else:
                                beList = beVals

                        # If there is already a BE with the same name as
                        # be_name, then raise an exception.
                        if be_name in (be.get("orig_be_name") for be in beList):
                                raise api_errors.DuplicateBEName(be_name)
                except AttributeError:
                        raise api_errors.BENamingNotSupported(be_name)
Beispiel #2
0
        def get_be_list(raise_error=False):
                # This check enables the test suite to run much more quickly.
                # It is necessary because pkg5unittest (eventually) imports this
                # module before the environment is sanitized.
                if "PKG_NO_LIVE_ROOT" in os.environ:
                        return BootEnvNull.get_be_list()
                # Check for the old beList() API since pkg(1) can be
                # back published and live on a system without the 
                # latest libbe.
                rc = 0

                beVals = be.beList()
                if isinstance(beVals[0], int):
                        rc, beList = beVals
                else:
                        beList = beVals
                if not beList or rc != 0:
                        if raise_error:
                                # Happens e.g. in zones (for now) or live CD
                                # environment.
                                raise RuntimeError, "nobootenvironments"
                        beList = []

                return beList
Beispiel #3
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:
                                emsg(_("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"