private void validate(APICreateEipMsg msg) {
VipVO vip = dbf.findByUuid(msg.getVipUuid(), VipVO.class);
if (vip.getUseFor() != null) {
VipUseForList useForList = new VipUseForList(vip.getUseFor());
if(!useForList.validateNewAdded(EipConstant.EIP_NETWORK_SERVICE_TYPE)) {
throw new ApiMessageInterceptionException(operr("vip[uuid:%s] has been occupied other network service entity[%s]", msg.getVipUuid(), vip.getUseFor()));
}
}
if (vip.getState() != VipState.Enabled) {
throw new ApiMessageInterceptionException(operr("vip[uuid:%s] is not in state[%s], current state is %s", msg.getVipUuid(), VipState.Enabled, vip.getState()));
}
if (msg.getVmNicUuid() != null) {
SimpleQuery<VmNicVO> nicq = dbf.createQuery(VmNicVO.class);
nicq.add(VmNicVO_.uuid, Op.EQ, msg.getVmNicUuid());
VmNicVO nic = nicq.find();
if (VmNicHelper.getL3Uuids(nic).contains(vip.getL3NetworkUuid())) {
throw new ApiMessageInterceptionException(argerr("guest l3Network of vm nic[uuid:%s] and vip l3Network of vip[uuid: %s] are the same network", msg.getVmNicUuid(), msg.getVipUuid()));
}
if (msg.getUsedIpUuid() == null) {
msg.setUsedIpUuid(nic.getUsedIpUuid());
} else {
validateEipGuestIpUuid(msg.getVmNicUuid(), msg.getUsedIpUuid());
}
checkIfVmAlreadyHasVipNetwork(nic.getVmInstanceUuid(), vip);
}
if (msg.getUsedIpUuid() != null) {
isVipInVmNicSubnet(msg.getVipUuid(), msg.getUsedIpUuid());
}
}