A client implementation for Rackspace CloudServers in node.js
npm install cloudserversA client implementation for Rackspace CloudServers in node.js
curl http://npmjs.org/install.sh | sh
npm install cloudservers
[http://blog.nodejitsu.com/nodejs-cloud-server-in-three-minutes][3]
The node-cloudservers library is compliant with the [Rackspace CloudServers API][0]. Using node-cloudservers is easy for a variety of scenarios: authenticating, getting flavors and images, creating servers, and working with servers.
var cloudservers = require('cloudservers');
var config = {
auth : {
username: 'your-username',
apiKey: 'your-api-key'
}
};
var client = cloudservers.createClient(config);
client.getFlavors(function (err, flavors) {
// Dump the flavors we have just received
util.inspect(flavors);
example.flavors = flavors;
});client.getImages(function (err, images) {
// Dump the flavors we have just received
util.inspect(images);
example.images = images;
});
var options = {
name: 'test-server',
image: 49, // Ubuntu Lucid
flavor: 1, // 256 server
};client.createServer(options, function (err, server) {
// Your server is now being built and will be ready shortly
});
var options = {
name: 'test-server',
image: 49, // Ubuntu Lucid
flavor: 1, // 256 server
personality: [{
path: '/path/on/your/server/file.txt',
contents: new Buffer('hello world').toString('base64')
}]
};
client.createServer(options, function (err, server) {
// Your server is now being built and will be ready shortly
});
server.setWait({ status: 'ACTIVE' }, 5000, function () {
// 'server' is now in the ACTIVE state and can be used normally.
});
client.getServers(true, function (err, servers) {
// Inspect the servers that have been returned
util.inspect(servers);
});
Once you're working with servers that are already active there are several operations that you can perform on it:
#### destroy
The 'destroy' method will delete a server from your [Rackspace CloudServer][4] account.
server.destroy(function () {
// Server has now been destroyed
});
#### disableBackup
The 'disableBackup' method will disable the backup schedule for the Server.
server.disableBackup(function () {
// Server backup has now been disabled
});
#### getAddresses
The 'getAddresses' method takes a callback which has the set of the valid IP addresses for the Server as a parameter. This method takes an optional first parameter with a value of 'public' or 'private', which will force only the public or private IP addresses to be returned respectively.
server.getAddresses(function (addresses) {
// Inspect the addresses that were returned
util.inspect(addresses);
});
#### getBackup
The 'getBackup' method will get the backup schedule for the Server.
server.getBackup(function (backup) {
// Inspect the backup schedule that was returned
util.inspect(backup);
});
#### getDetails
The 'getDetails' method will get the server with all details.
server.getDetails(function (server) {
// Inspect the server that was returned
util.inspect(server);
});
#### updateBackup
The 'updateBackup' method will update the backup schedule of the server on which it is called.
var backup = backup = {
"enabled": true,
"weekly": "THURSDAY",
"daily": "H_0400_0600"
};
server.updateBackup(backup, function () {
// Backup schedule has now been updated to match 'backup'
});
1. Get Server resize operations working: confirmResize, resize, revertResize.
2. Get miscellaneous Server operations working: rebuild.
3. Get the core 'createImage' operation working.
{
"auth": {
"username": "your-username",
"apiKey": "your-apikey"
}
}
Once you have valid Rackspace credentials you can run tests with [vows][2]:
vows test/*-test.js --spec
$ cd /path/to/node-cloudservers
$ mkdir test/fixtures
$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (~/.ssh/id_rsa): /path/to/node-cloudservers/test/fixtures/testkey
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /path/to/node-cloudservers/test/fixtures/testkey.

#### Author: Charlie Robbins
#### Contributors: Elijah Insua Matthew Bergman
[0]: http://docs.rackspacecloud.com/servers/api/cs-devguide-latest.pdf
[1]: http://nodejitsu.com
[2]: http://vowsjs.org
[3]: http://blog.nodejitsu.com/nodejs-cloud-server-in-three-minutes
[4]: http://www.rackspacecloud.com/1469-0-3-13.html