2121import java .net .URI ;
2222import java .util .List ;
2323
24- import javax .inject .Inject ;
2524import javax .ejb .Local ;
25+ import javax .inject .Inject ;
2626
2727import net .juniper .contrail .api .types .MacAddressesType ;
2828import net .juniper .contrail .api .types .VirtualMachineInterface ;
3434import org .apache .cloudstack .network .contrail .model .VirtualMachineModel ;
3535import org .apache .cloudstack .network .contrail .model .VirtualNetworkModel ;
3636
37+ import com .cloud .dc .DataCenter ;
38+ import com .cloud .dc .DataCenter .NetworkType ;
39+ import com .cloud .dc .dao .DataCenterDao ;
3740import com .cloud .deploy .DeployDestination ;
3841import com .cloud .deploy .DeploymentPlan ;
3942import com .cloud .exception .ConcurrentOperationException ;
4043import com .cloud .exception .InsufficientAddressCapacityException ;
4144import com .cloud .exception .InsufficientVirtualNetworkCapcityException ;
42- import com .cloud .dc .DataCenter ;
43- import com .cloud .dc .DataCenter .NetworkType ;
44- import com .cloud .dc .dao .DataCenterDao ;
45+ import com .cloud .network .IpAddressManager ;
4546import com .cloud .network .Network ;
4647import com .cloud .network .Network .State ;
4748import com .cloud .network .NetworkProfile ;
4849import com .cloud .network .Networks .AddressFormat ;
4950import com .cloud .network .Networks .BroadcastDomainType ;
5051import com .cloud .network .Networks .Mode ;
5152import com .cloud .network .Networks .TrafficType ;
53+ import com .cloud .network .PhysicalNetwork ;
54+ import com .cloud .network .addr .PublicIp ;
55+ import com .cloud .network .dao .IPAddressDao ;
56+ import com .cloud .network .dao .IPAddressVO ;
5257import com .cloud .network .dao .NetworkDao ;
5358import com .cloud .network .dao .NetworkVO ;
54- import com .cloud .network .guru .NetworkGuru ;
55- import com .cloud .network .PhysicalNetwork ;
5659import com .cloud .network .dao .PhysicalNetworkDao ;
5760import com .cloud .network .dao .PhysicalNetworkVO ;
58- import com .cloud .network .dao .IPAddressVO ;
59- import com .cloud .network .addr .PublicIp ;
61+ import com .cloud .network .guru .NetworkGuru ;
6062import com .cloud .offering .NetworkOffering ;
6163import com .cloud .user .Account ;
64+ import com .cloud .user .AccountManager ;
6265import com .cloud .utils .component .AdapterBase ;
6366import com .cloud .utils .exception .CloudRuntimeException ;
6467import com .cloud .utils .net .NetUtils ;
6568import com .cloud .vm .Nic .ReservationStrategy ;
6669import com .cloud .vm .NicProfile ;
6770import com .cloud .vm .NicVO ;
68- import com .cloud .network .dao .IPAddressDao ;
69- import com .cloud .user .AccountManager ;
70- import com .cloud .network .IpAddressManager ;
7171import com .cloud .vm .ReservationContext ;
7272import com .cloud .vm .VMInstanceVO ;
7373import com .cloud .vm .VirtualMachineProfile ;
@@ -96,6 +96,16 @@ public class ContrailGuru extends AdapterBase implements NetworkGuru {
9696 private static final TrafficType [] TrafficTypes = {TrafficType .Guest };
9797
9898 private boolean canHandle (NetworkOffering offering , NetworkType networkType , PhysicalNetwork physicalNetwork ) {
99+ if (physicalNetwork == null ) {
100+ // Physical network can be false for system network during initial setup of CloudStack
101+ return false ;
102+ }
103+
104+ if (_manager .getRouterOffering () == null || _manager .getVpcRouterOffering () == null ) {
105+ // FIXME The resource is apparently not configured, we need another way to check this.
106+ return false ;
107+ }
108+
99109 if (networkType == NetworkType .Advanced
100110 && (offering .getId () == _manager .getRouterOffering ().getId () || offering .getId () == _manager .getVpcRouterOffering ().getId ())
101111 && isMyTrafficType (offering .getTrafficType ())
@@ -121,8 +131,8 @@ public Network design(NetworkOffering offering, DeploymentPlan plan, Network use
121131 return null ;
122132 }
123133 NetworkVO network =
124- new NetworkVO (offering .getTrafficType (), Mode .Dhcp , BroadcastDomainType .Lswitch , offering .getId (), State .Allocated , plan .getDataCenterId (),
125- plan .getPhysicalNetworkId ());
134+ new NetworkVO (offering .getTrafficType (), Mode .Dhcp , BroadcastDomainType .Lswitch , offering .getId (), State .Allocated , plan .getDataCenterId (),
135+ plan .getPhysicalNetworkId ());
126136 if (userSpecified .getCidr () != null ) {
127137 network .setCidr (userSpecified .getCidr ());
128138 network .setGateway (userSpecified .getGateway ());
@@ -133,7 +143,7 @@ public Network design(NetworkOffering offering, DeploymentPlan plan, Network use
133143
134144 @ Override
135145 public Network implement (Network network , NetworkOffering offering , DeployDestination destination , ReservationContext context )
136- throws InsufficientVirtualNetworkCapcityException {
146+ throws InsufficientVirtualNetworkCapcityException {
137147 s_logger .debug ("Implement network: " + network .getName () + ", traffic type: " + network .getTrafficType ());
138148
139149 VirtualNetworkModel vnModel = _manager .getDatabase ().lookupVirtualNetwork (network .getUuid (), _manager .getCanonicalName (network ), network .getTrafficType ());
@@ -180,7 +190,7 @@ public Network implement(Network network, NetworkOffering offering, DeployDestin
180190 */
181191 @ Override
182192 public NicProfile allocate (Network network , NicProfile profile , VirtualMachineProfile vm ) throws InsufficientVirtualNetworkCapcityException ,
183- InsufficientAddressCapacityException , ConcurrentOperationException {
193+ InsufficientAddressCapacityException , ConcurrentOperationException {
184194 s_logger .debug ("allocate NicProfile on " + network .getName ());
185195
186196 if (profile != null && profile .getRequestedIpv4 () != null ) {
@@ -207,7 +217,7 @@ public NicProfile allocate(Network network, NicProfile profile, VirtualMachinePr
207217 */
208218 @ Override
209219 public void reserve (NicProfile nic , Network network , VirtualMachineProfile vm , DeployDestination dest , ReservationContext context )
210- throws InsufficientVirtualNetworkCapcityException , InsufficientAddressCapacityException , ConcurrentOperationException {
220+ throws InsufficientVirtualNetworkCapcityException , InsufficientAddressCapacityException , ConcurrentOperationException {
211221 s_logger .debug ("reserve NicProfile on network id: " + network .getId () + " " + network .getName ());
212222 s_logger .debug ("deviceId: " + nic .getDeviceId ());
213223
0 commit comments