-
Notifications
You must be signed in to change notification settings - Fork 3
CVMWebAPI.js Reference
The CVMWebAPI.js library provides a high-level interface to the CernVM Web API plugin. It takes care most of the demanding operations, letting you enjoy only the useful functionality.
First thing you should do after you include the library is to request API Access using the CVM.startCVMWebAPI() function:
<script type="text/javascript" src="http://labs.wavesoft.gr/micro/js/cvmwebapi-1.0.js"></script>
<script type="text/javascript">
// Start CernVM Web API
CVM.startCVMWebAPI(
function(plugin) {
}
);
</script>
The the successCallback is called after the plugin is instantiated and initialised. The first argument is a WebAPIPlugin object. Using this object you can request the creation of a session using the requestSession function:
function(plugin) {
plugin.requestSession("http://example.com/vmcp.cgi?vm=33123", function(session) {
// Now you can use your session in the 'session' variable.
}
}
This function will either resume a previous instance of the given session or create a new one. In both cases, the configuration obtained from the VMCP endpoint. You can check the VMCP Reference for more details on this topic.
The following methods are exposed under the CVM namespace.
void startCVMWebAPI | ( function( pluginInstance ) successCallback, function( message, code ) failureCallback (Optional) ) |
---|---|
Initialise CernVM WebAPI application and connect to it.
|
The following methods are exposed under the CVM.WebAPIPlugin class:
bool stopService | ( ) |
---|---|
Shut down the CernVM WebAPI Process.
|
|
void requestSession | ( string configURL, function( session ) successCallback, function( message, code ) failureCallback ) |
request a new (or resume an existing) session. The library will take care of prompting the user accordingly and when a session is open it will fire the successCallback function. |
|
void addEventListener | ( string eventName, function( ... ) eventHandler ) |
Register a function that will be called when the given event is fired. |
|
void removeEventListener | ( string eventName, function( ... ) eventHandler ) |
Unregister an event handler previously registered with the addEventListener function. |
The following methods are exposed under the CVM.WebAPISession class:
bool start | ( Object macroValues = { } ) |
---|---|
Boot the virtual machine if it's powered off, or resume it if it's pasued or hibernated. The macroValues parameter is a javascript object which contains the names and the values of the possible template variables that exist in the userData script. Consult the VMCP Reference for more details. |
|
bool stop | ( ) |
Stop the Virtual Machine. |
|
bool pause | ( ) |
Pause the Virtual Machine. |
|
bool resume | ( ) |
Resume the Virtual Machine. |
|
bool hibernate | ( ) |
Save the Virtual Machine on disk. |
|
bool reset | ( ) |
Issue a forced reboot to the Virtual Machine. |
|
bool close | ( ) |
Close the session by removing it's hypervisor reflection. This action performs a complete cleanup in the session but keeps the configuration. |
The following properties are exposed under the CVM.WebAPISession class:
(read-only) | int | state |
---|---|---|
(read-only) | string | stateName |
(read-only) | string | ip |
(read-only) | int | ram |
(read-only) | int | disk |
(read-only) | string | version |
(read-only) | string | flavor |
(read-only) | string | diskURL |
(read-only) | string | apiURL |
(read-only) | string | rdpURL |
(writable) | SessionFlags | flags |
(writable) | int | executionCap |