use of com.cloud.vm.NicVO in project cloudstack by apache.
the class RouterControlHelper method getRouterControlIp.
public String getRouterControlIp(final long routerId) {
String routerControlIpAddress = null;
final List<NicVO> nics = nicDao.listByVmId(routerId);
for (final NicVO n : nics) {
final NetworkVO nc = networkDao.findById(n.getNetworkId());
if (nc != null && nc.getTrafficType() == TrafficType.Control) {
routerControlIpAddress = n.getIPv4Address();
// router will have only one control ip
break;
}
}
if (routerControlIpAddress == null) {
logger.warn("Unable to find router's control ip in its attached NICs!. routerId: " + routerId);
final DomainRouterVO router = routerDao.findById(routerId);
return router.getPrivateIpAddress();
}
return routerControlIpAddress;
}
use of com.cloud.vm.NicVO in project cloudstack by apache.
the class VirtualNetworkApplianceManagerImpl method getRouterControlIP.
private String getRouterControlIP(DomainRouterVO router) {
final DataCenterVO dcVo = _dcDao.findById(router.getDataCenterId());
String controlIP = null;
if (router.getHypervisorType() == HypervisorType.VMware && dcVo.getNetworkType() == NetworkType.Basic) {
final List<NicVO> nics = _nicDao.listByVmId(router.getId());
for (final NicVO nic : nics) {
final NetworkVO nc = _networkDao.findById(nic.getNetworkId());
if (nc.getTrafficType() == TrafficType.Guest && nic.getIPv4Address() != null) {
controlIP = nic.getIPv4Address();
break;
}
}
s_logger.debug("Vmware with Basic network selected Guest NIC ip as control IP " + controlIP);
} else {
controlIP = _routerControlHelper.getRouterControlIp(router.getId());
}
s_logger.debug("IP of control NIC " + controlIP);
return controlIP;
}
use of com.cloud.vm.NicVO in project cloudstack by apache.
the class CommandSetupHelper method createDhcpEntryCommand.
public void createDhcpEntryCommand(final VirtualRouter router, final UserVm vm, final NicVO nic, final Commands cmds) {
final DhcpEntryCommand dhcpCommand = new DhcpEntryCommand(nic.getMacAddress(), nic.getIPv4Address(), vm.getHostName(), nic.getIPv6Address(), _networkModel.getExecuteInSeqNtwkElmtCmd());
String gatewayIp = nic.getIPv4Gateway();
final DataCenterVO dcVo = _dcDao.findById(router.getDataCenterId());
dhcpCommand.setDefaultRouter(gatewayIp);
dhcpCommand.setIp6Gateway(nic.getIPv6Gateway());
String ipaddress = null;
final NicVO domrDefaultNic = findDefaultDnsIp(vm.getId());
if (domrDefaultNic != null) {
ipaddress = domrDefaultNic.getIPv4Address();
}
dhcpCommand.setDefaultDns(ipaddress);
dhcpCommand.setDuid(NetUtils.getDuidLL(nic.getMacAddress()));
dhcpCommand.setDefault(nic.isDefaultNic());
dhcpCommand.setAccessDetail(NetworkElementCommand.ROUTER_IP, _routerControlHelper.getRouterControlIp(router.getId()));
dhcpCommand.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
dhcpCommand.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, _routerControlHelper.getRouterIpInNetwork(nic.getNetworkId(), router.getId()));
dhcpCommand.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString());
cmds.addCommand("dhcp", dhcpCommand);
}
use of com.cloud.vm.NicVO in project cloudstack by apache.
the class CommandSetupHelper method findDefaultDnsIp.
private NicVO findDefaultDnsIp(final long userVmId) {
final NicVO defaultNic = _nicDao.findDefaultNicForVM(userVmId);
// check if DNS provider is the domR
if (!_networkModel.isProviderSupportServiceInNetwork(defaultNic.getNetworkId(), Service.Dns, Provider.VirtualRouter)) {
return null;
}
final NetworkOffering offering = _networkOfferingDao.findById(_networkDao.findById(defaultNic.getNetworkId()).getNetworkOfferingId());
if (offering.getRedundantRouter()) {
return findGatewayIp(userVmId);
}
final DataCenter dc = _dcDao.findById(_networkModel.getNetwork(defaultNic.getNetworkId()).getDataCenterId());
final boolean isZoneBasic = dc.getNetworkType() == NetworkType.Basic;
// find domR's nic in the network
NicVO domrDefaultNic;
if (isZoneBasic) {
domrDefaultNic = _nicDao.findByNetworkIdTypeAndGateway(defaultNic.getNetworkId(), VirtualMachine.Type.DomainRouter, defaultNic.getIPv4Gateway());
} else {
domrDefaultNic = _nicDao.findByNetworkIdAndType(defaultNic.getNetworkId(), VirtualMachine.Type.DomainRouter);
}
return domrDefaultNic;
}
use of com.cloud.vm.NicVO in project cloudstack by apache.
the class FloatingIpModel method update.
@Override
public void update(ModelController controller) throws InternalErrorException, IOException {
assert _initialized;
ApiConnector api = controller.getApiAccessor();
ContrailManager manager = controller.getManager();
FloatingIp fip = _fip;
if (_fip == null) {
_fip = fip = (FloatingIp) controller.getApiAccessor().findById(FloatingIp.class, _uuid);
if (fip == null) {
fip = new FloatingIp();
fip.setUuid(_uuid);
fip.setAddress(_addr);
fip.setName(_name);
fip.setParent(_fipPoolModel.getFloatingIpPool());
}
}
IPAddressVO ipAddrVO = controller.getIPAddressDao().findById(_id);
assert ipAddrVO != null : "can not find address object in db";
Long vmId = ipAddrVO.getAssociatedWithVmId();
Long networkId = ipAddrVO.getAssociatedWithNetworkId();
if (vmId == null || networkId == null) {
s_logger.debug("Floating ip is not yet associated to either vm or network");
return;
}
NicVO nic = controller.getNicDao().findByNtwkIdAndInstanceId(networkId, vmId);
assert nic != null : "can not find nic for the given network and vm in db";
VMInstanceVO vm = controller.getVmDao().findById(vmId);
assert vm != null : "can not find vm in db";
VirtualMachineModel vmModel = manager.getDatabase().lookupVirtualMachine(vm.getUuid());
assert vmModel != null : "can not find vm model";
VMInterfaceModel vmiModel = vmModel.getVMInterface(nic.getUuid());
assert vmiModel != null && vmiModel.getVMInterface() != null : "can not find virtual machine interface";
fip.setVirtualMachineInterface(vmiModel.getVMInterface());
if (_fip == null) {
try {
api.create(fip);
} catch (Exception ex) {
s_logger.debug("floating ip create", ex);
throw new CloudRuntimeException("Failed to create floating ip", ex);
}
_fip = fip;
} else {
try {
api.update(fip);
} catch (IOException ex) {
s_logger.warn("floating ip update", ex);
throw new CloudRuntimeException("Unable to update floating ip object", ex);
}
}
addToVMInterface(vmiModel);
for (ModelObject successor : successors()) {
successor.update(controller);
}
}
Aggregations