protocore 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 45d2e321de942be06a53dc49f5c817895fc8b676
4
+ data.tar.gz: 68bb67438f039e7d027c37b23e8234783ec7242c
5
+ SHA512:
6
+ metadata.gz: 0972789eab2fc5c3672aeb812eda9cf3c34473f5044c0cfe746f656f1604ba2e1fb631afdceace61105c7f6a52521d9f0718218a6d3fa722957871f35ce5dfd7
7
+ data.tar.gz: d18c33b0f87e50210c77d959c375ccfbfe4d2bebd4247c5bb0ae509356c1a0d3d9e9c23edfb86e5b77962fad13c24ec20bcf490447ad27fd4162b79e944d83ad
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --require spec_helper
3
+ --format documentation
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "https://rubygems.org"
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Philip Vieira
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # Protocore
2
+ CoreOS cluster configuration generator
3
+
4
+ ## Installation
5
+
6
+ ```bash
7
+ $ gem install protocore
8
+ ```
9
+
10
+ ## Usage
11
+
12
+ ### Creating your cluster config templates
13
+ In your cluster config you need a hosts key containing an array of all the hosts in your cluster.
14
+ You can configure these hosts by using regular YAML inheritance. For a full example take a look at this [cluster-config.yaml](https://github.com/chatspry/protocore/tree/master/spec/fixtures/cluster-config.yaml).
15
+
16
+ ```yaml
17
+ node: &node
18
+ coreos:
19
+ update:
20
+ reboot-strategy: etcd-lock
21
+ group: beta
22
+ hosts:
23
+ - hostname: node.1
24
+ <<: *node
25
+ ```
26
+
27
+ ### Command line client
28
+
29
+ #### Plan your cluster and print cloud-config for all host
30
+
31
+ ```bash
32
+ $ protocore plan
33
+ #cloud-config
34
+ hostname: node.1
35
+ coreos:
36
+ etcd:
37
+ ...
38
+
39
+ #cloud-config
40
+ hostname: node.2
41
+ coreos:
42
+ etcd:
43
+ ...
44
+
45
+ #cloud-config
46
+ hostname: db.1
47
+ coreos:
48
+ etcd:
49
+ ...
50
+ ```
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/protocore ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require "protocore"
3
+ require "protocore/cli"
4
+ Protocore::Cli.start(ARGV)
data/lib/protocore.rb ADDED
@@ -0,0 +1,42 @@
1
+ require "protocore/version"
2
+ require "protocore/description"
3
+ require "yaml"
4
+
5
+ module Protocore
6
+
7
+ def self.load(path)
8
+ parse read path
9
+ end
10
+
11
+ def self.read(path)
12
+ File.read(path).
13
+ gsub(/(?<=\:\s)(off)(?=\n)/, '"\1"')
14
+ end
15
+
16
+ def self.parse(yaml)
17
+ hosts = YAML.load(yaml)["hosts"]
18
+ raise "could not parse 'hosts' key is missing" if hosts == nil
19
+ return hosts.map { |host| Host.new(host) }
20
+ end
21
+
22
+ class Host
23
+
24
+ attr_reader :structure
25
+ attr_reader :name
26
+
27
+ def initialize(structure)
28
+ raise ArgumentError, "structure cannot be nil" unless structure
29
+ @structure = structure
30
+ @name = structure["hostname"]
31
+ end
32
+
33
+ def to_yaml
34
+ @yaml ||= structure.to_yaml.
35
+ gsub(/(?<=\:\s)\"(.*)\"(?=\n)/i, '\1').
36
+ gsub(/(?<=\:\s)\'(off)\'(?=\n)/, '\1').
37
+ gsub(/^---/,"#cloud-config")
38
+ end
39
+
40
+ end
41
+
42
+ end
@@ -0,0 +1,28 @@
1
+ require "thor"
2
+
3
+ module Protocore
4
+
5
+ class Cli < Thor
6
+
7
+ desc "plan [HOSTNAME]", "Plan your cluster and print cloud-config for all host"
8
+ long_desc <<-LONGDESC
9
+ By planning you evaluate a cluster-config file and print all your host configuration to /dev/stdout
10
+
11
+ You can specify a specific path to your cluster-config yaml file:
12
+
13
+ $ protocore plan --config ./my/path/to/cluster-config.yaml
14
+ LONGDESC
15
+ option :config, default: "./cluster-config.yaml", aliases: ["-c"]
16
+ def plan(hostname=nil)
17
+ require "pathname"
18
+ path = Pathname.new(ENV["PWD"]).join(options[:config])
19
+ hosts = Protocore.load(path)
20
+ hosts.select! { |host| host.name == hostname } if hostname
21
+ hosts.each do |host|
22
+ puts host.to_yaml + "\n"
23
+ end
24
+ end
25
+
26
+ end
27
+
28
+ end
@@ -0,0 +1,3 @@
1
+ module Protocore
2
+ DESCRIPTION = "CoreOS cluster configuration generator"
3
+ end
@@ -0,0 +1,3 @@
1
+ module Protocore
2
+ VERSION = "0.0.1"
3
+ end
data/protocore.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "protocore/version"
5
+ require "protocore/description"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "protocore"
9
+ spec.version = Protocore::VERSION
10
+ spec.authors = ["Philip Vieira"]
11
+ spec.email = ["philip@chatspry.com"]
12
+ spec.summary = Protocore::DESCRIPTION
13
+ spec.description = %q{Create configuration files for your whole CoreOS cluster based on templates}
14
+ spec.homepage = "https://github.com/chatspry/protocore"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "thor"
23
+ spec.add_development_dependency "bundler", "~> 1.7"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec"
26
+ spec.add_development_dependency "pry"
27
+ end
@@ -0,0 +1,55 @@
1
+ etcd: &etcd
2
+ discovery: https://discovery.etcd.io/xxx
3
+ addr: $public_ipv4:4001
4
+ peer-addr: $public_ipv4:7001
5
+
6
+ fleet: &fleet
7
+ public-ip: $public_ipv4
8
+ metadata: region=eu-west-1
9
+
10
+ update: &update
11
+ reboot-strategy: etcd-lock
12
+ group: beta
13
+
14
+ units: &units
15
+ - name: etcd.service
16
+ command: reload-or-try-restart
17
+ - name: fleet.service
18
+ command: reload-or-try-restart
19
+
20
+ coreos: &coreos
21
+ etcd:
22
+ <<: *etcd
23
+ fleet:
24
+ <<: *fleet
25
+ update:
26
+ <<: *update
27
+ units: *units
28
+
29
+ ssh_authorized_keys: &keys
30
+ - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCzi8isXFT4oT4zfhY5K7NaETJqrfnFgS5aSN3u5v5scBozJBI09QSFQ8S85Wjz+0VM0JxU7Fcgf575nhGePcYuUixefw6JLXdHm7lXCmQ0IOjli6AebJ7H4En1wu9Qfj5BMCbzCstkEoNSsQE3gam6HHGKmC05g6WhD1QkfEx/ZpaDfHLo7xf41+TMOmeb5gyG+Bq/oDJEXK3qaSMlSrBJgmqlfgMpRRzXGAi+WFdush5hw4Zu8s48l1qRQjUeGdly6GIwi7eTC1+RzahU2/2iBwsAlEBDDcT2/SCsIJWSe+3mNbGeFdb/3jqPSJxJuOmWaXwCE/EJu/bvy5wszhyd
31
+ - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDBgPTcxpJwiyGsX6EXDXEpLZpPmtCL2v3d0sEZ5rL6e2tI1FO+zDI4+EYmm7HNZD+sYU1NgYoFUd6nFCZflbavLeEEPPkyB0YZa+xGpx/adZsvOyNlV7gDPBE695tfd1loKTJRa5jvNQNdOogcEbTF9VUgAp8Ign7Om5RhL99heCvyoyR1uNalw7melH09XD4e5fAEawVP0n7MTmXmaZK5E0n1WZsK5h8fcbponmUqYpAeGffeZ4hQCx4swuaipB3rwGrOt199/DoEKcCON+Qg8TfTN0n3u013sfuWlVI0CkkDd7mjolxOqHduzYS56hghlvt4UkHbunkR+ujcaZLN
32
+
33
+ base: &base
34
+ coreos:
35
+ <<: *coreos
36
+ ssh_authorized_keys: *keys
37
+
38
+ node: &node
39
+ <<: *base
40
+
41
+ db: &db
42
+ <<: *base
43
+ coreos:
44
+ <<: *coreos
45
+ update:
46
+ <<: *update
47
+ reboot-strategy: off
48
+
49
+ hosts:
50
+ - hostname: node.1
51
+ <<: *node
52
+ - hostname: node.2
53
+ <<: *node
54
+ - hostname: db.1
55
+ <<: *db
@@ -0,0 +1,21 @@
1
+ #cloud-config
2
+ hostname: db.1
3
+ coreos:
4
+ etcd:
5
+ discovery: https://discovery.etcd.io/xxx
6
+ addr: $public_ipv4:4001
7
+ peer-addr: $public_ipv4:7001
8
+ fleet:
9
+ public-ip: $public_ipv4
10
+ metadata: region=eu-west-1
11
+ update:
12
+ reboot-strategy: off
13
+ group: beta
14
+ units:
15
+ - name: etcd.service
16
+ command: reload-or-try-restart
17
+ - name: fleet.service
18
+ command: reload-or-try-restart
19
+ ssh_authorized_keys:
20
+ - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCzi8isXFT4oT4zfhY5K7NaETJqrfnFgS5aSN3u5v5scBozJBI09QSFQ8S85Wjz+0VM0JxU7Fcgf575nhGePcYuUixefw6JLXdHm7lXCmQ0IOjli6AebJ7H4En1wu9Qfj5BMCbzCstkEoNSsQE3gam6HHGKmC05g6WhD1QkfEx/ZpaDfHLo7xf41+TMOmeb5gyG+Bq/oDJEXK3qaSMlSrBJgmqlfgMpRRzXGAi+WFdush5hw4Zu8s48l1qRQjUeGdly6GIwi7eTC1+RzahU2/2iBwsAlEBDDcT2/SCsIJWSe+3mNbGeFdb/3jqPSJxJuOmWaXwCE/EJu/bvy5wszhyd
21
+ - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDBgPTcxpJwiyGsX6EXDXEpLZpPmtCL2v3d0sEZ5rL6e2tI1FO+zDI4+EYmm7HNZD+sYU1NgYoFUd6nFCZflbavLeEEPPkyB0YZa+xGpx/adZsvOyNlV7gDPBE695tfd1loKTJRa5jvNQNdOogcEbTF9VUgAp8Ign7Om5RhL99heCvyoyR1uNalw7melH09XD4e5fAEawVP0n7MTmXmaZK5E0n1WZsK5h8fcbponmUqYpAeGffeZ4hQCx4swuaipB3rwGrOt199/DoEKcCON+Qg8TfTN0n3u013sfuWlVI0CkkDd7mjolxOqHduzYS56hghlvt4UkHbunkR+ujcaZLN
@@ -0,0 +1,41 @@
1
+ require "pathname"
2
+
3
+ RSpec.describe Protocore do
4
+
5
+ let(:fixtures_path) { Pathname.new(__FILE__).dirname.join("fixtures") }
6
+ let(:cluster_data_file_path) { fixtures_path.join("cluster-config.yaml").to_s }
7
+
8
+ describe ".load" do
9
+ subject(:load) { described_class.load(cluster_data_file_path) }
10
+ it { expect(load).to be_kind_of Array }
11
+ end
12
+
13
+ describe ".read" do
14
+ subject(:read) { described_class.read(cluster_data_file_path) }
15
+ it { expect(read).to be_kind_of String }
16
+ end
17
+
18
+ describe ".parse" do
19
+ subject(:parse) { described_class.parse described_class.read cluster_data_file_path }
20
+ it "contains an array of Hosts" do
21
+ expect(parse).to match Array.new(3) { an_instance_of(Protocore::Host) }
22
+ end
23
+ end
24
+
25
+ describe Protocore::Host do
26
+
27
+ subject(:host) { Protocore.load(cluster_data_file_path).last }
28
+
29
+ let(:cloud_config_file_path) { fixtures_path.join("db.1.cloud-config.yaml").to_s }
30
+
31
+ describe "#to_yaml" do
32
+
33
+ it "contains three hosts with the correct data" do
34
+ expect(subject.to_yaml).to eq File.read(cloud_config_file_path)
35
+ end
36
+
37
+ end
38
+
39
+ end
40
+
41
+ end
@@ -0,0 +1,31 @@
1
+ require "rspec"
2
+ require "protocore"
3
+ require "pry"
4
+
5
+ RSpec.configure do |config|
6
+
7
+ config.expect_with :rspec do |expectations|
8
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
9
+ end
10
+
11
+ config.mock_with :rspec do |mocks|
12
+ mocks.verify_partial_doubles = true
13
+ end
14
+
15
+ config.filter_run :focus
16
+ config.run_all_when_everything_filtered = true
17
+
18
+ config.disable_monkey_patching!
19
+
20
+ config.warnings = false
21
+
22
+ if config.files_to_run.one?
23
+ config.default_formatter = 'doc'
24
+ end
25
+
26
+ config.profile_examples = 10
27
+ config.order = :random
28
+
29
+ Kernel.srand config.seed
30
+
31
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: protocore
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Philip Vieira
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Create configuration files for your whole CoreOS cluster based on templates
84
+ email:
85
+ - philip@chatspry.com
86
+ executables:
87
+ - protocore
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - Gemfile
94
+ - LICENSE
95
+ - README.md
96
+ - Rakefile
97
+ - bin/protocore
98
+ - lib/protocore.rb
99
+ - lib/protocore/cli.rb
100
+ - lib/protocore/description.rb
101
+ - lib/protocore/version.rb
102
+ - protocore.gemspec
103
+ - spec/fixtures/cluster-config.yaml
104
+ - spec/fixtures/db.1.cloud-config.yaml
105
+ - spec/protocore_spec.rb
106
+ - spec/spec_helper.rb
107
+ homepage: https://github.com/chatspry/protocore
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.2.2
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: CoreOS cluster configuration generator
131
+ test_files:
132
+ - spec/fixtures/cluster-config.yaml
133
+ - spec/fixtures/db.1.cloud-config.yaml
134
+ - spec/protocore_spec.rb
135
+ - spec/spec_helper.rb