Liking cljdoc? Tell your friends :D

clostack: clojure cloudstack client

Build Status Clojars Project

A simple clojure cloudstack client.

Reasoning

This client provides two ways to query the cloudstack HTTP API.

  • A standard synchronous way, which still pools outgoing requests.
  • A lower level access to the internal HTTP asynchronous client.

Configuring

Client are created with the http-client which takes an optional argument map:

  • config: a map of three keys:
    • api-key: cloustack api key
    • api-secret: cloustack api secret
    • endpoint: URL where cloudstack lives
    • page-size: page size (by default 500)

The api-key, api-secret and endpoint may also be fetched from the environment or a configuration file.

The environment takes precedence over the configuration file. When looking for environment variables, both actual environment variables and JVM system properties will be looked up.

The following system properties or environment variables can be used to provide settings:

PropertyEnvironmentDescription
clostack.api.keyCLOSTACK_API_KEYCloudstack API key
clostack.api.secretCLOSTACK_API_SECRETCloudstack API secret
clostack.endpointCLOSTACK_ENDPOINTCloudstack API endpoint

The configuration file allows for different profiles, two additional relevant variables may be set:

PropertyEnvironmentDescription
clostack.profileCLOSTACK_PROFILEConfiguration profile name
clostack.config.fileCLOSTACK_CONFIG_FILEConfiguration file location

A typical configuration will have the following aspect:

{:default :prod
 :prod    {:api-key    "xxxx"
           :api-secret "xxxx"
           :endpoint   "https://..."}
 :staging {:api-key    "xxxx"
           :api-secret "xxxx"
           :endpoint   "https://..."}}

In this configuration, we define two cloudstack installations, by default the production credentials will be used, setting clostack.profile to staging would switch this mode of operation.

Using in your project

The easiest way to use clostack in your own projects is via Leiningen. Add the following dependency to your project.clj file:

[exoscale/clostack "0.2.17"]

Documentation

https://exoscale.github.io/clostack

Sample Code

(def client (http-client {}))

;; Simple requests
(request client :list-virtual-machines {})
(request client :list-zones {})

;; Provide a callback to execute when response comes back
(async-request client :list-service-offerings {} (fn [resp] ...))

;; Page through all records and return a consistent lazy map
(paging-request client :list-events {})

;; Execute body when response comes back
(with-response [resp client :list-events]
  (println (pr-str resp)))

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close