Changeset 68135 in vbox
- Timestamp:
- Jul 27, 2017 10:36:37 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxManageMisc.cpp
r68134 r68135 1470 1470 } 1471 1471 1472 1473 1472 /* 1474 * Prepare.1473 * Get details about the machine so we can display them below. 1475 1474 */ 1476 1475 Bstr bstrMachineName; … … 1482 1481 Utf8Str strInstalledOS(bstrInstalledOS); 1483 1482 1484 /* open a session for the VM */ 1483 /* 1484 * Temporarily lock the machine to check whether it's running or not. 1485 * Note! Not sure if this is the cheapest way of doing this... 1486 */ 1485 1487 CHECK_ERROR2_RET(hrc, ptrMachine, LockMachine(a->session, LockType_Shared), RTEXITCODE_FAILURE); 1486 1487 /* get the associated console */ 1488 HRESULT rc; 1489 ComPtr<IConsole> console; 1490 CHECK_ERROR(a->session, COMGETTER(Console)(console.asOutParam())); 1491 if (console) 1492 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Machine '%ls' is currently running", bstrMachineName.raw()); 1493 1494 /* ... and session machine */ 1495 ComPtr<IMachine> sessionMachine; 1496 CHECK_ERROR_RET(a->session, COMGETTER(Machine)(sessionMachine.asOutParam()), RTEXITCODE_FAILURE); 1497 1498 do 1499 { 1500 RTPrintf("Start unattended installation OS %s on virtual machine '%ls'.\n" 1501 "UUID: %s\n", 1502 strInstalledOS.c_str(), 1503 bstrMachineName.raw(), 1504 Utf8Str(bstrUuid).c_str()); 1505 1506 /* 1507 * Do the work. 1508 */ 1509 CHECK_ERROR_BREAK(ptrUnattended,Prepare()); 1510 CHECK_ERROR_BREAK(ptrUnattended,ConstructMedia()); 1511 CHECK_ERROR_BREAK(ptrUnattended,ReconfigureVM()); 1512 1513 /* 1514 * Retrieve and display the parameters actually used. 1515 */ 1516 RTPrintf("Using values:\n"); 1488 { 1489 ComPtr<IConsole> ptrConsole; 1490 CHECK_ERROR2(hrc, a->session, COMGETTER(Console)(ptrConsole.asOutParam())); 1491 a->session->UnlockMachine(); 1492 if (FAILED(hrc)) 1493 return RTEXITCODE_FAILURE; 1494 if (ptrConsole.isNotNull()) 1495 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Machine '%ls' is currently running", bstrMachineName.raw()); 1496 } 1497 1498 /* 1499 * Do the work. 1500 */ 1501 RTMsgInfo("%s unattended installation of %s in machine '%ls' (%ls).\n", 1502 RTStrICmp(pszSessionType, "none") == 0 ? "Preparing" : "Starting", 1503 strInstalledOS.c_str(), bstrMachineName.raw(), bstrUuid.raw()); 1504 1505 CHECK_ERROR2_RET(hrc, ptrUnattended,Prepare(), RTEXITCODE_FAILURE); 1506 CHECK_ERROR2_RET(hrc, ptrUnattended,ConstructMedia(), RTEXITCODE_FAILURE); 1507 CHECK_ERROR2_RET(hrc, ptrUnattended,ReconfigureVM(), RTEXITCODE_FAILURE); 1508 1509 /* 1510 * Retrieve and display the parameters actually used. 1511 */ 1512 RTMsgInfo("Using values:\n"); 1517 1513 #define SHOW_ATTR(a_Attr, a_szText, a_Type, a_szFmt) do { \ 1518 a_Type Value; \1519 HRESULT hrc2 = ptrUnattended->COMGETTER(a_Attr)(&Value); \1520 if (SUCCEEDED(hrc2)) \1521 RTPrintf(" %32s = " a_szFmt "\n", a_szText, Value); \1522 else \1523 RTPrintf(" %32s = failed: %Rhrc\n", a_szText, hrc2); \1524 } while (0)1514 a_Type Value; \ 1515 HRESULT hrc2 = ptrUnattended->COMGETTER(a_Attr)(&Value); \ 1516 if (SUCCEEDED(hrc2)) \ 1517 RTPrintf(" %32s = " a_szFmt "\n", a_szText, Value); \ 1518 else \ 1519 RTPrintf(" %32s = failed: %Rhrc\n", a_szText, hrc2); \ 1520 } while (0) 1525 1521 #define SHOW_STR_ATTR(a_Attr, a_szText) do { \ 1526 Bstr bstrString; \1527 HRESULT hrc2 = ptrUnattended->COMGETTER(a_Attr)(bstrString.asOutParam()); \1528 if (SUCCEEDED(hrc2)) \1529 RTPrintf(" %32s = %ls\n", a_szText, bstrString.raw()); \1530 else \1531 RTPrintf(" %32s = failed: %Rhrc\n", a_szText, hrc2); \1532 } while (0)1533 1534 SHOW_STR_ATTR(IsoPath, "isoPath");1535 SHOW_STR_ATTR(User, "user");1536 SHOW_STR_ATTR(Password, "password");1537 SHOW_STR_ATTR(FullUserName, "fullUserName");1538 SHOW_STR_ATTR(ProductKey, "productKey");1539 SHOW_STR_ATTR(AdditionsIsoPath, "additionsIsoPath");1540 SHOW_ATTR( InstallGuestAdditions, "installGuestAdditions", BOOL, "%RTbool");1541 SHOW_STR_ATTR(ValidationKitIsoPath, "validationKitIsoPath");1542 SHOW_ATTR( InstallTestExecService, "installTestExecService", BOOL, "%RTbool");1543 SHOW_STR_ATTR(Locale, "locale");1544 SHOW_STR_ATTR(Country, "country");1545 SHOW_STR_ATTR(TimeZone, "timeZone");1546 SHOW_STR_ATTR(Proxy, "proxy");1547 SHOW_STR_ATTR(Hostname, "hostname");1548 SHOW_STR_ATTR(PackageSelectionAdjustments, "packageSelectionAdjustments");1549 SHOW_STR_ATTR(AuxiliaryBasePath, "auxiliaryBasePath");1550 SHOW_ATTR( ImageIndex, "imageIndex", ULONG, "%u");1551 SHOW_STR_ATTR(ScriptTemplatePath, "scriptTemplatePath");1552 SHOW_STR_ATTR(PostInstallScriptTemplatePath, "postInstallScriptTemplatePath");1553 SHOW_STR_ATTR(PostInstallCommand, "postInstallCommand");1554 SHOW_STR_ATTR(ExtraInstallKernelParameters, "extraInstallKernelParameters");1555 SHOW_STR_ATTR(DetectedOSTypeId, "detectedOSTypeId");1556 SHOW_STR_ATTR(DetectedOSVersion, "detectedOSVersion");1557 SHOW_STR_ATTR(DetectedOSFlavor, "detectedOSFlavor");1558 SHOW_STR_ATTR(DetectedOSHints, "detectedOSHints");1522 Bstr bstrString; \ 1523 HRESULT hrc2 = ptrUnattended->COMGETTER(a_Attr)(bstrString.asOutParam()); \ 1524 if (SUCCEEDED(hrc2)) \ 1525 RTPrintf(" %32s = %ls\n", a_szText, bstrString.raw()); \ 1526 else \ 1527 RTPrintf(" %32s = failed: %Rhrc\n", a_szText, hrc2); \ 1528 } while (0) 1529 1530 SHOW_STR_ATTR(IsoPath, "isoPath"); 1531 SHOW_STR_ATTR(User, "user"); 1532 SHOW_STR_ATTR(Password, "password"); 1533 SHOW_STR_ATTR(FullUserName, "fullUserName"); 1534 SHOW_STR_ATTR(ProductKey, "productKey"); 1535 SHOW_STR_ATTR(AdditionsIsoPath, "additionsIsoPath"); 1536 SHOW_ATTR( InstallGuestAdditions, "installGuestAdditions", BOOL, "%RTbool"); 1537 SHOW_STR_ATTR(ValidationKitIsoPath, "validationKitIsoPath"); 1538 SHOW_ATTR( InstallTestExecService, "installTestExecService", BOOL, "%RTbool"); 1539 SHOW_STR_ATTR(Locale, "locale"); 1540 SHOW_STR_ATTR(Country, "country"); 1541 SHOW_STR_ATTR(TimeZone, "timeZone"); 1542 SHOW_STR_ATTR(Proxy, "proxy"); 1543 SHOW_STR_ATTR(Hostname, "hostname"); 1544 SHOW_STR_ATTR(PackageSelectionAdjustments, "packageSelectionAdjustments"); 1545 SHOW_STR_ATTR(AuxiliaryBasePath, "auxiliaryBasePath"); 1546 SHOW_ATTR( ImageIndex, "imageIndex", ULONG, "%u"); 1547 SHOW_STR_ATTR(ScriptTemplatePath, "scriptTemplatePath"); 1548 SHOW_STR_ATTR(PostInstallScriptTemplatePath, "postInstallScriptTemplatePath"); 1549 SHOW_STR_ATTR(PostInstallCommand, "postInstallCommand"); 1550 SHOW_STR_ATTR(ExtraInstallKernelParameters, "extraInstallKernelParameters"); 1551 SHOW_STR_ATTR(DetectedOSTypeId, "detectedOSTypeId"); 1552 SHOW_STR_ATTR(DetectedOSVersion, "detectedOSVersion"); 1553 SHOW_STR_ATTR(DetectedOSFlavor, "detectedOSFlavor"); 1554 SHOW_STR_ATTR(DetectedOSHints, "detectedOSHints"); 1559 1555 1560 1556 #undef SHOW_STR_ATTR 1561 1557 #undef SHOW_ATTR 1562 1558 1563 ptrUnattended.setNull(); 1564 a->session->UnlockMachine(); 1565 1566 /* 1567 * Start the VM if requested. 1568 */ 1569 if (RTStrICmp(pszSessionType, "none") != 0) 1570 { 1571 Bstr env; 1559 /* We can drop the IUnatteded object now. */ 1560 ptrUnattended.setNull(); 1561 1562 /* 1563 * Start the VM if requested. 1564 */ 1565 if (RTStrICmp(pszSessionType, "none") == 0) 1566 hrc = S_OK; 1567 else 1568 { 1569 Bstr env; 1572 1570 #if defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS) 1573 /* make sure the VM process will start on the same display as VBoxManage */1574 Utf8Str str;1575 const char *pszDisplay = RTEnvGet("DISPLAY");1576 if (pszDisplay)1577 str = Utf8StrFmt("DISPLAY=%s\n", pszDisplay);1578 const char *pszXAuth = RTEnvGet("XAUTHORITY");1579 if (pszXAuth)1580 str.append(Utf8StrFmt("XAUTHORITY=%s\n", pszXAuth));1581 env = str;1571 /* make sure the VM process will start on the same display as VBoxManage */ 1572 Utf8Str str; 1573 const char *pszDisplay = RTEnvGet("DISPLAY"); 1574 if (pszDisplay) 1575 str = Utf8StrFmt("DISPLAY=%s\n", pszDisplay); 1576 const char *pszXAuth = RTEnvGet("XAUTHORITY"); 1577 if (pszXAuth) 1578 str.append(Utf8StrFmt("XAUTHORITY=%s\n", pszXAuth)); 1579 env = str; 1582 1580 #endif 1583 ComPtr<IProgress> progress; 1584 CHECK_ERROR(ptrMachine, LaunchVMProcess(a->session, Bstr(pszSessionType).raw(), env.raw(), progress.asOutParam())); 1585 if (SUCCEEDED(rc) && !progress.isNull()) 1581 ComPtr<IProgress> ptrProgress; 1582 CHECK_ERROR2(hrc, ptrMachine, LaunchVMProcess(a->session, Bstr(pszSessionType).raw(), env.raw(), ptrProgress.asOutParam())); 1583 if (SUCCEEDED(hrc) && !ptrProgress.isNull()) 1584 { 1585 RTMsgInfo("Waiting for VM \"%s\" to power on...\n", Utf8Str(bstrUuid).c_str()); 1586 CHECK_ERROR2(hrc, ptrProgress, WaitForCompletion(-1)); 1587 if (SUCCEEDED(hrc)) 1586 1588 { 1587 RTPrintf("Waiting for VM \"%s\" to power on...\n", Utf8Str(bstrUuid).c_str());1588 CHECK_ERROR (progress, WaitForCompletion(-1));1589 if (SUCCEEDED( rc))1589 BOOL fCompleted = true; 1590 CHECK_ERROR2(hrc, ptrProgress, COMGETTER(Completed)(&fCompleted)); 1591 if (SUCCEEDED(hrc)) 1590 1592 { 1591 BOOL fCompleted = true; 1592 CHECK_ERROR(progress, COMGETTER(Completed)(&fCompleted)); 1593 if (SUCCEEDED(rc)) 1593 ASSERT(fCompleted); 1594 1595 LONG iRc; 1596 CHECK_ERROR2(hrc, ptrProgress, COMGETTER(ResultCode)(&iRc)); 1597 if (SUCCEEDED(hrc)) 1594 1598 { 1595 ASSERT(fCompleted); 1596 1597 LONG iRc; 1598 CHECK_ERROR(progress, COMGETTER(ResultCode)(&iRc)); 1599 if (SUCCEEDED(rc)) 1599 if (SUCCEEDED(iRc)) 1600 RTMsgInfo("VM \"%s\" has been successfully started.\n", Utf8Str(bstrUuid).c_str()); 1601 else 1600 1602 { 1601 if (SUCCEEDED(iRc)) 1602 RTPrintf("VM \"%s\" has been successfully started.\n", Utf8Str(bstrUuid).c_str()); 1603 else 1604 { 1605 ProgressErrorInfo info(progress); 1606 com::GluePrintErrorInfo(info); 1607 } 1608 rc = iRc; 1603 ProgressErrorInfo info(ptrProgress); 1604 com::GluePrintErrorInfo(info); 1609 1605 } 1606 hrc = iRc; 1610 1607 } 1611 1608 } 1612 1609 } 1613 1614 /* 1615 * Do we wait for the VM to power down? 1616 */ 1617 } 1618 1619 } while (0); 1620 1621 return SUCCEEDED(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE; 1610 } 1611 1612 /* 1613 * Do we wait for the VM to power down? 1614 */ 1615 } 1616 1617 return SUCCEEDED(hrc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE; 1622 1618 }
Note:
See TracChangeset
for help on using the changeset viewer.

