Pearl1594 commented on a change in pull request #5977:
URL: https://github.com/apache/cloudstack/pull/5977#discussion_r812858617



##########
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:
       I don't think it is required @weizhouapache 




-- 
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]


Reply via email to