Cloudstack CLI
Cloudstack CLI is a CloudStack API client written in Ruby.
Installation
Install the cloudstack-cli gem:
$ gem install cloudstack-cli
Setup
Create the initial configuration:
$ cs setup
cloudstack-cli expects to find a configuartion file with the API URL and your CloudStack credentials in your home directory named .cloudstack-cli.yml. If the file is located elsewhere you can specify the loaction using the --config option.
Example content of the configuration file:
:url: "https://my-cloudstack-server/client/api/"
:api_key: "cloudstack-api-key"
:secret_key: "cloudstack-api-secret"
Usage
For additional documentation find the RubyDoc here.
See the help screen:
$ cs
Example 1
Bootsrap a server:
$ cs server create server01 --zone ZUERICH_IX --port-forwarding 193.218.104.10:22 193.218.104.10:80 --template CentOS-6.4-x64-v1.4 --offering 1cpu_1gb --networks M_Demo
Example 2
Run a custom API command:
$ cs command listAlerts type=8
Example 3
Create a stack of servers:
$ cs stack create my_stackfile.json
An example stackfile looks like this
{
"name": "web_stack-a",
"description": "Web Application Stack",
"version": "1.0",
"zone": "DC-BIE-1",
"servers": [
{
"name": "web-d1, web-d2",
"description": "Web nodes",
"template": "CentOS-6.4-x64-v1.2",
"offering": "1cpu_1gb",
"networks": "server_network",
"port_rules": ":80, :443"
},
{
"name": "db-01",
"description": "PostgreSQL Master",
"template": "CentOS-6.4-x64-v1.2",
"offering": "2cpu_4gb",
"networks": "server_network, storage_network"
}
]
}
Example 4
Sort all computing offerings by CPU and Memory grouped my Domain:
$ cs offering sort
Example 5
Stop all virtual routers of project Demo (you could filter by zone too): (This command is helpful if you have to deploy new versions of Cloudstack when using redundant routers)
$ cs router list --project Demo --status running --redundant-state BACKUP --command stop
Hint: You can watch the status of the command with watch.
$ watch -n cs router list --project Demo
References
- Cloudstack API documentation
- This tool was inspired by the Knife extension for Cloudstack: knife-cloudstack
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request
License
Released under the MIT License. See the LICENSE file for further details.