1616// under the License.
1717package com .cloud .hypervisor .vmware .resource ;
1818
19+ import java .io .File ;
20+ import java .io .IOException ;
21+ import java .net .ConnectException ;
22+ import java .net .InetSocketAddress ;
23+ import java .net .URI ;
24+ import java .nio .channels .SocketChannel ;
25+ import java .rmi .RemoteException ;
26+ import java .util .ArrayList ;
27+ import java .util .Arrays ;
28+ import java .util .Collection ;
29+ import java .util .Collections ;
30+ import java .util .Comparator ;
31+ import java .util .Date ;
32+ import java .util .GregorianCalendar ;
33+ import java .util .HashMap ;
34+ import java .util .List ;
35+ import java .util .Map ;
36+ import java .util .Random ;
37+ import java .util .TimeZone ;
38+ import java .util .UUID ;
39+
40+ import javax .naming .ConfigurationException ;
41+
42+ import org .apache .log4j .Logger ;
43+ import org .apache .log4j .NDC ;
44+
1945import com .cloud .agent .IAgentControl ;
2046import com .cloud .agent .api .Answer ;
2147import com .cloud .agent .api .AttachIsoCommand ;
4773import com .cloud .agent .api .DeleteStoragePoolCommand ;
4874import com .cloud .agent .api .DeleteVMSnapshotAnswer ;
4975import com .cloud .agent .api .DeleteVMSnapshotCommand ;
50- import com .cloud .agent .api .UnregisterVMCommand ;
5176import com .cloud .agent .api .GetDomRVersionAnswer ;
5277import com .cloud .agent .api .GetDomRVersionCmd ;
5378import com .cloud .agent .api .GetHostStatsAnswer ;
78103import com .cloud .agent .api .PoolEjectCommand ;
79104import com .cloud .agent .api .PrepareForMigrationAnswer ;
80105import com .cloud .agent .api .PrepareForMigrationCommand ;
106+ import com .cloud .agent .api .PvlanSetupCommand ;
81107import com .cloud .agent .api .ReadyAnswer ;
82108import com .cloud .agent .api .ReadyCommand ;
83109import com .cloud .agent .api .RebootAnswer ;
84110import com .cloud .agent .api .RebootCommand ;
85111import com .cloud .agent .api .RebootRouterCommand ;
86112import com .cloud .agent .api .RevertToVMSnapshotAnswer ;
87113import com .cloud .agent .api .RevertToVMSnapshotCommand ;
88- import com .cloud .agent .api .ScaleVmCommand ;
89114import com .cloud .agent .api .ScaleVmAnswer ;
115+ import com .cloud .agent .api .ScaleVmCommand ;
90116import com .cloud .agent .api .SetupAnswer ;
91117import com .cloud .agent .api .SetupCommand ;
92118import com .cloud .agent .api .SetupGuestNetworkAnswer ;
101127import com .cloud .agent .api .StoragePoolInfo ;
102128import com .cloud .agent .api .UnPlugNicAnswer ;
103129import com .cloud .agent .api .UnPlugNicCommand ;
130+ import com .cloud .agent .api .UnregisterVMCommand ;
104131import com .cloud .agent .api .UpgradeSnapshotCommand ;
105132import com .cloud .agent .api .ValidateSnapshotAnswer ;
106133import com .cloud .agent .api .ValidateSnapshotCommand ;
135162import com .cloud .agent .api .routing .VpnUsersCfgCommand ;
136163import com .cloud .agent .api .storage .CopyVolumeAnswer ;
137164import com .cloud .agent .api .storage .CopyVolumeCommand ;
138- import com .cloud .agent .api .storage .CreateVolumeOVACommand ;
139- import com .cloud .agent .api .storage .CreateVolumeOVAAnswer ;
140- import com .cloud .agent .api .storage .PrepareOVAPackingAnswer ;
141- import com .cloud .agent .api .storage .PrepareOVAPackingCommand ;
142165import com .cloud .agent .api .storage .CreateAnswer ;
143166import com .cloud .agent .api .storage .CreateCommand ;
144167import com .cloud .agent .api .storage .CreatePrivateTemplateAnswer ;
168+ import com .cloud .agent .api .storage .CreateVolumeOVAAnswer ;
169+ import com .cloud .agent .api .storage .CreateVolumeOVACommand ;
145170import com .cloud .agent .api .storage .DestroyCommand ;
171+ import com .cloud .agent .api .storage .PrepareOVAPackingAnswer ;
172+ import com .cloud .agent .api .storage .PrepareOVAPackingCommand ;
146173import com .cloud .agent .api .storage .PrimaryStorageDownloadAnswer ;
147174import com .cloud .agent .api .storage .PrimaryStorageDownloadCommand ;
148175import com .cloud .agent .api .storage .ResizeVolumeAnswer ;
250277import com .vmware .vim25 .VirtualMachinePowerState ;
251278import com .vmware .vim25 .VirtualMachineRuntimeInfo ;
252279import com .vmware .vim25 .VirtualSCSISharing ;
253- import org .apache .log4j .Logger ;
254- import org .apache .log4j .NDC ;
255-
256- import javax .naming .ConfigurationException ;
257- import java .io .File ;
258- import java .io .IOException ;
259- import java .net .ConnectException ;
260- import java .net .InetSocketAddress ;
261- import java .net .URI ;
262- import java .nio .channels .SocketChannel ;
263- import java .rmi .RemoteException ;
264- import java .util .ArrayList ;
265- import java .util .Arrays ;
266- import java .util .Collection ;
267- import java .util .Collections ;
268- import java .util .Comparator ;
269- import java .util .Date ;
270- import java .util .GregorianCalendar ;
271- import java .util .HashMap ;
272- import java .util .List ;
273- import java .util .Map ;
274- import java .util .Random ;
275- import java .util .TimeZone ;
276- import java .util .UUID ;
277280
278281
279282public class VmwareResource implements StoragePoolResource , ServerResource , VmwareHostService {
@@ -495,6 +498,8 @@ public Answer executeRequest(Command cmd) {
495498 return execute ((UnregisterVMCommand ) cmd );
496499 } else if (clz == ScaleVmCommand .class ) {
497500 return execute ((ScaleVmCommand ) cmd );
501+ } else if (clz == PvlanSetupCommand .class ) {
502+ return execute ((PvlanSetupCommand ) cmd );
498503 } else {
499504 answer = Answer .createUnsupportedCommandAnswer (cmd );
500505 }
@@ -1037,7 +1042,7 @@ private SetupGuestNetworkAnswer execute(SetupGuestNetworkCommand cmd) {
10371042 String domrGIP = cmd .getAccessDetail (NetworkElementCommand .ROUTER_GUEST_IP );
10381043 String domrName = cmd .getAccessDetail (NetworkElementCommand .ROUTER_NAME );
10391044 String gw = cmd .getAccessDetail (NetworkElementCommand .GUEST_NETWORK_GATEWAY );
1040- String cidr = Long .toString (NetUtils .getCidrSize (nic .getNetmask ()));;
1045+ String cidr = Long .toString (NetUtils .getCidrSize (nic .getNetmask ()));
10411046 String domainName = cmd .getNetworkDomain ();
10421047 String dns = cmd .getDefaultDns1 ();
10431048 if (dns == null || dns .isEmpty ()) {
@@ -1376,7 +1381,7 @@ private PlugNicAnswer execute(PlugNicCommand cmd) {
13761381
13771382 NicTO nicTo = cmd .getNic ();
13781383 VirtualDevice nic ;
1379- Pair <ManagedObjectReference , String > networkInfo = prepareNetworkFromNicInfo (vmMo .getRunningHost (), nicTo , false ) ;
1384+ Pair <ManagedObjectReference , String > networkInfo = prepareNetworkFromNicInfo (vmMo .getRunningHost (), nicTo , false , cmd . getVMType ()); ;
13801385 if (VmwareHelper .isDvPortGroup (networkInfo .first ())) {
13811386 String dvSwitchUuid ;
13821387 ManagedObjectReference dcMor = hyperHost .getHyperHostDatacenter ();
@@ -1643,7 +1648,7 @@ private void plugPublicNic(VirtualMachineMO vmMo, final String vlanId, final Str
16431648 vmMo .getRunningHost (), vlanId , null , null , this ._ops_timeout , true );
16441649 } else {
16451650 networkInfo = HypervisorHostHelper .prepareNetwork (this ._publicTrafficInfo .getVirtualSwitchName (), "cloud.public" ,
1646- vmMo .getRunningHost (), vlanId , null , null , this ._ops_timeout , vSwitchType , _portsPerDvPortGroup , null , false );
1651+ vmMo .getRunningHost (), vlanId , null , null , null , this ._ops_timeout , vSwitchType , _portsPerDvPortGroup , null , false );
16471652 }
16481653
16491654 int nicIndex = allocPublicNicIndex (vmMo );
@@ -2537,7 +2542,8 @@ protected StartAnswer execute(StartCommand cmd) {
25372542 s_logger .info ("Prepare NIC device based on NicTO: " + _gson .toJson (nicTo ));
25382543
25392544 boolean configureVServiceInNexus = (nicTo .getType () == TrafficType .Guest ) && (vmSpec .getDetails ().containsKey ("ConfigureVServiceInNexus" ));
2540- Pair <ManagedObjectReference , String > networkInfo = prepareNetworkFromNicInfo (vmMo .getRunningHost (), nicTo , configureVServiceInNexus );
2545+ VirtualMachine .Type vmType = cmd .getVirtualMachine ().getType ();
2546+ Pair <ManagedObjectReference , String > networkInfo = prepareNetworkFromNicInfo (vmMo .getRunningHost (), nicTo , configureVServiceInNexus , vmType );
25412547 if (VmwareHelper .isDvPortGroup (networkInfo .first ())) {
25422548 String dvSwitchUuid ;
25432549 ManagedObjectReference dcMor = hyperHost .getHyperHostDatacenter ();
@@ -2719,16 +2725,28 @@ private HashMap<String, Pair<ManagedObjectReference, DatastoreMO>> inferDatastor
27192725 return poolMors ;
27202726 }
27212727
2728+
2729+ private String getPvlanInfo (NicTO nicTo ) {
2730+ if (nicTo .getBroadcastType () == BroadcastDomainType .Pvlan ) {
2731+ return NetUtils .getIsolatedPvlanFromUri (nicTo .getBroadcastUri ());
2732+ }
2733+ return null ;
2734+ }
2735+
27222736 private String getVlanInfo (NicTO nicTo , String defaultVlan ) {
27232737 if (nicTo .getBroadcastType () == BroadcastDomainType .Native ) {
27242738 return defaultVlan ;
27252739 }
2726-
2727- if (nicTo .getBroadcastType () == BroadcastDomainType .Vlan ) {
2740+ if (nicTo .getBroadcastType () == BroadcastDomainType .Vlan || nicTo .getBroadcastType () == BroadcastDomainType .Pvlan ) {
27282741 if (nicTo .getBroadcastUri () != null ) {
2742+ if (nicTo .getBroadcastType () == BroadcastDomainType .Vlan )
2743+ // For vlan, the broadcast uri is of the form vlan://<vlanid>
27292744 return nicTo .getBroadcastUri ().getHost ();
2745+ else
2746+ // for pvlan, the broacast uri will be of the form pvlan://<vlanid>-i<pvlanid>
2747+ return NetUtils .getPrimaryPvlanFromUri (nicTo .getBroadcastUri ());
27302748 } else {
2731- s_logger .warn ("BroadcastType is not claimed as VLAN, but without vlan info in broadcast URI. Use vlan info from labeling: " + defaultVlan );
2749+ s_logger .warn ("BroadcastType is not claimed as VLAN or PVLAN , but without vlan info in broadcast URI. Use vlan info from labeling: " + defaultVlan );
27322750 return defaultVlan ;
27332751 }
27342752 }
@@ -2737,7 +2755,7 @@ private String getVlanInfo(NicTO nicTo, String defaultVlan) {
27372755 return defaultVlan ;
27382756 }
27392757
2740- private Pair <ManagedObjectReference , String > prepareNetworkFromNicInfo (HostMO hostMo , NicTO nicTo , boolean configureVServiceInNexus ) throws Exception {
2758+ private Pair <ManagedObjectReference , String > prepareNetworkFromNicInfo (HostMO hostMo , NicTO nicTo , boolean configureVServiceInNexus , VirtualMachine . Type vmType ) throws Exception {
27412759 Pair <String , String > switchName ;
27422760 TrafficType trafficType ;
27432761 VirtualSwitchType switchType ;
@@ -2761,12 +2779,22 @@ private Pair<ManagedObjectReference, String> prepareNetworkFromNicInfo(HostMO ho
27612779 s_logger .info ("Prepare network on " + switchType + " " + switchName + " with name prefix: " + namePrefix );
27622780
27632781 if (VirtualSwitchType .StandardVirtualSwitch == switchType ) {
2764- networkInfo = HypervisorHostHelper .prepareNetwork (switchName .first (), namePrefix , hostMo , getVlanInfo ( nicTo , switchName . second ()),
2765- nicTo .getNetworkRateMbps (), nicTo .getNetworkRateMulticastMbps (), _ops_timeout ,
2782+ networkInfo = HypervisorHostHelper .prepareNetwork (switchName .first (), namePrefix ,
2783+ hostMo , getVlanInfo ( nicTo , switchName . second ()), nicTo .getNetworkRateMbps (), nicTo .getNetworkRateMulticastMbps (), _ops_timeout ,
27662784 !namePrefix .startsWith ("cloud.private" ));
27672785 }
27682786 else {
2769- networkInfo = HypervisorHostHelper .prepareNetwork (switchName .first (), namePrefix , hostMo , getVlanInfo (nicTo , switchName .second ()),
2787+ String vlanId = getVlanInfo (nicTo , switchName .second ());
2788+ String svlanId = null ;
2789+ boolean pvlannetwork = (getPvlanInfo (nicTo ) == null )?false :true ;
2790+ if (vmType != null && vmType .equals (VirtualMachine .Type .DomainRouter ) && pvlannetwork ) {
2791+ // plumb this network to the promiscuous vlan.
2792+ svlanId = vlanId ;
2793+ } else {
2794+ // plumb this network to the isolated vlan.
2795+ svlanId = getPvlanInfo (nicTo );
2796+ }
2797+ networkInfo = HypervisorHostHelper .prepareNetwork (switchName .first (), namePrefix , hostMo , vlanId , svlanId ,
27702798 nicTo .getNetworkRateMbps (), nicTo .getNetworkRateMulticastMbps (), _ops_timeout , switchType , _portsPerDvPortGroup , nicTo .getGateway (), configureVServiceInNexus );
27712799 }
27722800
@@ -3253,7 +3281,7 @@ protected Answer execute(PrepareForMigrationCommand cmd) {
32533281 NicTO [] nics = vm .getNics ();
32543282 for (NicTO nic : nics ) {
32553283 // prepare network on the host
3256- prepareNetworkFromNicInfo (new HostMO (getServiceContext (), _morHyperHost ), nic , false );
3284+ prepareNetworkFromNicInfo (new HostMO (getServiceContext (), _morHyperHost ), nic , false , cmd . getVirtualMachine (). getType () );
32573285 }
32583286
32593287 String secStoreUrl = mgr .getSecondaryStorageStoreUrl (Long .parseLong (_dcId ));
@@ -3917,6 +3945,14 @@ public PrimaryStorageDownloadAnswer execute(PrimaryStorageDownloadCommand cmd) {
39173945 }
39183946 }
39193947
3948+ protected Answer execute (PvlanSetupCommand cmd ) {
3949+ // Pvlan related operations are performed in the start/stop command paths
3950+ // for vmware. This function is implemented to support mgmt layer code
3951+ // that issue this command. Note that pvlan operations are supported only
3952+ // in Distributed Virtual Switch environments for vmware deployments.
3953+ return new Answer (cmd , true , "success" );
3954+ }
3955+
39203956 protected Answer execute (UnregisterVMCommand cmd ){
39213957 if (s_logger .isInfoEnabled ()) {
39223958 s_logger .info ("Executing resource UnregisterVMCommand: " + _gson .toJson (cmd ));
@@ -4134,6 +4170,7 @@ public CopyVolumeAnswer execute(CopyVolumeCommand cmd) {
41344170 }
41354171 }
41364172
4173+ @ Override
41374174 public CreateVolumeOVAAnswer execute (CreateVolumeOVACommand cmd ) {
41384175 if (s_logger .isInfoEnabled ()) {
41394176 s_logger .info ("Executing resource CreateVolumeOVACommand: " + _gson .toJson (cmd ));
0 commit comments