use of com.cloud.network.router.VirtualRouter in project CloudStack-archive by CloudStack-extras.
the class UpgradeRouterCmd method execute.
@Override
public void execute() {
VirtualRouter router = _routerService.upgradeRouter(this);
if (router != null) {
DomainRouterResponse routerResponse = _responseGenerator.createDomainRouterResponse(router);
routerResponse.setResponseName(getCommandName());
this.setResponseObject(routerResponse);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to upgrade router");
}
}
use of com.cloud.network.router.VirtualRouter in project cloudstack by apache.
the class NetworkOrchestrator method destroyExpendableRouters.
@Override
public void destroyExpendableRouters(final List<? extends VirtualRouter> routers, final ReservationContext context) throws ResourceUnavailableException {
final List<VirtualRouter> remainingRouters = new ArrayList<>();
for (final VirtualRouter router : routers) {
if (router.getState() == VirtualMachine.State.Stopped || router.getState() == VirtualMachine.State.Error || router.getState() == VirtualMachine.State.Shutdown || router.getState() == VirtualMachine.State.Unknown) {
s_logger.debug("Destroying old router " + router);
_routerService.destroyRouter(router.getId(), context.getAccount(), context.getCaller().getId());
} else {
remainingRouters.add(router);
}
}
if (remainingRouters.size() < 2) {
return;
}
VirtualRouter backupRouter = null;
for (final VirtualRouter router : remainingRouters) {
if (router.getRedundantState() == VirtualRouter.RedundantState.BACKUP) {
backupRouter = router;
}
}
if (backupRouter == null) {
backupRouter = routers.get(routers.size() - 1);
}
if (backupRouter != null) {
_routerService.destroyRouter(backupRouter.getId(), context.getAccount(), context.getCaller().getId());
}
}
use of com.cloud.network.router.VirtualRouter in project cloudstack by apache.
the class UserVmDomRInvestigator method isVmAlive.
@Override
public boolean isVmAlive(VirtualMachine vm, 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)
UserVmVO userVm = _userVmDao.findById(vm.getId());
List<? extends Nic> nics = _networkMgr.getNicsForTraffic(userVm.getId(), TrafficType.Guest);
for (Nic nic : nics) {
if (nic.getIPv4Address() == null) {
continue;
}
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 (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 cloudstack by apache.
the class BasicNetworkVisitor method visit.
@SuppressWarnings("unchecked")
@Override
public boolean visit(final FirewallRules firewall) throws ResourceUnavailableException {
final Network network = firewall.getNetwork();
final VirtualRouter router = firewall.getRouter();
final List<? extends FirewallRule> rules = firewall.getRules();
final List<LoadBalancingRule> loadbalancingRules = firewall.getLoadbalancingRules();
final Purpose purpose = firewall.getPurpose();
final Commands cmds = new Commands(Command.OnError.Continue);
if (purpose == Purpose.LoadBalancing) {
_commandSetupHelper.createApplyLoadBalancingRulesCommands(loadbalancingRules, router, cmds, network.getId());
return _networkGeneralHelper.sendCommandsToRouter(router, cmds);
} else if (purpose == Purpose.PortForwarding) {
_commandSetupHelper.createApplyPortForwardingRulesCommands((List<? extends PortForwardingRule>) rules, router, cmds, network.getId());
return _networkGeneralHelper.sendCommandsToRouter(router, cmds);
} else if (purpose == Purpose.StaticNat) {
_commandSetupHelper.createApplyStaticNatRulesCommands((List<StaticNatRule>) rules, router, cmds, network.getId());
return _networkGeneralHelper.sendCommandsToRouter(router, cmds);
} else if (purpose == Purpose.Firewall) {
_commandSetupHelper.createApplyFirewallRulesCommands(rules, router, cmds, network.getId());
return _networkGeneralHelper.sendCommandsToRouter(router, cmds);
}
s_logger.warn("Unable to apply rules of purpose: " + rules.get(0).getPurpose());
return false;
}
use of com.cloud.network.router.VirtualRouter in project cloudstack by apache.
the class BasicNetworkVisitor method visit.
@Override
public boolean visit(final SshKeyToRouterRules sshkey) throws ResourceUnavailableException {
final VirtualRouter router = sshkey.getRouter();
final VirtualMachineProfile profile = sshkey.getProfile();
final String sshKeystr = sshkey.getSshPublicKey();
final UserVmVO userVM = sshkey.getUserVM();
final Commands commands = new Commands(Command.OnError.Stop);
final NicVO nicVo = sshkey.getNicVo();
final VMTemplateVO template = sshkey.getTemplate();
if (template != null && template.isEnablePassword()) {
_commandSetupHelper.createPasswordCommand(router, profile, nicVo, commands);
}
_commandSetupHelper.createVmDataCommand(router, userVM, nicVo, sshKeystr, commands);
return _networkGeneralHelper.sendCommandsToRouter(router, commands);
}
Aggregations