Created
November 15, 2010 02:13
-
-
Save tbatchelli/676332 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn start | |
"Starts the virtual machine represented by 'machine'. | |
Optional parameters are: | |
:session-type 'gui', 'vrdp' or 'sdl'. Default is 'gui' | |
:env environment as String to be passed to the machine at startup. See IVirtualbox::openRemoteSession for more details" | |
[^Machine machine & opt-kv] | |
(session/with-vbox (:server machine) [mgr vbox] | |
(let [opts (apply hash-map opt-kv) | |
machine-id (:id machine) | |
session (.getSessionObject mgr vbox) | |
session-type (or (:session-type opts) "gui") | |
env (or (:env opts) "DISPLAY:0.0")] | |
(try (let [progress (.openRemoteSession vbox session machine-id session-type env)] | |
(log/debug (str "Starting session for VM " machine-id "...")) | |
(.waitForCompletion progress 10000) | |
(let [result-code (.getResultCode progress)] | |
(if (zero? result-code) | |
nil | |
true))) | |
(catch javax.xml.ws.WebServiceException e | |
(conditions/wrap-vbox-runtime | |
e {:log-level :error} | |
{:E_UNEXPECTED {:message "Virtual Machine not registered."} | |
:E_INVALIDARG {:message (format "Invalid session type '%s'" session-type)} | |
:VBOX_E_OBJECT_NOT_FOUND {:message (format "No machine matching id '%s' found." machine-id)} | |
:VBOX_E_INVALID_OBJECT_STATE {:message "Session already open or opening."} | |
:VBOX_E_IPTR_ERROR {:message "Launching process for machine failed."} | |
:VBOX_E_VM_ERROR {:message "Failed to assign machine to session."}})) | |
(catch Exception e | |
(conditions/log-and-raise e {:log-level :error | |
:message "An error occurred while starting machine"})))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment