weizhouapache commented on a change in pull request #5977:
URL: https://github.com/apache/cloudstack/pull/5977#discussion_r810924538
##########
File path:
engine/storage/volume/src/main/java/org/apache/cloudstack/storage/datastore/provider/DefaultHostListener.java
##########
@@ -142,11 +192,63 @@ public boolean hostDisconnected(long hostId, long poolId)
{
@Override
public boolean hostAboutToBeRemoved(long hostId) {
+ // send host the cleanup persistent network resources
+ HostVO host = hostDao.findById(hostId);
+ if (host == null) {
+ s_logger.warn("Host with id " + hostId + " can't be found");
+ return false;
+ }
+
+ List<NetworkVO> allPersistentNetworks =
networkDao.getAllPersistentNetworksFromZone(host.getDataCenterId()); // find
zoneId of host
+ for (NetworkVO persistentNetworkVO : allPersistentNetworks) {
+ NetworkOfferingVO networkOfferingVO =
networkOfferingDao.findById(persistentNetworkVO.getNetworkOfferingId());
+ CleanupPersistentNetworkResourceCommand cleanupCmd =
+ new
CleanupPersistentNetworkResourceCommand(createNicTOFromNetworkAndOffering(persistentNetworkVO,
networkOfferingVO, host));
+ Answer answer = agentMgr.easySend(hostId, cleanupCmd);
+ if (answer == null) {
+ s_logger.error("Unable to get answer to the cleanup persistent
network command " + persistentNetworkVO.getId());
+ continue;
+ }
+ if (!answer.getResult()) {
+ String msg = String.format("Unable to cleanup persistent
network resources from network %d on the host %d", persistentNetworkVO.getId(),
hostId);
+ s_logger.error(msg);
Review comment:
minor issue: a space before `s_logger.error(msg);`
##########
File path:
engine/storage/volume/src/main/java/org/apache/cloudstack/storage/datastore/provider/DefaultHostListener.java
##########
@@ -62,12 +73,68 @@
StorageManager storageManager;
@Inject
StorageService storageService;
+ @Inject
+ NetworkOfferingDao networkOfferingDao;
+ @Inject
+ HostDao hostDao;
+ @Inject
+ NetworkModel networkModel;
+ @Inject
+ ConfigurationManager configManager;
+ @Inject
+ NetworkDao networkDao;
+
@Override
public boolean hostAdded(long hostId) {
return true;
}
+ private boolean createPersistentNetworkResourcesOnHost(long hostId) {
+ HostVO host = hostDao.findById(hostId);
+ if (host == null) {
+ s_logger.warn(String.format("Host with id %ld can't be found",
hostId));
+ return false;
+ }
+
+ List<NetworkVO> allPersistentNetworks =
networkDao.getAllPersistentNetworksFromZone(host.getDataCenterId());
+
+ for (NetworkVO networkVO : allPersistentNetworks) {
+ NetworkOfferingVO networkOfferingVO =
networkOfferingDao.findById(networkVO.getNetworkOfferingId());
+
+ SetupPersistentNetworkCommand persistentNetworkCommand =
+ new
SetupPersistentNetworkCommand(createNicTOFromNetworkAndOffering(networkVO,
networkOfferingVO, host));
+ Answer answer = agentMgr.easySend(hostId,
persistentNetworkCommand);
+ if (answer == null) {
+ throw new CloudRuntimeException("Unable to get answer to the
setup persistent network command " + networkVO.getId());
+ }
+ if (!answer.getResult()) {
+ String msg = String.format("Unable to create L2 persistent
network resources from network %ld on the host %ld in zone %ld",
networkVO.getId(), hostId, networkVO.getDataCenterId());
+ alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST,
networkVO.getDataCenterId(), host.getPodId(), msg, msg);
+ throw new CloudRuntimeException("Unable to create persistent
network resources from network " + networkVO.getId() +
+ " on " + hostId + " due to " + answer.getDetails());
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Creates a dummy NicTO object which is used by the respective
hypervisors to setup network elements / resources
+ * - bridges(KVM), VLANs(Xen) and portgroups(VMWare) for L2 network
+ */
+ private NicTO createNicTOFromNetworkAndOffering(NetworkVO networkVO,
NetworkOfferingVO networkOfferingVO, HostVO hostVO) {
+ NicTO to = new NicTO();
+ to.setName(networkModel.getNetworkTag(hostVO.getHypervisorType(),
networkVO));
+ to.setBroadcastType(networkVO.getBroadcastDomainType());
+ to.setType(networkVO.getTrafficType());
+ to.setBroadcastUri(networkVO.getBroadcastUri());
+ to.setIsolationuri(networkVO.getBroadcastUri());
+
to.setNetworkRateMbps(configManager.getNetworkOfferingNetworkRate(networkOfferingVO.getId(),
networkVO.getDataCenterId()));
+
to.setSecurityGroupEnabled(networkModel.isSecurityGroupSupportedInNetwork(networkVO));
+ return to;
Review comment:
in PR #5912, Hari added details to nicTO, is it needed here also ?
https://github.com/apache/cloudstack/pull/5912/files#diff-b048f92c96b32da16b08fa92eb30b7fe6d7be51f2e49bdc2579f985080a070e2R1191-R1212
##########
File path: engine/schema/src/main/java/com/cloud/network/dao/NetworkDaoImpl.java
##########
@@ -419,6 +419,16 @@ public int getOtherPersistentNetworksCount(long id, String
broadcastURI, boolean
return persistentNetworks.size();
}
+ @Override
+ public List<NetworkVO> getAllPersistentNetworksFromZone(long dataCenterId)
{
+ Object[] guestTypes = {"Isolated", "L2"};
Review comment:
@Pearl1594
oh thanks... stupid me. I thought it contains Shared and L2 ...
why exclude Shared networks ?
##########
File path:
engine/storage/volume/src/main/java/org/apache/cloudstack/storage/datastore/provider/DefaultHostListener.java
##########
@@ -142,11 +192,63 @@ public boolean hostDisconnected(long hostId, long poolId)
{
@Override
public boolean hostAboutToBeRemoved(long hostId) {
+ // send host the cleanup persistent network resources
+ HostVO host = hostDao.findById(hostId);
+ if (host == null) {
+ s_logger.warn("Host with id " + hostId + " can't be found");
+ return false;
+ }
+
+ List<NetworkVO> allPersistentNetworks =
networkDao.getAllPersistentNetworksFromZone(host.getDataCenterId()); // find
zoneId of host
+ for (NetworkVO persistentNetworkVO : allPersistentNetworks) {
+ NetworkOfferingVO networkOfferingVO =
networkOfferingDao.findById(persistentNetworkVO.getNetworkOfferingId());
+ CleanupPersistentNetworkResourceCommand cleanupCmd =
+ new
CleanupPersistentNetworkResourceCommand(createNicTOFromNetworkAndOffering(persistentNetworkVO,
networkOfferingVO, host));
+ Answer answer = agentMgr.easySend(hostId, cleanupCmd);
+ if (answer == null) {
+ s_logger.error("Unable to get answer to the cleanup persistent
network command " + persistentNetworkVO.getId());
+ continue;
+ }
+ if (!answer.getResult()) {
+ String msg = String.format("Unable to cleanup persistent
network resources from network %d on the host %d", persistentNetworkVO.getId(),
hostId);
+ s_logger.error(msg);
+ }
+ }
return true;
}
@Override
public boolean hostRemoved(long hostId, long clusterId) {
return true;
}
+
+ @Override
+ public boolean hostEnabled(long hostId) {
+ HostVO host = hostDao.findById(hostId);
+ if (host == null) {
+ s_logger.warn(String.format("Host with id %d can't be found",
hostId));
+ return false;
+ }
+ setupPersistentNetwork(host);
+ return true;
+ }
+
+ private void setupPersistentNetwork(HostVO host) {
Review comment:
I wonder if it is neccesary to create bridges, vlans on kvm hosts,
although it is not harmful.
from my understanding, persist L2/Isolated network means the vlan id will be
not released even if there is no vm running.
for vmware/xenserver, it might be useful.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]