Coder Social home page Coder Social logo

cloudstack_client's Introduction

cloudstack_client

Gem Version Build Status

A CloudStack API client written in Ruby.

Installation

Install the cloudstack_client gem:

$ gem install cloudstack_client

Features

  • Access to the whole CloudStack-API from Ruby
  • Interactive console for playing with the CloudStack API: cloudstack_client console
  • Dynamically builds API methods based on the listApis function of CloudStack
  • Command names are converted to match Ruby naming conventions (i.e. ListVirtualMachines becomes list_virtual_machines)
  • Accepts Ruby Hash arguments passed to commands as options (i.e. list_all: true becomes listall=true)
  • Assure all required arguments are passed
  • Removes unsupported arguments and arguments with nil values from commands

Usage

Basic usage

require "cloudstack_client"

cs = CloudstackClient::Client.new(
  "https://cloudstack.local/client/api",
  "API_KEY",
  "SECRET_KEY"
)

cs.list_virtual_machines(state: "running").each do |vm|
  puts vm["name"]
end

Advanced Options

Load API definition file from an alternative path and set the version:

cs = CloudstackClient::Client.new(
  "https://cloudstack.local/client/api",
  "API_KEY",
  "SECRET_KEY",
  {
    api_path: "~/cloudstack",
    api_version: "4.15"
  }
)

...or load the API definition directly from a file:

cs = CloudstackClient::Client.new(
  "https://cloudstack.local/client/api",
  "API_KEY",
  "API_SECRET",
  { api_file: "~/cloudstack/4.15.json.gz" }
)

Using the configuration module

The configuration module of CloudstackClient makes it easy to load CloudStack API settings from configuration files.

Example

require "cloudstack_client"
require "cloudstack_client/configuration"

# looks for ~/.cloudstack.yml per default
config = CloudstackClient::Configuration.load
cs = CloudstackClient::Client.new(config[:url], config[:api_key], config[:secret_key])

Configuration files

Configuration files support multiple environments (i.e. ~/.cloudstack.yml):

# default environment
:default: production

# production environment
production:
  :url: "https://my-cloudstack-server/client/api/"
  :api_key: "cloudstack-api-key"
  :secret_key: "cloudstack-api-secret"

# test environment
test:
  :url: "http://my-cloudstack-testserver/client/api/"
  :api_key: "cloudstack-api-key"
  :secret_key: "cloudstack-api-secret"

Configuration options

You can pass options as 4th argument in CloudstackClient::Client.new. All its keys are optional.

options = {
  symbolize_keys: true, # pass symbolize_names: true in JSON#parse for Cloudstack responses, default: false
  host: 'localhost', # custom host header to be used in Net::Http. May be useful when Cloudstack is set up locally via docker (i.e. Cloudstack-simulator), default: parsed from config[:url] via Net::Http
  read_timeout: 10 # timeout in seconds of a connection to the Cloudstack, default: 60
}
cs = CloudstackClient::Client.new(config[:url], config[:api_key], config[:secret_key], options)

Interactive Console

cloudstack_client comes with an interactive console.

Example

$ cloudstack_client console -e prod
prod >> list_virtual_machines

Development

Generate or update API definitions

New API definitions can be generated using the list_apis command.

Example

# running against a CloudStack 4.15 API endpoint:
$ cloudstack_client list_apis > data/4.15.json
$ gzip data/4.15.json

References

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

License

Released under the MIT License. See the LICENSE file for further details.

cloudstack_client's People

Contributors

elshialabeouf avatar niwo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

cloudstack_client's Issues

cs server error on cloudstack-cli 0.5.2 / cloudstack_client-0.3.4

cs server destroy --project PROJECTNAME -e environment nodename
/usr/lib64/ruby/gems/1.9.1/gems/cloudstack_client-0.3.4/lib/cloudstack_client/commands/server.rb:14:in `[]': can't convert Symbol into Integer (TypeError)
    from /usr/lib64/ruby/gems/1.9.1/gems/cloudstack_client-0.3.4/lib/cloudstack_client/commands/server.rb:14:in `get_server'
    from /usr/lib64/ruby/gems/1.9.1/gems/cloudstack-cli-0.5.2/lib/cloudstack-cli/commands/server.rb:148:in `block in destroy'
    from /usr/lib64/ruby/gems/1.9.1/gems/cloudstack-cli-0.5.2/lib/cloudstack-cli/commands/server.rb:147:in `each'
    from /usr/lib64/ruby/gems/1.9.1/gems/cloudstack-cli-0.5.2/lib/cloudstack-cli/commands/server.rb:147:in `destroy'
    from /usr/lib64/ruby/gems/1.9.1/gems/thor-0.18.1/lib/thor/command.rb:27:in `run'
    from /usr/lib64/ruby/gems/1.9.1/gems/thor-0.18.1/lib/thor/invocation.rb:120:in `invoke_command'
    from /usr/lib64/ruby/gems/1.9.1/gems/thor-0.18.1/lib/thor.rb:363:in `dispatch'
    from /usr/lib64/ruby/gems/1.9.1/gems/thor-0.18.1/lib/thor/invocation.rb:109:in `invoke'
    from /usr/lib64/ruby/gems/1.9.1/gems/thor-0.18.1/lib/thor.rb:232:in `block in subcommand'
    from /usr/lib64/ruby/gems/1.9.1/gems/thor-0.18.1/lib/thor/command.rb:27:in `run'
    from /usr/lib64/ruby/gems/1.9.1/gems/thor-0.18.1/lib/thor/invocation.rb:120:in `invoke_command'
    from /usr/lib64/ruby/gems/1.9.1/gems/thor-0.18.1/lib/thor.rb:363:in `dispatch'
    from /usr/lib64/ruby/gems/1.9.1/gems/thor-0.18.1/lib/thor/base.rb:439:in `start'
    from /usr/lib64/ruby/gems/1.9.1/gems/cloudstack-cli-0.5.2/bin/cs:5:in `<top (required)>'
    from /usr/bin/cs:23:in `load'
    from /usr/bin/cs:23:in `<main>'

Release latest version on the RubyGem

Hi there! I hope you're doing great.

Thanks a lot for this wonderful gem and all its functionality!

Would you be able to create a new release on the RubyGem with the latest PR merged into main? I believe it doesn't have the latest changes from main.
Link to PR

Thanks!

unsupported parameter value type "TrueClass" in 1.4.2

Hi,

I see that some behavior is changed since 1.4.1.
For example in list_tags, option listall with TrueClass value does not work now.

        22>>               cloudstack_api.list_tags(
        23:                  resourcetype: 'UserVm', listall: true,
        24:                  key: tag_key, value: tag_value).map { |x| x['resourceid'] }

Downgrade to 1.4.1 helps.
But should this happened? Since we have only patch version upgrade.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.