Example #1
0
def destroy(opts):
    """
    Function:    destroy

            Description: Destroy a Boot Environment. The following is the
                         subcommand, options and args that make up the
                         opts object passed in:

                         destroy [-fF] beName | beName@snapshot

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

            Returns:
                0 - Success
                1 - Failure
    """

    force_unmount = 0
    suppress_prompt = False
    be_active_on_boot = None
    be = BootEnvironment()

    try:
        opts_args, be.trgt_be_name_or_snapshot = getopt.getopt(opts, "fF")
    except getopt.GetoptError:
        msg.printMsg(msg.Msgs.BEADM_ERR_OPT_ARGS, None, -1)
        usage()

    # Counters for detecting multiple options.
    # e.g. beadm destroy -f -f newbe
    num_f_opts = 0
    num_sf_opts = 0

    for opt, arg in opts_args:
        if opt == "-f":
            force_unmount = 1
            num_sf_opts += 1
        elif opt == "-F":
            suppress_prompt = True
            num_f_opts += 1

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

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

    is_snapshot = False

    if "@" in be.trgt_be_name_or_snapshot[0]:
        is_snapshot = True
        be_name, snap_name = be.trgt_be_name_or_snapshot[0].split("@")
        if lb.beVerifyBEName(be_name) != 0:
            msg.printMsg(msg.Msgs.BEADM_ERR_BENAME, None, -1)
            return 1
    else:
        if lb.beVerifyBEName(be.trgt_be_name_or_snapshot[0]) != 0:
            msg.printMsg(msg.Msgs.BEADM_ERR_BENAME, None, -1)
            return 1

    # Get the 'active' BE and the 'active on boot' BE.
    be_active, be_active_on_boot = getActiveBEAndActiveOnBootBE()

    # If the user is trying to destroy the 'active' BE then quit now.
    if not is_snapshot and be_active == be.trgt_be_name_or_snapshot[0]:
        be.msg_buf["0"] = be.msg_buf["1"] = be_active
        msg.printMsg(msg.Msgs.BEADM_ERR_DESTROY_ACTIVE, be.msg_buf, -1)
        return 1

    if not suppress_prompt:

        # Display a destruction question and wait for user response.
        # Quit if negative user response.

        if not displayDestructionQuestion(be):
            return 0

    if is_snapshot:

        # Destroy a snapshot.
        rc = lb.beDestroySnapshot(be_name, snap_name)
    else:

        # Destroy a BE.  Passing in 1 for the second arg destroys
        # any snapshots the BE may have as well.

        rc = lb.beDestroy(be.trgt_be_name_or_snapshot[0], 1, force_unmount)

        # Check if the BE that was just destroyed was the
        # 'active on boot' BE. If it was, display a message letting
        # the user know that the 'active' BE is now also the
        # 'active on boot' BE.
        if be_active_on_boot == be.trgt_be_name_or_snapshot[0] and rc == 0:
            msg.printMsg(msg.Msgs.BEADM_MSG_ACTIVE_ON_BOOT, be_active, -1)

    if rc == 0:
        try:
            shutil.rmtree("/var/log/beadm/" + be.trgt_be_name_or_snapshot[0], True)
        except:
            msg.printMsg(msg.Msgs.BEADM_ERR_LOG_RM, "/var/log/beadm/" + be.trgt_be_name_or_snapshot[0], -1)

        return 0

    be.msg_buf["0"] = be.trgt_be_name_or_snapshot[0]
    if rc == msg.Msgs.BE_ERR_MOUNTED:
        be.msg_buf["1"] = be.msg_buf["2"] = be.trgt_be_name_or_snapshot[0]
        msg.printMsg(msg.Msgs.BEADM_ERR_MOUNTED, be.msg_buf, -1)
        return 1
    elif rc == msg.Msgs.BE_ERR_DESTROY_CURR_BE:
        msg.printMsg(msg.Msgs.BEADM_ERR_DESTROY_ACTIVE, be.msg_buf["0"], -1)
        return 1
    elif rc == msg.Msgs.BE_ERR_ZONES_UNMOUNT:
        be.msg_buf["1"] = be.trgt_be_name_or_snapshot[0]
        msg.printMsg(msg.Msgs.BE_ERR_ZONES_UNMOUNT, be.msg_buf, -1)
        return 1
    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_DESTROY, 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_DESTROY, be.msg_buf, -1)
    return 1
Example #2
0
def destroy(opts):
    """
    Function:    destroy

            Description: Destroy a Boot Environment. The following is the
                         subcommand, options and args that make up the
                         opts object passed in:

                         destroy [-fF] beName | beName@snapshot

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

            Returns:
                0 - Success
                1 - Failure
    """

    force_unmount = 0
    suppress_prompt = False
    be_active_on_boot = None
    be = BootEnvironment()

    try:
        opts_args, be.trgt_be_name_or_snapshot = getopt.getopt(opts, "fF")
    except getopt.GetoptError:
        msg.printMsg(msg.Msgs.BEADM_ERR_OPT_ARGS, None, -1)
        usage()

    # Counters for detecting multiple options.
    # e.g. beadm destroy -f -f newbe
    num_f_opts = 0
    num_sf_opts = 0

    for opt, arg in opts_args:
        if opt == "-f":
            force_unmount = 1
            num_sf_opts += 1
        elif opt == "-F":
            suppress_prompt = True
            num_f_opts += 1

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

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

    is_snapshot = False

    if "@" in be.trgt_be_name_or_snapshot[0]:
        is_snapshot = True
        be_name, snap_name = be.trgt_be_name_or_snapshot[0].split("@")
        if lb.beVerifyBEName(be_name) != 0:
            msg.printMsg(msg.Msgs.BEADM_ERR_BENAME, None, -1)
            return 1
    else:
        if lb.beVerifyBEName(be.trgt_be_name_or_snapshot[0]) != 0:
            msg.printMsg(msg.Msgs.BEADM_ERR_BENAME, None, -1)
            return 1

    # Get the 'active' BE and the 'active on boot' BE.
    be_active, be_active_on_boot = getActiveBEAndActiveOnBootBE()

    # If the user is trying to destroy the 'active' BE then quit now.
    if not is_snapshot and be_active == be.trgt_be_name_or_snapshot[0]:
        be.msg_buf["0"] = be.msg_buf["1"] = be_active
        msg.printMsg(msg.Msgs.BEADM_ERR_DESTROY_ACTIVE, be.msg_buf, -1)
        return 1

    if not suppress_prompt:

        # Display a destruction question and wait for user response.
        # Quit if negative user response.

        if not displayDestructionQuestion(be):
            return 0

    if is_snapshot:

        # Destroy a snapshot.
        rc = lb.beDestroySnapshot(be_name, snap_name)
    else:

        # Destroy a BE.  Passing in 1 for the second arg destroys
        # any snapshots the BE may have as well.

        rc = lb.beDestroy(be.trgt_be_name_or_snapshot[0], 1, force_unmount)

        # Check if the BE that was just destroyed was the
        # 'active on boot' BE. If it was, display a message letting
        # the user know that the 'active' BE is now also the
        # 'active on boot' BE.
        if be_active_on_boot == be.trgt_be_name_or_snapshot[0] and rc == 0:
            msg.printMsg(msg.Msgs.BEADM_MSG_ACTIVE_ON_BOOT,
            be_active, -1)

    if rc == 0:
        try:
            shutil.rmtree("/var/log/beadm/" + \
                          be.trgt_be_name_or_snapshot[0], True)
        except:
            msg.printMsg(msg.Msgs.BEADM_ERR_LOG_RM,
                         "/var/log/beadm/" + be.trgt_be_name_or_snapshot[0], -1)

        return 0

    be.msg_buf["0"] = be.trgt_be_name_or_snapshot[0]
    if rc == msg.Msgs.BE_ERR_MOUNTED:
        be.msg_buf["1"] = be.msg_buf["2"] = be.trgt_be_name_or_snapshot[0]
        msg.printMsg(msg.Msgs.BEADM_ERR_MOUNTED, be.msg_buf, -1)
        return 1
    elif rc == msg.Msgs.BE_ERR_DESTROY_CURR_BE:
        msg.printMsg(msg.Msgs.BEADM_ERR_DESTROY_ACTIVE, \
        be.msg_buf["0"], -1)
        return 1
    elif rc == msg.Msgs.BE_ERR_ZONES_UNMOUNT:
        be.msg_buf["1"] = be.trgt_be_name_or_snapshot[0]
        msg.printMsg(msg.Msgs.BE_ERR_ZONES_UNMOUNT, be.msg_buf, -1)
        return 1
    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_DESTROY, 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_DESTROY, be.msg_buf, -1)
    return 1
Example #3
0
 def destroy_be(be_name):
     return be.beDestroy(be_name, 1, True)
 def destroy_be(be_name):
         return be.beDestroy(be_name, 1, True)