npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

oc-csclient

v0.0.2

Published

oneclick API client for the CloudStack

Downloads

44

Readme

CloudStack API client for Node.js

Installation

$ npm install csclient

Usage

The client has three methods of note:

executeSync(cmd, params, callback), where cmd is a string with the actual API command and params is a key-value object with optional parameters.

The other one, executeAsync(cmd, params, callback), is for CloudStack's async API calls, polling until a result is received, or a timeout reached.

The third method execute is available with two modes:

  • Single Executor In this mode the execute method will be able to execute both sync and async requests. To enable this mode, set the singleExecutor attribute to true while creating the client instance. The method is available after the ready event has been emitted.

  • Separate Executor In this mode, the execute method acts as an alias to executeSync. It is immediately available, although the ready event is still emitted.

The execute method with Single Executor mode may be preferable as it takes away the reponsibility of identifying requests as async/sync away from the developer.

var CloudStackClient = require('csclient');

var options = {
    apiKey: 'abcd1234',                         // (mandatory)
    secretKey: 'efgh5678',                      // (mandatory)
    baseUrl: 'http://host:port/client/api?',    // (mandatory)
    pollingTime: 500,           // in milliseconds (optional)
    pollingNumber: 5,                           // (optional)
    singleExecutor: true                        // (optional)
};

var client = new CloudStackClient(options);

var handleError = (err) => {
    if (err.name === 'APIError') {
        switch (err.code) {
        case 401:
            return console.log('Unauthorized.');
        case 530:
            return console.log('Parameter error: ' + err.message);
        default:
            return console.log('API error ' + err.code + ': ' + err.message);
        }
    } else {
        return console.log('Oops, I did it again. ' + err.message);
    }
}

client.on ('ready', () => {

    client.execute('listVirtualMachines', {}, (err, response) => {
        if (err) return handleError(err);

        response = response.listvirtualmachinesresponse;
        for (var i = 0; i < response.count; i++) {
            var vm = response.virtualmachine[i];
            console.log(vm.name + " is in state " + vm.state);
        }
    });

    client.execute('associateIpAddress', { zoneid: 1 }, (err, response) => {
        if (err) return handleError(err);

        response = response.associateipaddressresponse;
        console.log('Id of IP address associated: ' + response.id);
    });

});

Deprecation Note:

The serverURL attribute has been deprecated in favour of baseUrl. It will continue to work in this version, but will be removed in the future.

License

This is free software released under the Simplified BSD License. See the LICENSE file for further information.