VirtualBox

Changeset 16517 in vbox


Ignore:
Timestamp:
Feb 4, 2009 4:25:29 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
42441
Message:

OVF: add IVirtualSystemDescription::disableItem(), fix disk import

Location:
trunk/src/VBox
Files:
4 edited

Legend:

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

    r16515 r16517  
    5454
    5555    Utf8Str strOvfFilename;
     56    bool fExecute = false;                  // if true, then we actually do the import (-exec argument)
    5657
    5758    for (int i = 0; i < a->argc; i++)
    5859    {
    59         if (!strOvfFilename)
     60        if (!strcmp(a->argv[i], "-exec"))
     61            fExecute = true;
     62        else if (!strOvfFilename)
    6063            strOvfFilename = a->argv[i];
    6164        else
     
    219222                }
    220223            }
    221             RTPrintf("\n");
    222         }
     224
     225            if (fExecute)
     226            {
     227                ComPtr<IProgress> progress;
     228                CHECK_ERROR_BREAK(appliance,
     229                                  ImportAppliance(progress.asOutParam()));
     230
     231                showProgress(progress);
     232
     233                if (SUCCEEDED(rc))
     234                {
     235                    progress->COMGETTER(ResultCode)(&rc);
     236                    if (FAILED (rc))
     237                    {
     238                        com::ProgressErrorInfo info(progress);
     239                        if (info.isBasicAvailable())
     240                            RTPrintf("Error: failed to import appliance. Error message: %lS\n", info.getText().raw());
     241                        else
     242                            RTPrintf("Error: failed to import appliance. No error message available!\n");
     243                    }
     244                    else
     245                        RTPrintf("Successfully imported the appliance.\n");
     246                }
     247            }
     248        } // end if (aVirtualSystemDescriptions.size() > 0)
    223249    } while (0);
    224250
  • trunk/src/VBox/Main/ApplianceImpl.cpp

    r16515 r16517  
    226226    ss << val;
    227227    return Utf8Str(ss.str().c_str());
     228}
     229
     230static Utf8Str stripFilename(const Utf8Str &strFile)
     231{
     232    Utf8Str str2(strFile);
     233    RTPathStripFilename(str2.mutableRaw());
     234    return str2;
    228235}
    229236
     
    433440                            pelmDisk->getLineNumber());
    434441
    435         // RTPrintf("  found disk: %s\n", d.strDiskId.c_str());
    436442        m->mapDisks[d.strDiskId] = d;
    437443    }
     
    14281434                                                  pController->ulIndex);
    14291435                        pNewDesc->addEntry(VirtualSystemDescriptionType_HardDiskImage,
    1430                                            "",
     1436                                           hd.strDiskId,
    14311437                                           di.strHref,
    14321438                                           strPath,
     
    14981504    char *tmpName = RTStrDup(aName.c_str());
    14991505    int i = 1;
    1500     /* @todo: Maybe to cost intensive; try to find a lighter way */
     1506    /* @todo: Maybe too cost-intensive; try to find a lighter way */
    15011507    while (mVirtualBox->FindMachine(Bstr(tmpName), &machine) != VBOX_E_OBJECT_NOT_FOUND)
    15021508    {
     
    15181524    /* Check if the file exists or if a file with this path is registered
    15191525     * already */
    1520     /* @todo: Maybe to cost intensive; try to find a lighter way */
     1526    /* @todo: Maybe too cost-intensive; try to find a lighter way */
    15211527    while (RTPathExists(tmpName) ||
    15221528           mVirtualBox->FindHardDisk2(Bstr(tmpName), &harddisk) != VBOX_E_OBJECT_NOT_FOUND)
     
    15271533        char *tmpFile = RTStrDup(RTPathFilename(aName.c_str()));
    15281534        RTPathStripExt(tmpFile);
    1529         char *tmpExt = RTPathExt(aName.c_str());
     1535        const char *tmpExt = RTPathExt(aName.c_str());
    15301536        RTStrAPrintf(&tmpName, "%s/%s_%d%s", tmpDir, tmpFile, i, tmpExt);
    15311537        RTStrFree(tmpFile);
     
    15801586            std::list<VirtualSystemDescriptionEntry*> vsdeOS = vsdescThis->findByType(VirtualSystemDescriptionType_OS);
    15811587            Assert(vsdeOS.size() == 1);
    1582             const Utf8Str &osTypeVBox = vsdeOS.front()->strConfig;
     1588            const Utf8Str &strOsTypeVBox = vsdeOS.front()->strConfig;
    15831589
    15841590            /* Now that we know the base system get our internal defaults based on that. */
    15851591            ComPtr<IGuestOSType> osType;
    1586             rc = app->mVirtualBox->GetGuestOSType(Bstr(osTypeVBox), osType.asOutParam());
     1592            rc = app->mVirtualBox->GetGuestOSType(Bstr(strOsTypeVBox), osType.asOutParam());
    15871593            CheckComRCThrowRC(rc);
    15881594
     
    15911597            std::list<VirtualSystemDescriptionEntry*> vsdeName = vsdescThis->findByType(VirtualSystemDescriptionType_Name);
    15921598            Assert(vsdeName.size() == 1);
    1593             const Utf8Str &nameVBox = vsdeName.front()->strConfig;
    1594             ComPtr<IMachine> newMachine;
    1595             rc = app->mVirtualBox->CreateMachine(Bstr(nameVBox.c_str()), Bstr(osTypeVBox.c_str()),
     1599            const Utf8Str &strNameVBox = vsdeName.front()->strConfig;
     1600            ComPtr<IMachine> pNewMachine;
     1601            rc = app->mVirtualBox->CreateMachine(Bstr(strNameVBox), Bstr(strOsTypeVBox),
    15961602                                                 Bstr(), Guid(),
    1597                                                  newMachine.asOutParam());
     1603                                                 pNewMachine.asOutParam());
    15981604            CheckComRCThrowRC(rc);
    15991605
     
    16091615            uint64_t tt = RTStrToUInt64(memoryVBox.c_str()) / _1M;
    16101616
    1611             rc = newMachine->COMSETTER(MemorySize)(tt);
     1617            rc = pNewMachine->COMSETTER(MemorySize)(tt);
    16121618            CheckComRCThrowRC(rc);
    16131619
     
    16191625            CheckComRCThrowRC(rc);
    16201626            /* Set the VRAM */
    1621             rc = newMachine->COMSETTER(VRAMSize)(vramVBox);
     1627            rc = pNewMachine->COMSETTER(VRAMSize)(vramVBox);
    16221628            CheckComRCThrowRC(rc);
    16231629
     
    16321638                    uint32_t audio = RTStrToUInt32(audioAdapterVBox.c_str());
    16331639                    ComPtr<IAudioAdapter> audioAdapter;
    1634                     rc = newMachine->COMGETTER(AudioAdapter)(audioAdapter.asOutParam());
     1640                    rc = pNewMachine->COMGETTER(AudioAdapter)(audioAdapter.asOutParam());
    16351641                    CheckComRCThrowRC(rc);
    16361642                    rc = audioAdapter->COMSETTER(Enabled)(true);
     
    16701676            /* USB Controller */
    16711677            std::list<VirtualSystemDescriptionEntry*> vsdeUSBController = vsdescThis->findByType(VirtualSystemDescriptionType_USBController);
    1672             /* If there is no USB controller entry it will be disabled */
     1678            // USB support is enabled if there's at least one such entry; to disable USB support,
     1679            // the type of the USB item would have been changed to "ignore"
    16731680            bool fUSBEnabled = vsdeUSBController.size() > 0;
    1674             if (fUSBEnabled)
    1675             {
    1676                 /* Check if the user has disabled the USB controller in the client */
    1677                 const Utf8Str& usbVBox = vsdeUSBController.front()->strConfig;
    1678                 fUSBEnabled = usbVBox == "1";
    1679             }
     1681
    16801682            ComPtr<IUSBController> usbController;
    1681             rc = newMachine->COMGETTER(USBController)(usbController.asOutParam());
     1683            rc = pNewMachine->COMGETTER(USBController)(usbController.asOutParam());
    16821684            CheckComRCThrowRC(rc);
    16831685            rc = usbController->COMSETTER(Enabled)(fUSBEnabled);
     
    16901692                /* No network adapters, so we have to disable our default one */
    16911693                ComPtr<INetworkAdapter> nwVBox;
    1692                 rc = newMachine->GetNetworkAdapter(0, nwVBox.asOutParam());
     1694                rc = pNewMachine->GetNetworkAdapter(0, nwVBox.asOutParam());
    16931695                CheckComRCThrowRC(rc);
    16941696                rc = nwVBox->COMSETTER(Enabled)(false);
     
    16991701                list<VirtualSystemDescriptionEntry*>::const_iterator nwIt;
    17001702                /* Iterate through all network cards. We support 8 network adapters
    1701                  * at the maximum. (@todo: warn if it are more!) */
     1703                 * at the maximum. (@todo: warn if there are more!) */
    17021704                size_t a = 0;
    17031705                for (nwIt = vsdeNW.begin();
     
    17081710                    uint32_t tt1 = RTStrToUInt32(nwTypeVBox.c_str());
    17091711                    ComPtr<INetworkAdapter> nwVBox;
    1710                     rc = newMachine->GetNetworkAdapter((ULONG)a, nwVBox.asOutParam());
     1712                    rc = pNewMachine->GetNetworkAdapter((ULONG)a, nwVBox.asOutParam());
    17111713                    CheckComRCThrowRC(rc);
    17121714                    /* Enable the network card & set the adapter type */
     
    17211723            /* Floppy drive */
    17221724            std::list<VirtualSystemDescriptionEntry*> vsdeFloppy = vsdescThis->findByType(VirtualSystemDescriptionType_Floppy);
    1723             /* If there is no floppy drive entry it will be disabled */
     1725            // Floppy support is enabled if there's at least one such entry; to disable floppy support,
     1726            // the type of the floppy item would have been changed to "ignore"
    17241727            bool fFloppyEnabled = vsdeFloppy.size() > 0;
    1725             if (fFloppyEnabled)
    1726             {
    1727                 /* Check if the user has disabled the floppy drive in the client */
    1728                 const Utf8Str& floppyVBox = vsdeFloppy.front()->strConfig;
    1729                 fFloppyEnabled = floppyVBox == "1";
    1730             }
    17311728            ComPtr<IFloppyDrive> floppyDrive;
    1732             rc = newMachine->COMGETTER(FloppyDrive)(floppyDrive.asOutParam());
     1729            rc = pNewMachine->COMGETTER(FloppyDrive)(floppyDrive.asOutParam());
    17331730            CheckComRCThrowRC(rc);
    17341731            rc = floppyDrive->COMSETTER(Enabled)(fFloppyEnabled);
     
    17441741            if (vsdeHDCIDE.size() > 0)
    17451742            {
    1746                 IDEControllerType_T hdcVBox = static_cast<IDEControllerType_T>(RTStrToUInt32(vsdeHDCIDE.front()->strConfig.c_str()));
    1747                 /* Set the appropriate IDE controller in the virtual BIOS of the
    1748                  * VM. */
     1743                // set the appropriate IDE controller in the virtual BIOS of the VM
    17491744                ComPtr<IBIOSSettings> biosSettings;
    1750                 rc = newMachine->COMGETTER(BIOSSettings)(biosSettings.asOutParam());
     1745                rc = pNewMachine->COMGETTER(BIOSSettings)(biosSettings.asOutParam());
    17511746                CheckComRCThrowRC(rc);
    1752                 rc = biosSettings->COMSETTER(IDEControllerType)(hdcVBox);
     1747                const char *pcszIDEType = vsdeHDCIDE.front()->strConfig.c_str();
     1748                if (!strcmp(pcszIDEType, "PIIX3"))
     1749                    rc = biosSettings->COMSETTER(IDEControllerType)(IDEControllerType_PIIX3);
     1750                else if (!strcmp(pcszIDEType, "PIIX4"))
     1751                    rc = biosSettings->COMSETTER(IDEControllerType)(IDEControllerType_PIIX4);
     1752                else
     1753                    throw setError(VBOX_E_FILE_ERROR,
     1754                                   tr("Invalid IDE controller type \"%s\""),
     1755                                   pcszIDEType);
    17531756                CheckComRCThrowRC(rc);
    17541757            }
     
    17641767                    /* For now we have just to enable the AHCI controller. */
    17651768                    ComPtr<ISATAController> hdcSATAVBox;
    1766                     rc = newMachine->COMGETTER(SATAController)(hdcSATAVBox.asOutParam());
     1769                    rc = pNewMachine->COMGETTER(SATAController)(hdcSATAVBox.asOutParam());
    17671770                    CheckComRCThrowRC(rc);
    17681771                    rc = hdcSATAVBox->COMSETTER(Enabled)(true);
     
    17751778            }
    17761779#endif /* VBOX_WITH_AHCI */
    1777 #ifdef VBOX_WITH_SCSI
     1780
    17781781            /* Hard disk controller SCSI */
    1779             EntriesList vsdeHDCSCSI = vsdescThis->findByType(VirtualSystemDescriptionType_HardDiskControllerSCSI);
     1782            std::list<VirtualSystemDescriptionEntry*> vsdeHDCSCSI = vsdescThis->findByType(VirtualSystemDescriptionType_HardDiskControllerSCSI);
    17801783            /* @todo: do we support more than one SCSI controller? */
    17811784            if (vsdeHDCSCSI.size() > 0)
    17821785            {
    1783                 /* @todo: Currently I have no idea how to enable this. Someone has
    1784                  * to write main support for SCSI at all. */
     1786                /* @todo: revisit when Main support for SCSI is ready */
    17851787            }
    1786 #endif /* VBOX_WITH_SCSI */
    17871788
    17881789            /* Now its time to register the machine before we add any hard disks */
    1789             rc = app->mVirtualBox->RegisterMachine(newMachine);
     1790            rc = app->mVirtualBox->RegisterMachine(pNewMachine);
    17901791            CheckComRCThrowRC(rc);
    17911792
     
    17981799            {
    17991800                Guid newMachineId;
    1800                 rc = newMachine->COMGETTER(Id)(newMachineId.asOutParam());
     1801                rc = pNewMachine->COMGETTER(Id)(newMachineId.asOutParam());
    18011802                CheckComRCThrowRC(rc);
    18021803                /* If in the next block an error occur we have to deregister
     
    18051806                try
    18061807                {
    1807                     /* That we can attach hard disks we need to open a session for the
    1808                      * new machine */
     1808                    // in order to attach hard disks we need to open a session for the new machine
    18091809                    rc = session.createInprocObject(CLSID_Session);
    18101810                    CheckComRCThrowRC(rc);
     
    18151815                    /* The disk image has to be on the same place as the OVF file. So
    18161816                     * strip the filename out of the full file path. */
    1817                     char *pszSrcDir = RTStrDup(Utf8Str(app->m->bstrPath).raw());
    1818                     RTPathStripFilename(pszSrcDir);
    1819                     Utf8Str strSrcDir(pszSrcDir);
    1820                     RTStrFree(pszSrcDir);
     1817                    Utf8Str strSrcDir = stripFilename(Utf8Str(app->m->bstrPath).raw());
    18211818
    18221819                    /* Iterate over all given disk images */
     
    18311828                        /* Check if the destination file exists already or the
    18321829                         * destination path is empty. */
    1833                         if (RTPathExists(pcszDstFilePath) ||
    1834                             !RTStrCmp(pcszDstFilePath, ""))
    1835                         {
     1830                        if (    !(*pcszDstFilePath)
     1831                             || RTPathExists(pcszDstFilePath)
     1832                           )
    18361833                            /* This isn't allowed */
    18371834                            throw setError(VBOX_E_FILE_ERROR,
    18381835                                           tr("Destination file '%s' exists",
    18391836                                              pcszDstFilePath));
    1840                         }
    18411837
    18421838                        // find the disk from the OVF's disk list
    18431839                        DiskImagesMap::const_iterator itDiskImage = app->m->mapDisks.find(vsdeHD->strRef);
     1840                        // vsdeHD->strRef contains the disk identifier (e.g. "vmdisk1", which should exist
     1841                        // in the virtual system's disks map under that ID and also in the global images map
    18441842                        VirtualDisksMap::const_iterator itVirtualDisk = vsysThis.mapVirtualDisks.find(vsdeHD->strRef);
    18451843
     
    20482046}
    20492047
     2048STDMETHODIMP VirtualSystemDescription::DisableItem(ULONG index)
     2049{
     2050    AutoCaller autoCaller(this);
     2051    CheckComRCReturnRC(autoCaller.rc());
     2052
     2053    AutoWriteLock alock(this);
     2054
     2055    list<VirtualSystemDescriptionEntry>::iterator it;
     2056    for (it = m->descriptions.begin();
     2057         it != m->descriptions.end();
     2058         ++it)
     2059    {
     2060        VirtualSystemDescriptionEntry &e = *it;
     2061        if (e.ulIndex == index)
     2062        {
     2063            e.type = VirtualSystemDescriptionType_Ignore;
     2064            return S_OK;
     2065        }
     2066    }
     2067
     2068    return setError(VBOX_E_OBJECT_NOT_FOUND,
     2069                    tr("Array item index %d not found"),
     2070                    index);
     2071}
     2072
    20502073STDMETHODIMP VirtualSystemDescription::SetFinalValues(ComSafeArrayIn(IN_BSTR, aFinalValues))
    20512074{
     
    21252148    return NULL;
    21262149}
     2150
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r16515 r16517  
    31183118    </method>
    31193119
     3120    <method name="disableItem">
     3121      <desc>
     3122        Disables part of the configuration, as represented by the array items returned by
     3123        <link to="getDescription" />. For example, to disable USB support for a given
     3124        virtual system, pass in the array item index of the USB controller; its type will
     3125        then be changed by this method from "USBController" to "Ignore".
     3126
     3127        This works only for items of the types HardDiskControllerIDE, HardDiskControllerSATA,
     3128        HardDiskControllerSCSI, HardDiskImage, CDROM, Floppy, NetworkAdapter, USBController
     3129        and SoundCard.
     3130      </desc>
     3131
     3132      <param name="index" type="unsigned long" dir="in">
     3133      </param>
     3134    </method>
     3135
    31203136    <method name="SetFinalValues">
    31213137      <desc></desc>
  • trunk/src/VBox/Main/include/ApplianceImpl.h

    r16515 r16517  
    149149                              ComSafeArrayOut(BSTR, aConfigValues),
    150150                              ComSafeArrayOut(BSTR, aExtraConfigValues));
     151    STDMETHOD(DisableItem)(ULONG index);
    151152    STDMETHOD(SetFinalValues)(ComSafeArrayIn(IN_BSTR, aFinalValues));
    152153
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