Martin Betak has uploaded a new change for review. Change subject: restapi: [WIP] Add Reboot support ......................................................................
restapi: [WIP] Add Reboot support Added new VM actions reboot and powercycle along with new VM properties used to configure the power-down behavior of given VM. Change-Id: Ie9a5007a1364392830e4112e57ec54a7025fee02 Signed-off-by: Martin Betak <[email protected]> --- 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/api.xsd 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 4 files changed, 74 insertions(+), 2 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/94/16194/1 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 20bc074..307cf74 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 @@ -62,6 +62,20 @@ @Formatted @Consumes({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, ApiMediaType.APPLICATION_X_YAML}) @Actionable + @Path("reboot") + public Response reboot(Action action); + + @POST + @Formatted + @Consumes({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, ApiMediaType.APPLICATION_X_YAML}) + @Actionable + @Path("powercycle") + public Response powercycle(Action action); + + @POST + @Formatted + @Consumes({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, ApiMediaType.APPLICATION_X_YAML}) + @Actionable @Path("suspend") public Response suspend(Action action); diff --git a/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd b/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd index 0df3464..c33f505 100644 --- a/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd +++ b/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd @@ -159,6 +159,8 @@ <xs:element name="exclusive" type="xs:boolean" minOccurs="0"/> <!-- For VM start --> <xs:element ref="vm" minOccurs="0" maxOccurs="1"/> + <!-- For VM shutdown/reboot --> + <xs:element name="gracefulTimeout" type="xs:int" minOccurs="0" maxOccurs="1" /> <!-- For import template --> <xs:element ref="template" minOccurs="0" maxOccurs="1"/> <!-- For Setup Networks --> @@ -2148,6 +2150,8 @@ <xs:element ref="quota" minOccurs="0" maxOccurs="1"/> <xs:element ref="usb" minOccurs="0" maxOccurs="1"/> <xs:element name="tunnel_migration" type="xs:boolean" minOccurs="0" maxOccurs="1"/> + <xs:element name="powerdown_forced" type="xs:boolean" minOccurs="0" maxOccurs="1" /> + <xs:element name="graceful_timeout" type="xs:int" minOccurs="0" maxOccurs="1" /> <xs:element ref="vmpool" minOccurs="0" maxOccurs="1"> <xs:annotation> 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 13441d0..fe9fccc 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 @@ -136,6 +136,8 @@ vm.tunnel_migration: xs:boolean vm.payloads.payload--COLLECTION: {payload.type: 'xs:string', payload.file.name: 'xs:string', payload.file.content: 'xs:string'} vm.cpu.cpu_tune.vcpu_pin--COLLECTION: {vcpu_pin.vcpu: 'xs:int', vcpu_pin.cpu_set: 'xs:string'} + vm.powerdown_forced: xs:boolean + vm.graceful_timeout: xs:int # the following signature is for clone VM from a Snapshot - requires the Snapshot ID - mandatoryArguments: {vm.name: 'xs:string', vm.template.id|name: 'xs:string', vm.cluster.id|name: 'xs:string', vm.snapshots.snapshot--COLLECTION: {snapshot.id: 'xs:string'}} @@ -172,6 +174,8 @@ vm.tunnel_migration: xs:boolean vm.payloads.payload--COLLECTION: {payload.type: 'xs:string', payload.file.name: 'xs:string', payload.file.content: 'xs:string'} vm.cpu.cpu_tune.vcpu_pin--COLLECTION: {vcpu_pin.vcpu: 'xs:int', vcpu_pin.cpu_set: 'xs:string'} + vm.powerdown_forced: xs:boolean + vm.graceful_timeout: xs:int urlparams: {} headers: Content-Type: {value: application/xml|json, required: true} @@ -186,6 +190,24 @@ headers: Content-Type: {value: application/xml|json, required: true} Correlation-Id: {value: 'any string', required: false} +- name: /api/vms/{vm:id}/reboot|rel=reboot + request: + body: + parameterType: Action + signatures: [] + urlparams: {} + headers: + Content-Type: {value: application/xml|json, required: true} + Correlation-Id: {value: 'any string', required: false} +- name: /api/vms/{vm:id}/powercycle|rel=powercycle + request: + body: + parameterType: Action + signatures: [] + urlparams: {} + headers: + Content-Type: {value: application/xml|json, required: true} + Correlation-Id: {value: 'any string', required: false} - name: /api/vms/{vm:id}/stop|rel=stop request: body: 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 673b52e..4359a61 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 @@ -42,10 +42,10 @@ import org.ovirt.engine.core.common.action.MigrateVmParameters; import org.ovirt.engine.core.common.action.MigrateVmToServerParameters; import org.ovirt.engine.core.common.action.MoveVmParameters; +import org.ovirt.engine.core.common.action.PowerDownVmParameters; import org.ovirt.engine.core.common.action.RemoveVmFromPoolParameters; import org.ovirt.engine.core.common.action.RunVmOnceParams; import org.ovirt.engine.core.common.action.SetVmTicketParameters; -import org.ovirt.engine.core.common.action.ShutdownVmParameters; import org.ovirt.engine.core.common.action.StopVmParameters; import org.ovirt.engine.core.common.action.StopVmTypeEnum; import org.ovirt.engine.core.common.action.VdcActionParametersBase; @@ -209,8 +209,40 @@ public Response shutdown(Action action) { // REVISIT add waitBeforeShutdown Action paramater // to api schema before next sub-milestone + + org.ovirt.engine.core.common.businessentities.VM vm = getEntity(entityType, + VdcQueryType.GetVmByVmId, + new IdQueryParameters(guid), + "VM"); + int timeout = action.isSetGracefulTimeout() ? action.getGracefulTimeout() : vm.getGracefulTimeout(); return doAction(VdcActionType.ShutdownVm, - new ShutdownVmParameters(guid, true), + new PowerDownVmParameters(guid, timeout, vm.isPowerdownForced()), + action); + } + + @Override + public Response reboot(Action action) { + + org.ovirt.engine.core.common.businessentities.VM vm = getEntity(entityType, + VdcQueryType.GetVmByVmId, + new IdQueryParameters(guid), + "VM"); + int timeout = action.isSetGracefulTimeout() ? action.getGracefulTimeout() : vm.getGracefulTimeout(); + return doAction(VdcActionType.RebootVm, + new PowerDownVmParameters(guid, timeout, vm.isPowerdownForced()), + action); + } + + @Override + public Response powercycle(Action action) { + int timeout; + if (action.isSetGracefulTimeout()) { + timeout = action.getGracefulTimeout(); + } else { + timeout = getEntity(entityType, VdcQueryType.GetVmByVmId, new IdQueryParameters(guid), "VM").getGracefulTimeout(); + } + return doAction(VdcActionType.RebootVm, + new PowerDownVmParameters(guid, timeout, true), action); } -- To view, visit http://gerrit.ovirt.org/16194 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ie9a5007a1364392830e4112e57ec54a7025fee02 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Martin Betak <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
