use of com.cloud.vm.dao.NicDao in project cloudstack by apache.
the class VpcIpAssociationRules method accept.
@Override
public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException {
_router = router;
_vlanMacAddress = new HashMap<String, String>();
_ipsToSend = new ArrayList<PublicIpAddress>();
NicDao nicDao = visitor.getVirtualNetworkApplianceFactory().getNicDao();
for (PublicIpAddress ipAddr : _ipAddresses) {
String broadcastURI = BroadcastDomainType.Vlan.toUri(ipAddr.getVlanTag()).toString();
Nic nic = nicDao.findByNetworkIdInstanceIdAndBroadcastUri(ipAddr.getNetworkId(), _router.getId(), broadcastURI);
String macAddress = null;
if (nic == null) {
if (ipAddr.getState() != IpAddress.State.Releasing) {
throw new CloudRuntimeException("Unable to find the nic in network " + ipAddr.getNetworkId() + " to apply the ip address " + ipAddr + " for");
}
s_logger.debug("Not sending release for ip address " + ipAddr + " as its nic is already gone from VPC router " + _router);
} else {
macAddress = nic.getMacAddress();
_vlanMacAddress.put(BroadcastDomainType.getValue(BroadcastDomainType.fromString(ipAddr.getVlanTag())), macAddress);
_ipsToSend.add(ipAddr);
}
}
return visitor.visit(this);
}
use of com.cloud.vm.dao.NicDao in project cloudstack by apache.
the class NicPlugInOutRules method getNicsToChangeOnRouter.
private Pair<Map<String, PublicIpAddress>, Map<String, PublicIpAddress>> getNicsToChangeOnRouter(final NetworkTopologyVisitor visitor) {
// 1) check which nics need to be plugged/unplugged and plug/unplug them
final Map<String, PublicIpAddress> nicsToPlug = new HashMap<String, PublicIpAddress>();
final Map<String, PublicIpAddress> nicsToUnplug = new HashMap<String, PublicIpAddress>();
VpcManager vpcMgr = visitor.getVirtualNetworkApplianceFactory().getVpcMgr();
NicDao nicDao = visitor.getVirtualNetworkApplianceFactory().getNicDao();
// find out nics to unplug
for (PublicIpAddress ip : _ipAddresses) {
long publicNtwkId = ip.getNetworkId();
// rules, release it on the backend
if (!vpcMgr.isIpAllocatedToVpc(ip)) {
ip.setState(IpAddress.State.Releasing);
}
if (ip.getState() == IpAddress.State.Releasing) {
Nic nic = nicDao.findByIp4AddressAndNetworkIdAndInstanceId(publicNtwkId, _router.getId(), ip.getAddress().addr());
if (nic != null) {
nicsToUnplug.put(ip.getVlanTag(), ip);
s_logger.debug("Need to unplug the nic for ip=" + ip + "; vlan=" + ip.getVlanTag() + " in public network id =" + publicNtwkId);
}
}
}
// find out nics to plug
for (PublicIpAddress ip : _ipAddresses) {
URI broadcastUri = BroadcastDomainType.Vlan.toUri(ip.getVlanTag());
long publicNtwkId = ip.getNetworkId();
// rules, release it on the backend
if (!vpcMgr.isIpAllocatedToVpc(ip)) {
ip.setState(IpAddress.State.Releasing);
}
if (ip.getState() == IpAddress.State.Allocated || ip.getState() == IpAddress.State.Allocating) {
// nic has to be plugged only when there are no nics for this
// vlan tag exist on VR
Nic nic = nicDao.findByNetworkIdInstanceIdAndBroadcastUri(publicNtwkId, _router.getId(), broadcastUri.toString());
if (nic == null && nicsToPlug.get(ip.getVlanTag()) == null) {
nicsToPlug.put(ip.getVlanTag(), ip);
s_logger.debug("Need to plug the nic for ip=" + ip + "; vlan=" + ip.getVlanTag() + " in public network id =" + publicNtwkId);
} else {
final PublicIpAddress nicToUnplug = nicsToUnplug.get(ip.getVlanTag());
if (nicToUnplug != null) {
NicVO nicVO = nicDao.findByIp4AddressAndNetworkIdAndInstanceId(publicNtwkId, _router.getId(), nicToUnplug.getAddress().addr());
nicVO.setIPv4Address(ip.getAddress().addr());
nicDao.update(nicVO.getId(), nicVO);
s_logger.debug("Updated the nic " + nicVO + " with the new ip address " + ip.getAddress().addr());
nicsToUnplug.remove(ip.getVlanTag());
}
}
}
}
Pair<Map<String, PublicIpAddress>, Map<String, PublicIpAddress>> nicsToChange = new Pair<Map<String, PublicIpAddress>, Map<String, PublicIpAddress>>(nicsToPlug, nicsToUnplug);
return nicsToChange;
}
use of com.cloud.vm.dao.NicDao in project cloudstack by apache.
the class PasswordToRouterRules method accept.
@Override
public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException {
_router = router;
UserVmDao userVmDao = visitor.getVirtualNetworkApplianceFactory().getUserVmDao();
userVmDao.loadDetails((UserVmVO) profile.getVirtualMachine());
// for basic zone, send vm data/password information only to the router in the same pod
NicDao nicDao = visitor.getVirtualNetworkApplianceFactory().getNicDao();
nicVo = nicDao.findById(nic.getId());
return visitor.visit(this);
}
use of com.cloud.vm.dao.NicDao in project cloudstack by apache.
the class DhcpEntryRules method accept.
@Override
public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException {
_router = router;
UserVmDao userVmDao = visitor.getVirtualNetworkApplianceFactory().getUserVmDao();
_userVM = userVmDao.findById(_profile.getId());
userVmDao.loadDetails(_userVM);
NicDao nicDao = visitor.getVirtualNetworkApplianceFactory().getNicDao();
_nicVo = nicDao.findById(_nic.getId());
return visitor.visit(this);
}
Aggregations