156156import com .cloud .hypervisor .vmware .mo .DiskControllerType ;
157157import com .cloud .hypervisor .vmware .mo .HostFirewallSystemMO ;
158158import com .cloud .hypervisor .vmware .mo .HostMO ;
159- import com .cloud .hypervisor .vmware .mo .HostVirtualNicType ;
160159import com .cloud .hypervisor .vmware .mo .HypervisorHostHelper ;
161160import com .cloud .hypervisor .vmware .mo .NetworkDetails ;
162161import com .cloud .hypervisor .vmware .mo .VirtualEthernetCardType ;
@@ -1445,35 +1444,39 @@ protected StartAnswer execute(StartCommand cmd) {
14451444 if (vol .getType () != Volume .Type .ISO ) {
14461445 Pair <ManagedObjectReference , DatastoreMO > volumeDsDetails = dataStoresDetails .get (vol .getPoolUuid ());
14471446 assert (volumeDsDetails != null );
1448- VirtualDevice device ;
1449- datastoreDiskPath = String .format ("[%s] %s.vmdk" , volumeDsDetails .second ().getName (), vol .getPath ());
1450- String chainInfo = vol .getChainInfo ();
1451-
1452- if (chainInfo != null && !chainInfo .isEmpty ()) {
1453- String [] diskChain = _gson .fromJson (chainInfo , String [].class );
1454- if (diskChain == null || diskChain .length < 1 ) {
1455- s_logger .warn ("Empty previously-saved chain info, fall back to the original" );
1456- device = VmwareHelper .prepareDiskDevice (vmMo , controllerKey , new String [] { datastoreDiskPath }, volumeDsDetails .first (), i , i + 1 );
1457- } else {
1458- s_logger .info ("Attach the disk with stored chain info: " + chainInfo );
1459- for (int j = 0 ; j < diskChain .length ; j ++) {
1460- diskChain [j ] = String .format ("[%s] %s" , volumeDsDetails .second ().getName (), diskChain [j ]);
1461- }
1447+ VirtualDevice device ;
1448+ datastoreDiskPath = String .format ("[%s] %s.vmdk" , volumeDsDetails .second ().getName (), vol .getPath ());
1449+ String chainInfo = vol .getChainInfo ();
1450+
1451+ if (chainInfo != null && !chainInfo .isEmpty ()) {
1452+ String [] diskChain = _gson .fromJson (chainInfo , String [].class );
1453+ if (diskChain == null || diskChain .length < 1 ) {
1454+ s_logger .warn ("Empty previously-saved chain info, fall back to the original" );
1455+ device = VmwareHelper .prepareDiskDevice (vmMo , controllerKey , new String [] { datastoreDiskPath }, volumeDsDetails .first (), i , i + 1 );
1456+ } else {
1457+ s_logger .info ("Attach the disk with stored chain info: " + chainInfo );
1458+ for (int j = 0 ; j < diskChain .length ; j ++) {
1459+ diskChain [j ] = String .format ("[%s] %s" , volumeDsDetails .second ().getName (), diskChain [j ]);
1460+ }
1461+
1462+ device = VmwareHelper .prepareDiskDevice (vmMo , controllerKey , diskChain , volumeDsDetails .first (), i , i + 1 );
1463+ }
1464+ } else {
1465+ device = VmwareHelper .prepareDiskDevice (vmMo , controllerKey , new String [] { datastoreDiskPath }, volumeDsDetails .first (), i , i + 1 );
1466+ }
1467+ deviceConfigSpecArray [i ].setDevice (device );
1468+ deviceConfigSpecArray [i ].setOperation (VirtualDeviceConfigSpecOperation .add );
1469+
1470+ if (s_logger .isDebugEnabled ())
1471+ s_logger .debug ("Prepare volume at new device " + _gson .toJson (device ));
1472+
1473+ i ++;
1474+ }
1475+ }
14621476
1463- device = VmwareHelper .prepareDiskDevice (vmMo , controllerKey , diskChain , volumeDsDetails .first (), i , i + 1 );
1464- }
1465- } else {
1466- device = VmwareHelper .prepareDiskDevice (vmMo , controllerKey , new String [] { datastoreDiskPath }, volumeDsDetails .first (), i , i + 1 );
1467- }
1468- deviceConfigSpecArray [i ].setDevice (device );
1469- deviceConfigSpecArray [i ].setOperation (VirtualDeviceConfigSpecOperation .add );
1470-
1471- if (s_logger .isDebugEnabled ())
1472- s_logger .debug ("Prepare volume at new device " + _gson .toJson (device ));
1473-
1474- i ++;
1475- }
1476- }
1477+ String switchUuid ;
1478+ ManagedObjectReference dcMor = hyperHost .getHyperHostDatacenter ();
1479+ DatacenterMO dataCenterMo = new DatacenterMO (context , dcMor );
14771480
14781481 VirtualDevice nic ;
14791482 int nicMask = 0 ;
@@ -1482,13 +1485,17 @@ protected StartAnswer execute(StartCommand cmd) {
14821485 s_logger .info ("Prepare NIC device based on NicTO: " + _gson .toJson (nicTo ));
14831486
14841487 Pair <ManagedObjectReference , String > networkInfo = prepareNetworkFromNicInfo (vmMo .getRunningHost (), nicTo );
1485-
1486- nic = VmwareHelper .prepareNicDevice (vmMo , networkInfo .first (), nicDeviceType , networkInfo .second (), nicTo .getMac (), i , i + 1 , true , true );
1487- deviceConfigSpecArray [i ] = new VirtualDeviceConfigSpec ();
1488- deviceConfigSpecArray [i ].setDevice (nic );
1489- deviceConfigSpecArray [i ].setOperation (VirtualDeviceConfigSpecOperation .add );
1490-
1491- if (s_logger .isDebugEnabled ())
1488+
1489+ ManagedObjectReference dvsMor = dataCenterMo .getDvSwitchMor (networkInfo .first ());
1490+ switchUuid = dataCenterMo .getDvSwitchUuid (dvsMor );
1491+ s_logger .info ("Preparing NIC device on dvSwitch : " + switchUuid );
1492+
1493+ nic = VmwareHelper .prepareNicDevice (vmMo , networkInfo .first (), nicDeviceType , networkInfo .second (), nicTo .getMac (), i , i + 1 , true , true );
1494+ deviceConfigSpecArray [i ] = new VirtualDeviceConfigSpec ();
1495+ deviceConfigSpecArray [i ].setDevice (nic );
1496+ deviceConfigSpecArray [i ].setOperation (VirtualDeviceConfigSpecOperation .add );
1497+
1498+ if (s_logger .isDebugEnabled ())
14921499 s_logger .debug ("Prepare NIC at new device " + _gson .toJson (deviceConfigSpecArray [i ]));
14931500
14941501 // this is really a hacking for DomR, upon DomR startup, we will reset all the NIC allocation after eth3
@@ -4022,16 +4029,25 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
40224029 cfmMo .ensureCustomFieldDef ("Network" , CustomFieldConstants .CLOUD_GC );
40234030 cfmMo .ensureCustomFieldDef ("VirtualMachine" , CustomFieldConstants .CLOUD_UUID );
40244031 cfmMo .ensureCustomFieldDef ("VirtualMachine" , CustomFieldConstants .CLOUD_NIC_MASK );
4025-
4026- VmwareHypervisorHost hostMo = this .getHyperHost (context );
4032+
4033+ VmwareHypervisorHost hostMo = this .getHyperHost (context );
40274034 _hostName = hostMo .getHyperHostName ();
4028- } catch (Exception e ) {
4029- s_logger .error ("Unexpected Exception " , e );
4035+ _privateNetworkVSwitchName = mgr .getPrivateVSwitchName (Long .parseLong (_dcId ), HypervisorType .VMware );
4036+ _publicNetworkVSwitchName = mgr .getPublicVSwitchName (Long .parseLong (_dcId ), HypervisorType .VMware );
4037+ _guestNetworkVSwitchName = mgr .getGuestVSwitchName (Long .parseLong (_dcId ), HypervisorType .VMware );
4038+ } catch (Exception e ) {
4039+ s_logger .error ("Unexpected Exception " , e );
4040+ }
4041+
4042+ if (_privateNetworkVSwitchName == null ) {
4043+ _privateNetworkVSwitchName = (String ) params .get ("private.network.vswitch.name" );
4044+ }
4045+ if (_publicNetworkVSwitchName == null ) {
4046+ _publicNetworkVSwitchName = (String ) params .get ("public.network.vswitch.name" );
4047+ }
4048+ if (_guestNetworkVSwitchName == null ) {
4049+ _guestNetworkVSwitchName = (String ) params .get ("guest.network.vswitch.name" );
40304050 }
4031-
4032- _privateNetworkVSwitchName = (String ) params .get ("private.network.vswitch.name" );
4033- _publicNetworkVSwitchName = (String ) params .get ("public.network.vswitch.name" );
4034- _guestNetworkVSwitchName = (String ) params .get ("guest.network.vswitch.name" );
40354051
40364052 String value = (String ) params .get ("cpu.overprovisioning.factor" );
40374053 if (value != null )
0 commit comments