use of com.cloud.vm.VirtualMachine in project cosmic by MissionCriticalCloud.
the class ConsoleProxyServlet method doGet.
@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) {
if (_accountMgr == null || _vmMgr == null || _ms == null) {
sendResponse(resp, "Service is not ready");
return;
}
if (_keysMgr.getHashKey() == null) {
s_logger.debug("Console/thumbnail access denied. Ticket service is not ready yet");
sendResponse(resp, "Service is not ready");
return;
}
String userId = null;
String account = null;
Account accountObj = null;
final Map<String, Object[]> params = new HashMap<>();
params.putAll(req.getParameterMap());
final HttpSession session = req.getSession(false);
if (session == null) {
if (verifyRequest(params)) {
userId = (String) params.get("userid")[0];
account = (String) params.get("account")[0];
accountObj = (Account) params.get("accountobj")[0];
} else {
s_logger.debug("Invalid web session or API key in request, reject console/thumbnail access");
sendResponse(resp, "Access denied. Invalid web session or API key in request");
return;
}
} else {
// adjust to latest API refactoring changes
if (session.getAttribute("userid") != null) {
userId = ((Long) session.getAttribute("userid")).toString();
}
accountObj = (Account) session.getAttribute("accountobj");
if (accountObj != null) {
account = "" + accountObj.getId();
}
}
// Do a sanity check here to make sure the user hasn't already been deleted
if ((userId == null) || (account == null) || (accountObj == null) || !verifyUser(Long.valueOf(userId))) {
s_logger.debug("Invalid user/account, reject console/thumbnail access");
sendResponse(resp, "Access denied. Invalid or inconsistent account is found");
return;
}
final String cmd = req.getParameter("cmd");
if (cmd == null || !isValidCmd(cmd)) {
s_logger.debug("invalid console servlet command: " + cmd);
sendResponse(resp, "");
return;
}
final String vmIdString = req.getParameter("vm");
final VirtualMachine vm = _entityMgr.findByUuid(VirtualMachine.class, vmIdString);
if (vm == null) {
s_logger.info("invalid console servlet command parameter: " + vmIdString);
sendResponse(resp, "");
return;
}
final Long vmId = vm.getId();
if (!checkSessionPermision(req, vmId, accountObj)) {
sendResponse(resp, "Permission denied");
return;
}
if (cmd.equalsIgnoreCase("thumbnail")) {
handleThumbnailRequest(req, resp, vmId);
} else if (cmd.equalsIgnoreCase("access")) {
handleAccessRequest(req, resp, vmId);
} else {
handleAuthRequest(req, resp, vmId);
}
}
use of com.cloud.vm.VirtualMachine in project cosmic by MissionCriticalCloud.
the class ConsoleProxyServlet method handleThumbnailRequest.
private void handleThumbnailRequest(final HttpServletRequest req, final HttpServletResponse resp, final long vmId) {
final VirtualMachine vm = _vmMgr.findById(vmId);
if (vm == null) {
s_logger.warn("VM " + vmId + " does not exist, sending blank response for thumbnail request");
sendResponse(resp, "");
return;
}
if (vm.getHostId() == null) {
s_logger.warn("VM " + vmId + " lost host info, sending blank response for thumbnail request");
sendResponse(resp, "");
return;
}
final HostVO host = _ms.getHostBy(vm.getHostId());
if (host == null) {
s_logger.warn("VM " + vmId + "'s host does not exist, sending blank response for thumbnail request");
sendResponse(resp, "");
return;
}
final String rootUrl = _ms.getConsoleAccessUrlRoot(vmId);
if (rootUrl == null) {
sendResponse(resp, "");
return;
}
int w = DEFAULT_THUMBNAIL_WIDTH;
int h = DEFAULT_THUMBNAIL_HEIGHT;
String value = req.getParameter("w");
try {
w = Integer.parseInt(value);
} catch (final NumberFormatException e) {
s_logger.info("[ignored] not a number: " + value);
}
value = req.getParameter("h");
try {
h = Integer.parseInt(value);
} catch (final NumberFormatException e) {
s_logger.info("[ignored] not a number: " + value);
}
try {
resp.sendRedirect(composeThumbnailUrl(rootUrl, vm, host, w, h));
} catch (final IOException e) {
s_logger.info("Client may already close the connection", e);
}
}
use of com.cloud.vm.VirtualMachine in project cosmic by MissionCriticalCloud.
the class ConsoleProxyServlet method handleAuthRequest.
private void handleAuthRequest(final HttpServletRequest req, final HttpServletResponse resp, final long vmId) {
// TODO authentication channel between console proxy VM and management server needs to be secured,
// the data is now being sent through private network, but this is apparently not enough
final VirtualMachine vm = _vmMgr.findById(vmId);
if (vm == null) {
s_logger.warn("VM " + vmId + " does not exist, sending failed response for authentication request from console proxy");
sendResponse(resp, "failed");
return;
}
if (vm.getHostId() == null) {
s_logger.warn("VM " + vmId + " lost host info, failed response for authentication request from console proxy");
sendResponse(resp, "failed");
return;
}
final HostVO host = _ms.getHostBy(vm.getHostId());
if (host == null) {
s_logger.warn("VM " + vmId + "'s host does not exist, sending failed response for authentication request from console proxy");
sendResponse(resp, "failed");
return;
}
final String sid = req.getParameter("sid");
if (sid == null || !sid.equals(vm.getVncPassword())) {
s_logger.warn("sid " + sid + " in url does not match stored sid.");
sendResponse(resp, "failed");
return;
}
sendResponse(resp, "success");
}
use of com.cloud.vm.VirtualMachine in project cloudstack by apache.
the class DestroySystemVmCmd method execute.
@Override
public void execute() {
CallContext.current().setEventDetails("Vm Id: " + this._uuidMgr.getUuid(VirtualMachine.class, getId()));
VirtualMachine instance = _mgr.destroySystemVM(this);
if (instance != null) {
SystemVmResponse response = _responseGenerator.createSystemVmResponse(instance);
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Fail to destroy system vm");
}
}
use of com.cloud.vm.VirtualMachine in project cloudstack by apache.
the class ScaleSystemVMCmd method execute.
@Override
public void execute() {
CallContext.current().setEventDetails("SystemVm Id: " + this._uuidMgr.getUuid(VirtualMachine.class, getId()));
ServiceOffering serviceOffering = _entityMgr.findById(ServiceOffering.class, serviceOfferingId);
if (serviceOffering == null) {
throw new InvalidParameterValueException("Unable to find service offering: " + serviceOfferingId);
}
VirtualMachine result = null;
try {
result = _mgr.upgradeSystemVM(this);
} catch (ResourceUnavailableException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
} catch (ConcurrentOperationException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
} catch (ManagementServerException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
} catch (VirtualMachineMigrationException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
}
if (result != null) {
SystemVmResponse response = _responseGenerator.createSystemVmResponse(result);
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to upgrade system vm");
}
}
Aggregations