[ovirt-users] Announcing oVirt.js prototype

Vojtech Szocs vszocs at redhat.com
Tue Jun 17 10:13:34 EDT 2014


Hello everyone,

in past few weeks, we've been working on JavaScript SDK for oVirt Engine.

Today, I'm happy to announce the first prototype called oVirt.js :)

Attached, there's an "sdk-testdrive" UI plugin which:
- bundles oVirt.js prototype [ovirt.js]
- contains test code for DataCenter object [plugin.js]

To install this plugin, simply copy (or symlink) sdk-testdrive.json file and
sdk-testdrive-resources directory under /usr/share/ovirt-engine/ui-plugins.

Following is a quick recap of test code exercising oVirt.js.

To add new DataCenter:

  // Obtain DataCenter resource collection.
  // Resource collection is a handle to work with RESTful objects.
  var dcColl = ovirt.api.datacenters;

  // Obtain "add DataCenter" operation.
  // Operation is a reusable, uhm, operation, backed by HTTP request.
  // You can run the same operation multiple times, if necessary.
  var addOp = dcColl.add({ name: 'test-dc', local: false });

  // Register result handler and run the operation.
  addOp.success(dcAddedCallback).run();

  // Example of operation result handler that receives a single resource.
  function dcAddedCallback (dc) {
    console.log('Added: ' + dc.data().name);
  }

In dcAddedCallback function shown above, "dc" is a resource object,
representing a handle to work with RESTful DataCenter object. It provides
access to underlying resource data:

  var dcDataObj = dc.data();

  // Get
  var dcName = dcDataObj.name;
  var dcDesc = dcDataObj.description;

  // Set multiple properties at once ...
  dc.data({ name: 'test-dc-updated', description: 'test' });
  // ... or one by one
  dcDataObj.name = 'test-dc-updated';
  dcDataObj.description = 'test';

It also gives access to nested collections (if any) and supported
actions (if any):

  // Obtain Cluster resource collection for given DataCenter.
  var dcClusterColl = dc.clusters;

oVirt.js is currently only 445 lines of code, yey :) we're not using
any code generation at this point, we're simply relying on HATEOAS [1]
principle of REST and dynamically augmenting resource objects with
nested collections and supported actions, which are part of resource
representation.

[1] http://en.wikipedia.org/wiki/HATEOAS

I feel we'll eventually come to a point where code generation can be
useful, but for now, we're trying to keep things small and simple.

oVirt.js currently uses Lo-Dash library [2] containing various utility
functions. I think that Lo-Dash is great because it makes working with
JavaScript a bit easier.

[2] http://lodash.com/

Overall, oVirt.js will be self-contained, which means there will be
no additional dependencies from JavaScript perspective. Using oVirt.js
in HTML page will be as simple as this:

  <script src="ovirt.js"></script>

This means that (build-time) dependencies such as Lo-Dash will be
inlined into resulting oVirt.js build. We're also planning to provide
minified version + Source Maps for better debugging.

oVirt.js is planned to be usable NOT ONLY in web browsers. In fact,
there's "ovirt.svc" namespace containing services used by oVirt.js API
implementation. You (or any 3rd party extension) can override these
services to achieve SDK portability for given runtime environment.

In other words, I'd love to see oVirt.js used also with Node.js :)

Finally, an important thing to mention - oVirt.js requires AT LEAST
ECMAScript 5.1 compliant environment. All modern browsers support
ES5, including IE9+. Unfortunately, IE9 doesn't support ES5 Strict
Mode, but that's not that big of a deal.

I'll send some more emails outlining implementation design and also
how to manage source control & distribution of oVirt.js.

Regards,
Vojtech
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ovirt-js-sdk.tar.gz
Type: application/x-compressed-tar
Size: 5319 bytes
Desc: not available
URL: <http://lists.ovirt.org/pipermail/users/attachments/20140617/3d5913dd/attachment.bin>


More information about the Users mailing list