rancher-api 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +70 -0
- data/.ruby-version +1 -1
- data/.simplecov +3 -0
- data/.travis.yml +2 -2
- data/CHANGELOG.md +7 -0
- data/Gemfile.lock +40 -1
- data/Guardfile +16 -0
- data/Rakefile +2 -2
- data/circle.yml +2 -2
- data/examples/create_docker_host.rb +1 -1
- data/lib/rancher/api.rb +4 -1
- data/lib/rancher/api/configuration.rb +1 -0
- data/lib/rancher/api/helpers/model.rb +52 -0
- data/lib/rancher/api/logger.rb +17 -0
- data/lib/rancher/api/models.rb +3 -0
- data/lib/rancher/api/models/environment.rb +2 -1
- data/lib/rancher/api/models/host.rb +2 -1
- data/lib/rancher/api/models/instance.rb +1 -0
- data/lib/rancher/api/models/instance/action.rb +3 -3
- data/lib/rancher/api/models/ipaddress.rb +1 -0
- data/lib/rancher/api/models/machine.rb +14 -3
- data/lib/rancher/api/models/project.rb +8 -0
- data/lib/rancher/api/models/service.rb +1 -0
- data/lib/rancher/api/version.rb +1 -1
- data/rancher-api.gemspec +2 -0
- metadata +36 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e9dc7fd9ad65a52a06dc3102fd28e42ad351c94f
|
4
|
+
data.tar.gz: 4516084002b8c5553f9e58531488dedc0b9e65ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 24ad7ced55183d634829837a85fb8f89875d91ce8e828abd645a6412ada28c9745ed1b56cd2efb00aedb05b772ae54162e4114d5b2cd44e1dc0dc45a15fd03ba
|
7
|
+
data.tar.gz: e15136bc80186c7fefa734e2dc1b5590c8164d082a7a2a176d2c6d3435e0cff6bde82531e9d2e2860676bb32d419068afbe1fe6a0b58bba79e962992956378f1
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.2
|
3
|
+
Exclude:
|
4
|
+
- '*.gemspec'
|
5
|
+
- 'Gemfile*'
|
6
|
+
|
7
|
+
Metrics/ModuleLength:
|
8
|
+
Max: 108
|
9
|
+
Exclude:
|
10
|
+
- 'spec/lib/**/*'
|
11
|
+
|
12
|
+
# Offense count: 33
|
13
|
+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
|
14
|
+
# URISchemes: http, https
|
15
|
+
Metrics/LineLength:
|
16
|
+
Max: 120
|
17
|
+
|
18
|
+
# Offense count: 6
|
19
|
+
# Configuration parameters: CountComments.
|
20
|
+
Metrics/MethodLength:
|
21
|
+
Max: 18
|
22
|
+
|
23
|
+
# Offense count: 1
|
24
|
+
# Cop supports --auto-correct.
|
25
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
26
|
+
# SupportedStyles: with_first_parameter, with_fixed_indentation
|
27
|
+
Style/AlignParameters:
|
28
|
+
Exclude:
|
29
|
+
- 'bin/rspec'
|
30
|
+
|
31
|
+
# Offense count: 2
|
32
|
+
# Cop supports --auto-correct.
|
33
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
34
|
+
# SupportedStyles: always, conditionals
|
35
|
+
Style/AndOr:
|
36
|
+
Exclude:
|
37
|
+
- 'bin/setup'
|
38
|
+
- 'bin/update'
|
39
|
+
|
40
|
+
# Offense count: 17
|
41
|
+
Style/Documentation:
|
42
|
+
Enabled: false
|
43
|
+
|
44
|
+
# Offense count: 6
|
45
|
+
# Cop supports --auto-correct.
|
46
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues.
|
47
|
+
# SupportedStyles: ruby19, ruby19_no_mixed_keys, hash_rockets
|
48
|
+
Style/HashSyntax:
|
49
|
+
Enabled: false
|
50
|
+
|
51
|
+
# Offense count: 3
|
52
|
+
# Cop supports --auto-correct.
|
53
|
+
# Configuration parameters: SupportedStyles.
|
54
|
+
# SupportedStyles: call, braces
|
55
|
+
Style/LambdaCall:
|
56
|
+
EnforcedStyle: braces
|
57
|
+
|
58
|
+
# Offense count: 2
|
59
|
+
# Cop supports --auto-correct.
|
60
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
|
61
|
+
# SupportedStyles: aligned, indented
|
62
|
+
Style/MultilineMethodCallIndentation:
|
63
|
+
Enabled: false
|
64
|
+
|
65
|
+
# Offense count: 1
|
66
|
+
# Cop supports --auto-correct.
|
67
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
|
68
|
+
# SupportedStyles: space, no_space
|
69
|
+
Style/SpaceInsideBlockBraces:
|
70
|
+
Enabled: false
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.2.5
|
data/.simplecov
ADDED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,13 @@
|
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
4
4
|
|
5
|
+
## [0.5.0] - 2016-08-10
|
6
|
+
|
7
|
+
- added few helpers:
|
8
|
+
- #wait_for_state - waiting (EM looping) until a desired state is reached
|
9
|
+
- #reload - reloading of resources
|
10
|
+
- #run - run actions (custom posts)
|
11
|
+
|
5
12
|
## [0.4.0] - 2016-07-14
|
6
13
|
|
7
14
|
- update dependencies to work with Rails 5
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rancher-api (0.
|
4
|
+
rancher-api (0.5.0)
|
5
5
|
faraday_middleware
|
6
6
|
faye-websocket
|
7
7
|
her (~> 0.8.1)
|
@@ -26,6 +26,7 @@ GEM
|
|
26
26
|
crack (0.4.2)
|
27
27
|
safe_yaml (~> 1.0.0)
|
28
28
|
diff-lcs (1.2.5)
|
29
|
+
docile (1.1.5)
|
29
30
|
eventmachine (1.2.0.1)
|
30
31
|
faraday (0.9.2)
|
31
32
|
multipart-post (>= 1.2, < 3)
|
@@ -34,6 +35,22 @@ GEM
|
|
34
35
|
faye-websocket (0.10.4)
|
35
36
|
eventmachine (>= 0.12.0)
|
36
37
|
websocket-driver (>= 0.5.1)
|
38
|
+
ffi (1.9.10)
|
39
|
+
formatador (0.2.5)
|
40
|
+
guard (2.14.0)
|
41
|
+
formatador (>= 0.2.4)
|
42
|
+
listen (>= 2.7, < 4.0)
|
43
|
+
lumberjack (~> 1.0)
|
44
|
+
nenv (~> 0.1)
|
45
|
+
notiffany (~> 0.0)
|
46
|
+
pry (>= 0.9.12)
|
47
|
+
shellany (~> 0.0)
|
48
|
+
thor (>= 0.18.1)
|
49
|
+
guard-compat (1.2.1)
|
50
|
+
guard-rspec (4.7.2)
|
51
|
+
guard (~> 2.1)
|
52
|
+
guard-compat (~> 1.1)
|
53
|
+
rspec (>= 2.99.0, < 4.0)
|
37
54
|
her (0.8.1)
|
38
55
|
activemodel (>= 3.0.0, <= 4.3.0)
|
39
56
|
activesupport (>= 3.0.0, <= 4.3.0)
|
@@ -41,15 +58,27 @@ GEM
|
|
41
58
|
multi_json (~> 1.7)
|
42
59
|
i18n (0.7.0)
|
43
60
|
json (1.8.3)
|
61
|
+
listen (3.1.5)
|
62
|
+
rb-fsevent (~> 0.9, >= 0.9.4)
|
63
|
+
rb-inotify (~> 0.9, >= 0.9.7)
|
64
|
+
ruby_dep (~> 1.2)
|
65
|
+
lumberjack (1.0.10)
|
44
66
|
method_source (0.8.2)
|
45
67
|
minitest (5.9.0)
|
46
68
|
multi_json (1.12.1)
|
47
69
|
multipart-post (2.0.0)
|
70
|
+
nenv (0.3.0)
|
71
|
+
notiffany (0.1.0)
|
72
|
+
nenv (~> 0.1)
|
73
|
+
shellany (~> 0.0)
|
48
74
|
pry (0.10.1)
|
49
75
|
coderay (~> 1.1.0)
|
50
76
|
method_source (~> 0.8.1)
|
51
77
|
slop (~> 3.4)
|
52
78
|
rake (10.4.2)
|
79
|
+
rb-fsevent (0.9.7)
|
80
|
+
rb-inotify (0.9.7)
|
81
|
+
ffi (>= 0.5.0)
|
53
82
|
rspec (3.3.0)
|
54
83
|
rspec-core (~> 3.3.0)
|
55
84
|
rspec-expectations (~> 3.3.0)
|
@@ -63,8 +92,16 @@ GEM
|
|
63
92
|
diff-lcs (>= 1.2.0, < 2.0)
|
64
93
|
rspec-support (~> 3.3.0)
|
65
94
|
rspec-support (3.3.0)
|
95
|
+
ruby_dep (1.3.1)
|
66
96
|
safe_yaml (1.0.4)
|
97
|
+
shellany (0.0.1)
|
98
|
+
simplecov (0.12.0)
|
99
|
+
docile (~> 1.1.0)
|
100
|
+
json (>= 1.8, < 3)
|
101
|
+
simplecov-html (~> 0.10.0)
|
102
|
+
simplecov-html (0.10.0)
|
67
103
|
slop (3.6.0)
|
104
|
+
thor (0.19.1)
|
68
105
|
thread_safe (0.3.5)
|
69
106
|
tzinfo (1.2.2)
|
70
107
|
thread_safe (~> 0.1)
|
@@ -83,10 +120,12 @@ DEPENDENCIES
|
|
83
120
|
awesome_print
|
84
121
|
bundler (~> 1.10)
|
85
122
|
byebug
|
123
|
+
guard-rspec
|
86
124
|
pry
|
87
125
|
rake (~> 10.0)
|
88
126
|
rancher-api!
|
89
127
|
rspec (~> 3.3.0)
|
128
|
+
simplecov
|
90
129
|
vcr (= 2.9.3)
|
91
130
|
webmock (= 1.21.0)
|
92
131
|
|
data/Guardfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
guard :rspec, cmd: 'bundle exec rspec' do
|
2
|
+
require 'guard/rspec/dsl'
|
3
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
4
|
+
|
5
|
+
# Feel free to open issues for suggestions and improvements
|
6
|
+
|
7
|
+
# RSpec files
|
8
|
+
rspec = dsl.rspec
|
9
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
10
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
11
|
+
watch(rspec.spec_files)
|
12
|
+
|
13
|
+
# Ruby files
|
14
|
+
ruby = dsl.ruby
|
15
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
16
|
+
end
|
data/Rakefile
CHANGED
data/circle.yml
CHANGED
data/lib/rancher/api.rb
CHANGED
@@ -4,6 +4,7 @@ require 'her'
|
|
4
4
|
require 'rancher/api/configuration'
|
5
5
|
require 'rancher/api/middlewares'
|
6
6
|
require 'rancher/api/version'
|
7
|
+
require 'rancher/api/logger'
|
7
8
|
|
8
9
|
module Rancher
|
9
10
|
module Api
|
@@ -27,7 +28,7 @@ module Rancher
|
|
27
28
|
def self.configure
|
28
29
|
yield(configuration)
|
29
30
|
|
30
|
-
Her::API.setup url: configuration.url do |c|
|
31
|
+
api = Her::API.setup url: configuration.url do |c|
|
31
32
|
# Request
|
32
33
|
c.request :json
|
33
34
|
|
@@ -37,12 +38,14 @@ module Rancher
|
|
37
38
|
# Response
|
38
39
|
c.use Rancher::Api::JsonParserMiddleware
|
39
40
|
c.use Her::Middleware::DefaultParseJSON
|
41
|
+
c.use Faraday::Response::Logger, ActiveSupport::Logger.new(STDOUT) if configuration.verbose
|
40
42
|
|
41
43
|
# Adapter
|
42
44
|
c.use Faraday::Adapter::NetHttp
|
43
45
|
end
|
44
46
|
|
45
47
|
require 'rancher/api/models'
|
48
|
+
api
|
46
49
|
end
|
47
50
|
end
|
48
51
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'eventmachine'
|
2
|
+
|
3
|
+
module Rancher
|
4
|
+
module Api
|
5
|
+
module Helpers
|
6
|
+
module Model
|
7
|
+
class RancherWaitTimeOutError < StandardError; end
|
8
|
+
class RancherModelError < StandardError; end
|
9
|
+
class RancherActionNotAvailableError < StandardError; end
|
10
|
+
|
11
|
+
TIMEOUT_LIMIT = 900
|
12
|
+
|
13
|
+
def self_url
|
14
|
+
links['self']
|
15
|
+
end
|
16
|
+
|
17
|
+
def reload
|
18
|
+
assign_attributes(self.class.find(id).attributes)
|
19
|
+
end
|
20
|
+
|
21
|
+
def run(action, data: {})
|
22
|
+
url = actions[action.to_s]
|
23
|
+
raise RancherActionNotAvailableError, "Available actions: '#{actions.inspect}'" if url.blank?
|
24
|
+
handle_response(self.class.post(url, data))
|
25
|
+
end
|
26
|
+
|
27
|
+
def handle_response(response)
|
28
|
+
raise RancherModelError, response.inspect if response.type.eql?('error')
|
29
|
+
end
|
30
|
+
|
31
|
+
def wait_for_state(desired_state)
|
32
|
+
EM.run do
|
33
|
+
EM.add_timer(TIMEOUT_LIMIT) do
|
34
|
+
raise RancherWaitTimeOutError, "Timeout while waiting for transition to: #{desired_state}"
|
35
|
+
end
|
36
|
+
EM.tick_loop do
|
37
|
+
reload
|
38
|
+
current_state = state
|
39
|
+
if current_state.eql?(desired_state.to_s)
|
40
|
+
Logger.log.info "state changed from: #{current_state} => #{desired_state}"
|
41
|
+
EM.stop
|
42
|
+
else
|
43
|
+
Logger.log.info "waiting for state change: #{current_state} => #{desired_state}"
|
44
|
+
sleep(1)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/rancher/api/models.rb
CHANGED
@@ -31,16 +31,16 @@ module Rancher
|
|
31
31
|
ws = Faye::WebSocket::Client.new(uri.to_s)
|
32
32
|
|
33
33
|
ws.on :message do |event|
|
34
|
-
|
34
|
+
response << Base64.decode64(event.data)
|
35
35
|
end
|
36
36
|
|
37
|
-
ws.on :close do |
|
37
|
+
ws.on :close do |_event|
|
38
38
|
ws = nil
|
39
39
|
EM.stop
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
self.response =
|
43
|
+
self.response = response.join
|
44
44
|
|
45
45
|
self
|
46
46
|
end
|
@@ -3,10 +3,11 @@ require 'rancher/api/models/machine/driver_config'
|
|
3
3
|
module Rancher
|
4
4
|
module Api
|
5
5
|
class Machine
|
6
|
-
DIGITAL_OCEAN = 'digitalocean'
|
7
|
-
VMWARE_VSPHERE = 'vmwarevsphere'
|
8
|
-
|
9
6
|
include Her::Model
|
7
|
+
include Helpers::Model
|
8
|
+
|
9
|
+
DIGITAL_OCEAN = 'digitalocean'.freeze
|
10
|
+
VMWARE_VSPHERE = 'vmwarevsphere'.freeze
|
10
11
|
|
11
12
|
attributes :name, :state, :amazonec2Config, :azureConfig, :description,
|
12
13
|
:digitaloceanConfig, :driver, :exoscaleConfig, :externalId,
|
@@ -16,6 +17,16 @@ module Rancher
|
|
16
17
|
|
17
18
|
has_many :hosts
|
18
19
|
|
20
|
+
class << self
|
21
|
+
def transitioning
|
22
|
+
all.select { |m| m.transitioning.eql?('yes') }
|
23
|
+
end
|
24
|
+
|
25
|
+
def active
|
26
|
+
where(state: 'active')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
19
30
|
def driver_config
|
20
31
|
case driver
|
21
32
|
when DIGITAL_OCEAN, VMWARE_VSPHERE
|
@@ -3,10 +3,18 @@ module Rancher
|
|
3
3
|
module Api
|
4
4
|
class Project
|
5
5
|
include Her::Model
|
6
|
+
include Helpers::Model
|
6
7
|
|
7
8
|
has_many :machines
|
8
9
|
has_many :environments
|
9
10
|
has_many :services
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def find_by_name(name:)
|
14
|
+
# filters not working for name yet, so using select
|
15
|
+
all.reject { |e| e.state.eql?('purged') }.select { |e| e.name.eql?(name) }
|
16
|
+
end
|
17
|
+
end
|
10
18
|
end
|
11
19
|
end
|
12
20
|
end
|
data/lib/rancher/api/version.rb
CHANGED
data/rancher-api.gemspec
CHANGED
@@ -39,4 +39,6 @@ Gem::Specification.new do |spec|
|
|
39
39
|
spec.add_development_dependency 'webmock', '1.21.0'
|
40
40
|
spec.add_development_dependency 'vcr', '2.9.3'
|
41
41
|
spec.add_development_dependency 'awesome_print'
|
42
|
+
spec.add_development_dependency 'guard-rspec'
|
43
|
+
spec.add_development_dependency 'simplecov'
|
42
44
|
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.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Kurkin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: her
|
@@ -164,6 +164,34 @@ dependencies:
|
|
164
164
|
- - ">="
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: guard-rspec
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: simplecov
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - ">="
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
167
195
|
description: Ruby gem to easily connect to Rancher API. Via this gem you can do anything
|
168
196
|
that API lets you to do it
|
169
197
|
email:
|
@@ -174,11 +202,14 @@ extra_rdoc_files: []
|
|
174
202
|
files:
|
175
203
|
- ".gitignore"
|
176
204
|
- ".rspec"
|
205
|
+
- ".rubocop.yml"
|
177
206
|
- ".ruby-version"
|
207
|
+
- ".simplecov"
|
178
208
|
- ".travis.yml"
|
179
209
|
- CHANGELOG.md
|
180
210
|
- Gemfile
|
181
211
|
- Gemfile.lock
|
212
|
+
- Guardfile
|
182
213
|
- LICENSE
|
183
214
|
- LICENSE.txt
|
184
215
|
- README.md
|
@@ -189,6 +220,8 @@ files:
|
|
189
220
|
- examples/create_docker_host.rb
|
190
221
|
- lib/rancher/api.rb
|
191
222
|
- lib/rancher/api/configuration.rb
|
223
|
+
- lib/rancher/api/helpers/model.rb
|
224
|
+
- lib/rancher/api/logger.rb
|
192
225
|
- lib/rancher/api/middlewares.rb
|
193
226
|
- lib/rancher/api/middlewares/json_parser_middleware.rb
|
194
227
|
- lib/rancher/api/models.rb
|
@@ -224,7 +257,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
224
257
|
version: '0'
|
225
258
|
requirements: []
|
226
259
|
rubyforge_project:
|
227
|
-
rubygems_version: 2.5.1
|
260
|
+
rubygems_version: 2.4.5.1
|
228
261
|
signing_key:
|
229
262
|
specification_version: 4
|
230
263
|
summary: Easily connect to Rancher API!
|