Frank Kobzik has uploaded a new change for review.
Change subject: restapi: Phase 5: Retrieve console descriptor file
......................................................................
restapi: Phase 5: Retrieve console descriptor file
via request on /vms/{vmid}/display/graphics_consoles/{consoleId}
with header containing "Accept: application/x-virt-viewer"
where consoleId is "5350494345" for SPICE and "564e43" for VNC
console (hexa encoded SPICE/VNC strings).
Change-Id: Ie14b3ce0623a082397cc48fa45687a276052e01b
Signed-off-by: Frantisek Kobzik <[email protected]>
Bug-Url: https://bugzilla.redhat.com/1128763
---
M
backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/ApiMediaType.java
M
backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/VmResource.java
M
backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml
M
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmResource.java
A
backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/GraphicsTypeHelper.java
5 files changed, 92 insertions(+), 0 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/58/39058/1
diff --git
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/ApiMediaType.java
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/ApiMediaType.java
index 6e524f7..d77206c 100644
---
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/ApiMediaType.java
+++
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/ApiMediaType.java
@@ -22,4 +22,5 @@
public final static javax.ws.rs.core.MediaType APPLICATION_X_YAML_TYPE =
new javax.ws.rs.core.MediaType("application", "x-yaml");
public final static String APPLICATION_PDF = "application/pdf";
+ public final static String APPLICATION_X_VIRT_VIEWER =
"application/x-virt-viewer";
}
diff --git
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/VmResource.java
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/VmResource.java
index 32787b5..61d84f0 100644
---
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/VmResource.java
+++
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/VmResource.java
@@ -17,6 +17,7 @@
package org.ovirt.engine.api.resource;
import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
@@ -171,4 +172,9 @@
@Path("sessions")
public VmSessionsResource getVmSessionsResource();
+ @GET
+ @Produces({ApiMediaType.APPLICATION_X_VIRT_VIEWER})
+ @Path("display/graphics_consoles/{id}")
+ public Response getConsoleDescriptor(@PathParam("id") String consoleId);
+
}
diff --git
a/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml
b/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml
index 52e90a9..0996719 100644
---
a/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml
+++
b/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml
@@ -535,6 +535,17 @@
urlparams: {}
headers:
Correlation-Id: {value: 'any string', required: false}
+- name: /vms/{vm:id}/display/graphics_consoles/{graphics_console:id}|rel=get
+ description: Generates text filled filled with console data. This file can
be used to initiate console session using remote-viewer application.
+ request:
+ body:
+ parameterType: null
+ signatures: []
+ urlparams:
+ str: {context: matrix, type: 'xs:string', value: 'todo', required: true}
+ headers:
+ Content-Type: {value: application/x-virt-viewer, required: true}
+ Filter: {value: true|false, required: false}
- name: /vms/{vm:id}/logon|rel=logon
description: Perform automatic logon on the VM using the guest agent.
request:
diff --git
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmResource.java
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmResource.java
index 0f53f82..dbbbb8c 100644
---
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmResource.java
+++
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmResource.java
@@ -24,6 +24,7 @@
import org.ovirt.engine.api.model.Ticket;
import org.ovirt.engine.api.model.VM;
import org.ovirt.engine.api.resource.ActionResource;
+import org.ovirt.engine.api.resource.ApiMediaType;
import org.ovirt.engine.api.resource.AssignedPermissionsResource;
import org.ovirt.engine.api.resource.AssignedTagsResource;
import org.ovirt.engine.api.resource.CreationResource;
@@ -39,6 +40,7 @@
import org.ovirt.engine.api.resource.VmSessionsResource;
import org.ovirt.engine.api.resource.WatchdogsResource;
import org.ovirt.engine.api.restapi.logging.Messages;
+import org.ovirt.engine.api.restapi.types.GraphicsTypeHelper;
import org.ovirt.engine.api.restapi.types.RngDeviceMapper;
import org.ovirt.engine.api.restapi.types.VmMapper;
import org.ovirt.engine.api.restapi.util.DisplayHelper;
@@ -72,6 +74,9 @@
import org.ovirt.engine.core.common.businessentities.VmInit;
import org.ovirt.engine.core.common.businessentities.VmStatic;
import org.ovirt.engine.core.common.businessentities.VmTemplate;
+import org.ovirt.engine.core.common.console.ConsoleOptions;
+import org.ovirt.engine.core.common.queries.ConfigureConsoleOptionsParams;
+import org.ovirt.engine.core.common.queries.ConsoleOptionsParams;
import org.ovirt.engine.core.common.queries.GetPermissionsForObjectParameters;
import org.ovirt.engine.core.common.queries.GetVmTemplateParameters;
import org.ovirt.engine.core.common.queries.IdQueryParameters;
@@ -647,4 +652,26 @@
public VmNumaNodesResource getVirtualNumaNodesResource() {
return inject(new BackendVmNumaNodesResource(guid));
}
+
+ @Override
+ public Response getConsoleDescriptor(String consoleId) {
+ GraphicsType graphicsType =
GraphicsTypeHelper.fromGraphicsTypeHexa(consoleId);
+
+ if (graphicsType == null) {
+ throw new NullPointerException("something is wrong");
+ }
+
+ ConsoleOptions consoleOptions = new ConsoleOptions(graphicsType);
+ consoleOptions.setVmId(guid);
+ ConsoleOptions configuredOptions =
runQuery(VdcQueryType.ConfigureConsoleOptions,
+ new ConfigureConsoleOptionsParams(consoleOptions,
true)).getReturnValue(); // fill required data from BE
+ // todo adjust console opts based on query/matrix/whatever params
+
+ String descriptor = runQuery(VdcQueryType.GetConsoleDescriptorFile,
new ConsoleOptionsParams(configuredOptions))
+ .getReturnValue();
+
+ Response.ResponseBuilder builder = Response.ok(descriptor,
ApiMediaType.APPLICATION_X_VIRT_VIEWER);
+ return builder.build();
+ }
+
}
diff --git
a/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/GraphicsTypeHelper.java
b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/GraphicsTypeHelper.java
new file mode 100644
index 0000000..3c2790f
--- /dev/null
+++
b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/GraphicsTypeHelper.java
@@ -0,0 +1,47 @@
+package org.ovirt.engine.api.restapi.types;
+
+import org.ovirt.engine.api.restapi.utils.HexUtils;
+import org.ovirt.engine.core.common.businessentities.GraphicsType;
+
+public class GraphicsTypeHelper {
+
+ private static final String SPICE_STRING = "SPICE";
+ private static final String VNC_STRING = "VNC";
+
+
+ public static String graphicsTypeToString(GraphicsType graphicsType) {
+ if (graphicsType != null) {
+ switch (graphicsType) {
+ case SPICE:
+ return SPICE_STRING;
+ case VNC:
+ return VNC_STRING;
+ }
+ }
+
+ return null;
+ }
+
+ public static GraphicsType fromGraphicsTypeHexa(String graphicsTypeHexa) {
+ if (graphicsTypeHexa != null) {
+ String graphicsTypeString = HexUtils.hex2string(graphicsTypeHexa);
+ return fromGraphicsTypeString(graphicsTypeString);
+ }
+
+ return null;
+ }
+
+ private static GraphicsType fromGraphicsTypeString(String
graphicsTypeString) {
+ if (graphicsTypeString != null) {
+ switch (graphicsTypeString) {
+ case SPICE_STRING:
+ return GraphicsType.SPICE;
+ case VNC_STRING:
+ return GraphicsType.VNC;
+ }
+ }
+
+ return null;
+ }
+
+}
--
To view, visit https://gerrit.ovirt.org/39058
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie14b3ce0623a082397cc48fa45687a276052e01b
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Frank Kobzik <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches