L2: add default L2 network offerings (#2683)

Adds default L2 network offerings. Adds check for existing default L2 networks.
This commit is contained in:
Nicolas Vazquez 2018-06-07 02:53:35 -03:00 committed by Rohit Yadav
parent 99ca81a676
commit 76367db8fb
5 changed files with 61 additions and 0 deletions

View File

@ -57,6 +57,10 @@ public interface NetworkOffering extends InfrastructureEntity, InternalIdentity,
public final static String DefaultIsolatedNetworkOfferingForVpcNetworks = "DefaultIsolatedNetworkOfferingForVpcNetworks";
public final static String DefaultIsolatedNetworkOfferingForVpcNetworksNoLB = "DefaultIsolatedNetworkOfferingForVpcNetworksNoLB";
public final static String DefaultIsolatedNetworkOfferingForVpcNetworksWithInternalLB = "DefaultIsolatedNetworkOfferingForVpcNetworksWithInternalLB";
public final static String DefaultL2NetworkOffering = "DefaultL2NetworkOffering";
public final static String DefaultL2NetworkOfferingVlan = "DefaultL2NetworkOfferingVlan";
public final static String DefaultL2NetworkOfferingConfigDrive = "DefaultL2NetworkOfferingConfigDrive";
public final static String DefaultL2NetworkOfferingConfigDriveVlan = "DefaultL2NetworkOfferingConfigDriveVlan";
/**
* @return name for the network offering.

View File

@ -561,6 +561,8 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
offering.setDedicatedLB(false);
_networkOfferingDao.update(offering.getId(), offering);
}
_networkOfferingDao.persistDefaultL2NetworkOfferings();
}
});

View File

@ -64,4 +64,9 @@ public interface NetworkOfferingDao extends GenericDao<NetworkOfferingVO, Long>
List<Long> listNetworkOfferingID();
boolean isUsingServicePackage(String uuid);
/**
* Create default L2 network offerings
*/
void persistDefaultL2NetworkOfferings();
}

View File

@ -23,6 +23,7 @@ import java.util.Map;
import javax.inject.Inject;
import javax.persistence.EntityExistsException;
import com.cloud.offerings.NetworkOfferingServiceMapVO;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Component;
@ -52,6 +53,8 @@ public class NetworkOfferingDaoImpl extends GenericDaoBase<NetworkOfferingVO, Lo
private final GenericSearchBuilder<NetworkOfferingVO, Long> UpgradeSearch;
@Inject
NetworkOfferingDetailsDao _detailsDao;
@Inject
private NetworkOfferingServiceMapDao networkOfferingServiceMapDao;
protected NetworkOfferingDaoImpl() {
super();
@ -221,4 +224,49 @@ public class NetworkOfferingDaoImpl extends GenericDaoBase<NetworkOfferingVO, Lo
return false;
}
/**
* Persist L2 deafult Network offering
*/
private void persistL2DefaultNetworkOffering(String name, String displayText, boolean specifyVlan, boolean configDriveEnabled) {
NetworkOfferingVO offering = new NetworkOfferingVO(name, displayText, TrafficType.Guest, false, specifyVlan,
null, null, true, Availability.Optional, null, Network.GuestType.L2,
true,false, false, false, false, false);
offering.setState(NetworkOffering.State.Enabled);
persistDefaultNetworkOffering(offering);
if (configDriveEnabled) {
NetworkOfferingServiceMapVO offService = new NetworkOfferingServiceMapVO(offering.getId(),
Network.Service.UserData, Network.Provider.ConfigDrive);
networkOfferingServiceMapDao.persist(offService);
}
}
/**
* Check for default L2 Network Offerings, create them if they are not already created
*/
private void checkPersistL2NetworkOffering(String name, String displayText, boolean specifyVlan, boolean configDriveEnabled) {
if (findByUniqueName(name) == null) {
persistL2DefaultNetworkOffering(name, displayText, specifyVlan, configDriveEnabled);
}
}
@Override
public void persistDefaultL2NetworkOfferings() {
checkPersistL2NetworkOffering(NetworkOffering.DefaultL2NetworkOffering,
"Offering for L2 networks",
false, false);
checkPersistL2NetworkOffering(NetworkOffering.DefaultL2NetworkOfferingVlan,
"Offering for L2 networks VLAN",
true, false);
checkPersistL2NetworkOffering(NetworkOffering.DefaultL2NetworkOfferingConfigDrive,
"Offering for L2 networks with config drive user data",
false, true);
checkPersistL2NetworkOffering(NetworkOffering.DefaultL2NetworkOfferingConfigDriveVlan,
"Offering for L2 networks with config drive user data VLAN",
true, true);
}
}

View File

@ -1175,6 +1175,8 @@ public class ConfigurationServerImpl extends ManagerBase implements Configuratio
_ntwkOfferingServiceMapDao.persist(offService);
s_logger.trace("Added service for the network offering: " + offService);
}
_networkOfferingDao.persistDefaultL2NetworkOfferings();
}
});
}