README.md in rancher-api-0.3.5 vs README.md in rancher-api-0.3.6
- old
+ new
@@ -1,7 +1,16 @@
# Rancher::Api
+[![Gem Version](https://badge.fury.io/rb/rancher-api.svg)](http://badge.fury.io/rb/rancher-api)
+![Downloads](http://ruby-gem-downloads-badge.herokuapp.com/rancher-api)
+
+
+[![Circle CI](https://circleci.com/gh/akurkin/rancher-api/tree/master.svg?style=svg)](https://circleci.com/gh/akurkin/rancher-api/tree/master)
+[![Code Climate](https://codeclimate.com/github/akurkin/rancher-api/badges/gpa.svg)](https://codeclimate.com/github/akurkin/rancher-api)
+[![Test Coverage](https://codeclimate.com/github/akurkin/rancher-api/badges/coverage.svg)](https://codeclimate.com/github/akurkin/rancher-api/coverage)
+
+
Rancher::Api is a Ruby wrapper around [Rancher](http://rancher.com/) API built with [Her](http://www.her-rb.org/)
Connect to Rancher and execute requests from your ruby scripts.
It allows you to use some of the super nice features from Rancher:
@@ -27,35 +36,57 @@
$ gem install rancher-api
## Rancher Version
Tested with:
-Rancher v0.32.0
+Rancher v0.63.1
## Usage
Configure Rancher::Api first by providing url, access and secret keys:
-### Entities
+### Classes
-**Project** - Top level object that represents "Environment" in Rancher UI
-**Service** - Service (combines containers from the same image)
-**Machine** - Physical docker hosts
-**Instance** - represents containers that were ever installed via Rancher. Better to query containers as nested resource, cuz there can be thousands of containers that were running before and still available to query via API. Removed containers are marked as 'removed' respectively.
-**Environment** - In rancher UI these are known as **Stack**, though in API they are **environments**. We're sticking to API resource name.
-**Host** - these are hosts, with detailed information about docker installation and resources
+- **Project**
+Top level object that represents "Environment" in Rancher UI
+- **Service**
+Service (combines containers from the same image)
+- **Machine**
+Physical docker hosts
+- **Instance**
+represents containers that were ever installed via Rancher. Better to query containers as nested resource, cuz there can be thousands of containers that were running before and still available to query via API. Removed containers are marked as 'removed' respectively
+- **Environment**
+In Rancher UI these are known as **Stack**, though in API they are **environments**. We're sticking to API resource name
+- **Host**
+These are hosts, with detailed information about docker installation and resources
### Setup
+#### Using initializer
+
```ruby
+require 'rancher/api'
+
Rancher::Api.configure do |config|
config.url = 'http://127.0.0.1:8080/v1/'
config.access_key = '8604A1FC8C108BAFB1E3'
config.secret_key = '4BhuyyyAaaaaBbbbi7yaZzzAaa3y13pC6D7e569'
end
```
+#### Using environment variables
+
+You can configure `rancher-api` gem using `rancher-compose`-compatible environment variables:
+
+- RANCHER_URL
+- RANCHER_ACCESS_KEY
+- RANCHER_SECRET_KEY
+
+```ruby
+Rancher::Api.setup!
+```
+
### Querying
Now, you're able to query entities like this:
```ruby
@@ -64,10 +95,14 @@
```
### Creating new machines
Creating new machine using **Digital Ocean** driver:
+**NOTICE**: First specify driver, so that driver_config= accessor can correctly map config on the right attribute. I.e. for 'digitalocean' config attribute is 'digitaloceanConfig'.
+
+#### Digital Ocean
+
```ruby
project = Rancher::Api::Project.all.to_a.first
new_machine = project.machines.build
new_machine.driver = Rancher::Api::Machine::DIGITAL_OCEAN
@@ -79,17 +114,42 @@
)
new_machine.save
```
-**NOTICE**: First specify driver, so that driver_config= accessor can correctly map config on the right attribute. I.e. for 'digitalocean' config attribute is 'digitaloceanConfig'.
+#### Vmware Vsphere
+```ruby
+project = Rancher::Api::Project.all.to_a.first
+new_machine = project.machines.build
+new_machine.name = 'api-test'
+new_machine.driver = Rancher::Api::Machine::VMWARE_VSPHERE
+new_machine.driver_config = Rancher::Api::Machine::DriverConfig.new(
+ boot2dockerUrl: nil,
+ cpuCount: '1',
+ datacenter: 'ha-dc',
+ datastore: 'prod',
+ diskSize: '10000',
+ memorySize: '1024',
+ network: 'prod',
+ password: 'holamundo',
+ pool: nil,
+ username: 'myuser',
+ vcenter: 'vcenter.happyops.com',
+ vcenterPort: nil
+)
+
+new_machine.save
+```
+
+
### Executing shell commands in containers
```ruby
container = Rancher::Api::Instance.find('1i382')
puts container.execute('whoami').response
+puts container.execute(['bundle', 'exec', 'rake', 'db:create', 'db:migrate']).response
```
## Development
To load environment with pry run `pry -I lib -r rancher/api`