VirtualBox

Changeset 37449 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Jun 14, 2011 4:34:16 PM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
72256
Message:

Main;VBoxManage: more clone vm work

Location:
trunk/src/VBox/Frontends/VBoxManage
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp

    r37272 r37449  
    334334        RTStrmPrintf(pStrm,
    335335                     "VBoxManage clonevm          <uuid>|<name>\n"
     336                     "                            [--snapshot <uuid>|<name>]\n"
    336337                     "                            [--name <name>]\n"
    337338                     "                            [--basefolder <basefolder>]\n"
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageMisc.cpp

    r37118 r37449  
    270270static const RTGETOPTDEF g_aCloneVMOptions[] =
    271271{
     272    { "--snapshot",       's', RTGETOPT_REQ_STRING },
    272273    { "--name",           'n', RTGETOPT_REQ_STRING },
     274    { "--mode",           'm', RTGETOPT_REQ_STRING },
    273275    { "--register",       'r', RTGETOPT_REQ_NOTHING },
    274276    { "--basefolder",     'p', RTGETOPT_REQ_STRING },
     
    276278};
    277279
     280static int parseCloneMode(const char *psz, CloneMode_T *pMode)
     281{
     282    if (!RTStrICmp(psz, "machine"))
     283        *pMode = CloneMode_MachineState;
     284    else if (!RTStrICmp(psz, "machineandchilds"))
     285        *pMode = CloneMode_MachineAndChildStates;
     286    else if (!RTStrICmp(psz, "all"))
     287        *pMode = CloneMode_AllStates;
     288    else
     289        return VERR_PARSE_ERROR;
     290
     291    return VINF_SUCCESS;
     292}
     293
    278294int handleCloneVM(HandlerArg *a)
    279295{
    280     HRESULT rc;
     296    HRESULT     rc;
    281297    const char *pszSrcName       = NULL;
     298    const char *pszSnapshotName  = NULL;
     299    CloneMode_T mode             = CloneMode_MachineState;
    282300    const char *pszTrgName       = NULL;
    283301    const char *pszTrgBaseFolder = NULL;
    284     bool fRegister               = false;
    285     RTUUID trgUuid;
     302    bool        fRegister        = false;
     303    RTUUID      trgUuid;
    286304
    287305    int c;
     
    295313        switch (c)
    296314        {
     315            case 's':   // --snapshot
     316                pszSnapshotName = ValueUnion.psz;
     317                break;
     318
     319            case 'm':   // --mode
     320                if (RT_FAILURE(parseCloneMode(ValueUnion.psz, &mode)))
     321                    return errorArgument("Invalid clone mode '%s'\n", ValueUnion.psz);
     322                break;
     323
    297324            case 'n':   // --name
    298325                pszTrgName = ValueUnion.psz;
     
    324351    }
    325352
    326     /* ~heck for required options */
     353    /* Check for required options */
    327354    if (!pszSrcName)
    328355        return errorSyntax(USAGE_CLONEVM, "VM name required");
    329356
     357    /* Get the machine object */
    330358    ComPtr<IMachine> srcMachine;
    331359    CHECK_ERROR_RET(a->virtualBox, FindMachine(Bstr(pszSrcName).raw(),
     
    333361                    RTEXITCODE_FAILURE);
    334362
     363    /* If a snapshot name/uuid was given, get the particular machine of this
     364     * snapshot. */
     365    if (pszSnapshotName)
     366    {
     367        ComPtr<ISnapshot> srcSnapshot;
     368        CHECK_ERROR_RET(srcMachine, FindSnapshot(Bstr(pszSnapshotName).raw(),
     369                                                 srcSnapshot.asOutParam()),
     370                        RTEXITCODE_FAILURE);
     371        CHECK_ERROR_RET(srcSnapshot, COMGETTER(Machine)(srcMachine.asOutParam()),
     372                        RTEXITCODE_FAILURE);
     373    }
     374
    335375    /* Default name necessary? */
    336376    if (!pszTrgName)
    337         pszTrgName = RTStrAPrintf2("%s Copy", pszSrcName);
     377        pszTrgName = RTStrAPrintf2("%s Clone", pszSrcName);
    338378
    339379    Bstr bstrSettingsFile;
     
    354394    ComPtr<IProgress> progress;
    355395    CHECK_ERROR_RET(srcMachine, CloneTo(trgMachine,
     396                                        mode,
    356397                                        FALSE,
    357398                                        progress.asOutParam()),
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette