pb-builder

1.1.8 • Public • Published

profitbricks-builder

Description

node.js builder and wrapper for the profitbricks soap api

Motivation

The process of creating Virtual machines with the Profitbricks Soap Api requires a lot of Soap Api Calls. Every "Item" like DataCenter, Server, Storage, NIC, Server Storage Connection is created by a single soap call. For some Items it is even required to wait until the Datacenter is provisioned, before the next item can be created.

Since node http calls are always asynchronous, a good way to make a series of soap calls is to use a Promises/A+ library. The profitbricks-builder is using the petkaantonov/bluebird Promise library and is returning a thenable Promise for most calls.

This Frameworks wraps all soap api calls into a promise that can be queued by using .then

Usage

how to create the builder instance

PBBuilder = require('pb-builder')
pbBuilder = new PBBuilder()
promise = pbBuilder.initAsync(pb_wsdl_uri, pb_user, pb_pwd)

example to get detailed information on a dataCenter by dataCenterName

pbBuilder
    .initAsync(credentials.pb_url, credentials.pb_user, credentials.pb_pwd)
    .then ->
        return pbBuilder.getAllDataCentersAsync()
    .then (allDataCenters) ->
        dataCenter = pbContext.firstItem(
            pbContext.filter(allDataCenters, {dataCenterName: "myDataCenterName"}))
        return pbBuilder.getDataCenterDetailsAsync(dataCenter)
    .then (dataCenterDetails) ->
        debug(JSON.stringify(dataCenterDetails))
    .catch (e) ->
        console.log "pbBuilder chain failed '#{e}'"
        console.log e.stack

check the examples for more information.

The Profitbricks builder implementation has node style function only and is promisified with the bluebird lib. For that reason the promisified methods have an Async at the end of the method names.

running tests and samples

to not forget to run "npm install" once after checkout

run mocha tests:

./node_modules/.bin/mocha  -R tap --compilers coffee:coffee-script test/soapclient-test.coffee
./node_modules/.bin/mocha  -R tap --compilers coffee:coffee-script test/profitbricks_jobbuilder-test.coffee

# or just run
./node_modules/.bin/cake test

run samples:

# first provide your profitbricks credentials

# copy the credentials template file to credentials.json in your current working directory
cp credentials_tmpl.json credentials.json
#  and config with your profitbricks user and passsword

# after that run a sample like this:
DEBUG=* ./node_modules/.bin/coffee examples/create_datacenter.coffee

simple repl tool

# in the examples dir there is a very simple repl (read eval print loop) command line tool, start it with

./bin/pb_cli

# see "run samples" section how to set up your credentials

# cmd can be any profitbricks soap api method, args are passed as JSON string, p.e.

pb_cli:command: getAllDataCenters

pb_cli:command: getDataCenter {"dataCenterId": "0e381ab3-133b-49d3-b5fa-6382c7add1a4"}

# there is a help command, that list soapMethod and there input. Help data is from wsdl description

pb_cli:command: help
# list all soap methods

pb_cli:command: help snapshot
# list all soap methods containing the word snapshot

pb_cli:command: help getDataCenter
# shows the input description for the soap method

development

development is taking place in the coffee files in the src folder. the javascript files are generated into the lib directory with the command:

./node_modules/.bin/cake build

Readme

Keywords

none

Package Sidebar

Install

npm i pb-builder

Weekly Downloads

0

Version

1.1.8

License

none

Last publish

Collaborators

  • pithu