Search in sources :

Example 56 with VirtualRouter

use of com.cloud.network.router.VirtualRouter in project cloudstack by apache.

the class RebootRouterCmd method execute.

@Override
public void execute() throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
    CallContext.current().setEventDetails("Router Id: " + this._uuidMgr.getUuid(VirtualMachine.class, getId()));
    VirtualRouter result = _routerService.rebootRouter(getId(), true, isForced());
    if (result != null) {
        DomainRouterResponse response = _responseGenerator.createDomainRouterResponse(result);
        response.setResponseName("router");
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to reboot router");
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) DomainRouterResponse(org.apache.cloudstack.api.response.DomainRouterResponse) VirtualRouter(com.cloud.network.router.VirtualRouter)

Example 57 with VirtualRouter

use of com.cloud.network.router.VirtualRouter in project cloudstack by apache.

the class ApiResponseHelper method createSystemVmInstanceResponse.

@Override
public SystemVmInstanceResponse createSystemVmInstanceResponse(VirtualMachine vm) {
    SystemVmInstanceResponse vmResponse = new SystemVmInstanceResponse();
    vmResponse.setId(vm.getUuid());
    vmResponse.setSystemVmType(vm.getType().toString().toLowerCase());
    vmResponse.setName(vm.getHostName());
    if (vm.getHostId() != null) {
        Host host = ApiDBUtils.findHostById(vm.getHostId());
        if (host != null) {
            vmResponse.setHostId(host.getUuid());
        }
    }
    if (vm.getState() != null) {
        vmResponse.setState(vm.getState().toString());
    }
    if (vm.getType() == Type.DomainRouter) {
        VirtualRouter router = (VirtualRouter) vm;
        if (router.getRole() != null) {
            vmResponse.setRole(router.getRole().toString());
        }
    }
    vmResponse.setObjectName("systemvminstance");
    return vmResponse;
}
Also used : SystemVmInstanceResponse(org.apache.cloudstack.api.response.SystemVmInstanceResponse) ManagementServerHost(org.apache.cloudstack.management.ManagementServerHost) Host(com.cloud.host.Host) VirtualRouter(com.cloud.network.router.VirtualRouter)

Example 58 with VirtualRouter

use of com.cloud.network.router.VirtualRouter in project cloudstack by apache.

the class VirtualRouterElement method savePassword.

@Override
public boolean savePassword(final Network network, final NicProfile nic, final VirtualMachineProfile vm) throws ResourceUnavailableException {
    if (!canHandle(network, null)) {
        return false;
    }
    final List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
    if (routers == null || routers.isEmpty()) {
        s_logger.debug("Can't find virtual router element in network " + network.getId());
        return true;
    }
    final VirtualMachineProfile uservm = vm;
    final DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
    final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
    // If any router is running then send save password command otherwise
    // save the password in DB
    boolean savePasswordResult = true;
    boolean isVrRunning = false;
    for (final VirtualRouter router : routers) {
        if (router.getState() == State.Running) {
            final boolean result = networkTopology.savePasswordToRouter(network, nic, uservm, router);
            if (!result) {
                s_logger.error("Unable to save password for VM " + vm.getInstanceName() + " on router " + router.getInstanceName());
                return false;
            }
            isVrRunning = true;
            savePasswordResult = savePasswordResult && result;
        }
    }
    // return the result only if one of the vr is running
    if (isVrRunning) {
        if (savePasswordResult) {
            // Explicit password reset, while VM hasn't generated a password yet.
            final UserVmVO userVmVO = _userVmDao.findById(vm.getId());
            userVmVO.setUpdateParameters(false);
            _userVmDao.update(userVmVO.getId(), userVmVO);
        }
        return savePasswordResult;
    }
    final String password = (String) uservm.getParameter(VirtualMachineProfile.Param.VmPassword);
    final String password_encrypted = DBEncryptionUtil.encrypt(password);
    final UserVmVO userVmVO = _userVmDao.findById(vm.getId());
    _userVmDao.loadDetails(userVmVO);
    userVmVO.setDetail(VmDetailConstants.PASSWORD, password_encrypted);
    _userVmDao.saveDetails(userVmVO);
    userVmVO.setUpdateParameters(true);
    _userVmDao.update(userVmVO.getId(), userVmVO);
    return true;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) UserVmVO(com.cloud.vm.UserVmVO) NetworkTopology(org.apache.cloudstack.network.topology.NetworkTopology) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) DomainRouterVO(com.cloud.vm.DomainRouterVO) VirtualRouter(com.cloud.network.router.VirtualRouter)

Example 59 with VirtualRouter

use of com.cloud.network.router.VirtualRouter in project cloudstack by apache.

the class InternalLoadBalancerElement method shutdown.

@Override
public boolean shutdown(Network network, ReservationContext context, boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException {
    List<? extends VirtualRouter> internalLbVms = _routerDao.listByNetworkAndRole(network.getId(), Role.INTERNAL_LB_VM);
    if (internalLbVms == null || internalLbVms.isEmpty()) {
        return true;
    }
    boolean result = true;
    for (VirtualRouter internalLbVm : internalLbVms) {
        result = result && _internalLbMgr.destroyInternalLbVm(internalLbVm.getId(), context.getAccount(), context.getCaller().getId());
        if (cleanup) {
            if (!result) {
                s_logger.warn("Failed to stop internal lb element " + internalLbVm + ", but would try to process clean up anyway.");
            }
            result = (_internalLbMgr.destroyInternalLbVm(internalLbVm.getId(), context.getAccount(), context.getCaller().getId()));
            if (!result) {
                s_logger.warn("Failed to clean up internal lb element " + internalLbVm);
            }
        }
    }
    return result;
}
Also used : VirtualRouter(com.cloud.network.router.VirtualRouter)

Example 60 with VirtualRouter

use of com.cloud.network.router.VirtualRouter in project cloudstack by apache.

the class StopInternalLBVMCmd method execute.

@Override
public void execute() throws ConcurrentOperationException, ResourceUnavailableException {
    CallContext.current().setEventDetails("Internal lb vm Id: " + getId());
    VirtualRouter result = null;
    VirtualRouter vm = _routerService.findRouter(getId());
    if (vm == null || vm.getRole() != Role.INTERNAL_LB_VM) {
        throw new InvalidParameterValueException("Can't find internal lb vm by id");
    } else {
        result = _internalLbSvc.stopInternalLbVm(getId(), isForced(), CallContext.current().getCallingAccount(), CallContext.current().getCallingUserId());
    }
    if (result != null) {
        DomainRouterResponse response = _responseGenerator.createDomainRouterResponse(result);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to stop internal lb vm");
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) DomainRouterResponse(org.apache.cloudstack.api.response.DomainRouterResponse) VirtualRouter(com.cloud.network.router.VirtualRouter)

Aggregations

VirtualRouter (com.cloud.network.router.VirtualRouter)72 Commands (com.cloud.agent.manager.Commands)34 DomainRouterResponse (com.cloud.api.response.DomainRouterResponse)11 NicVO (com.cloud.vm.NicVO)11 ServerApiException (com.cloud.api.ServerApiException)10 UserVmVO (com.cloud.vm.UserVmVO)10 VirtualMachineProfile (com.cloud.vm.VirtualMachineProfile)10 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)9 ArrayList (java.util.ArrayList)9 ServerApiException (org.apache.cloudstack.api.ServerApiException)9 DataCenter (com.cloud.dc.DataCenter)8 Network (com.cloud.network.Network)8 DomainRouterResponse (org.apache.cloudstack.api.response.DomainRouterResponse)8 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)6 UpdateVmOverviewCommand (com.cloud.agent.api.UpdateVmOverviewCommand)5 VMOverviewTO (com.cloud.agent.api.to.overviews.VMOverviewTO)5 UpdateNetworkOverviewCommand (com.cloud.agent.api.UpdateNetworkOverviewCommand)4 NetworkOverviewTO (com.cloud.agent.api.to.overviews.NetworkOverviewTO)4 DeployDestination (com.cloud.deploy.DeployDestination)4 PvlanSetupCommand (com.cloud.agent.api.PvlanSetupCommand)2