/** * 初始化IP,将IP的状态设置为未使用状态,关联的HostServer设置为null. 如果IP不存在数据库中,则返回null值. * * @param ipAddress * @return */ public IpPool initIpPool(String ipAddress) { IpPool ipPool = ipPoolDao.findByIpAddress(ipAddress); if (ipPool != null) { ipPool.setStatus(IpPoolConstant.IpStatus.未使用.toInteger()); ipPool.setHostServer(null); return this.saveOrUpdate(ipPool); } return null; }
@Transactional(readOnly = false) public void updateIpPoolByIpAddress(String ipAddress, Integer status, HostServer hostServer) { // TODO 待优化,最终目标是删除此方法. IpPool ipPool = ipPoolDao.findByIpAddress(ipAddress); if (ipPool != null) { ipPool.setStatus(status); ipPool.setHostServer(hostServer); ipPoolDao.save(ipPool); } }
/** * 保存单个IP * * @param ipAddress * @param poolType * @param ipStatus * @param vlan * @param hostServer * @return */ @Transactional(readOnly = false) public boolean saveIpPool( String ipAddress, Integer poolType, Integer ipStatus, Vlan vlan, HostServer hostServer) { // TODO 待优化,最终目标是删除此方法. IpPool ipPool = new IpPool(poolType, vlan, ipAddress, ipStatus, new Date()); ipPool.setHostServer(hostServer); this.saveOrUpdate(ipPool); return true; }
/** * 返回类型为String的所有IpAddress List * * @return */ private List<String> getAllIpAddress() { List<IpPool> ipPools = (List<IpPool>) ipPoolDao.findAll(); List<String> list = new ArrayList<String>(); for (IpPool ipPool : ipPools) { list.add(ipPool.getIpAddress()); } return list; }
/** * 保存IP * * @param ipPool */ @Transactional(readOnly = false) public void saveIpPool(IpPool ipPool) { // 同步至oneCMDB List<IpPool> ipPools = new ArrayList<IpPool>(); ipPools.add(ipPool); comm.oneCmdbUtilService.saveIpPoolToOneCMDB(ipPools, ipPool.getPoolType()); ipPoolDao.save(ipPool); }