Changeset 83169 in vbox for trunk/src/VBox/Main/src-server
- Timestamp:
- Feb 27, 2020 9:28:41 AM (5 years ago)
- svn:sync-xref-src-repo-rev:
- 136290
- Location:
- trunk/src/VBox/Main/src-server
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-server/MachineImpl.cpp
r82968 r83169 7310 7310 7311 7311 #ifdef VBOX_WITH_CLOUD_NET 7312 HRESULT 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 7312 7360 HRESULT Machine::i_connectToCloudNetwork(ProgressProxy *aProgress) 7313 7361 { … … 7317 7365 HRESULT hrc = E_FAIL; 7318 7366 Bstr name; 7367 ULONG iSlot = ULONG_MAX; 7319 7368 7320 7369 LogFlowThisFunc(("Checking if cloud network needs to be connected\n")); … … 7334 7383 if (name.isNotEmpty()) 7335 7384 { 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", 7337 7386 mUserData->s.strName.c_str(), name.raw())); 7338 7387 continue; … … 7341 7390 if (SUCCEEDED(hrc)) 7342 7391 { 7343 LogRel((" VM '%s' uses cloud network '%ls'\n",7392 LogRel(("OCI-NET: VM '%s' uses cloud network '%ls'\n", 7344 7393 mUserData->s.strName.c_str(), name.raw())); 7394 iSlot = slot; 7345 7395 } 7346 7396 } … … 7353 7403 if (FAILED(hrc)) 7354 7404 { 7355 LogRel((" Could not find cloud network '%ls'.\n", name.raw()));7405 LogRel(("OCI-NET: Could not find cloud network '%ls'.\n", name.raw())); 7356 7406 return hrc; 7357 7407 } 7408 Bstr MacAddress; 7409 Utf8Str strMacAddress; 7358 7410 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 } 7359 7429 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(); 7360 7434 if (SUCCEEDED(hrc)) 7361 7435 { 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 } 7364 7448 } 7365 7449 } … … 7379 7463 7380 7464 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()); 7381 7467 return hrc; 7382 7468 } -
trunk/src/VBox/Main/src-server/VirtualBoxImpl.cpp
r82968 r83169 1507 1507 ComObjPtr<CloudNetwork> *aNetwork) 1508 1508 { 1509 HRESULT rc = E_FAIL;1509 HRESULT rc = VBOX_E_OBJECT_NOT_FOUND; 1510 1510 ComPtr<CloudNetwork> found; 1511 1511 Bstr bstrNameToFind(aNetworkName); … … 1518 1518 { 1519 1519 Bstr bstrCloudNetworkName; 1520 rc = (*it)->COMGETTER(NetworkName)(bstrCloudNetworkName.asOutParam());1521 if (FAILED( rc)) returnrc;1520 HRESULT hrc = (*it)->COMGETTER(NetworkName)(bstrCloudNetworkName.asOutParam()); 1521 if (FAILED(hrc)) return hrc; 1522 1522 1523 1523 if (bstrCloudNetworkName == bstrNameToFind) … … 1617 1617 #endif /* !VBOX_WITH_CLOUD_NET */ 1618 1618 } 1619 1620 #ifdef VBOX_WITH_CLOUD_NET 1621 HRESULT VirtualBox::i_getEventSource(ComPtr<IEventSource>& aSource) 1622 { 1623 m->pEventSource.queryInterfaceTo(aSource.asOutParam()); 1624 return S_OK; 1625 } 1626 #endif /* VBOX_WITH_CLOUD_NET */ 1619 1627 1620 1628 HRESULT VirtualBox::getCloudProviderManager(ComPtr<ICloudProviderManager> &aCloudProviderManager)
Note:
See TracChangeset
for help on using the changeset viewer.