Beispiel #1
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
Beispiel #2
0
def createBE(be):
    """Create a Boot Environment."""

    rc = lb.beCopy(be.trgt_be_name_or_snapshot[0], be.src_be_name_or_snapshot,
            None, be.trgt_rpool, be.properties, be.description)[0]
    
    if rc == 0:
        msg.printMsg(msg.Msgs.BEADM_MSG_BE_CREATE_SUCCESS,
            be.trgt_be_name_or_snapshot[0], be.log_id)
        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.src_be_name_or_snapshot)
    elif rc == msg.Msgs.BE_ERR_BE_EXISTS:
        be.msg_buf["1"] = msg.getMsg(msg.Msgs.BEADM_ERR_BE_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, be.log_id)

    return 1
Beispiel #3
0
def getActiveBEAndActiveOnBootBE():
    """Return the 'active on boot' BE, the 'active' BE or None."""

    active_be = None
    active_be_on_boot = None

    rc, be_list = lb.beList()

    if rc != 0:
        if rc == msg.Msgs.BE_ERR_BE_NOENT:
            string = msg.getMsg(msg.Msgs.BEADM_ERR_NO_BES_EXIST)
        else:
            string = lb.beGetErrDesc(rc)
            if string == None:
                string = msg.getMsg(msg.Msgs.BEADM_ERR_NO_MSG, rc)

        msg.printMsg(msg.Msgs.BEADM_ERR_LIST, string, -1)
        return None

    for be_vals in be_list:
        srcBeName = be_vals.get("orig_be_name")
        if be_vals.get("active"):
            active_be = srcBeName
        if be_vals.get("active_boot"):
            active_be_on_boot = srcBeName
        if active_be is not None and active_be_on_boot is not None:
            break

    return active_be, active_be_on_boot
Beispiel #4
0
def getActiveBEAndActiveOnBootBE():
    """Return the 'active on boot' BE, the 'active' BE or None."""

    active_be = None
    active_be_on_boot = None

    rc, be_list = lb.beList()

    if rc != 0:
        if rc == msg.Msgs.BE_ERR_BE_NOENT:
            string = \
                msg.getMsg(msg.Msgs.BEADM_ERR_NO_BES_EXIST)
        else:
            string = lb.beGetErrDesc(rc)
            if string == None:
                string = \
                    msg.getMsg(msg.Msgs.BEADM_ERR_NO_MSG, rc)

        msg.printMsg(msg.Msgs.BEADM_ERR_LIST, string, -1)
        return None

    for be_vals in be_list:
        srcBeName = be_vals.get("orig_be_name")
        if be_vals.get("active"):
            active_be = srcBeName
        if be_vals.get("active_boot"):
            active_be_on_boot = srcBeName
        if active_be is not None and active_be_on_boot is not None:
            break

    return active_be, active_be_on_boot
Beispiel #5
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
Beispiel #6
0
def createBEFromSnapshot(be):
    """Create a BE based off a snapshot."""

    be_name, snap_name = be.src_be_name_or_snapshot.split("@")

    rc = lb.beCopy(be.trgt_be_name_or_snapshot[0], be_name, snap_name, be.trgt_rpool, be.properties, be.description)[0]

    if rc == 0:
        msg.printMsg(msg.Msgs.BEADM_MSG_BE_CREATE_SUCCESS, be.trgt_be_name_or_snapshot[0], be.log_id)
        return 0

    be.msg_buf["0"] = be.trgt_be_name_or_snapshot[0]
    if rc == msg.Msgs.BE_ERR_SS_NOENT:
        be.msg_buf["1"] = msg.getMsg(msg.Msgs.BEADM_ERR_SNAP_DOES_NOT_EXISTS, be.src_be_name_or_snapshot)
    elif rc == msg.Msgs.BE_ERR_BE_EXISTS:
        be.msg_buf["1"] = msg.getMsg(msg.Msgs.BEADM_ERR_BE_EXISTS, be.trgt_be_name_or_snapshot[0])
    elif 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_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, be.log_id)

    return 1
Beispiel #7
0
def rename(opts):
    """
            Description: Rename the name of a Boot Environment.
                         The following is the subcommand, options
                         and args that make up the opts object
                         passed in:

                         rename beName newBeName

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

            Returns:
                0 - Success
                1 - Failure
    """

    be = BootEnvironment()

    try:
        be_names = getopt.getopt(opts, "")[1]
    except getopt.GetoptError:
        msg.printMsg(msg.Msgs.BEADM_ERR_OPT_ARGS, None, -1)
        usage()

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

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

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

    rc = lb.beRename(be_names[0], be_names[1])

    if rc == 0:
        return 0

    be.msg_buf["0"] = be_names[0]
    if rc == msg.Msgs.BE_ERR_BE_NOENT:
        be.msg_buf["1"] = msg.getMsg(msg.Msgs.BEADM_ERR_BE_DOES_NOT_EXIST, be_names[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_RENAME, 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_RENAME, be.msg_buf, -1)
    return 1
Beispiel #8
0
def activate(opts):
    """ 
    Function:    activate

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

            Parameters:
                opts - A string containing the active subcommand

            Returns:
                0 - Success
                1 - Failure
    """

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

    be = BootEnvironment()

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

    rc = lb.beActivate(opts[0])
    if rc == 0:
        return 0

    be.msg_buf["0"] = opts[0]
    if rc == msg.Msgs.BE_ERR_BE_NOENT:
        be.msg_buf["1"] = \
            msg.getMsg(msg.Msgs.BEADM_ERR_BE_DOES_NOT_EXIST, opts[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_ACTIVATE, 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_ACTIVATE, be.msg_buf, -1)
    return 1
Beispiel #9
0
def activate(opts):
    """ 
    Function:    activate

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

            Parameters:
                opts - A string containing the active subcommand

            Returns:
                0 - Success
                1 - Failure
    """

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

    be = BootEnvironment()

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

    rc = lb.beActivate(opts[0])
    if rc == 0:
        return 0

    be.msg_buf["0"] = opts[0]
    if rc == msg.Msgs.BE_ERR_BE_NOENT:
        be.msg_buf["1"] = msg.getMsg(msg.Msgs.BEADM_ERR_BE_DOES_NOT_EXIST, opts[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_ACTIVATE, 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_ACTIVATE, be.msg_buf, -1)
    return 1
Beispiel #10
0
def activateBE(be):
    """
    Activate a BE. Called from create() when -a is provided as CLI
    Option.
    """

    rc = lb.beActivate(be.trgt_be_name_or_snapshot[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, opts[0])
    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_ACTIVATE, be.msg_buf, -1)

    return 1
Beispiel #11
0
def createBEFromSnapshot(be):
    """Create a BE based off a snapshot."""

    be_name, snap_name = be.src_be_name_or_snapshot.split("@")

    rc = lb.beCopy(be.trgt_be_name_or_snapshot[0], be_name, snap_name, 
        be.trgt_rpool, be.properties, be.description)[0]

    if rc == 0:
        msg.printMsg(msg.Msgs.BEADM_MSG_BE_CREATE_SUCCESS,
            be.trgt_be_name_or_snapshot[0], be.log_id)
        return 0

    be.msg_buf["0"] = be.trgt_be_name_or_snapshot[0]
    if rc == msg.Msgs.BE_ERR_SS_NOENT:
        be.msg_buf["1"] = \
            msg.getMsg(msg.Msgs.BEADM_ERR_SNAP_DOES_NOT_EXISTS,
            be.src_be_name_or_snapshot)
    elif rc == msg.Msgs.BE_ERR_BE_EXISTS:
        be.msg_buf["1"] = msg.getMsg(msg.Msgs.BEADM_ERR_BE_EXISTS, \
            be.trgt_be_name_or_snapshot[0])
    elif 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_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, be.log_id)

    return 1
Beispiel #12
0
def activateBE(be):
    """
    Activate a BE. Called from create() when -a is provided as CLI
    Option.
    """

    rc = lb.beActivate(be.trgt_be_name_or_snapshot[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, opts[0])
    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_ACTIVATE, be.msg_buf, -1)

    return 1
Beispiel #13
0
def mount(opts):
    """
            Description: Mount a Boot Environment on a directory.
                         The following is the subcommand, options
                         and args that make up the opts object
                         passed in:

                         mount beName [mountpoint]

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

            Returns:
                0 - Success
                1 - Failure
    """

    be = BootEnvironment()

    mountpoint = None

    try:
        be_name_mnt_point = getopt.getopt(opts, "")[1]
    except getopt.GetoptError:
        msg.printMsg(msg.Msgs.BEADM_ERR_OPT_ARGS, None, -1)
        usage()

    mnt_point_len = len(be_name_mnt_point)

    if mnt_point_len != 2:
        msg.printMsg(msg.Msgs.BEADM_ERR_OPT_ARGS, None, -1)
        usage()
    else:
        # Check for leading / in mount point
        mountpoint = be_name_mnt_point[1]
        if not mountpoint.startswith('/'):
            msg.printMsg(msg.Msgs.BEADM_ERR_MOUNTPOINT,
                mountpoint, -1)
            return 1

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

    rc = lb.beMount(be_name_mnt_point[0], mountpoint)
    if rc == 0:
        return 0

    be.msg_buf["0"] = be_name_mnt_point[0]
    if rc == msg.Msgs.BE_ERR_MOUNTED:
        be.msg_buf["1"] = \
            msg.getMsg(msg.Msgs.BEADM_ERR_MOUNT_EXISTS,
            be_name_mnt_point[0])
    elif rc == msg.Msgs.BE_ERR_BE_NOENT:
        be.msg_buf["1"] = \
            msg.getMsg(msg.Msgs.BEADM_ERR_BE_DOES_NOT_EXIST,
            be_name_mnt_point[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_MOUNT, 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_MOUNT, be.msg_buf, -1)
    return 1
Beispiel #14
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
Beispiel #15
0
def rename(opts):
    """
            Description: Rename the name of a Boot Environment.
                         The following is the subcommand, options
                         and args that make up the opts object
                         passed in:

                         rename beName newBeName

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

            Returns:
                0 - Success
                1 - Failure
    """

    be = BootEnvironment()

    try:
        be_names = getopt.getopt(opts, "")[1]
    except getopt.GetoptError:
        msg.printMsg(msg.Msgs.BEADM_ERR_OPT_ARGS, None, -1)
        usage()

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

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

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

    rc = lb.beRename(be_names[0], be_names[1])

    if rc == 0:
        return 0

    be.msg_buf["0"] = be_names[0]
    if rc == msg.Msgs.BE_ERR_BE_NOENT:
        be.msg_buf["1"] = \
            msg.getMsg(msg.Msgs.BEADM_ERR_BE_DOES_NOT_EXIST,
            be_names[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_RENAME, 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_RENAME, be.msg_buf, -1)
    return 1
Beispiel #16
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
Beispiel #17
0
def list(opts):
    """ 
            Description: List the attributes of a Boot Environment.
                         The following is the subcommand, options
                         and args that make up the opts object
                         passed in:

                         list [[-a] | [-d] [-s]] [-H] [beName]

                         -a displays all info
                         -d displays BE info plus dataset info
                         -s displays BE info plus snapshot info
                         -H displays info parsable by a computer

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

            Returns:
                0 - Success
                1 - Failure
    """

    be = BootEnvironment()

    list_all_attrs = ""
    list_datasets = ""
    list_snapshots = ""
    dont_display_headers = False
    be_name = None
    be_list = None

    # Counters for detecting multiple options.
    # e.g. beadm list -a -a newbe
    num_a_opts = 0
    num_d_opts = 0
    num_s_opts = 0
    num_h_opts = 0

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

    for opt, arg in opts_args:
        if opt == "-a":
            list_all_attrs = opt
            num_a_opts += 1
        elif opt == "-d":
            list_datasets = opt
            num_d_opts += 1
        elif opt == "-s":
            list_snapshots = opt
            num_s_opts += 1
        elif opt == "-H":
            dont_display_headers = True
            num_h_opts += 1

    if num_a_opts > 1 or num_d_opts > 1 or num_s_opts > 1 or num_h_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()

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

    if (list_all_attrs == "-a" and (list_datasets == "-d" \
        or list_snapshots == "-s")):
        msg.printMsg(msg.Msgs.BEADM_ERR_MUTUALLY_EXCL,
            list_all_attrs + " " + list_datasets + " " +
            list_snapshots, -1)
        usage()

    list_options = ""

    # When zones are implemented add "listZones == "-z" below

    # Coelesce options to pass to displayBEs

    if (list_datasets == "-d" and list_snapshots == "-s" or \
        list_all_attrs == "-a"):
        list_options = "-a"
    elif list_datasets != "" or list_snapshots != "" or list_all_attrs != "":
        list_options = list_datasets + " " + list_snapshots

    rc, be_list = lb.beList()
    if rc != 0:
        if rc == msg.Msgs.BE_ERR_BE_NOENT:
            if be_name == None:
                msg.printMsg(msg.Msgs.BEADM_ERR_NO_BES_EXIST,
                None, -1)
                return 1

            string = \
                msg.getMsg(msg.Msgs.BEADM_ERR_BE_DOES_NOT_EXIST,
                be_name)
        else:
            string = lb.beGetErrDesc(rc)
            if string == None:
                string = \
                    msg.getMsg(msg.Msgs.BEADM_ERR_NO_MSG, rc)

        msg.printMsg(msg.Msgs.BEADM_ERR_LIST, string, -1)
        return 1

    # classify according to command line options
    if list_options.find("-a") != -1 or \
        (list_options.find("-d") != -1 and list_options.find("-s") != -1):
        list_object = CompleteList(dont_display_headers) #all
    elif list_options.find("-d") != -1:
        list_object = DatasetList(dont_display_headers) #dataset
    elif list_options.find("-s") != -1:
        list_object = SnapshotList(dont_display_headers) #snapshot
    else: list_object = BEList(dont_display_headers) #only BE

    # use list method for object
    if list_object.list(be_list, dont_display_headers, be_name) != 0:
        msg.printMsg(msg.Msgs.BEADM_ERR_LIST_DATA, None, -1)
        return 1

    return 0
Beispiel #18
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
Beispiel #19
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
Beispiel #20
0
def mount(opts):
    """
            Description: Mount a Boot Environment on a directory.
                         The following is the subcommand, options
                         and args that make up the opts object
                         passed in:

                         mount beName [mountpoint]

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

            Returns:
                0 - Success
                1 - Failure
    """

    be = BootEnvironment()

    mountpoint = None

    try:
        be_name_mnt_point = getopt.getopt(opts, "")[1]
    except getopt.GetoptError:
        msg.printMsg(msg.Msgs.BEADM_ERR_OPT_ARGS, None, -1)
        usage()

    mnt_point_len = len(be_name_mnt_point)

    if mnt_point_len != 2:
        msg.printMsg(msg.Msgs.BEADM_ERR_OPT_ARGS, None, -1)
        usage()
    else:
        # Check for leading / in mount point
        mountpoint = be_name_mnt_point[1]
        if not mountpoint.startswith("/"):
            msg.printMsg(msg.Msgs.BEADM_ERR_MOUNTPOINT, mountpoint, -1)
            return 1

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

    rc = lb.beMount(be_name_mnt_point[0], mountpoint)
    if rc == 0:
        return 0

    be.msg_buf["0"] = be_name_mnt_point[0]
    if rc == msg.Msgs.BE_ERR_MOUNTED:
        be.msg_buf["1"] = msg.getMsg(msg.Msgs.BEADM_ERR_MOUNT_EXISTS, be_name_mnt_point[0])
    elif rc == msg.Msgs.BE_ERR_BE_NOENT:
        be.msg_buf["1"] = msg.getMsg(msg.Msgs.BEADM_ERR_BE_DOES_NOT_EXIST, be_name_mnt_point[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_MOUNT, 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_MOUNT, be.msg_buf, -1)
    return 1
Beispiel #21
0
def list(opts):
    """ 
            Description: List the attributes of a Boot Environment.
                         The following is the subcommand, options
                         and args that make up the opts object
                         passed in:

                         list [[-a] | [-d] [-s]] [-H] [beName]

                         -a displays all info
                         -d displays BE info plus dataset info
                         -s displays BE info plus snapshot info
                         -H displays info parsable by a computer

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

            Returns:
                0 - Success
                1 - Failure
    """

    be = BootEnvironment()

    list_all_attrs = ""
    list_datasets = ""
    list_snapshots = ""
    dont_display_headers = False
    be_name = None
    be_list = None

    # Counters for detecting multiple options.
    # e.g. beadm list -a -a newbe
    num_a_opts = 0
    num_d_opts = 0
    num_s_opts = 0
    num_h_opts = 0

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

    for opt, arg in opts_args:
        if opt == "-a":
            list_all_attrs = opt
            num_a_opts += 1
        elif opt == "-d":
            list_datasets = opt
            num_d_opts += 1
        elif opt == "-s":
            list_snapshots = opt
            num_s_opts += 1
        elif opt == "-H":
            dont_display_headers = True
            num_h_opts += 1

    if num_a_opts > 1 or num_d_opts > 1 or num_s_opts > 1 or num_h_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()

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

    if list_all_attrs == "-a" and (list_datasets == "-d" or list_snapshots == "-s"):
        msg.printMsg(msg.Msgs.BEADM_ERR_MUTUALLY_EXCL, list_all_attrs + " " + list_datasets + " " + list_snapshots, -1)
        usage()

    list_options = ""

    # When zones are implemented add "listZones == "-z" below

    # Coelesce options to pass to displayBEs

    if list_datasets == "-d" and list_snapshots == "-s" or list_all_attrs == "-a":
        list_options = "-a"
    elif list_datasets != "" or list_snapshots != "" or list_all_attrs != "":
        list_options = list_datasets + " " + list_snapshots

    rc, be_list = lb.beList()
    if rc != 0:
        if rc == msg.Msgs.BE_ERR_BE_NOENT:
            if be_name == None:
                msg.printMsg(msg.Msgs.BEADM_ERR_NO_BES_EXIST, None, -1)
                return 1

            string = msg.getMsg(msg.Msgs.BEADM_ERR_BE_DOES_NOT_EXIST, be_name)
        else:
            string = lb.beGetErrDesc(rc)
            if string == None:
                string = msg.getMsg(msg.Msgs.BEADM_ERR_NO_MSG, rc)

        msg.printMsg(msg.Msgs.BEADM_ERR_LIST, string, -1)
        return 1

    # classify according to command line options
    if list_options.find("-a") != -1 or (list_options.find("-d") != -1 and list_options.find("-s") != -1):
        list_object = CompleteList(dont_display_headers)  # all
    elif list_options.find("-d") != -1:
        list_object = DatasetList(dont_display_headers)  # dataset
    elif list_options.find("-s") != -1:
        list_object = SnapshotList(dont_display_headers)  # snapshot
    else:
        list_object = BEList(dont_display_headers)  # only BE

    # use list method for object
    if list_object.list(be_list, dont_display_headers, be_name) != 0:
        msg.printMsg(msg.Msgs.BEADM_ERR_LIST_DATA, None, -1)
        return 1

    return 0