CloudStackClient

CloudStackClient is a pure Ruby library and commandline utility to interact with a CloudStack Platform. The CloudStackClient::API is a collection of low level functions to query the API. Based on these the CloudStackClient::Connector class provides a simpler and more convenient interface to the CloudStack Service.

The comandline client cloud-stack.rb executes one arbitrary command against the API. The result will be returned or saved to a file. Login credentials and other settings can be specified in a configuration file.

Authentication

There are two authentication methods available.

  1. API Key and Secure Key
  2. Username, Password and Domain (will emulate an cookie based browser session)

Current state

Please note: The library is in an rough and early state. This means not everything is perfect and things are likely to change in the upcoming versions.

Any feedback or bug reports are highly appreciated.

Setup

Requirements

Just a normal Ruby installation. No additional gems required.

Installation

Add this line to your application's Gemfile:

gem 'cloud_stack_client'

And then execute:

$ bundle

Or install it yourself as:

$ gem install cloud_stack_client

Usage

Example: Start all stopped VMs

require 'cloud_stack_client'

# Authenticate by starting a session using username, password and domain
cs = CloudStackClient::Connector.new 'https://cloud.example.com/client/api'
if cs. 'Username', 'Password', 'Domain'
  result = cs.listVirtualMachines :response => :json, :state => :stopped
  if result && result['listvirtualmachinesresponse'] && result['listvirtualmachinesresponse'].any?
    vms = result['listvirtualmachinesresponse']['virtualmachine']
    vms.each do |machine|
      job = cs.startVirtualMachine :id => machine['id']
      # ...
    end
  end
end

Example: Commandline usage

$ cloud-stack.rb --help
$ cloud-stack.rb --config-stub > my_cloudstack_credentials.yml
$ cloud-stack.rb --config my_cloudstack_credentials.yml \
  --command listNetworks --isdefault true
$ cloud-stack.rb --config my_cloudstack_credentials.yml \
  --command listIsos --isofilter self --response xml --output my_isos.xml

License

This is free software, distributed under the terms of the MIT-License.