rancher-api 0.3.5 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +28 -10
- data/README.md +70 -10
- data/circle.yml +7 -0
- data/examples/create_docker_host.rb +62 -0
- data/lib/rancher/api.rb +5 -0
- data/lib/rancher/api/configuration.rb +6 -0
- data/lib/rancher/api/models/machine.rb +5 -4
- data/lib/rancher/api/version.rb +1 -1
- data/rancher-api.gemspec +3 -0
- metadata +46 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb8f88ffae8adb164999403ecdbd8448c5396c9c
|
4
|
+
data.tar.gz: d36bb511111622f42f4d7fb5e81bea7ac5856622
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8932873e8728d37462c7cf1a8ac969c717d981a68623b358d126ee74860e9d426dcc8f7f448c1ec27acd55d00a38f0aa2f437ebcfab776c23701b38bb5719bca
|
7
|
+
data.tar.gz: 767307b8bbd15e462e1c23144c676c0c529a9737acc647676df2cbbf6a5dcb917a751309e2814a81859ab1b1664cc7f01af186d2d8af85c36b5dc33695c4501c
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rancher-api (0.3.
|
4
|
+
rancher-api (0.3.6)
|
5
5
|
faraday_middleware
|
6
6
|
faye-websocket
|
7
7
|
her (~> 0.7.6)
|
@@ -9,24 +9,28 @@ PATH
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
-
activemodel (4.2.
|
13
|
-
activesupport (= 4.2.
|
12
|
+
activemodel (4.2.5.2)
|
13
|
+
activesupport (= 4.2.5.2)
|
14
14
|
builder (~> 3.1)
|
15
|
-
activesupport (4.2.
|
15
|
+
activesupport (4.2.5.2)
|
16
16
|
i18n (~> 0.7)
|
17
17
|
json (~> 1.7, >= 1.7.7)
|
18
18
|
minitest (~> 5.1)
|
19
19
|
thread_safe (~> 0.3, >= 0.3.4)
|
20
20
|
tzinfo (~> 1.1)
|
21
|
+
addressable (2.3.8)
|
21
22
|
builder (3.2.2)
|
22
23
|
byebug (6.0.0)
|
24
|
+
coderay (1.1.0)
|
25
|
+
crack (0.4.2)
|
26
|
+
safe_yaml (~> 1.0.0)
|
23
27
|
diff-lcs (1.2.5)
|
24
|
-
eventmachine (1.0.
|
25
|
-
faraday (0.9.
|
28
|
+
eventmachine (1.0.9.1)
|
29
|
+
faraday (0.9.2)
|
26
30
|
multipart-post (>= 1.2, < 3)
|
27
|
-
faraday_middleware (0.
|
31
|
+
faraday_middleware (0.10.0)
|
28
32
|
faraday (>= 0.7.4, < 0.10)
|
29
|
-
faye-websocket (0.10.
|
33
|
+
faye-websocket (0.10.3)
|
30
34
|
eventmachine (>= 0.12.0)
|
31
35
|
websocket-driver (>= 0.5.1)
|
32
36
|
her (0.7.6)
|
@@ -36,9 +40,14 @@ GEM
|
|
36
40
|
multi_json (~> 1.7)
|
37
41
|
i18n (0.7.0)
|
38
42
|
json (1.8.3)
|
39
|
-
|
43
|
+
method_source (0.8.2)
|
44
|
+
minitest (5.8.4)
|
40
45
|
multi_json (1.11.2)
|
41
46
|
multipart-post (2.0.0)
|
47
|
+
pry (0.10.1)
|
48
|
+
coderay (~> 1.1.0)
|
49
|
+
method_source (~> 0.8.1)
|
50
|
+
slop (~> 3.4)
|
42
51
|
rake (10.4.2)
|
43
52
|
rspec (3.3.0)
|
44
53
|
rspec-core (~> 3.3.0)
|
@@ -53,10 +62,16 @@ GEM
|
|
53
62
|
diff-lcs (>= 1.2.0, < 2.0)
|
54
63
|
rspec-support (~> 3.3.0)
|
55
64
|
rspec-support (3.3.0)
|
65
|
+
safe_yaml (1.0.4)
|
66
|
+
slop (3.6.0)
|
56
67
|
thread_safe (0.3.5)
|
57
68
|
tzinfo (1.2.2)
|
58
69
|
thread_safe (~> 0.1)
|
59
|
-
|
70
|
+
vcr (2.9.3)
|
71
|
+
webmock (1.21.0)
|
72
|
+
addressable (>= 2.3.6)
|
73
|
+
crack (>= 0.3.2)
|
74
|
+
websocket-driver (0.6.3)
|
60
75
|
websocket-extensions (>= 0.1.0)
|
61
76
|
websocket-extensions (0.1.2)
|
62
77
|
|
@@ -66,9 +81,12 @@ PLATFORMS
|
|
66
81
|
DEPENDENCIES
|
67
82
|
bundler (~> 1.10)
|
68
83
|
byebug
|
84
|
+
pry
|
69
85
|
rake (~> 10.0)
|
70
86
|
rancher-api!
|
71
87
|
rspec (~> 3.3.0)
|
88
|
+
vcr (= 2.9.3)
|
89
|
+
webmock (= 1.21.0)
|
72
90
|
|
73
91
|
BUNDLED WITH
|
74
92
|
1.10.5
|
data/README.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
# Rancher::Api
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/rancher-api.svg)](http://badge.fury.io/rb/rancher-api)
|
4
|
+
![Downloads](http://ruby-gem-downloads-badge.herokuapp.com/rancher-api)
|
5
|
+
|
6
|
+
|
7
|
+
[![Circle CI](https://circleci.com/gh/akurkin/rancher-api/tree/master.svg?style=svg)](https://circleci.com/gh/akurkin/rancher-api/tree/master)
|
8
|
+
[![Code Climate](https://codeclimate.com/github/akurkin/rancher-api/badges/gpa.svg)](https://codeclimate.com/github/akurkin/rancher-api)
|
9
|
+
[![Test Coverage](https://codeclimate.com/github/akurkin/rancher-api/badges/coverage.svg)](https://codeclimate.com/github/akurkin/rancher-api/coverage)
|
10
|
+
|
11
|
+
|
3
12
|
Rancher::Api is a Ruby wrapper around [Rancher](http://rancher.com/) API built with [Her](http://www.her-rb.org/)
|
4
13
|
|
5
14
|
Connect to Rancher and execute requests from your ruby scripts.
|
@@ -29,24 +38,34 @@ Or install it yourself as:
|
|
29
38
|
## Rancher Version
|
30
39
|
|
31
40
|
Tested with:
|
32
|
-
Rancher v0.
|
41
|
+
Rancher v0.63.1
|
33
42
|
|
34
43
|
## Usage
|
35
44
|
|
36
45
|
Configure Rancher::Api first by providing url, access and secret keys:
|
37
46
|
|
38
|
-
###
|
39
|
-
|
40
|
-
**Project**
|
41
|
-
|
42
|
-
**
|
43
|
-
|
44
|
-
|
45
|
-
|
47
|
+
### Classes
|
48
|
+
|
49
|
+
- **Project**
|
50
|
+
Top level object that represents "Environment" in Rancher UI
|
51
|
+
- **Service**
|
52
|
+
Service (combines containers from the same image)
|
53
|
+
- **Machine**
|
54
|
+
Physical docker hosts
|
55
|
+
- **Instance**
|
56
|
+
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
|
57
|
+
- **Environment**
|
58
|
+
In Rancher UI these are known as **Stack**, though in API they are **environments**. We're sticking to API resource name
|
59
|
+
- **Host**
|
60
|
+
These are hosts, with detailed information about docker installation and resources
|
46
61
|
|
47
62
|
### Setup
|
48
63
|
|
64
|
+
#### Using initializer
|
65
|
+
|
49
66
|
```ruby
|
67
|
+
require 'rancher/api'
|
68
|
+
|
50
69
|
Rancher::Api.configure do |config|
|
51
70
|
config.url = 'http://127.0.0.1:8080/v1/'
|
52
71
|
config.access_key = '8604A1FC8C108BAFB1E3'
|
@@ -54,6 +73,18 @@ Rancher::Api.configure do |config|
|
|
54
73
|
end
|
55
74
|
```
|
56
75
|
|
76
|
+
#### Using environment variables
|
77
|
+
|
78
|
+
You can configure `rancher-api` gem using `rancher-compose`-compatible environment variables:
|
79
|
+
|
80
|
+
- RANCHER_URL
|
81
|
+
- RANCHER_ACCESS_KEY
|
82
|
+
- RANCHER_SECRET_KEY
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
Rancher::Api.setup!
|
86
|
+
```
|
87
|
+
|
57
88
|
### Querying
|
58
89
|
|
59
90
|
Now, you're able to query entities like this:
|
@@ -66,6 +97,10 @@ machine = Rancher::Api::Machine.find('1ph1')
|
|
66
97
|
### Creating new machines
|
67
98
|
Creating new machine using **Digital Ocean** driver:
|
68
99
|
|
100
|
+
**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'.
|
101
|
+
|
102
|
+
#### Digital Ocean
|
103
|
+
|
69
104
|
```ruby
|
70
105
|
project = Rancher::Api::Project.all.to_a.first
|
71
106
|
|
@@ -81,7 +116,31 @@ new_machine.driver_config = Rancher::Api::Machine::DriverConfig.new(
|
|
81
116
|
new_machine.save
|
82
117
|
```
|
83
118
|
|
84
|
-
|
119
|
+
#### Vmware Vsphere
|
120
|
+
|
121
|
+
```ruby
|
122
|
+
project = Rancher::Api::Project.all.to_a.first
|
123
|
+
|
124
|
+
new_machine = project.machines.build
|
125
|
+
new_machine.name = 'api-test'
|
126
|
+
new_machine.driver = Rancher::Api::Machine::VMWARE_VSPHERE
|
127
|
+
new_machine.driver_config = Rancher::Api::Machine::DriverConfig.new(
|
128
|
+
boot2dockerUrl: nil,
|
129
|
+
cpuCount: '1',
|
130
|
+
datacenter: 'ha-dc',
|
131
|
+
datastore: 'prod',
|
132
|
+
diskSize: '10000',
|
133
|
+
memorySize: '1024',
|
134
|
+
network: 'prod',
|
135
|
+
password: 'holamundo',
|
136
|
+
pool: nil,
|
137
|
+
username: 'myuser',
|
138
|
+
vcenter: 'vcenter.happyops.com',
|
139
|
+
vcenterPort: nil
|
140
|
+
)
|
141
|
+
|
142
|
+
new_machine.save
|
143
|
+
```
|
85
144
|
|
86
145
|
|
87
146
|
### Executing shell commands in containers
|
@@ -89,6 +148,7 @@ new_machine.save
|
|
89
148
|
```ruby
|
90
149
|
container = Rancher::Api::Instance.find('1i382')
|
91
150
|
puts container.execute('whoami').response
|
151
|
+
puts container.execute(['bundle', 'exec', 'rake', 'db:create', 'db:migrate']).response
|
92
152
|
```
|
93
153
|
|
94
154
|
## Development
|
data/circle.yml
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# Objectives of this script is to:
|
2
|
+
# - check if docker host for branch exists (using labels)
|
3
|
+
# - create docker host via Rancher if it doesn't exist
|
4
|
+
#
|
5
|
+
require 'rancher/api'
|
6
|
+
|
7
|
+
BRANCH = ENV['CIRCLE_BRANCH']
|
8
|
+
DIGITAL_OCEAN_ACCESS_TOKEN = 'xxx'
|
9
|
+
|
10
|
+
Rancher::Api.configure do |config|
|
11
|
+
config.url = "http://#{ENV['RANCHER_HOST']}/v1/"
|
12
|
+
config.access_key = ENV['RANCHER_ACCESS_KEY']
|
13
|
+
config.secret_key = ENV['RANCHER_SECRET_KEY']
|
14
|
+
end
|
15
|
+
|
16
|
+
project = Rancher::Api::Project.all.to_a.first
|
17
|
+
all_machines = project.machines
|
18
|
+
|
19
|
+
# 1. check if docker host exists, label branch must be equal to current branch
|
20
|
+
machine = all_machines.select { |x| x.labels['branch'] == BRANCH }.first
|
21
|
+
|
22
|
+
# 2. docker host doesn't exist, let's create one
|
23
|
+
unless machine
|
24
|
+
machine = project.machines.build
|
25
|
+
machine.name = 'app-' + BRANCH
|
26
|
+
machine.driver = Rancher::Api::Machine::DIGITAL_OCEAN
|
27
|
+
machine.driver_config = Rancher::Api::Machine::DriverConfig.new(
|
28
|
+
accessToken: DIGITAL_OCEAN_ACCESS_TOKEN,
|
29
|
+
size: '1gb',
|
30
|
+
region: 'ams3',
|
31
|
+
image: 'ubuntu-14-04-x64'
|
32
|
+
)
|
33
|
+
|
34
|
+
machine.labels = {
|
35
|
+
branch: BRANCH
|
36
|
+
}
|
37
|
+
|
38
|
+
machine.save
|
39
|
+
|
40
|
+
puts "CREATING NEW MACHINE: #{machine.id} - #{machine.name}"
|
41
|
+
puts 'Set timeout to 5 minutes'
|
42
|
+
|
43
|
+
# Wait until machine is active, on Digital Ocean claim to be 55 seconds
|
44
|
+
#
|
45
|
+
Timeout.timeout(300) do
|
46
|
+
i = 45
|
47
|
+
puts "Waiting #{i} seconds..."
|
48
|
+
sleep i
|
49
|
+
|
50
|
+
while machine.transitioning == 'yes'
|
51
|
+
wait_time = 5
|
52
|
+
i += wait_time
|
53
|
+
|
54
|
+
puts machine.transitioningMessage
|
55
|
+
puts "Waiting total: #{i} seconds ..."
|
56
|
+
|
57
|
+
sleep wait_time
|
58
|
+
|
59
|
+
machine = Rancher::Api::Machine.find(machine.id)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/lib/rancher/api.rb
CHANGED
@@ -4,6 +4,7 @@ module Rancher
|
|
4
4
|
module Api
|
5
5
|
class Machine
|
6
6
|
DIGITAL_OCEAN = 'digitalocean'
|
7
|
+
VMWARE_VSPHERE = 'vmwarevsphere'
|
7
8
|
|
8
9
|
include Her::Model
|
9
10
|
|
@@ -17,15 +18,15 @@ module Rancher
|
|
17
18
|
|
18
19
|
def driver_config
|
19
20
|
case driver
|
20
|
-
when DIGITAL_OCEAN
|
21
|
-
DriverConfig.new(attributes["#{
|
21
|
+
when DIGITAL_OCEAN, VMWARE_VSPHERE
|
22
|
+
DriverConfig.new(attributes["#{driver}Config"])
|
22
23
|
end
|
23
24
|
end
|
24
25
|
|
25
26
|
def driver_config=(dc)
|
26
27
|
case driver
|
27
|
-
when DIGITAL_OCEAN
|
28
|
-
attributes["#{
|
28
|
+
when DIGITAL_OCEAN, VMWARE_VSPHERE
|
29
|
+
attributes["#{driver}Config"] = dc.attributes
|
29
30
|
end
|
30
31
|
end
|
31
32
|
end
|
data/lib/rancher/api/version.rb
CHANGED
data/rancher-api.gemspec
CHANGED
@@ -34,5 +34,8 @@ Gem::Specification.new do |spec|
|
|
34
34
|
spec.add_development_dependency 'bundler', '~> 1.10'
|
35
35
|
spec.add_development_dependency 'rake', '~> 10.0'
|
36
36
|
spec.add_development_dependency 'rspec', '~> 3.3.0'
|
37
|
+
spec.add_development_dependency 'pry'
|
37
38
|
spec.add_development_dependency 'byebug'
|
39
|
+
spec.add_development_dependency 'webmock', '1.21.0'
|
40
|
+
spec.add_development_dependency 'vcr', '2.9.3'
|
38
41
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rancher-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Kurkin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-03-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: her
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: 3.3.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: byebug
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,6 +122,34 @@ dependencies:
|
|
108
122
|
- - ">="
|
109
123
|
- !ruby/object:Gem::Version
|
110
124
|
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: webmock
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 1.21.0
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 1.21.0
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: vcr
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - '='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 2.9.3
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - '='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 2.9.3
|
111
153
|
description: Ruby gem to easily connect to Rancher API. Via this gem you can do anything
|
112
154
|
that API lets you to do it
|
113
155
|
email:
|
@@ -128,6 +170,8 @@ files:
|
|
128
170
|
- Rakefile
|
129
171
|
- bin/console
|
130
172
|
- bin/setup
|
173
|
+
- circle.yml
|
174
|
+
- examples/create_docker_host.rb
|
131
175
|
- lib/rancher/api.rb
|
132
176
|
- lib/rancher/api/configuration.rb
|
133
177
|
- lib/rancher/api/middlewares.rb
|