VirtualBox

Changeset 37862 in vbox


Ignore:
Timestamp:
Jul 11, 2011 10:09:29 AM (13 years ago)
Author:
vboxsync
Message:

Main-OVF;FE/*: allow to specify if MAC addresses should be reinitialized on OVF/OVA import

Location:
trunk/src/VBox
Files:
10 edited

Legend:

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

    r36527 r37862  
    7575
    7676    return false;
     77}
     78
     79static int parseImportOptions(const char *psz, com::SafeArray<ImportOptions_T> *options)
     80{
     81    int rc = VINF_SUCCESS;
     82    while (psz && *psz && RT_SUCCESS(rc))
     83    {
     84        size_t len;
     85        const char *pszComma = strchr(psz, ',');
     86        if (pszComma)
     87            len = pszComma - psz;
     88        else
     89            len = strlen(psz);
     90        if (len > 0)
     91        {
     92            if (!RTStrNICmp(psz, "KeepAllMACs", len))
     93                options->push_back(ImportOptions_KeepAllMACs);
     94            else if (!RTStrNICmp(psz, "KeepNATMACs", len))
     95                options->push_back(ImportOptions_KeepNATMACs);
     96            else
     97                rc = VERR_PARSE_ERROR;
     98        }
     99        if (pszComma)
     100            psz += len + 1;
     101        else
     102            psz += len;
     103    }
     104
     105    return rc;
    77106}
    78107
     
    112141#endif
    113142    { "--disk",                 'D', RTGETOPT_REQ_STRING },
     143    { "--options",              'O', RTGETOPT_REQ_STRING },
    114144};
    115145
     
    120150    Utf8Str strOvfFilename;
    121151    bool fExecute = true;                  // if true, then we actually do the import
     152    com::SafeArray<ImportOptions_T> options;
    122153    uint32_t ulCurVsys = (uint32_t)-1;
    123154    uint32_t ulCurUnit = (uint32_t)-1;
     
    221252                    return errorSyntax(USAGE_IMPORTAPPLIANCE, "Option \"%s\" requires preceding --unit argument.", GetState.pDef->pszLong);
    222253                mapArgsMapsPerVsys[ulCurVsys][Utf8StrFmt("disk%u", ulCurUnit)] = ValueUnion.psz;
     254                break;
     255
     256            case 'O':   // --options
     257                if (RT_FAILURE(parseImportOptions(ValueUnion.psz, &options)))
     258                    return errorArgument("Invalid import options '%s'\n", ValueUnion.psz);
    223259                break;
    224260
     
    747783                ComPtr<IProgress> progress;
    748784                CHECK_ERROR_BREAK(pAppliance,
    749                                   ImportMachines(progress.asOutParam()));
     785                                  ImportMachines(ComSafeArrayAsInParam(options), progress.asOutParam()));
    750786
    751787                rc = showProgress(progress);
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp

    r37824 r37862  
    345345    if (u64Cmd & USAGE_IMPORTAPPLIANCE)
    346346        RTStrmPrintf(pStrm,
    347                      "VBoxManage import           <ovf/ova> [--dry-run|-n] [more options]\n"
     347                     "VBoxManage import           <ovf/ova>\n"
     348                     "                            [--dry-run|-n]\n"
     349                     "                            [--options keepallmacs|keepnatmacs]\n"
     350                     "                            [more options]\n"
    348351                     "                            (run with -n to have options displayed\n"
    349352                     "                             for a particular OVF)\n\n");
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/VBoxApplianceEditorWgt.cpp

    r35979 r37862  
    10881088    mTvSettings->header()->setResizeMode (QHeaderView::ResizeToContents);
    10891089
     1090    /* Hidden by default */
     1091    mReinitMACsCheckBox->setHidden(true);
     1092
    10901093    /* Applying language settings */
    10911094    retranslateUi();
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/VBoxApplianceEditorWgt.ui

    r28800 r37862  
    1010     you can redistribute it and/or modify it under the terms of the GNU
    1111     General Public License (GPL) as published by the Free Software
    12      Foundation, in version 2 as it comes in the "COPYING" file of the
     12     Foundation, in version 2 as it comes in the &quot;COPYING&quot; file of the
    1313     VirtualBox OSE distribution. VirtualBox OSE is distributed in the
    1414     hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
     
    2020    <x>0</x>
    2121    <y>0</y>
    22     <width>459</width>
    23     <height>305</height>
     22    <width>548</width>
     23    <height>411</height>
    2424   </rect>
    2525  </property>
     
    3939   </item>
    4040   <item>
     41    <widget class="QCheckBox" name="mReinitMACsCheckBox">
     42     <property name="toolTip">
     43      <string>When checked a new unique MAC address will assigned to all configured network cards.</string>
     44     </property>
     45     <property name="text">
     46      <string>&amp;Reinitialize the MAC address of all network cards</string>
     47     </property>
     48    </widget>
     49   </item>
     50   <item>
    4151    <widget class="QWidget" name="mWarningWidget" native="true">
    4252     <property name="sizePolicy">
     
    4757     </property>
    4858     <layout class="QVBoxLayout" name="verticalLayout">
    49       <property name="sizeConstraint">
    50        <enum>QLayout::SetDefaultConstraint</enum>
    51       </property>
    5259      <property name="margin">
    5360       <number>0</number>
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/VBoxImportApplianceWgt.cpp

    r34530 r37862  
    4242    : VBoxApplianceEditorWgt (aParent)
    4343{
     44    /* Show the MAC check box */
     45    mReinitMACsCheckBox->setHidden(false);
    4446}
    4547
     
    134136        /* Start the import asynchronously */
    135137        CProgress progress;
    136         progress = mAppliance->ImportMachines();
     138        QVector<KImportOptions> options;
     139        if (!mReinitMACsCheckBox->isChecked())
     140            options.append(KImportOptions_KeepAllMACs);
     141        progress = mAppliance->ImportMachines(options);
    137142        bool fResult = mAppliance->isOk();
    138143        if (fResult)
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r37851 r37862  
    19271927      </param>
    19281928      <param name="forceNewUuid" type="boolean" dir="in">
    1929         <desc>Allows the caller to request a completely new medium UUID for
    1930         the image which is to be opened. Useful if one intends to open an exact
    1931         copy of a previously opened image, as this would normally fail due to
    1932         the duplicate UUID.</desc>
    1933       </param>
     1929         <desc>Allows the caller to request a completely new medium UUID for
     1930           the image which is to be opened. Useful if one intends to open an exact
     1931           copy of a previously opened image, as this would normally fail due to
     1932           the duplicate UUID.</desc>
     1933         </param>
    19341934      <param name="medium" type="IMedium" dir="return">
    19351935        <desc>Opened medium object.</desc>
     
    23562356  </interface>
    23572357
     2358  <enum
     2359    name="ImportOptions" extends="$unknown"
     2360    uuid="0a981523-3b20-4004-8ee3-dfd322202ace"
     2361    >
     2362
     2363    <desc>
     2364    Import options, used with <link to="IAppliance::importMachines" />.
     2365    </desc>
     2366
     2367    <const name="KeepAllMACs"        value="1">
     2368      <desc>Don't generate new MAC addresses of the attached network adapters.</desc>
     2369    </const>
     2370    <const name="KeepNATMACs"        value="2">
     2371      <desc>Don't generate new MAC addresses of the attached network adapters when they are using NAT.</desc>
     2372    </const>
     2373
     2374  </enum>
     2375
     2376
    23582377  <!--
    23592378  // IAppliance
     
    23632382  <interface
    23642383    name="IAppliance" extends="$unknown"
    2365     uuid="7b148032-4124-4f46-b56a-b48ac1273f5a"
     2384    uuid="3059cf9e-25c7-4f0b-9fa5-3c42e441670b"
    23662385    wsmap="managed"
    23672386    >
     
    25582577        retrieved from the <link to="#machines" /> array attribute.
    25592578      </desc>
     2579
     2580      <param name="options" type="ImportOptions" dir="in" safearray="yes">
     2581        <desc>Options for the importing operation.</desc>
     2582      </param>
    25602583
    25612584      <param name="aProgress" type="IProgress" dir="return">
  • trunk/src/VBox/Main/include/ApplianceImpl.h

    r35638 r37862  
    9797    STDMETHOD(Read)(IN_BSTR path, IProgress **aProgress);
    9898    STDMETHOD(Interpret)(void);
    99     STDMETHOD(ImportMachines)(IProgress **aProgress);
     99    STDMETHOD(ImportMachines)(ComSafeArrayIn(ImportOptions_T, options), IProgress **aProgress);
    100100    /* Export methods */
    101101    STDMETHOD(CreateVFSExplorer)(IN_BSTR aURI, IVFSExplorer **aExplorer);
  • trunk/src/VBox/Main/include/ApplianceImplPrivate.h

    r34101 r37862  
    7373    LocationInfo        locInfo;        // location info for the currently processed OVF
    7474    bool                fManifest;      // Create a manifest file on export
     75    RTCList<ImportOptions_T> optList;
    7576
    7677    ovf::OVFReader      *pReader;
  • trunk/src/VBox/Main/src-server/ApplianceImplImport.cpp

    r37200 r37862  
    3737#include "MediumFormatImpl.h"
    3838#include "SystemPropertiesImpl.h"
     39#include "HostImpl.h"
    3940
    4041#include "AutoCaller.h"
     
    665666 * @return
    666667 */
    667 STDMETHODIMP Appliance::ImportMachines(IProgress **aProgress)
     668STDMETHODIMP Appliance::ImportMachines(ComSafeArrayIn(ImportOptions_T, options), IProgress **aProgress)
    668669{
    669670    CheckComArgOutPointerValid(aProgress);
     
    671672    AutoCaller autoCaller(this);
    672673    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     674
     675    if (options != NULL)
     676        m->optList = com::SafeArray<ImportOptions_T>(ComSafeArrayInArg(options)).toList();
     677
     678    AssertReturn(!(m->optList.contains(ImportOptions_KeepAllMACs) && m->optList.contains(ImportOptions_KeepNATMACs)), E_INVALIDARG);
    673679
    674680    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     
    25272533    /* First disable all network cards, they will be enabled below again. */
    25282534    settings::NetworkAdaptersList::iterator it1;
     2535    bool fKeepAllMACs = m->optList.contains(ImportOptions_KeepAllMACs);
     2536    bool fKeepNATMACs = m->optList.contains(ImportOptions_KeepNATMACs);
    25292537    for (it1 = llNetworkAdapters.begin(); it1 != llNetworkAdapters.end(); ++it1)
     2538    {
    25302539        it1->fEnabled = false;
     2540        if (!(   fKeepAllMACs
     2541              || (fKeepNATMACs && it1->mode == NetworkAttachmentType_NAT)))
     2542            Host::generateMACAddress(it1->strMACAddress);
     2543    }
    25312544    /* Now iterate over all network entries. */
    25322545    std::list<VirtualSystemDescriptionEntry*> avsdeNWs = vsdescThis->findByType(VirtualSystemDescriptionType_NetworkAdapter);
     
    25342547    {
    25352548        /* Iterate through all network adapter entries and search for the
    2536          * corrosponding one in the machine config. If one is found, configure
     2549         * corresponding one in the machine config. If one is found, configure
    25372550         * it based on the user settings. */
    25382551        list<VirtualSystemDescriptionEntry*>::const_iterator itNW;
  • trunk/src/VBox/Main/testcase/tstOVF.cpp

    r33294 r37862  
    233233
    234234    RTPrintf("%s: importing %d machine(s)...\n", pcszPrefix, aDescriptions.size());
    235     rc = pAppl->ImportMachines(pProgress.asOutParam());
     235    SafeArray<ImportOptions_T> sfaOptions;
     236    rc = pAppl->ImportMachines(ComSafeArrayAsInParam(sfaOptions), pProgress.asOutParam());
    236237    if (FAILED(rc)) throw MyError(rc, "Appliance::ImportMachines() failed\n");
    237238    rc = pProgress->WaitForCompletion(-1);
Note: See TracChangeset for help on using the changeset viewer.

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