rancher-api 0.2.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 +7 -0
- data/.gitignore +35 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +74 -0
- data/LICENSE +22 -0
- data/LICENSE.txt +21 -0
- data/README.md +98 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/rancher/api.rb +43 -0
- data/lib/rancher/api/configuration.rb +9 -0
- data/lib/rancher/api/middlewares.rb +1 -0
- data/lib/rancher/api/middlewares/json_parser_middleware.rb +44 -0
- data/lib/rancher/api/models.rb +4 -0
- data/lib/rancher/api/models/host.rb +10 -0
- data/lib/rancher/api/models/instance.rb +73 -0
- data/lib/rancher/api/models/instance/action.rb +50 -0
- data/lib/rancher/api/models/machine.rb +33 -0
- data/lib/rancher/api/models/machine/driver_config.rb +9 -0
- data/lib/rancher/api/models/project.rb +9 -0
- data/lib/rancher/api/version.rb +5 -0
- data/rancher-api.gemspec +38 -0
- metadata +169 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: fb6ea154624762ec7c91dfe7db9689f6cdc53d03
|
|
4
|
+
data.tar.gz: 70385e013a06c81dde08b83f370c22747ddbab54
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 6efeee9741e0ec187a68148b38667d0d9618b08889ef5da7e1098c9815c70a980c06e6527d1c30433f3d43ee72b13e1675f65bbc649ae0ea2f2f1b14b216c758
|
|
7
|
+
data.tar.gz: 11f49715abca57c4efa766f71df423fc012e0bbdfe92a42e9f1df65319c24687af650b552f306f926c4d45eb0ed74ca3295d0e4508acd12a431774fc0846dcde
|
data/.gitignore
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
*.gem
|
|
2
|
+
*.rbc
|
|
3
|
+
/.config
|
|
4
|
+
/coverage/
|
|
5
|
+
/InstalledFiles
|
|
6
|
+
/pkg/
|
|
7
|
+
/spec/reports/
|
|
8
|
+
/test/tmp/
|
|
9
|
+
/test/version_tmp/
|
|
10
|
+
/tmp/
|
|
11
|
+
|
|
12
|
+
## Specific to RubyMotion:
|
|
13
|
+
.dat*
|
|
14
|
+
.repl_history
|
|
15
|
+
build/
|
|
16
|
+
|
|
17
|
+
## Documentation cache and generated files:
|
|
18
|
+
/.yardoc/
|
|
19
|
+
/_yardoc/
|
|
20
|
+
/doc/
|
|
21
|
+
/rdoc/
|
|
22
|
+
|
|
23
|
+
## Environment normalisation:
|
|
24
|
+
/.bundle/
|
|
25
|
+
/vendor/bundle
|
|
26
|
+
/lib/bundler/man/
|
|
27
|
+
|
|
28
|
+
# for a library or gem, you might want to ignore these files since the code is
|
|
29
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
30
|
+
# Gemfile.lock
|
|
31
|
+
# .ruby-version
|
|
32
|
+
# .ruby-gemset
|
|
33
|
+
|
|
34
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
|
35
|
+
.rvmrc
|
data/.rspec
ADDED
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
2.2.2
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
rancher-api (0.2.0)
|
|
5
|
+
faraday_middleware
|
|
6
|
+
faye-websocket
|
|
7
|
+
her (~> 0.7.6)
|
|
8
|
+
|
|
9
|
+
GEM
|
|
10
|
+
remote: https://rubygems.org/
|
|
11
|
+
specs:
|
|
12
|
+
activemodel (4.2.3)
|
|
13
|
+
activesupport (= 4.2.3)
|
|
14
|
+
builder (~> 3.1)
|
|
15
|
+
activesupport (4.2.3)
|
|
16
|
+
i18n (~> 0.7)
|
|
17
|
+
json (~> 1.7, >= 1.7.7)
|
|
18
|
+
minitest (~> 5.1)
|
|
19
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
|
20
|
+
tzinfo (~> 1.1)
|
|
21
|
+
builder (3.2.2)
|
|
22
|
+
byebug (6.0.0)
|
|
23
|
+
diff-lcs (1.2.5)
|
|
24
|
+
eventmachine (1.0.8)
|
|
25
|
+
faraday (0.9.1)
|
|
26
|
+
multipart-post (>= 1.2, < 3)
|
|
27
|
+
faraday_middleware (0.9.1)
|
|
28
|
+
faraday (>= 0.7.4, < 0.10)
|
|
29
|
+
faye-websocket (0.10.0)
|
|
30
|
+
eventmachine (>= 0.12.0)
|
|
31
|
+
websocket-driver (>= 0.5.1)
|
|
32
|
+
her (0.7.6)
|
|
33
|
+
activemodel (>= 3.0.0, <= 4.3.0)
|
|
34
|
+
activesupport (>= 3.0.0, <= 4.3.0)
|
|
35
|
+
faraday (>= 0.8, < 1.0)
|
|
36
|
+
multi_json (~> 1.7)
|
|
37
|
+
i18n (0.7.0)
|
|
38
|
+
json (1.8.3)
|
|
39
|
+
minitest (5.8.0)
|
|
40
|
+
multi_json (1.11.2)
|
|
41
|
+
multipart-post (2.0.0)
|
|
42
|
+
rake (10.4.2)
|
|
43
|
+
rspec (3.3.0)
|
|
44
|
+
rspec-core (~> 3.3.0)
|
|
45
|
+
rspec-expectations (~> 3.3.0)
|
|
46
|
+
rspec-mocks (~> 3.3.0)
|
|
47
|
+
rspec-core (3.3.2)
|
|
48
|
+
rspec-support (~> 3.3.0)
|
|
49
|
+
rspec-expectations (3.3.1)
|
|
50
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
51
|
+
rspec-support (~> 3.3.0)
|
|
52
|
+
rspec-mocks (3.3.2)
|
|
53
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
54
|
+
rspec-support (~> 3.3.0)
|
|
55
|
+
rspec-support (3.3.0)
|
|
56
|
+
thread_safe (0.3.5)
|
|
57
|
+
tzinfo (1.2.2)
|
|
58
|
+
thread_safe (~> 0.1)
|
|
59
|
+
websocket-driver (0.6.2)
|
|
60
|
+
websocket-extensions (>= 0.1.0)
|
|
61
|
+
websocket-extensions (0.1.2)
|
|
62
|
+
|
|
63
|
+
PLATFORMS
|
|
64
|
+
ruby
|
|
65
|
+
|
|
66
|
+
DEPENDENCIES
|
|
67
|
+
bundler (~> 1.10)
|
|
68
|
+
byebug
|
|
69
|
+
rake (~> 10.0)
|
|
70
|
+
rancher-api!
|
|
71
|
+
rspec (~> 3.3.0)
|
|
72
|
+
|
|
73
|
+
BUNDLED WITH
|
|
74
|
+
1.10.5
|
data/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2015 Alex Kurkin
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2015 Alex Kurkin
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# Rancher::Api
|
|
2
|
+
|
|
3
|
+
Rancher::Api is a Ruby wrapper around [Rancher](http://rancher.com/) API built with [Her](http://www.her-rb.org/)
|
|
4
|
+
|
|
5
|
+
Connect to Rancher and execute requests from your ruby scripts.
|
|
6
|
+
It allows you to use some of the super nice features from Rancher:
|
|
7
|
+
|
|
8
|
+
- provision VMs from different cloud providers (behind the scenes Rancher uses docker-machine, so that means you can create VMs in DigitalOcean, AWS, Rackspace and many more, check [list of supported drivers by Docker Machine](https://docs.docker.com/machine/drivers/))
|
|
9
|
+
- deploy your containers
|
|
10
|
+
- watch your containers
|
|
11
|
+
- scale your containers as you wish
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
Add this line to your application's Gemfile:
|
|
16
|
+
|
|
17
|
+
```ruby
|
|
18
|
+
gem 'rancher-api'
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
And then execute:
|
|
22
|
+
|
|
23
|
+
$ bundle
|
|
24
|
+
|
|
25
|
+
Or install it yourself as:
|
|
26
|
+
|
|
27
|
+
$ gem install rancher-api
|
|
28
|
+
|
|
29
|
+
## Rancher Version
|
|
30
|
+
|
|
31
|
+
Tested with:
|
|
32
|
+
Rancher v0.32.0
|
|
33
|
+
|
|
34
|
+
## Usage
|
|
35
|
+
|
|
36
|
+
Configure Rancher::Api first by providing url, access and secret keys:
|
|
37
|
+
|
|
38
|
+
```ruby
|
|
39
|
+
Rancher::Api.configure do |config|
|
|
40
|
+
config.url = 'http://127.0.0.1:8080/v1/'
|
|
41
|
+
config.access_key = '8604A1FC8C108BAFB1E3'
|
|
42
|
+
config.secret_key = '4BhuyyyAaaaaBbbbi7yaZzzAaa3y13pC6D7e569'
|
|
43
|
+
end
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Querying
|
|
47
|
+
|
|
48
|
+
Now, you're able to query entities like this:
|
|
49
|
+
|
|
50
|
+
```ruby
|
|
51
|
+
project = Rancher::Api::Project.all.to_a
|
|
52
|
+
machine = Rancher::Api::Machine.find('1ph1')
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Creating new machines
|
|
56
|
+
Creating new machine using **Digital Ocean** driver:
|
|
57
|
+
|
|
58
|
+
```ruby
|
|
59
|
+
project = Rancher::Api::Project.all.to_a.first
|
|
60
|
+
|
|
61
|
+
new_machine = project.machines.build
|
|
62
|
+
new_machine.driver = Rancher::Api::Machine::DIGITAL_OCEAN
|
|
63
|
+
new_machine.driver_config = Rancher::Api::Machine::DriverConfig.new(
|
|
64
|
+
accessToken: 'xyz',
|
|
65
|
+
size: '1gb',
|
|
66
|
+
region: 'ams3',
|
|
67
|
+
image: 'ubuntu-14-04-x64'
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
new_machine.save
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
**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'.
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
## Executing shell commands in containers
|
|
77
|
+
|
|
78
|
+
```ruby
|
|
79
|
+
container = Rancher::Api::Instance.find('1i382')
|
|
80
|
+
puts container.execute('whoami').response
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Development
|
|
84
|
+
|
|
85
|
+
To load environment with pry run `pry -I lib -r rancher/api`
|
|
86
|
+
|
|
87
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
88
|
+
|
|
89
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
90
|
+
|
|
91
|
+
## Contributing
|
|
92
|
+
|
|
93
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/akurkin/rancher-api.
|
|
94
|
+
|
|
95
|
+
## License
|
|
96
|
+
|
|
97
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
|
98
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "rancher/api"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/rancher/api.rb
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
require 'faraday_middleware'
|
|
2
|
+
require 'her'
|
|
3
|
+
|
|
4
|
+
require 'rancher/api/configuration'
|
|
5
|
+
require 'rancher/api/middlewares'
|
|
6
|
+
require 'rancher/api/version'
|
|
7
|
+
|
|
8
|
+
module Rancher
|
|
9
|
+
module Api
|
|
10
|
+
class << self
|
|
11
|
+
attr_writer :configuration
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.configuration
|
|
15
|
+
@configuration ||= Configuration.new
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def self.reset
|
|
19
|
+
@configuration = Configuration.new
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.configure
|
|
23
|
+
yield(configuration)
|
|
24
|
+
|
|
25
|
+
Her::API.setup url: configuration.url do |c|
|
|
26
|
+
# Request
|
|
27
|
+
c.request :json
|
|
28
|
+
|
|
29
|
+
c.use Her::Middleware::AcceptJSON
|
|
30
|
+
c.use Faraday::Request::BasicAuthentication, configuration.access_key, configuration.secret_key
|
|
31
|
+
|
|
32
|
+
# Response
|
|
33
|
+
c.use Rancher::Api::JsonParserMiddleware
|
|
34
|
+
c.use Her::Middleware::DefaultParseJSON
|
|
35
|
+
|
|
36
|
+
# Adapter
|
|
37
|
+
c.use Faraday::Adapter::NetHttp
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
require 'rancher/api/models'
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require 'rancher/api/middlewares/json_parser_middleware'
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
module Rancher
|
|
2
|
+
module Api
|
|
3
|
+
class JsonParserMiddleware < Faraday::Response::Middleware
|
|
4
|
+
def on_complete(env)
|
|
5
|
+
body = env[:body]
|
|
6
|
+
|
|
7
|
+
# Case when resource requested individually doesn't require special
|
|
8
|
+
# handling
|
|
9
|
+
#
|
|
10
|
+
# {
|
|
11
|
+
# "id": "1ph1",
|
|
12
|
+
# "type": "machine",
|
|
13
|
+
# ...
|
|
14
|
+
# }
|
|
15
|
+
#
|
|
16
|
+
|
|
17
|
+
# Case when resources are nested inside another 'data' key in response
|
|
18
|
+
# require sepcial handling like the one below
|
|
19
|
+
#
|
|
20
|
+
# {
|
|
21
|
+
# "type": "collection",
|
|
22
|
+
# "resourceType": "machine",
|
|
23
|
+
# "data": [
|
|
24
|
+
# {
|
|
25
|
+
# "id": "1ph1",
|
|
26
|
+
# "type": "machine",
|
|
27
|
+
# ...
|
|
28
|
+
# }
|
|
29
|
+
# ]
|
|
30
|
+
# }
|
|
31
|
+
#
|
|
32
|
+
|
|
33
|
+
# If requested resource has type collection - massage data a bit
|
|
34
|
+
# if it's a single resource, just return and render response
|
|
35
|
+
#
|
|
36
|
+
return unless body[:data][:type] == 'collection'
|
|
37
|
+
|
|
38
|
+
env[:body] = {
|
|
39
|
+
data: body[:data][:data]
|
|
40
|
+
}
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
require 'rancher/api/models/instance/action'
|
|
2
|
+
|
|
3
|
+
module Rancher
|
|
4
|
+
module Api
|
|
5
|
+
#
|
|
6
|
+
# instance usually container
|
|
7
|
+
#
|
|
8
|
+
class Instance
|
|
9
|
+
include ::Her::Model
|
|
10
|
+
|
|
11
|
+
belongs_to :host
|
|
12
|
+
|
|
13
|
+
def container?
|
|
14
|
+
type == 'container'
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
#
|
|
18
|
+
# Actions: execute, logs, restart, setlabels, stop, update
|
|
19
|
+
#
|
|
20
|
+
|
|
21
|
+
#
|
|
22
|
+
# Execute works like this:
|
|
23
|
+
# - send request with command (array of strings)
|
|
24
|
+
# - in response you get WebSocket URL and token
|
|
25
|
+
# - connect to container using WebSocket and send token as parameter
|
|
26
|
+
# - get response and exit websocket connection
|
|
27
|
+
#
|
|
28
|
+
|
|
29
|
+
# HTTP/1.1 POST /v1/projects/1a5/containers/1i382/?action=execute
|
|
30
|
+
# Host: 188.166.70.58:8080
|
|
31
|
+
# Accept: application/json
|
|
32
|
+
# Content-Type: application/json
|
|
33
|
+
# Content-Length: 112
|
|
34
|
+
|
|
35
|
+
# {
|
|
36
|
+
# "attachStdin": true,
|
|
37
|
+
# "attachStdout": true,
|
|
38
|
+
# "command": [
|
|
39
|
+
# "rake",
|
|
40
|
+
# "db:create",
|
|
41
|
+
# "db:schema:load",
|
|
42
|
+
# "db:seed"
|
|
43
|
+
# ],
|
|
44
|
+
# "tty": true
|
|
45
|
+
# }
|
|
46
|
+
|
|
47
|
+
def execute(command)
|
|
48
|
+
url = actions['execute']
|
|
49
|
+
|
|
50
|
+
data = {
|
|
51
|
+
'attachStdin' => true,
|
|
52
|
+
'attachStdout' => true,
|
|
53
|
+
'command' => command,
|
|
54
|
+
'tty': true
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
action = Action.post(url, data)
|
|
58
|
+
action.run!
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def logs(lines = 20)
|
|
62
|
+
url = actions['logs']
|
|
63
|
+
data = {
|
|
64
|
+
'follow' => false,
|
|
65
|
+
'lines' => lines
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
action = Action.post(url, data)
|
|
69
|
+
action.run!
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
require 'faye/websocket'
|
|
2
|
+
require 'eventmachine'
|
|
3
|
+
|
|
4
|
+
module Rancher
|
|
5
|
+
module Api
|
|
6
|
+
class Instance
|
|
7
|
+
# Few possible actions are:
|
|
8
|
+
# - execute shell command
|
|
9
|
+
# - render logs
|
|
10
|
+
# - restart
|
|
11
|
+
#
|
|
12
|
+
class Action
|
|
13
|
+
include Her::Model
|
|
14
|
+
|
|
15
|
+
attributes :token, :url, :response
|
|
16
|
+
|
|
17
|
+
def run!
|
|
18
|
+
uri = URI.parse(url)
|
|
19
|
+
uri.userinfo = "#{Rancher::Api.configuration.access_key}:#{Rancher::Api.configuration.secret_key}"
|
|
20
|
+
uri.query = "token=#{token}"
|
|
21
|
+
|
|
22
|
+
self.response = []
|
|
23
|
+
|
|
24
|
+
EM.run do
|
|
25
|
+
# 15 seconds timeout in case of slow operation
|
|
26
|
+
#
|
|
27
|
+
EM.add_timer(15) do
|
|
28
|
+
EM.stop
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
ws = Faye::WebSocket::Client.new(uri.to_s)
|
|
32
|
+
|
|
33
|
+
ws.on :message do |event|
|
|
34
|
+
self.response << Base64.decode64(event.data)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
ws.on :close do |event|
|
|
38
|
+
ws = nil
|
|
39
|
+
EM.stop
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
self.response = self.response.join
|
|
44
|
+
|
|
45
|
+
self
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require 'rancher/api/models/machine/driver_config'
|
|
2
|
+
|
|
3
|
+
module Rancher
|
|
4
|
+
module Api
|
|
5
|
+
class Machine
|
|
6
|
+
DIGITAL_OCEAN = 'digitalocean'
|
|
7
|
+
|
|
8
|
+
include Her::Model
|
|
9
|
+
|
|
10
|
+
attributes :name, :state, :amazonec2Config, :azureConfig, :description,
|
|
11
|
+
:digitaloceanConfig, :driver, :exoscaleConfig, :externalId,
|
|
12
|
+
:labels, :openstackConfig, :packetConfig, :rackspaceConfig,
|
|
13
|
+
:removed, :softlayerConfig, :virtualboxConfig,
|
|
14
|
+
:vmwarevcloudairConfig, :vmwarevsphereConfig
|
|
15
|
+
|
|
16
|
+
has_many :hosts
|
|
17
|
+
|
|
18
|
+
def driver_config
|
|
19
|
+
case driver
|
|
20
|
+
when DIGITAL_OCEAN
|
|
21
|
+
DriverConfig.new(attributes["#{DIGITAL_OCEAN}Config"])
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def driver_config=(dc)
|
|
26
|
+
case driver
|
|
27
|
+
when DIGITAL_OCEAN
|
|
28
|
+
attributes["#{DIGITAL_OCEAN}Config"] = dc.attributes
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
data/rancher-api.gemspec
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'rancher/api/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = 'rancher-api'
|
|
8
|
+
spec.version = Rancher::Api::VERSION
|
|
9
|
+
spec.authors = ['Alex Kurkin']
|
|
10
|
+
spec.email = ['thaold@thaold.com']
|
|
11
|
+
|
|
12
|
+
spec.summary = 'Easily connect to Rancher API!'
|
|
13
|
+
spec.description = 'Ruby gem to easily connect to Rancher API. Via this gem you can do anything that API lets you to do it'
|
|
14
|
+
spec.homepage = 'https://github.com/akurkin/rancher-api'
|
|
15
|
+
spec.license = 'MIT'
|
|
16
|
+
|
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
|
19
|
+
if spec.respond_to?(:metadata)
|
|
20
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
|
21
|
+
else
|
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
26
|
+
spec.bindir = 'exe'
|
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
28
|
+
spec.require_paths = ['lib']
|
|
29
|
+
|
|
30
|
+
spec.add_dependency 'her', '~> 0.7.6'
|
|
31
|
+
spec.add_dependency 'faye-websocket'
|
|
32
|
+
spec.add_dependency 'faraday_middleware'
|
|
33
|
+
|
|
34
|
+
spec.add_development_dependency 'bundler', '~> 1.10'
|
|
35
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
|
36
|
+
spec.add_development_dependency 'rspec', '~> 3.3.0'
|
|
37
|
+
spec.add_development_dependency 'byebug'
|
|
38
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: rancher-api
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.2.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Alex Kurkin
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-08-18 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: her
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 0.7.6
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: 0.7.6
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: faye-websocket
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: faraday_middleware
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: bundler
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '1.10'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '1.10'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: rake
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '10.0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '10.0'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: rspec
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - "~>"
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: 3.3.0
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - "~>"
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: 3.3.0
|
|
97
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: byebug
|
|
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'
|
|
111
|
+
description: Ruby gem to easily connect to Rancher API. Via this gem you can do anything
|
|
112
|
+
that API lets you to do it
|
|
113
|
+
email:
|
|
114
|
+
- thaold@thaold.com
|
|
115
|
+
executables: []
|
|
116
|
+
extensions: []
|
|
117
|
+
extra_rdoc_files: []
|
|
118
|
+
files:
|
|
119
|
+
- ".gitignore"
|
|
120
|
+
- ".rspec"
|
|
121
|
+
- ".ruby-version"
|
|
122
|
+
- ".travis.yml"
|
|
123
|
+
- Gemfile
|
|
124
|
+
- Gemfile.lock
|
|
125
|
+
- LICENSE
|
|
126
|
+
- LICENSE.txt
|
|
127
|
+
- README.md
|
|
128
|
+
- Rakefile
|
|
129
|
+
- bin/console
|
|
130
|
+
- bin/setup
|
|
131
|
+
- lib/rancher/api.rb
|
|
132
|
+
- lib/rancher/api/configuration.rb
|
|
133
|
+
- lib/rancher/api/middlewares.rb
|
|
134
|
+
- lib/rancher/api/middlewares/json_parser_middleware.rb
|
|
135
|
+
- lib/rancher/api/models.rb
|
|
136
|
+
- lib/rancher/api/models/host.rb
|
|
137
|
+
- lib/rancher/api/models/instance.rb
|
|
138
|
+
- lib/rancher/api/models/instance/action.rb
|
|
139
|
+
- lib/rancher/api/models/machine.rb
|
|
140
|
+
- lib/rancher/api/models/machine/driver_config.rb
|
|
141
|
+
- lib/rancher/api/models/project.rb
|
|
142
|
+
- lib/rancher/api/version.rb
|
|
143
|
+
- rancher-api.gemspec
|
|
144
|
+
homepage: https://github.com/akurkin/rancher-api
|
|
145
|
+
licenses:
|
|
146
|
+
- MIT
|
|
147
|
+
metadata:
|
|
148
|
+
allowed_push_host: https://rubygems.org
|
|
149
|
+
post_install_message:
|
|
150
|
+
rdoc_options: []
|
|
151
|
+
require_paths:
|
|
152
|
+
- lib
|
|
153
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
154
|
+
requirements:
|
|
155
|
+
- - ">="
|
|
156
|
+
- !ruby/object:Gem::Version
|
|
157
|
+
version: '0'
|
|
158
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
159
|
+
requirements:
|
|
160
|
+
- - ">="
|
|
161
|
+
- !ruby/object:Gem::Version
|
|
162
|
+
version: '0'
|
|
163
|
+
requirements: []
|
|
164
|
+
rubyforge_project:
|
|
165
|
+
rubygems_version: 2.4.5
|
|
166
|
+
signing_key:
|
|
167
|
+
specification_version: 4
|
|
168
|
+
summary: Easily connect to Rancher API!
|
|
169
|
+
test_files: []
|