def activate_live_be(cmd):
            cmd += [self.clone_dir]

            # Activate the clone.
            exec_cmd(cmd)

            if be.beActivate(self.be_name_clone) != 0:
                logger.error(_("pkg: unable to activate %s") \
                    % self.be_name_clone)
                return

            # Consider the last operation a success, and log it as
            # ending here so that it will be recorded in the new
            # image's history.
            self.img.history.log_operation_end()

            if be.beUnmount(self.be_name_clone) != 0:
                logger.error(_("pkg: unable to unmount %s") \
                    % self.clone_dir)
                return

            os.rmdir(self.clone_dir)

            logger.info(_("""
A clone of %s exists and has been updated and activated.
On the next boot the Boot Environment %s will be mounted on '/'.
Reboot when ready to switch to this updated BE.
""") % \
                (self.be_name, self.be_name_clone))
                def activate_live_be(cmd):
                        cmd += [self.clone_dir]

                        # Activate the clone.
                        exec_cmd(cmd)

                        if be.beActivate(self.be_name_clone) != 0:
                                logger.error(_("pkg: unable to activate %s") \
                                    % self.be_name_clone)
                                return

                        # Consider the last operation a success, and log it as
                        # ending here so that it will be recorded in the new
                        # image's history.
                        self.img.history.log_operation_end()

                        if be.beUnmount(self.be_name_clone) != 0:
                                logger.error(_("pkg: unable to unmount %s") \
                                    % self.clone_dir)
                                return

                        os.rmdir(self.clone_dir)

                        logger.info(_("""
A clone of %s exists and has been updated and activated.
On the next boot the Boot Environment %s will be mounted on '/'.
Reboot when ready to switch to this updated BE.
""") % \
                            (self.be_name, self.be_name_clone))
Exemple #3
0
        def activate_live_be():
            if set_active:
                if set_active == "bootnext":
                    ret = be.beActivate(self.be_name_clone, temporary=1)
                else:
                    ret = be.beActivate(self.be_name_clone)
                if ret != 0:
                    logger.error(
                        _("pkg: unable to activate "
                          "{0}").format(self.be_name_clone))
                    return

            # Consider the last operation a success, and log it as
            # ending here so that it will be recorded in the new
            # image's history.
            self.img.history.operation_new_be = self.be_name_clone
            self.img.history.operation_new_be_uuid = self.be_name_clone_uuid
            self.img.history.log_operation_end(
                release_notes=self.img.imageplan.pd.release_notes_name)

            if be.beUnmount(self.be_name_clone) != 0:
                logger.error(
                    _("unable to unmount BE "
                      "{be_name} mounted at {be_path}").format(
                          be_name=self.be_name_clone, be_path=self.clone_dir))
                return

            os.rmdir(self.clone_dir)

            if set_active:
                logger.info(
                    _("""
A clone of {be_name} exists and has been updated and activated.
On the next boot the Boot Environment {be_name_clone} will be
mounted on '/'.  Reboot when ready to switch to this updated BE.

*** Reboot required ***
New BE: {be_name_clone}
""").format(**self.__dict__))
            else:
                logger.info(
                    _("""
A clone of {be_name} exists and has been updated.  To set the
new BE as the active one on next boot, execute the following
command as a privileged user and reboot when ready to switch to
the updated BE:

beadm activate {be_name_clone}
""").format(**self.__dict__))
Exemple #4
0
def post_install_cleanup(install_profile, rootpool_name):
    '''Do final cleanup to prep system for first boot, such as resetting
    the ZFS dataset mountpoints
    
    '''
    # reset_zfs_mount_property
    # Setup mountpoint property back to "/" from "/a" for
    # /, /opt, /export, /export/home

    # make sure we are not in the alternate root.
    # Otherwise, be_unmount() fails
    os.chdir("/root")

    # since be_unmount() can not currently handle shared filesystems,
    # it's necesary to manually set their mountpoint to the appropriate value
    for fs in ZFS_SHARED_FS:
        exec_cmd(["/usr/sbin/zfs", "unmount", rootpool_name + fs],
                 "unmount " + rootpool_name + fs)
        exec_cmd(
            ["/usr/sbin/zfs", "set", "mountpoint=" + fs, rootpool_name + fs],
            "change mount point for " + rootpool_name + fs)

    # Transfer the log file
    final_log_loc = INSTALLED_ROOT_DIR + install_profile.log_final
    logging.debug("Copying %s to %s", install_profile.log_location,
                  final_log_loc)
    try:
        dirname = os.path.dirname(final_log_loc)
        if (not os.path.isdir(dirname)):
            os.makedirs(dirname, 0o755)
        shutil.copyfile(install_profile.log_location, final_log_loc)
    except (IOError, OSError) as err:
        logging.error("Failed to copy %s to %s", install_profile.log_location,
                      install_profile.log_final)
        logging.exception(err)
        raise ti_utils.InstallationError

    # 0 for the 2nd argument because force-umount need to be 0
    if beUnmount(install_profile.be_name, 0) != 0:
        logging.error("beUnmount failed for %s", install_profile.be_name)
        raise ti_utils.InstallationError
Exemple #5
0
    final_log_loc = INSTALLED_ROOT_DIR + install_profile.log_final
    logging.debug("Copying %s to %s", install_profile.log_location,
                  final_log_loc)
    try:
        dirname = os.path.dirname(final_log_loc)
        if (not os.path.isdir(dirname)):
            os.makedirs(dirname, 0755)
        shutil.copyfile(install_profile.log_location, final_log_loc)
    except (IOError, OSError), err:
        logging.error("Failed to copy %s to %s", install_profile.log_location,
                      install_profile.log_final)
        logging.exception(err)
        raise ti_utils.InstallationError

    # 0 for the 2nd argument because force-umount need to be 0
    if beUnmount(INIT_BE_NAME, 0) != 0:
        logging.error("beUnmount failed for %s", INIT_BE_NAME)
        raise ti_utils.InstallationError


# pylint: disable-msg=C0103
def run_ICTs(install_profile, hostname, ict_mesg, inst_device, locale,
             root_pass, ulogin, upass, ureal_name, rootpool_name):
    '''Run all necessary ICTs. This function ensures that each ICT is run,
    regardless of the success/failure of any others. After running all ICTs
    (including those supplied by install-finish), if any of them failed,
    an InstallationError is raised.
    
    '''

    failed_icts = 0
    final_log_loc = INSTALLED_ROOT_DIR + install_profile.log_final
    logging.debug("Copying %s to %s", install_profile.log_location,
                  final_log_loc)
    try:
        dirname=os.path.dirname(final_log_loc)
        if (not os.path.isdir(dirname)):
            os.makedirs(dirname,0755) 
        shutil.copyfile(install_profile.log_location, final_log_loc)
    except (IOError, OSError), err: 
        logging.error("Failed to copy %s to %s", install_profile.log_location,
                      install_profile.log_final)
        logging.exception(err)
        raise ti_utils.InstallationError
        
    # 0 for the 2nd argument because force-umount need to be 0
    if beUnmount(install_profile.be_name, 0) != 0:
        logging.error("beUnmount failed for %s", install_profile.be_name)
        raise ti_utils.InstallationError

# pylint: disable-msg=C0103
def run_ICTs(install_profile, hostname, ict_mesg, locale,
             root_pass, ulogin, upass, ureal_name, rootpool_name):
    '''Run all necessary ICTs. This function ensures that each ICT is run,
    regardless of the success/failure of any others. After running all ICTs
    (including those supplied by install-finish), if any of them failed,
    an InstallationError is raised.
    
    '''
    
    failed_icts = 0
    
Exemple #7
0
def unmount(opts):
    """
            Description: Unmount a Boot Environment.
                         The following is the subcommand, options
                         and args that make up the opts object
                         passed in:

                         unmount [-f] beName

            Parameters:
                opts - A object containing the unmount subcommand
                       and all the options and arguments passed in
                       on the command line mentioned above.

            Returns:
                0 - Success
                1 - Failure
    """

    be = BootEnvironment()

    force_unmount = 0

    # Counter for detecting multiple options.
    # e.g. beadm unmount -f -f newbe
    num_f_opts = 0

    try:
        optlist, args = getopt.getopt(opts, "f")
    except getopt.GetoptError:
        msg.printMsg(msg.Msgs.BEADM_ERR_OPT_ARGS, None, -1)
        usage()

    for opt, arg in optlist:
        if opt == "-f":
            force_unmount = 1
            num_f_opts += 1

    if num_f_opts > 1:
        msg.printMsg(msg.Msgs.BEADM_ERR_OPT_ARGS, None, -1)
        usage()

    if len(args) != 1:
        msg.printMsg(msg.Msgs.BEADM_ERR_OPT_ARGS, None, -1)
        usage()

    if lb.beVerifyBEName(args[0]) != 0:
        msg.printMsg(msg.Msgs.BEADM_ERR_BENAME, None, -1)
        return 1

    rc = lb.beUnmount(args[0], force_unmount)
    if rc == 0:
        return 0

    be.msg_buf["0"] = args[0]
    if rc == msg.Msgs.BE_ERR_UMOUNT_CURR_BE:
        be.msg_buf["1"] = msg.getMsg(msg.Msgs.BEADM_ERR_UNMOUNT_ACTIVE, args[0])
    elif rc == msg.Msgs.BE_ERR_UMOUNT_SHARED:
        be.msg_buf["1"] = msg.getMsg(msg.Msgs.BEADM_ERR_SHARED_FS, args[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_UNMOUNT, 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_UNMOUNT, be.msg_buf, -1)
    return 1
Exemple #8
0
 def unmount_be(be_name, force=False):
     return be.beUnmount(be_name, force=force)
                 rootpool_name + fs)

    # Transfer the log file
    final_log_loc = INSTALLED_ROOT_DIR + install_profile.log_final
    logging.debug("Copying %s to %s", install_profile.log_location,
                  final_log_loc)
    try:
        shutil.copyfile(install_profile.log_location, final_log_loc)
    except (IOError, OSError), err: 
        logging.error("Failed to copy %s to %s", install_profile.log_location,
                      install_profile.log_final)
        logging.exception(err)
        raise ti_utils.InstallationError
        
    # 0 for the 2nd argument because force-umount need to be 0
    if beUnmount(INIT_BE_NAME, 0) != 0:
        logging.error("beUnmount failed for %s", INIT_BE_NAME)
        raise ti_utils.InstallationError

# pylint: disable-msg=C0103
def run_ICTs(install_profile, hostname, ict_mesg, inst_device, locale,
             root_pass, ulogin, upass, ureal_name, rootpool_name):
    '''Run all necessary ICTs. This function ensures that each ICT is run,
    regardless of the success/failure of any others. After running all ICTs
    (including those supplied by install-finish), if any of them failed,
    an InstallationError is raised.
    
    '''
    
    failed_icts = 0
    
Exemple #10
0
def unmount(opts):
    """
            Description: Unmount a Boot Environment.
                         The following is the subcommand, options
                         and args that make up the opts object
                         passed in:

                         unmount [-f] beName

            Parameters:
                opts - A object containing the unmount subcommand
                       and all the options and arguments passed in
                       on the command line mentioned above.

            Returns:
                0 - Success
                1 - Failure
    """

    be = BootEnvironment()

    force_unmount = 0

    # Counter for detecting multiple options.
    # e.g. beadm unmount -f -f newbe
    num_f_opts = 0

    try:
        optlist, args = getopt.getopt(opts, "f")
    except getopt.GetoptError:
        msg.printMsg(msg.Msgs.BEADM_ERR_OPT_ARGS, None, -1)
        usage()

    for opt, arg in optlist:
        if opt == "-f":
            force_unmount = 1
            num_f_opts += 1

    if num_f_opts > 1:
        msg.printMsg(msg.Msgs.BEADM_ERR_OPT_ARGS, None, -1)
        usage()

    if len(args) != 1:
        msg.printMsg(msg.Msgs.BEADM_ERR_OPT_ARGS, None, -1)
        usage()

    if lb.beVerifyBEName(args[0]) != 0:
        msg.printMsg(msg.Msgs.BEADM_ERR_BENAME, None, -1)
        return 1

    rc = lb.beUnmount(args[0], force_unmount)
    if rc == 0:
        return 0

    be.msg_buf["0"] = args[0]
    if rc == msg.Msgs.BE_ERR_UMOUNT_CURR_BE:
        be.msg_buf["1"] = \
            msg.getMsg(msg.Msgs.BEADM_ERR_UNMOUNT_ACTIVE,
            args[0])
    elif rc == msg.Msgs.BE_ERR_UMOUNT_SHARED:
        be.msg_buf["1"] = \
            msg.getMsg(msg.Msgs.BEADM_ERR_SHARED_FS, args[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_UNMOUNT, 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_UNMOUNT, be.msg_buf, -1)
    return 1