VirtualBox

Changeset 83169 in vbox for trunk/src/VBox/Main/src-server


Ignore:
Timestamp:
Feb 27, 2020 9:28:41 AM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
136290
Message:

OCI: (bugref:9469) cloud network integration multiple targets and configuration support (enabled in Config.kmk).

Location:
trunk/src/VBox/Main/src-server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-server/MachineImpl.cpp

    r82968 r83169  
    73107310
    73117311#ifdef VBOX_WITH_CLOUD_NET
     7312HRESULT Machine::i_setMacAddress(int slot, const Utf8Str& strMac)
     7313{
     7314    Bstr macAddress = strMac;
     7315    ComPtr<ISession> session;
     7316    HRESULT hrc = session.createInprocObject(CLSID_Session);
     7317    if (FAILED(hrc))
     7318        LogRel(("OCI-NET: Failed to create a session. hrc=%x\n", hrc));
     7319
     7320    hrc = lockMachine(session, LockType_Write);
     7321    if (FAILED(hrc))
     7322    {
     7323        LogRel(("OCI-NET: Failed to lock target VM for modifications. hrc=%x\n", hrc));
     7324        return hrc;
     7325    }
     7326
     7327    ComPtr<IMachine> sessionMachine;
     7328    hrc = session->COMGETTER(Machine)(sessionMachine.asOutParam());
     7329    if (FAILED(hrc))
     7330    {
     7331        LogRel(("OCI-NET: Failed to obtain a mutable machine. hrc=%x\n", hrc));
     7332        return hrc;
     7333    }
     7334
     7335    ComPtr<INetworkAdapter> networkAdapter;
     7336    hrc = sessionMachine->GetNetworkAdapter(slot, networkAdapter.asOutParam());
     7337    if (FAILED(hrc))
     7338    {
     7339        LogRel(("OCI-NET: Failed to locate the second network adapter. hrc=%x\n", hrc));
     7340        return hrc;
     7341    }
     7342
     7343    hrc = networkAdapter->COMSETTER(MACAddress)(macAddress.raw());
     7344    if (FAILED(hrc))
     7345    {
     7346        LogRel(("OCI-NET: Failed to set network name for the second network adapter. hrc=%x\n", hrc));
     7347        return hrc;
     7348    }
     7349
     7350    hrc = sessionMachine->SaveSettings();
     7351    if (FAILED(hrc))
     7352        LogRel(("OCI-NET: Failed to save 'lgw' settings. hrc=%x\n", hrc));
     7353
     7354    session->UnlockMachine();
     7355
     7356    return hrc;
     7357}
     7358
     7359
    73127360HRESULT Machine::i_connectToCloudNetwork(ProgressProxy *aProgress)
    73137361{
     
    73177365    HRESULT hrc = E_FAIL;
    73187366    Bstr name;
     7367    ULONG iSlot = ULONG_MAX;
    73197368
    73207369    LogFlowThisFunc(("Checking if cloud network needs to be connected\n"));
     
    73347383            if (name.isNotEmpty())
    73357384            {
    7336                 LogRel(("VM '%s' uses multiple cloud network attachments. '%ls' will be ignored.\n",
     7385                LogRel(("OCI-NET: VM '%s' uses multiple cloud network attachments. '%ls' will be ignored.\n",
    73377386                        mUserData->s.strName.c_str(), name.raw()));
    73387387                continue;
     
    73417390            if (SUCCEEDED(hrc))
    73427391            {
    7343                 LogRel(("VM '%s' uses cloud network '%ls'\n",
     7392                LogRel(("OCI-NET: VM '%s' uses cloud network '%ls'\n",
    73447393                        mUserData->s.strName.c_str(), name.raw()));
     7394                iSlot = slot;
    73457395            }
    73467396        }
     
    73537403        if (FAILED(hrc))
    73547404        {
    7355             LogRel(("Could not find cloud network '%ls'.\n", name.raw()));
     7405            LogRel(("OCI-NET: Could not find cloud network '%ls'.\n", name.raw()));
    73567406            return hrc;
    73577407        }
     7408        Bstr MacAddress;
     7409        Utf8Str strMacAddress;
    73587410        GatewayInfo gateways;
     7411        gateways.mTargetVM = mUserData->s.strName;
     7412        gateways.mAdapterSlot = iSlot;
     7413        hrc = mNetworkAdapters[iSlot]->COMGETTER(MACAddress)(MacAddress.asOutParam());
     7414        if (FAILED(hrc))
     7415        {
     7416            Host::i_generateMACAddress(strMacAddress);
     7417            LogRel(("OCI-NET: Failed to get MAC address of adapter connected to cloud network '%ls'.\n"
     7418                    "OCI-NET: Will use auto-generated '%s'.\n", name.raw(), strMacAddress.c_str()));
     7419        }
     7420        else
     7421            strMacAddress = MacAddress;
     7422        hrc = gateways.setLocalMacAddress(strMacAddress);
     7423        if (FAILED(hrc))
     7424        {
     7425            LogRel(("OCI-NET: Failed to obtain valid MAC address (%s) from cloud gateway '%ls'.\n",
     7426                    strMacAddress, name.raw()));
     7427            return hrc;
     7428        }
    73597429        hrc = startGateways(mParent, network, gateways);
     7430        /* We copy gateways structure unconditionally in order to be able to undo partially failed gateway setup. */
     7431        AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     7432        mData->mGatewayInfo = gateways;
     7433        alock.release();
    73607434        if (SUCCEEDED(hrc))
    73617435        {
    7362             AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    7363             mData->mGatewayInfo = gateways;
     7436            if (iSlot == ULONG_MAX)
     7437                LogRel(("OCI-NET: No slot information available for cloud network attachment!\n"));
     7438            else
     7439            {
     7440                hrc = i_setMacAddress(iSlot, gateways.getCloudMacAddressWithoutColons());
     7441                if (SUCCEEDED(hrc))
     7442                    LogRel(("OCI-NET: Updated MAC address for '%s' to %RTmac\n",
     7443                            mUserData->s.strName.c_str(), &gateways.mCloudMacAddress));
     7444                else
     7445                    LogRel(("OCI-NET: Failed to update MAC address for '%s' to %RTmac\n",
     7446                            mUserData->s.strName.c_str(), &gateways.mCloudMacAddress));
     7447            }
    73647448        }
    73657449    }
     
    73797463
    73807464    HRESULT hrc = stopGateways(mParent, gateways);
     7465    // @todo Restore original MAC address. I'd hate to wait here for Machine to power off though.
     7466    // i_setMacAddress(gateways.mAdapterSlot, gateways.getLocalMacAddressWithoutColons());
    73817467    return hrc;
    73827468}
  • trunk/src/VBox/Main/src-server/VirtualBoxImpl.cpp

    r82968 r83169  
    15071507                                             ComObjPtr<CloudNetwork> *aNetwork)
    15081508{
    1509     HRESULT rc = E_FAIL;
     1509    HRESULT rc = VBOX_E_OBJECT_NOT_FOUND;
    15101510    ComPtr<CloudNetwork> found;
    15111511    Bstr bstrNameToFind(aNetworkName);
     
    15181518    {
    15191519        Bstr bstrCloudNetworkName;
    1520         rc = (*it)->COMGETTER(NetworkName)(bstrCloudNetworkName.asOutParam());
    1521         if (FAILED(rc)) return rc;
     1520        HRESULT hrc = (*it)->COMGETTER(NetworkName)(bstrCloudNetworkName.asOutParam());
     1521        if (FAILED(hrc)) return hrc;
    15221522
    15231523        if (bstrCloudNetworkName == bstrNameToFind)
     
    16171617#endif /* !VBOX_WITH_CLOUD_NET */
    16181618}
     1619
     1620#ifdef VBOX_WITH_CLOUD_NET
     1621HRESULT VirtualBox::i_getEventSource(ComPtr<IEventSource>& aSource)
     1622{
     1623    m->pEventSource.queryInterfaceTo(aSource.asOutParam());
     1624    return S_OK;
     1625}
     1626#endif /* VBOX_WITH_CLOUD_NET */
    16191627
    16201628HRESULT VirtualBox::getCloudProviderManager(ComPtr<ICloudProviderManager> &aCloudProviderManager)
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