use of com.cloud.network.router.VirtualRouter in project cosmic by MissionCriticalCloud.
the class UserVmDomRInvestigator method isVmAlive.
@Override
public boolean isVmAlive(final VirtualMachine vm, final Host host) throws UnknownVM {
if (vm.getType() != VirtualMachine.Type.User) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Not a User Vm, unable to determine state of " + vm + " returning null");
}
throw new UnknownVM();
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("testing if " + vm + " is alive");
}
// to verify that the VM is alive, we ask the domR (router) to ping the VM (private IP)
final UserVmVO userVm = _userVmDao.findById(vm.getId());
final List<? extends Nic> nics = _networkMgr.getNicsForTraffic(userVm.getId(), TrafficType.Guest);
for (final Nic nic : nics) {
if (nic.getIPv4Address() == null) {
continue;
}
final List<VirtualRouter> routers = _vnaMgr.getRoutersForNetwork(nic.getNetworkId());
if (routers == null || routers.isEmpty()) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Unable to find a router in network " + nic.getNetworkId() + " to ping " + vm);
}
continue;
}
Boolean result = null;
for (final VirtualRouter router : routers) {
result = testUserVM(vm, nic, router);
if (result != null) {
break;
}
}
if (result == null) {
continue;
}
return result;
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Returning null since we're unable to determine state of " + vm);
}
throw new UnknownVM();
}
use of com.cloud.network.router.VirtualRouter in project cosmic by MissionCriticalCloud.
the class AdvancedNetworkVisitor method visit.
@Override
public boolean visit(final NicPlugInOutRules nicPlugInOutRules) throws ResourceUnavailableException {
final VirtualRouter router = nicPlugInOutRules.getRouter();
final Commands commands = nicPlugInOutRules.getNetUsageCommands();
if (commands.size() > 0) {
return _networkGeneralHelper.sendCommandsToRouter(router, commands);
}
return true;
}
use of com.cloud.network.router.VirtualRouter in project cosmic by MissionCriticalCloud.
the class AdvancedNetworkVisitor method visit.
@Override
public boolean visit(final NetworkAclsRules acls) throws ResourceUnavailableException {
final VirtualRouter router = acls.getRouter();
final Network network = acls.getNetwork();
final Commands commands = new Commands(Command.OnError.Continue);
final List<? extends NetworkACLItem> rules = acls.getRules();
_commandSetupHelper.createNetworkACLsCommands(rules, router, commands, network.getId(), acls.isPrivateGateway());
return _networkGeneralHelper.sendCommandsToRouter(router, commands);
}
use of com.cloud.network.router.VirtualRouter in project cosmic by MissionCriticalCloud.
the class AdvancedNetworkVisitor method visit.
@Override
public boolean visit(final PrivateGatewayRules privateGW) throws ResourceUnavailableException {
final VirtualRouter router = privateGW.getRouter();
final NicProfile nicProfile = privateGW.getNicProfile();
final boolean add = privateGW.isAddOperation();
if (router.getState() == State.Running) {
final PrivateIpVO ipVO = privateGW.retrivePrivateIP(this);
final Network network = privateGW.retrievePrivateNetwork(this);
final String netmask = NetUtils.getCidrNetmask(network.getCidr());
final PrivateIpAddress ip = new PrivateIpAddress(ipVO, network.getBroadcastUri().toString(), network.getGateway(), netmask, nicProfile.getMacAddress());
final Commands cmds = new Commands(Command.OnError.Stop);
final List<Ip> ipsToExclude = new ArrayList<>();
if (!add) {
ipsToExclude.add(new Ip(ip.getIpAddress()));
}
final NetworkOverviewTO networkOverview = _commandSetupHelper.createNetworkOverviewFromRouter(router, new ArrayList<>(), ipsToExclude, new ArrayList<>(), null, null);
final UpdateNetworkOverviewCommand updateNetworkOverviewCommand = _commandSetupHelper.createUpdateNetworkOverviewCommand(router, networkOverview);
cmds.addCommand(updateNetworkOverviewCommand);
try {
if (_networkGeneralHelper.sendCommandsToRouter(router, cmds)) {
s_logger.debug("Successfully applied ip association for ip " + ip + " in vpc network " + network);
return true;
} else {
s_logger.warn("Failed to associate ip address " + ip + " in vpc network " + network);
return false;
}
} catch (final Exception ex) {
s_logger.warn("Failed to send " + (add ? "add " : "delete ") + " private network " + network + " commands to rotuer ");
return false;
}
} else if (router.getState() == State.Stopped || router.getState() == State.Stopping) {
s_logger.debug("Router " + router.getInstanceName() + " is in " + router.getState() + ", so not sending setup private network command to the backend");
} else {
s_logger.warn("Unable to setup private gateway, virtual router " + router + " is not in the right state " + router.getState());
throw new ResourceUnavailableException("Unable to setup Private gateway on the backend," + " virtual router " + router + " is not in the right state", DataCenter.class, router.getDataCenterId());
}
return true;
}
use of com.cloud.network.router.VirtualRouter in project cosmic by MissionCriticalCloud.
the class AdvancedNetworkVisitor method visit.
@Override
public boolean visit(final DhcpEntryRules dhcp) throws ResourceUnavailableException {
final VirtualRouter router = dhcp.getRouter();
final Commands commands = new Commands(Command.OnError.Stop);
final VMOverviewTO vmOverview = _commandSetupHelper.createVmOverviewFromRouter(router);
final UpdateVmOverviewCommand updateVmOverviewCommand = _commandSetupHelper.createUpdateVmOverviewCommand(router, vmOverview);
commands.addCommand(updateVmOverviewCommand);
return _networkGeneralHelper.sendCommandsToRouter(router, commands);
}
Aggregations