• Stars
    star
    159
  • Rank 235,916 (Top 5 %)
  • Language
    JavaScript
  • License
    Other
  • Created over 14 years ago
  • Updated almost 12 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A client implementation for Rackspace CloudServers in node.js

node-cloudservers

A client implementation for Rackspace CloudServers in node.js

THIS LIBRARY IS DEPRECATED. ALL FIXES SHOULD BE DIRECTED to pkgcloud

Installation

Installing npm (node package manager)

  curl http://npmjs.org/install.sh | sh

Installing cloudservers

  npm install cloudservers

Getting Rackspace Account

Usage

http://blog.nodejitsu.com/nodejs-cloud-server-in-three-minutes

The node-cloudservers library is compliant with the Rackspace CloudServers API. Using node-cloudservers is easy for a variety of scenarios: authenticating, getting flavors and images, creating servers, and working with servers.

Getting Started

Before we can do anything with cloudfiles, we have to create a client with valid credentials. Cloudservers will authenticate for you automatically:

  var cloudservers = require('cloudservers');
  var config = {
    auth : {
      username: 'your-username',
      apiKey: 'your-api-key'
    }
  };
  var client = cloudservers.createClient(config);

Getting Flavors and Images

There are several entities in the Rackspace CloudServer ecosystem: images, flavors, and servers. Both the getFlavors and getImages methods take an optional first parameter which when set to true will return more details for the objects returned. Here's how to get the list of all available flavors and images associated with your Rackspace account:

  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;
  });

Create Server

If you manually create servers yourself via the Rackspace CloudServer management console, you can skip this section. For dynamically load balanced applications like nodejitsu, creating servers on-the-fly is important. To create a server, you will need the id of the image and flavor of the server. You can also pass an instance of a node-cloudservers Flavor or Image.

  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
  });

Setting a 'personality' for a Server

Rackspace CloudServers exposes an API that allows you to include an arbitrary number of files less than 10kb on a new server. Each file must be Base64 encoded. To use this functionality in node-cloudservers just include the path and contents of each file when creating a server:

  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
  });

Waiting for Servers to Become 'Active'

Once you've created a server, you can't work with it until it has become active. The node-cloudservers library is designed to allow you to wait for a server to meet a set of criteria:

  server.setWait({ status: 'ACTIVE' }, 5000, function () {
    // 'server' is now in the ACTIVE state and can be used normally.
  });

Working with Servers

If you have already created a some Rackspace CloudServer instances it is easy to get them from your account with node-cloudservers with the getServers method. This method takes an optional first parameter that when set to true will return all details for the servers:

  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 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'
  });

Roadmap

  1. Get Server resize operations working: confirmResize, resize, revertResize.
  2. Get miscellaneous Server operations working: rebuild.
  3. Get the core 'createImage' operation working.

Run Tests

All of the node-cloudservers tests are written in vows, and cover all of the use cases described above. You will need to add your Rackspace API username and API key to test/data/test-config.json before running tests:

  {
    "auth": {
      "username": "your-username",
      "apiKey": "your-apikey"
    }
  }

Once you have valid Rackspace credentials you can run tests with vows:

  vows test/*-test.js --spec

Running Personality tests

One common usage of the personality features in Rackspace CloudServers is to upload your own SSH keys for communicating with your new server. To run these tests you will need to generate a test key locally.

  $ 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.

This project is built and supported by Nodejitsu. If it does not work as expected, please let us know and we will fix it

Author: Charlie Robbins

Contributors: Elijah Insua Matthew Bergman

More Repositories

1

haibu

[Deprecated] a node.js application server - spawn your own node.js clouds, on your own hardware
JavaScript
722
star
2

jitsu

Flawless command line deployment of your Node.js apps to the cloud
JavaScript
648
star
3

handbook

A gentle introduction to the art of Nodejitsu
JavaScript
473
star
4

nexpect

spawn and control child processes in node.js with ease
JavaScript
290
star
5

godot

Godot is a streaming real-time event processor based on Riemann written in Node.js
JavaScript
265
star
6

docs

Community powered rocket fuel for node.js
JavaScript
194
star
7

require-analyzer

Determine the set of requirements for a given node.js file, directory tree, or module
JavaScript
152
star
8

node-cloudfiles

A client implementation for Rackspace CloudFIles in node.js
JavaScript
151
star
9

kohai

I am kohai. I am a pluggable irc bot for managing real-time data events.
JavaScript
91
star
10

prenup

A collaborative bdd project planning tool for node. uses kyuri and VowsJS
JavaScript
83
star
11

module-foundry

A web service for building node.js modules that runs on Linux, SmartOS and Windows.
JavaScript
80
star
12

mock-request

A simple testing tool for mocking HTTP sequences of request / response pairs in node.js
JavaScript
77
star
13

haibu-carapace

The application host used by the haibu node.js application deployment / management server.
JavaScript
69
star
14

txn

Process and update CouchDB data in atomic, all-or-nothing transactions
JavaScript
65
star
15

nodejitsu-api

a collection of client wrappers for nodejitsu's core api
JavaScript
47
star
16

browsenpm.org

Browse packages, users, code, stats and more the public npm registry in style.
JavaScript
44
star
17

forza

A lightweight agent for Godot
C
36
star
18

jitsu-ui

A terminal interface for jitsu.
JavaScript
34
star
19

aeternum

A process monitor in libuv
C
31
star
20

module-smith

A simple extensible npm build bot that works on Linux, SmartOS, and Windows.
JavaScript
19
star
21

solenoid

Jump start an application
JavaScript
19
star
22

overwatch

A deterministic couchdb replication watcher
JavaScript
19
star
23

persistent-ghost

Wrapper to deploy the Ghost blog on Nodejitsu
JavaScript
18
star
24

haibu-api

A collection of client wrappers for haibu's core api
JavaScript
11
star
25

defaultable

Transparent, drop-in helper for overridable, inheritable defaults in CommonJS modules
JavaScript
9
star
26

contour

Collection of BigPipe Pagelets for fast prototyping and scaffold of templates
CSS
8
star
27

npm-pkg-top

Lists the top binary packages by npm stars and github stars
JavaScript
7
star
28

npm-ev-source

The transform module or daemon that takes a `skimdb` based couch and turns it into an `event-sourced` complete npm
JavaScript
7
star
29

packages-pagelet

A pagelet for rendering a npm package page.
JavaScript
4
star
30

npm-package-json-pagelet

An interactive guide for package.json
HTML
3
star
31

npm-search-pagelet

Search the npm registry.
JavaScript
2
star
32

nodejitsu-npm

A simple command line utility to get started with a Nodejitsu Private npm!
JavaScript
2
star
33

npm-dependencies-pagelet

Pagelet for the dependencies UI for a single package
JavaScript
1
star
34

registry-status-pagelet

Pagelet for visual overview of npm registry statuses
JavaScript
1
star
35

service-select

Service selector pagelet for selecting
JavaScript
1
star
36

npm-documentation-pagelet

Display documentation of npm
CSS
1
star