Changeset 84618 in vbox for trunk/src/VBox/Main/src-server
- Timestamp:
- May 29, 2020 6:43:11 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-server/MachineImpl.cpp
r84395 r84618 50 50 #include "ExtPackManagerImpl.h" 51 51 #include "MachineLaunchVMCommonWorker.h" 52 #ifdef VBOX_WITH_CLOUD_NET53 #include "ApplianceImpl.h"54 #include "CloudGateway.h"55 #endif /* VBOX_WITH_CLOUD_NET */56 52 57 53 // generated header … … 3335 3331 if (SUCCEEDED(rc)) 3336 3332 { 3337 #ifdef VBOX_WITH_CLOUD_NET3338 i_connectToCloudNetwork(progress);3339 #endif /* VBOX_WITH_CLOUD_NET */3340 3341 3333 rc = i_launchVMProcess(control, strFrontend, aEnvironmentChanges, progress); 3342 3334 if (SUCCEEDED(rc)) … … 7308 7300 return (mUSBControllers->size() > 0); 7309 7301 } 7310 7311 #ifdef VBOX_WITH_CLOUD_NET7312 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 7360 HRESULT Machine::i_connectToCloudNetwork(ProgressProxy *aProgress)7361 {7362 LogFlowThisFuncEnter();7363 AssertReturn(aProgress, E_FAIL);7364 7365 HRESULT hrc = E_FAIL;7366 Bstr name;7367 int iSlot = -1;7368 7369 LogFlowThisFunc(("Checking if cloud network needs to be connected\n"));7370 for (int slot = 0; (unsigned)slot < mNetworkAdapters.size(); ++slot)7371 {7372 BOOL enabled;7373 hrc = mNetworkAdapters[slot]->COMGETTER(Enabled)(&enabled);7374 if ( FAILED(hrc)7375 || !enabled)7376 continue;7377 7378 NetworkAttachmentType_T type;7379 hrc = mNetworkAdapters[slot]->COMGETTER(AttachmentType)(&type);7380 if ( SUCCEEDED(hrc)7381 && type == NetworkAttachmentType_Cloud)7382 {7383 if (name.isNotEmpty())7384 {7385 LogRel(("OCI-NET: VM '%s' uses multiple cloud network attachments. '%ls' will be ignored.\n",7386 mUserData->s.strName.c_str(), name.raw()));7387 continue;7388 }7389 hrc = mNetworkAdapters[slot]->COMGETTER(CloudNetwork)(name.asOutParam());7390 if (SUCCEEDED(hrc))7391 {7392 LogRel(("OCI-NET: VM '%s' uses cloud network '%ls'\n",7393 mUserData->s.strName.c_str(), name.raw()));7394 iSlot = slot;7395 }7396 }7397 }7398 if (name.isNotEmpty())7399 {7400 LogFlowThisFunc(("Connecting to cloud network '%ls'...\n", name.raw()));7401 ComObjPtr<CloudNetwork> network;7402 hrc = mParent->i_findCloudNetworkByName(name, &network);7403 if (FAILED(hrc))7404 {7405 LogRel(("OCI-NET: Could not find cloud network '%ls'.\n", name.raw()));7406 return hrc;7407 }7408 Bstr MacAddress;7409 Utf8Str strMacAddress;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 else7421 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.c_str(), name.raw()));7427 return hrc;7428 }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();7434 if (SUCCEEDED(hrc))7435 {7436 if (iSlot == -1)7437 LogRel(("OCI-NET: No slot information available for cloud network attachment!\n"));7438 else7439 {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 else7445 LogRel(("OCI-NET: Failed to update MAC address for '%s' to %RTmac\n",7446 mUserData->s.strName.c_str(), &gateways.mCloudMacAddress));7447 }7448 }7449 }7450 else7451 LogFlowThisFunc(("VM '%s' has no cloud network attachments.\n", mUserData->s.strName.c_str()));7452 7453 LogFlowThisFuncLeave();7454 return hrc;7455 }7456 7457 HRESULT Machine::i_disconnectFromCloudNetwork()7458 {7459 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);7460 GatewayInfo gateways(mData->mGatewayInfo);7461 mData->mGatewayInfo.setNull();7462 alock.release();7463 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());7467 return hrc;7468 }7469 #endif /* VBOX_WITH_CLOUD_NET */7470 7302 7471 7303 … … 13264 13096 LogFlowThisFuncEnter(); 13265 13097 13266 #ifdef VBOX_WITH_CLOUD_NET13267 mPeer->i_disconnectFromCloudNetwork();13268 #endif /* VBOX_WITH_CLOUD_NET */13269 13270 13098 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 13271 13099
Note:
See TracChangeset
for help on using the changeset viewer.