コード例 #1
0
ファイル: beadm.py プロジェクト: nxmirrors/onnv
def create(opts):
    """ 
    Function:    create

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

                         create [-a] [-d description]
                            [-e non-activeBeName | beName@Snapshot]
                            [-o property=value] ... [-p zpool] beName

                         create beName@Snapshot

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

            Returns:
                0 - Success
                1 - Failure
    """

    be = BootEnvironment()

    activate = False

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

    # Counters for detecting multiple options.
    # e.g. beadm create -p rpool -p rpool2 newbe
    num_a_opts = 0
    num_e_opts = 0
    num_p_opts = 0
    num_d_opts = 0

    for opt, arg in opts_args:
        if opt == "-a":
            activate = True
            num_a_opts += 1
        elif opt == "-e":
            be.src_be_name_or_snapshot = arg
            num_e_opts += 1
        elif opt == "-o":
            key, value = arg.split("=")
            be.properties[key] = value
        elif opt == "-p":
            be.trgt_rpool = arg
            num_p_opts += 1
        elif opt == "-d":
            be.description = arg
            num_d_opts += 1

    if num_a_opts > 1 or num_e_opts > 1 or num_p_opts > 1 or num_d_opts > 1:
        msg.printMsg(msg.Msgs.BEADM_ERR_OPT_ARGS, None, -1)
        usage()

    # Check that all info provided from the user is legitimate.
    if verifyCreateOptionsArgs(be) != 0:
        usage()

    if initBELog("create", be) != 0:
        return 1

    msg.printMsg(msg.Msgs.BEADM_MSG_BE_CREATE_START, be.trgt_be_name_or_snapshot[0], be.log_id)

    if "@" in be.trgt_be_name_or_snapshot[0]:
        # Create a snapshot
        rc = createSnapshot(be)
    else:
        if lb.beVerifyBEName(be.trgt_be_name_or_snapshot[0]) != 0:
            msg.printMsg(msg.Msgs.BEADM_ERR_BENAME, None, -1)
            return 1

        # Create a BE based on a snapshot
        if be.src_be_name_or_snapshot is not None and "@" in be.src_be_name_or_snapshot:
            # Create a BE from a snapshot
            rc = createBEFromSnapshot(be)
        else:
            rc = createBE(be)

        # Activate the BE if the user chose to.
        if activate and rc == 0:
            rc = activateBE(be)
    cleanupBELog(be)

    return rc
コード例 #2
0
ファイル: beadm.py プロジェクト: jubalskaggs/onnv-gate
def create(opts):
    """ 
    Function:    create

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

                         create [-a] [-d description]
                            [-e non-activeBeName | beName@Snapshot]
                            [-o property=value] ... [-p zpool] beName

                         create beName@Snapshot

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

            Returns:
                0 - Success
                1 - Failure
    """

    be = BootEnvironment()

    activate = False

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

    # Counters for detecting multiple options.
    # e.g. beadm create -p rpool -p rpool2 newbe
    num_a_opts = 0
    num_e_opts = 0
    num_p_opts = 0
    num_d_opts = 0

    for opt, arg in opts_args:
        if opt == "-a":
            activate = True
            num_a_opts += 1
        elif opt == "-e":
            be.src_be_name_or_snapshot = arg
            num_e_opts += 1
        elif opt == "-o":
            key, value = arg.split("=")
            be.properties[key] = value
        elif opt == "-p":
            be.trgt_rpool = arg
            num_p_opts += 1
        elif opt == "-d":
            be.description = arg
            num_d_opts += 1

    if num_a_opts > 1 or num_e_opts > 1 or num_p_opts > 1 or num_d_opts > 1:
        msg.printMsg(msg.Msgs.BEADM_ERR_OPT_ARGS, None, -1)
        usage()

    # Check that all info provided from the user is legitimate.
    if (verifyCreateOptionsArgs(be) != 0):
        usage()

    if initBELog("create", be) != 0:
        return 1

    msg.printMsg(msg.Msgs.BEADM_MSG_BE_CREATE_START,
        be.trgt_be_name_or_snapshot[0], be.log_id)

    if '@' in be.trgt_be_name_or_snapshot[0]:
        # Create a snapshot
        rc = createSnapshot(be)
    else:
        if lb.beVerifyBEName(be.trgt_be_name_or_snapshot[0]) != 0:
            msg.printMsg(msg.Msgs.BEADM_ERR_BENAME, None, -1)
            return 1

        # Create a BE based on a snapshot
        if be.src_be_name_or_snapshot is not None and \
            '@' in be.src_be_name_or_snapshot:
            # Create a BE from a snapshot
            rc = createBEFromSnapshot(be)
        else:
            rc = createBE(be)

        # Activate the BE if the user chose to.
        if activate and rc == 0:
            rc = activateBE(be)
    cleanupBELog(be)

    return rc