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");
}
}
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;
}
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;
}
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;
}
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");
}
}
Aggregations