VirtualBox

Changeset 30881 in vbox


Ignore:
Timestamp:
Jul 16, 2010 2:34:31 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
63716
Message:

Main/OVF: add Appliance::machines[] attribute so that caller can figure out which machines were actually created; improve OVF testcase (not done yet)

Location:
trunk/src/VBox/Main
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/ApplianceImpl.cpp

    r30764 r30881  
    454454}
    455455
     456/**
     457 * Public method implementation.
     458 * @param aDisks
     459 * @return
     460 */
     461STDMETHODIMP Appliance::COMGETTER(Machines)(ComSafeArrayOut(BSTR, aMachines))
     462{
     463    CheckComArgOutSafeArrayPointerValid(aMachines);
     464
     465    AutoCaller autoCaller(this);
     466    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     467
     468    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     469
     470    if (!isApplianceIdle())
     471        return E_ACCESSDENIED;
     472
     473    com::SafeArray<BSTR> sfaMachines(m->llGuidsMachinesCreated.size());
     474    size_t u = 0;
     475    for (std::list<Guid>::const_iterator it = m->llGuidsMachinesCreated.begin();
     476         it != m->llGuidsMachinesCreated.end();
     477         ++it)
     478    {
     479        const Guid &uuid = *it;
     480        Bstr bstr(uuid.toUtf16());
     481        bstr.detachTo(&sfaMachines[u]);
     482        ++u;
     483    }
     484
     485    sfaMachines.detachTo(ComSafeArrayOutArg(aMachines));
     486
     487    return S_OK;
     488}
     489
    456490STDMETHODIMP Appliance::CreateVFSExplorer(IN_BSTR aURI, IVFSExplorer **aExplorer)
    457491{
  • trunk/src/VBox/Main/ApplianceImplImport.cpp

    r30876 r30881  
    11141114    ImportStack stack(locInfo, reader.m_mapDisks, pProgress);
    11151115
     1116    // clear the list of imported machines, if any
     1117    m->llGuidsMachinesCreated.clear();
     1118
    11161119    try
    11171120    {
     
    12591262
    12601263        // finally, deregister and remove all machines
    1261         list<Bstr>::iterator itID;
    1262         for (itID = stack.llMachinesRegistered.begin();
    1263              itID != stack.llMachinesRegistered.end();
     1264        for (list<Guid>::iterator itID = m->llGuidsMachinesCreated.begin();
     1265             itID != m->llGuidsMachinesCreated.end();
    12641266             ++itID)
    12651267        {
    1266             Bstr bstrGuid = *itID;      // make a copy, Windows can't handle const Bstr
     1268            Guid guid = *itID;
     1269            Bstr bstrGuid = guid.toUtf16();
    12671270            ComPtr<IMachine> failedMachine;
    12681271            rc2 = mVirtualBox->UnregisterMachine(bstrGuid, failedMachine.asOutParam());
     
    17381741    rc = pNewMachine->COMGETTER(Id)(bstrNewMachineId.asOutParam());
    17391742    if (FAILED(rc)) DebugBreakThrow(rc);
    1740     stack.llMachinesRegistered.push_back(bstrNewMachineId);
     1743    m->llGuidsMachinesCreated.push_back(Guid(bstrNewMachineId));
    17411744
    17421745    // Add floppies and CD-ROMs to the appropriate controllers.
     
    21532156    rc = pNewMachine->COMGETTER(Id)(bstrNewMachineId.asOutParam());
    21542157    if (FAILED(rc)) DebugBreakThrow(rc);
    2155     stack.llMachinesRegistered.push_back(bstrNewMachineId);
     2158    m->llGuidsMachinesCreated.push_back(Guid(bstrNewMachineId));
    21562159}
    21572160
  • trunk/src/VBox/Main/VirtualBoxImpl.cpp

    r30871 r30881  
    13921392    /* save the global registry */
    13931393    rc = saveSettings();
     1394
     1395    alock.release();
    13941396
    13951397    /* return the unregistered machine to the caller */
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r30871 r30881  
    13161316  <interface
    13171317    name="IVirtualBox" extends="$unknown"
    1318     uuid="f0c2e058-8c72-4d56-95e7-3107627aba6e"
     1318    uuid="2275c97d-31b0-41c7-a138-c77d3c28406e"
    13191319    wsmap="managed"
    13201320  >
     
    17101710    <method name="unregisterMachine">
    17111711      <desc>
    1712 
    17131712        Unregisters the machine previously registered using
    17141713        <link to="#registerMachine"/>. After successful method invocation, the
     
    28942893  <interface
    28952894     name="IAppliance" extends="$unknown"
    2896      uuid="e3ba9ab9-ac2c-4266-8bd2-91c4bf721ceb"
     2895     uuid="fb61a4fc-57e7-48d6-859b-71f37d484cf2"
    28972896     wsmap="managed"
    28982897     >
     
    29462945          <li>Finally, call <link to="#importMachines" /> to  create virtual machines in
    29472946              VirtualBox as instances of <link to="IMachine" /> that match the information in the
    2948               virtual system descriptions.
     2947              virtual system descriptions. After this call suceeded, the UUIDs of the machines created
     2948              can be found in the <link to="#machines" /> array attribute.
    29492949          </li>
    29502950        </ol>
     
    30273027    </attribute>
    30283028
     3029    <attribute name="machines" type="wstring" readonly="yes" safearray="yes">
     3030      <desc>
     3031        Contains the UUIDs of the machines created from the information in this appliances. This is only
     3032        relevant for the import case, and will only contain data after a call to <link to="#importMachines" />
     3033        succeeded.
     3034      </desc>
     3035    </attribute>
     3036
    30293037    <method name="read">
    30303038      <desc>
     
    30763084        disk images, which can take a long time, this method operates asynchronously and
    30773085        returns an IProgress object to allow the caller to monitor the progress.
     3086
     3087        After the import succeeded, the UUIDs of the IMachine instances created can be
     3088        retrieved from the <link to="#machines" /> array attribute.
    30783089      </desc>
    30793090
  • trunk/src/VBox/Main/include/ApplianceImpl.h

    r30764 r30881  
    8484    STDMETHOD(COMGETTER(Disks))(ComSafeArrayOut(BSTR, aDisks));
    8585    STDMETHOD(COMGETTER(VirtualSystemDescriptions))(ComSafeArrayOut(IVirtualSystemDescription*, aVirtualSystemDescriptions));
     86    STDMETHOD(COMGETTER(Machines))(ComSafeArrayOut(BSTR, aMachines));
    8687
    8788    /* IAppliance methods */
  • trunk/src/VBox/Main/include/ApplianceImplPrivate.h

    r30764 r30881  
    8080    ULONG               cDisks;
    8181    Utf8Str             strOVFSHA1Digest;
     82
     83    std::list<Guid>     llGuidsMachinesCreated;
    8284};
    8385
     
    166168    std::list<MyHardDiskAttachment> llHardDiskAttachments;      // disks that were attached
    167169    std::list< ComPtr<IMedium> >    llHardDisksCreated;         // media that were created
    168     std::list<Bstr>                 llMachinesRegistered;       // machines that were registered; list of string UUIDs
    169170
    170171    ImportStack(const LocationInfo &aLocInfo,
  • trunk/src/VBox/Main/testcase/tstOVF.cpp

    r30876 r30881  
    7575 * Imports the given OVF file, with all bells and whistles.
    7676 * Throws MyError on errors.
     77 * @param pcszPrefix Descriptive short prefix string for console output.
    7778 * @param pVirtualBox VirtualBox instance.
    78  * @param pcszOVF File to import.
     79 * @param pcszOVF0 File to import.
     80 * @param llMachinesCreated out: UUIDs of machines that were created so that caller can clean up.
    7981 */
    8082void importOVF(const char *pcszPrefix,
    8183               ComPtr<IVirtualBox> &pVirtualBox,
    82                const char *pcszOVF0)
     84               const char *pcszOVF0,
     85               std::list<Guid> &llMachinesCreated)
    8386{
    8487    char szAbsOVF[RTPATH_MAX];
     
    8891    ComPtr<IAppliance> pAppl;
    8992    HRESULT rc = pVirtualBox->CreateAppliance(pAppl.asOutParam());
    90     if (FAILED(rc))
    91         throw MyError(rc, "failed to create appliance\n");
     93    if (FAILED(rc)) throw MyError(rc, "failed to create appliance\n");
    9294
    9395    ComPtr<IProgress> pProgress;
    9496    rc = pAppl->Read(Bstr(szAbsOVF), pProgress.asOutParam());
    95     if (FAILED(rc))
    96         throw MyError(rc, "Appliance::Read() failed\n");
     97    if (FAILED(rc)) throw MyError(rc, "Appliance::Read() failed\n");
    9798    rc = pProgress->WaitForCompletion(-1);
    98     if (FAILED(rc))
    99         throw MyError(rc, "Progress::WaitForCompletion() failed\n");
     99    if (FAILED(rc)) throw MyError(rc, "Progress::WaitForCompletion() failed\n");
    100100    LONG rc2;
    101101    pProgress->COMGETTER(ResultCode)(&rc2);
    102     if (FAILED(rc2))
    103         throw MyError(rc2, "Appliance::Read() failed\n", pProgress);
     102    if (FAILED(rc2)) throw MyError(rc2, "Appliance::Read() failed\n", pProgress);
    104103
    105104    RTPrintf("%s: interpreting appliance \"%s\"...\n", pcszPrefix, szAbsOVF);
    106105    rc = pAppl->Interpret();
    107     if (FAILED(rc))
    108         throw MyError(rc, "Appliance::Interpret() failed\n");
     106    if (FAILED(rc)) throw MyError(rc, "Appliance::Interpret() failed\n");
    109107
    110108    com::SafeIfaceArray<IVirtualSystemDescription> aDescriptions;
     
    126124                                   ComSafeArrayAsOutParam(aVboxValues),
    127125                                   ComSafeArrayAsOutParam(aExtraConfigValues));
     126        if (FAILED(rc)) throw MyError(rc, "VirtualSystemDescription::GetDescription() failed\n");
     127
    128128        for (uint32_t u2 = 0;
    129129             u2 < aTypes.size();
     
    234234    RTPrintf("%s: importing %d machine(s)...\n", pcszPrefix, aDescriptions.size());
    235235    rc = pAppl->ImportMachines(pProgress.asOutParam());
    236     if (FAILED(rc))
    237         throw MyError(rc, "Appliance::ImportMachines() failed\n");
     236    if (FAILED(rc)) throw MyError(rc, "Appliance::ImportMachines() failed\n");
    238237    rc = pProgress->WaitForCompletion(-1);
    239     if (FAILED(rc))
    240         throw MyError(rc, "Progress::WaitForCompletion() failed\n");
     238    if (FAILED(rc)) throw MyError(rc, "Progress::WaitForCompletion() failed\n");
    241239    pProgress->COMGETTER(ResultCode)(&rc2);
    242     if (FAILED(rc2))
    243         throw MyError(rc2, "Progress::GetResultCode() failed\n");
     240    if (FAILED(rc2)) throw MyError(rc2, "Progress::GetResultCode() failed\n");
     241
     242    com::SafeArray<BSTR> aMachineUUIDs;
     243    rc = pAppl->COMGETTER(Machines)(ComSafeArrayAsOutParam(aMachineUUIDs));
     244    if (FAILED(rc)) throw MyError(rc, "Appliance::GetMachines() failed\n");
     245
     246    for (size_t u = 0;
     247         u < aMachineUUIDs.size();
     248         ++u)
     249    {
     250        RTPrintf("%s: created machine %u: %ls\n", pcszPrefix, u, aMachineUUIDs[u]);
     251        llMachinesCreated.push_back(Guid(Bstr(aMachineUUIDs[u])));
     252    }
     253
    244254    RTPrintf("%s: success!\n", pcszPrefix);
    245255}
     
    255265{
    256266    int vrc = RTFileCopy("ovf-testcases/ovf-dummy.vmdk", pcszDest);
    257     if (RT_FAILURE(vrc))
    258         throw MyError(0, Utf8StrFmt("Cannot copy ovf-dummy.vmdk to %s: %Rra\n", pcszDest, vrc).c_str());
     267    if (RT_FAILURE(vrc)) throw MyError(0, Utf8StrFmt("Cannot copy ovf-dummy.vmdk to %s: %Rra\n", pcszDest, vrc).c_str());
    259268    llFiles2Delete.push_back(pcszDest);
    260269}
     
    273282
    274283    std::list<Utf8Str> llFiles2Delete;
     284    std::list<Guid> llMachinesCreated;
     285
     286    ComPtr<IVirtualBox> pVirtualBox;
    275287
    276288    try
     
    278290        RTPrintf("Initializing COM...\n");
    279291        rc = com::Initialize();
    280         if (FAILED(rc))
    281             throw MyError(rc, "failed to initialize COM!\n");
    282 
    283         ComPtr<IVirtualBox> pVirtualBox;
     292        if (FAILED(rc)) throw MyError(rc, "failed to initialize COM!\n");
     293
    284294        ComPtr<ISession> pSession;
    285295
    286296        RTPrintf("Creating VirtualBox object...\n");
    287297        rc = pVirtualBox.createLocalObject(CLSID_VirtualBox);
    288         if (FAILED(rc))
    289             throw MyError(rc, "failed to create the VirtualBox object!\n");
     298        if (FAILED(rc)) throw MyError(rc, "failed to create the VirtualBox object!\n");
    290299
    291300        rc = pSession.createInprocObject(CLSID_Session);
    292         if (FAILED(rc))
    293             throw MyError(rc, "failed to create a session object!\n");
     301        if (FAILED(rc)) throw MyError(rc, "failed to create a session object!\n");
    294302
    295303        // create the event queue
     
    298306
    299307        // testcase 1: import ovf-joomla-0.9/joomla-1.1.4-ovf.ovf
    300 //         copyDummyDiskImage(llFiles2Delete, "ovf-testcases/ovf-joomla-0.9/joomla-1.1.4-ovf-0.vmdk");
    301 //         copyDummyDiskImage(llFiles2Delete, "ovf-testcases/ovf-joomla-0.9/joomla-1.1.4-ovf-1.vmdk");
    302 //         importOVF("joomla-0.9", pVirtualBox, "ovf-testcases/ovf-joomla-0.9/joomla-1.1.4-ovf.ovf");
     308        copyDummyDiskImage(llFiles2Delete, "ovf-testcases/ovf-joomla-0.9/joomla-1.1.4-ovf-0.vmdk");
     309        copyDummyDiskImage(llFiles2Delete, "ovf-testcases/ovf-joomla-0.9/joomla-1.1.4-ovf-1.vmdk");
     310        importOVF("joomla-0.9", pVirtualBox, "ovf-testcases/ovf-joomla-0.9/joomla-1.1.4-ovf.ovf", llMachinesCreated);
    303311
    304312        // testcase 2: import ovf-winxp-vbox-sharedfolders/winxp.ovf
    305313        copyDummyDiskImage(llFiles2Delete, "ovf-testcases/ovf-winxp-vbox-sharedfolders/Windows 5.1 XP 1 merged.vmdk");
    306314        copyDummyDiskImage(llFiles2Delete, "ovf-testcases/ovf-winxp-vbox-sharedfolders/smallvdi.vmdk");
    307         importOVF("winxp-vbox-sharedfolders", pVirtualBox, "ovf-testcases/ovf-winxp-vbox-sharedfolders/winxp.ovf");
    308 
    309         RTPrintf ("tstOVF all done, no errors.\n");
    310 
    311         // todo: cleanup created machines, created disk images
     315        importOVF("winxp-vbox-sharedfolders", pVirtualBox, "ovf-testcases/ovf-winxp-vbox-sharedfolders/winxp.ovf", llMachinesCreated);
     316
     317        RTPrintf("Machine imports done, no errors. Cleaning up...\n");
    312318    }
    313319    catch (MyError &e)
     
    317323    }
    318324
    319     // clean up
     325    try
     326    {
     327        // clean up the machines created
     328        for (std::list<Guid>::const_iterator it = llMachinesCreated.begin();
     329             it != llMachinesCreated.end();
     330             ++it)
     331        {
     332//             const Guid &uuid = *it;
     333//             Bstr bstrUUID(uuid.toUtf16());
     334//             ComPtr<IMachine> pMachine;
     335//             rc = pVirtualBox->GetMachine(bstrUUID, pMachine.asOutParam());
     336//             if (FAILED(rc)) throw MyError(rc, "VirtualBox::FindMachine() failed\n");
     337//
     338//             SafeIfaceArray<IMediumAttachment> aMediumAttachments;
     339//             rc = pMachine->COMGETTER(MediumAttachments)(ComSafeArrayAsOutParam(aMediumAttachments));
     340//             if (FAILED(rc)) throw MyError(rc, "Machine::MediumAttachments() failed\n");
     341//
     342//             for (size_t u2 = 0;
     343//                  u2 < aMediumAttachments.size();
     344//                  ++u2)
     345//             {
     346//                 ComPtr<IMediumAttachment> pMediumAttachment(aMediumAttachments[u2]);
     347//                 ComPtr<IMedium> pMedium;
     348//                 rc = pMediumAttachment->COMGETTER(Medium)(pMedium.asOutParam());
     349//                 if (FAILED(rc)) throw MyError(rc, "MediumAttachment::GetMedium() failed\n");
     350//
     351//                 if (!pMedium.isNull())
     352//                 {
     353//                     Bstr bstrLocation;
     354//                     rc = pMedium->COMGETTER(Location)(bstrLocation.asOutParam());
     355//                     if (FAILED(rc)) throw MyError(rc, "Medium::GetLocation() failed\n");
     356//
     357//                     llFiles2Delete.push_back(bstrLocation);
     358//                 }
     359//             }
     360
     361            RTPrintf("  Deleting machine %ls...\n", bstrUUID.raw());
     362            pVirtualBox->UnregisterMachine(bstrUUID, pMachine.asOutParam());
     363            if (FAILED(rc)) throw MyError(rc, "VirtualBox::UnregisterMachine() failed\n");
     364
     365            if (!pMachine.isNull())
     366            {
     367                rc = pMachine->DeleteSettings();
     368                if (FAILED(rc)) throw MyError(rc, "Machine::DeleteSettings() failed\n");
     369            }
     370        }
     371    }
     372    catch (MyError &e)
     373    {
     374        rc = e.m_rc;
     375        RTPrintf("%s", e.m_str.c_str());
     376    }
     377
     378    // clean up the VMDK copies that we made in copyDummyDiskImage()
    320379    for (std::list<Utf8Str>::const_iterator it = llFiles2Delete.begin();
    321380         it != llFiles2Delete.end();
     
    326385    }
    327386
     387    pVirtualBox.setNull();
     388
    328389    RTPrintf("Shutting down COM...\n");
    329390    com::Shutdown();
     391    RTPrintf ("tstOVF all done!\n");
    330392
    331393    return rc;
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