Skip to content
This repository has been archived by the owner on Nov 20, 2023. It is now read-only.

Commit

Permalink
moved to base minimalistic implementation to provide support for all …
Browse files Browse the repository at this point in the history
…api endpoints
  • Loading branch information
timsavery committed Jul 12, 2012
1 parent 8cd4cf1 commit c964a79
Show file tree
Hide file tree
Showing 13 changed files with 103 additions and 429 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ language: node_js
node_js:
- 0.4
- 0.6
- 0.7 # development version of 0.8, may be unstable
- 0.8

notifications:
email:
Expand Down
25 changes: 9 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# node-cloudstack
# cloudstack

`node-cloudstack` is a CloudStack client implementation for Node.js.
`cloudstack` is a minimalistic wrapper for the CloudStack API in Node.js.

## Build Status

Expand All @@ -9,21 +9,14 @@
## Usage

```javascript
var cloudstack = require('cloudstack')
, templateId = 1
, serviceOfferingId = 1
, zoneId = 1;

client.deployVirtualMachine(templateId, serviceOfferingId, zoneId, function(result) {
var virtualMachineId = result.vmid;

result.emitter.on('success', function() {
console.log('Machine deployed successfully and it is ready to use!');
});
var cloudstack = new (require('./cloudstack'))({
apiUri: config.api_uri, // overrides process.env.CLOUDSTACK_API_URI
apiKey: config.api_key, // overrides process.env.CLOUDSTACK_API_KEY
apiSecret: config.api_secret // overrides process.env.CLOUDSTACK_API_SECRET
});

result.emitter.on('fail', function() {
console.log('Machine failed to deploy.');
});
cloudstack.exec('listVirtualMachines', {}, function(error, result) {
console.log(result);
});
```

Expand Down
40 changes: 0 additions & 40 deletions lib/asyncJobPoller.js

This file was deleted.

65 changes: 62 additions & 3 deletions lib/cloudstack.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,66 @@
exports.createClient = function(options) {
var request = require('request')
, crypto = require('crypto');

module.exports = function cloudstack(options) {
if (!options) {
throw Error('Missing parameter "options".')
options = {};
}

return new (require('./cloudstackClient'))(options);
var apiUri = options.apiUri || process.env.CLOUDSTACK_API_URI
, apiKey = options.apiKey || process.env.CLOUDSTACK_API_KEY
, apiSecret = options.apiSecret || process.env.CLOUDSTACK_API_SECRET;

this.exec = function(cmd, params, callback) {
var paramString = genSignedParamString(
apiKey,
apiSecret,
cmd,
params
);

var uri = apiUri + '?' + paramString;
request(uri, function(err, res, body) {
if (err) {
return callback(err);
}

var parsedBody = JSON.parse(body);

if (res.statusCode == 200) {
var result = parsedBody[cmd.toLowerCase() + 'response'];

return callback(null, result);
}

// TODO: need all the error condition here
callback(parsedBody);
});
};

var genSignedParamString = function(apiKey, apiSecret, cmd, params) {
params.apiKey = apiKey;
params.command = cmd;
params.response = 'json';

var paramKeys = [];
for(var key in params) {
if(params.hasOwnProperty(key)){
paramKeys.push(key);
};
};

paramKeys.sort();

var qsParameters = [];
for(var i = 0; i < paramKeys.length; i++) {
key = paramKeys[i];
qsParameters.push(key + '=' + encodeURIComponent(params[key]));
}

var queryString = qsParameters.join('&')
, cryptoAlg = crypto.createHmac('sha1', apiSecret)
, signature = cryptoAlg.update(queryString.toLowerCase()).digest('base64');

return queryString + '&signature=' + encodeURIComponent(signature);
};
};
157 changes: 0 additions & 157 deletions lib/cloudstackClient.js

This file was deleted.

43 changes: 0 additions & 43 deletions lib/querystring.js

This file was deleted.

Loading

0 comments on commit c964a79

Please sign in to comment.