-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Synchronization of network devices on newly added hosts for Persistent Networks #5977
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
93ecc87
55e5934
9a9d042
aa678bb
d80623b
aec13dd
0e522fb
03c2b7d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,10 +20,21 @@ | |
|
|
||
| import com.cloud.agent.AgentManager; | ||
| import com.cloud.agent.api.Answer; | ||
| import com.cloud.agent.api.CleanupPersistentNetworkResourceCommand; | ||
| import com.cloud.agent.api.ModifyStoragePoolAnswer; | ||
| import com.cloud.agent.api.ModifyStoragePoolCommand; | ||
| import com.cloud.agent.api.SetupPersistentNetworkCommand; | ||
| import com.cloud.agent.api.to.NicTO; | ||
| import com.cloud.alert.AlertManager; | ||
| import com.cloud.configuration.ConfigurationManager; | ||
| import com.cloud.exception.StorageConflictException; | ||
| import com.cloud.host.HostVO; | ||
| import com.cloud.host.dao.HostDao; | ||
| import com.cloud.network.NetworkModel; | ||
| import com.cloud.network.dao.NetworkDao; | ||
| import com.cloud.network.dao.NetworkVO; | ||
| import com.cloud.offerings.NetworkOfferingVO; | ||
| import com.cloud.offerings.dao.NetworkOfferingDao; | ||
| import com.cloud.storage.DataStoreRole; | ||
| import com.cloud.storage.Storage; | ||
| import com.cloud.storage.StorageManager; | ||
|
|
@@ -62,12 +73,50 @@ public class DefaultHostListener implements HypervisorHostListener { | |
| 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; | ||
| } | ||
| setupPersistentNetwork(host); | ||
| 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; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in PR #5912, Hari added details to nicTO, is it needed here also ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it is required @weizhouapache
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Pearl1594 ok to me. |
||
| } | ||
|
|
||
|
|
||
| @Override | ||
| public boolean hostConnect(long hostId, long poolId) throws StorageConflictException { | ||
| StoragePool pool = (StoragePool) this.dataStoreMgr.getDataStore(poolId, DataStoreRole.Primary); | ||
|
|
@@ -109,7 +158,8 @@ public boolean hostConnect(long hostId, long poolId) throws StorageConflictExcep | |
| storageService.updateStorageCapabilities(poolId, false); | ||
|
|
||
| s_logger.info("Connection established between storage pool " + pool + " and host " + hostId); | ||
| return true; | ||
|
|
||
| return createPersistentNetworkResourcesOnHost(hostId); | ||
| } | ||
|
|
||
| private void updateStoragePoolHostVOAndDetails(StoragePool pool, long hostId, ModifyStoragePoolAnswer mspAnswer) { | ||
|
|
@@ -124,7 +174,7 @@ private void updateStoragePoolHostVOAndDetails(StoragePool pool, long hostId, Mo | |
| StoragePoolVO poolVO = this.primaryStoreDao.findById(pool.getId()); | ||
| poolVO.setUsedBytes(mspAnswer.getPoolInfo().getCapacityBytes() - mspAnswer.getPoolInfo().getAvailableBytes()); | ||
| poolVO.setCapacityBytes(mspAnswer.getPoolInfo().getCapacityBytes()); | ||
| if(StringUtils.isNotEmpty(mspAnswer.getPoolType())) { | ||
| if (StringUtils.isNotEmpty(mspAnswer.getPoolType())) { | ||
| StoragePoolDetailVO poolType = storagePoolDetailsDao.findDetail(pool.getId(), "pool_type"); | ||
| if (poolType == null) { | ||
| StoragePoolDetailVO storagePoolDetailVO = new StoragePoolDetailVO(pool.getId(), "pool_type", mspAnswer.getPoolType(), false); | ||
|
|
@@ -142,11 +192,62 @@ 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); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @Pearl1594 - @NuxRo found there is an issue when the host is on maintenance, the command cannot be sent and the resources are not removed, can you please check? Could verify it works using the deleteHost API passing forced=true |
||
| 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) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if it is neccesary to create bridges, vlans on kvm hosts, although it is not harmful.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Pearl1594
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, we had persistent networks in ACS - and by definition, these networks are meant to be setup at the time of network created across all hosts. However, while the definition in the docs said that, it didn't actually behave that way. So when a new host is added no bridge/vlan/port-group of the existing persistent network is present. So the idea of this enhancement, is to setup network on the new hosts or when disable hosts are enabled to stay true to the definition of Persistent networks as per docs.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Pearl1594 The only thing different from what I understand is I do not see the benifit to have permanent linux bridges but without any vm on kvm hosts. in my understanding, |
||
| 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(host.getId(), 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 persistent network resources for network %d on the host %d in zone %d", networkVO.getId(), host.getId(), networkVO.getDataCenterId()); | ||
| s_logger.error(msg); | ||
| } | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Pearl1594
cannot Isolated network be persistent ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
they can @weizhouapache hence Isolated & l2 are included in the search criteria
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Pearl1594
oh thanks... stupid me. I thought it contains Shared and L2 ...
why exclude Shared networks ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We dont have a concept of Persistent shared networks currently @weizhouapache
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Pearl1594 ok.