cyclid-mist-plugin 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/cyclid/plugins/builder/mist.rb +107 -0
- metadata +72 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 09cdb07ce5d51c98f5060dc2d6642130e49a0f3d
|
4
|
+
data.tar.gz: aff76eda4de9cb6c8991e510bda356354d393c1d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c4e0d9cabe154fb5c8d88bf47a346c5a1ab488129219f3eaee33089668a46a520edfec683ffa5916bcf38d461c056ecce3aa2c85ae26850c5e17efc8fa5e75bb
|
7
|
+
data.tar.gz: 3651181b4412ec9c2e26ded23b2f1a12dd4e217da8d1643e2ac449fe8e6fc976d31a26000e25cca005ee632c2a2db2d9883d54ae8797a5dff3043a237094ed71
|
@@ -0,0 +1,107 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# Copyright 2016 Liqwyd Ltd.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
require 'mist/config'
|
17
|
+
require 'mist/pool'
|
18
|
+
require 'mist/client'
|
19
|
+
|
20
|
+
# Top level module for the core Cyclid code.
|
21
|
+
module Cyclid
|
22
|
+
# Module for the Cyclid API
|
23
|
+
module API
|
24
|
+
# Module for Cyclid Plugins
|
25
|
+
module Plugins
|
26
|
+
# Mist build host
|
27
|
+
class MistHost < BuildHost
|
28
|
+
# SSH is the only acceptable Transport
|
29
|
+
def transports
|
30
|
+
['ssh']
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Mist builder. Calls out to Mist to obtain a build host instance.
|
35
|
+
class Mist < Builder
|
36
|
+
def initialize
|
37
|
+
mist_config_file = ENV.fetch('MIST_CONFIG', File.join(%w(/ etc mist config)))
|
38
|
+
@config = ::Mist::Config.new(mist_config_file)
|
39
|
+
|
40
|
+
pool = ::Mist::Pool.get(@config.servers)
|
41
|
+
@client = ::Mist::Client.new(pool)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Create & return a build host
|
45
|
+
def get(args = {})
|
46
|
+
args.symbolize_keys!
|
47
|
+
|
48
|
+
Cyclid.logger.debug "mist: args=#{args}"
|
49
|
+
|
50
|
+
# If there is one, split the 'os' into a 'distro' and 'release'
|
51
|
+
if args.key? :os
|
52
|
+
match = args[:os].match(/\A(\w*)_(.*)\Z/)
|
53
|
+
distro = match[1] if match
|
54
|
+
release = match[2] if match
|
55
|
+
else
|
56
|
+
# No OS was specified; use the default
|
57
|
+
# XXX Defaults should be configurable
|
58
|
+
distro = 'ubuntu'
|
59
|
+
release = 'trusty'
|
60
|
+
end
|
61
|
+
|
62
|
+
begin
|
63
|
+
result = @client.call(:create, distro: distro, release: release)
|
64
|
+
Cyclid.logger.debug "mist result=#{result}"
|
65
|
+
|
66
|
+
raise "failed to create build host: #{result['message']}" \
|
67
|
+
unless result['status']
|
68
|
+
|
69
|
+
buildhost = MistHost.new(name: result['name'],
|
70
|
+
host: result['ip'],
|
71
|
+
username: result['username'],
|
72
|
+
workspace: "/home/#{result['username']}",
|
73
|
+
password: nil,
|
74
|
+
key: @config.ssh_private_key,
|
75
|
+
server: result['server'],
|
76
|
+
distro: distro,
|
77
|
+
release: release)
|
78
|
+
rescue MessagePack::RPC::TimeoutError => ex
|
79
|
+
Cyclid.logger.error "Mist create call timedout: #{ex}"
|
80
|
+
raise "mist failed: #{ex}"
|
81
|
+
rescue StandardError => ex
|
82
|
+
Cyclid.logger.error "couldn't get a build host from Mist: #{ex}"
|
83
|
+
raise "mist failed: #{ex}"
|
84
|
+
end
|
85
|
+
|
86
|
+
Cyclid.logger.debug "mist buildhost=#{buildhost.inspect}"
|
87
|
+
return buildhost
|
88
|
+
end
|
89
|
+
|
90
|
+
# Destroy the build host
|
91
|
+
def release(_transport, buildhost)
|
92
|
+
name = buildhost[:name]
|
93
|
+
server = buildhost[:server]
|
94
|
+
|
95
|
+
begin
|
96
|
+
@client.call(:destroy, name: name, server: server)
|
97
|
+
rescue MessagePack::RPC::TimeoutError => ex
|
98
|
+
Cyclid.logger.error "Mist destroy timed out: #{ex}"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
# Register this plugin
|
103
|
+
register_plugin 'mist'
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cyclid-mist-plugin
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kristian Van Der Vliet
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-12-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: cyclid
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: mist-client
|
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
|
+
description: Creates build hosts via. Mist
|
42
|
+
email: contact@cyclid.io
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- lib/cyclid/plugins/builder/mist.rb
|
48
|
+
homepage: https://cyclid.io
|
49
|
+
licenses:
|
50
|
+
- Apache-2.0
|
51
|
+
metadata: {}
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
requirements: []
|
67
|
+
rubyforge_project:
|
68
|
+
rubygems_version: 2.5.1
|
69
|
+
signing_key:
|
70
|
+
specification_version: 4
|
71
|
+
summary: Cyclid Mist Builder plugin
|
72
|
+
test_files: []
|