tmuxinator-bosh-console 0.1.3 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a2e1fe18712e9dea2cdeb85656dc8832fc7bf214
4
- data.tar.gz: d7c4d46b8244541f0fbcc800a5e1560ea5589644
3
+ metadata.gz: fed7bba2c5ce851367554e8b5cfbec831077a36b
4
+ data.tar.gz: b6986938f82ccf78d487bee16f76758e29b0ee93
5
5
  SHA512:
6
- metadata.gz: 7dadc7fce7daf4490f68761bb207fb3148d701d08e3609a0ec7aa900501b68d580544f134018ccc46054e53f2f222043ddffa9f75e1973c002f8bb893486a356
7
- data.tar.gz: 183f8d6ab4cab8e9066eae557acd9f98a5907ee589fa88ce956befe32fd13d64cc5f150d2e2b3ff1932d0648e47786f409bca1258dcbfbb0f45792e9210c3cdf
6
+ metadata.gz: 78e1a2988d056cc147120c6020a9eab258015f7bc4bca70e997afbcee5bc83bf9bd16761c29d34e66d03cb974cdc5d74ae95e6457aa5c21aeddedd1a5f287301
7
+ data.tar.gz: 7b3c106e8d6f22a99ec0c748d87ddd44565cb531e23d04541c82077816d54d43f675e6b57a8c7550ac2f4c566d7e2752564e78764842f7c59b590b60056303eb
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ .rake_t_cache
1
2
  /.bundle/
2
3
  /.envrc/
3
4
  /Gemfile.lock
data/.rspec CHANGED
@@ -1,3 +1,4 @@
1
1
  --format documentation
2
2
  --require spec_helper
3
3
  --color
4
+ --order random
data/.rubocop.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.3
2
+ TargetRubyVersion: 2.4
3
3
  Include:
4
4
  - '**/Gemfile'
5
5
  - '**/Guardfile'
@@ -31,6 +31,11 @@ Lint/UnusedMethodArgument:
31
31
  Metrics/AbcSize:
32
32
  Enabled: false
33
33
 
34
+ Metrics/BlockLength:
35
+ Exclude:
36
+ - '*.gemspec'
37
+ - spec/**/*
38
+
34
39
  Metrics/ClassLength:
35
40
  Enabled: false
36
41
 
data/.travis.yml CHANGED
@@ -3,4 +3,6 @@ language: ruby
3
3
  rvm:
4
4
  - 2.3.1
5
5
  - 2.4.0
6
- before_install: gem install bundler -v 1.13.2
6
+ before_install: gem install bundler
7
+ script:
8
+ - bundle exec rake spec:ci
data/Guardfile CHANGED
@@ -8,5 +8,5 @@ end
8
8
 
9
9
  guard :rspec, cmd: 'bundle exec rspec' do
10
10
  watch(%r{^spec/.+_spec\.rb$})
11
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11
+ watch(%r{^lib/(.+/.+)\.rb$}) { |m| "spec/unit/#{m[1]}_spec.rb" }
12
12
  end
data/README.markdown CHANGED
@@ -1,5 +1,7 @@
1
1
  # BOSH tmuxinator console
2
2
 
3
+ [![Build Status](https://travis-ci.org/suhlig/tmuxinator-bosh-console.svg?branch=master)](https://travis-ci.org/suhlig/tmuxinator-bosh-console)
4
+
3
5
  ## Synopsis
4
6
 
5
7
  ```bash
@@ -20,3 +22,9 @@ $ gem install tmuxinator-bosh-console
20
22
  ## Prerequisites
21
23
 
22
24
  `bosh instances` must return a zero or more instances.
25
+
26
+ ## TODO
27
+
28
+ * repeated `--include`s
29
+ * `--exclude` this VM (blacklisting); may be repeated
30
+ * `--custom` bosh ssh command, e.g. gateway-host
data/Rakefile CHANGED
@@ -10,4 +10,9 @@ RSpec::Core::RakeTask.new do |t|
10
10
  t.pattern = 'spec/**/*_spec.rb'
11
11
  end
12
12
 
13
+ namespace :spec do
14
+ desc 'Run ci tests'
15
+ task ci: ['rubocop', :spec]
16
+ end
17
+
13
18
  task default: ['rubocop:auto_correct', :spec]
@@ -3,18 +3,31 @@
3
3
 
4
4
  $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
5
5
 
6
- require 'erb'
6
+ require 'optparse'
7
7
  require 'pathname'
8
+ require 'tmuxinator/bosh/console/director_gateway'
9
+ require 'tmuxinator/bosh/console/template'
8
10
 
9
11
  def die(msg)
10
12
  warn "Error: #{msg}"
11
13
  exit(1)
12
14
  end
13
15
 
14
- # TODO
15
- # --include only this VM (whitelisting); may be repeated
16
- # --exclude this VM (blacklisting); may be repeated
17
- # --custom bosh ssh command, e.g. gateway-host
16
+ filter = {}
17
+
18
+ OptionParser.new do |opts|
19
+ opts.banner = "Generates a tmuxinator configuration for the VMs of a BOSH deployment\n\n" + opts.banner
20
+ opts.separator "\nOptions:"
21
+
22
+ opts.on('-IFILTER', '--include=FILTER', 'include only jobs with a name matching FILTER') do |f|
23
+ filter[:include] = Regexp.new(f)
24
+ end
25
+
26
+ opts.on('-XFILTER', '--exclude=FILTER', 'exclude jobs with a name matching FILTER') do |f|
27
+ filter[:exclude] = Regexp.new(f)
28
+ end
29
+ end.parse!
30
+
18
31
  project_name = ARGV.first || die('Missing argument for the tmuxinator project name')
19
32
  project_file = Pathname("~/.tmuxinator/#{project_name}.yml").expand_path
20
33
 
@@ -22,16 +35,9 @@ if project_file.exist?
22
35
  die("Not overriding tmuxinator project file #{project_file}")
23
36
  end
24
37
 
25
- vms = `bosh instances`.lines.map { |line|
26
- md = line.match(%r{\| (?<job>\w+)\/(?<index>\d+)})
27
-
28
- if md
29
- {
30
- job: md['job'],
31
- index: md['index'],
32
- }
33
- end
34
- }.compact
38
+ include Tmuxinator::BOSH::Console
39
+ template = Template.new(Pathname(__dir__) / '../templates/bosh-console.yml')
35
40
 
36
- template = Pathname(__dir__) / '../templates/bosh-console.yml'
37
- project_file.write(ERB.new(Pathname(template).read).result(binding))
41
+ instances = DirectorGateway.new.instances(filter)
42
+ output = template.render(binding)
43
+ project_file.write(output)
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+ require 'tmuxinator/bosh/console/job'
3
+
4
+ module Tmuxinator
5
+ module BOSH
6
+ module Console
7
+ #
8
+ # Gateway to the BOSH director
9
+ #
10
+ class DirectorGateway
11
+ def initialize(report=`bosh instances`)
12
+ @report = report
13
+ end
14
+
15
+ def instances(filter={})
16
+ @report.lines.map { |line|
17
+ md = line.match(%r{\| (?<job>\w+)\/(?<index>\d+)})
18
+ Job.new(md['job'], md['index']) if md
19
+ }.compact.tap do |result|
20
+ result.select! { |job| filter[:include].match?(job.name) } if filter[:include]
21
+ result.reject! { |job| filter[:exclude].match?(job.name) } if filter[:exclude]
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+ module Tmuxinator
3
+ module BOSH
4
+ module Console
5
+ Job = Struct.new(:name, :index) do
6
+ def to_s
7
+ "#{name}/#{index}"
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+ require 'erb'
3
+
4
+ module Tmuxinator
5
+ module BOSH
6
+ module Console
7
+ class Template
8
+ def initialize(io)
9
+ @content = io.read
10
+ end
11
+
12
+ def render(source_binding)
13
+ ERB.new(@content).result(source_binding)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -2,7 +2,7 @@
2
2
  module Tmuxinator
3
3
  module BOSH
4
4
  module Console
5
- VERSION = '0.1.3'
5
+ VERSION = '0.2.0'
6
6
  end
7
7
  end
8
8
  end
@@ -3,18 +3,18 @@
3
3
  name: <%= project_name %>
4
4
 
5
5
  windows:
6
- <% vms.each do |vm| %>
7
- - <%= vm[:job] %>/<%= vm[:index] %>:
6
+ <% instances.each do |vm| %>
7
+ - <%= vm.name %>/<%= vm.index %>:
8
8
  layout: main-vertical
9
9
  panes:
10
10
  - shell:
11
- - bosh ssh <%= vm[:job] %>/<%= vm[:index] %>
11
+ - bosh ssh <%= vm.name %>/<%= vm.index %>
12
12
  - sudo su -
13
13
  - cd /var/vcap
14
14
  - monit:
15
- - bosh ssh <%= vm[:job] %>/<%= vm[:index] %>
15
+ - bosh ssh <%= vm.name %>/<%= vm.index %>
16
16
  - sudo watch -n 1 /var/vcap/bosh/bin/monit summary
17
17
  - logs:
18
- - bosh ssh <%= vm[:job] %>/<%= vm[:index] %>
18
+ - bosh ssh <%= vm.name %>/<%= vm.index %>
19
19
  - tail -f /var/vcap/sys/log/*/*
20
20
  <% end %>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tmuxinator-bosh-console
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steffen Uhlig
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-15 00:00:00.000000000 Z
11
+ date: 2017-01-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bosh_cli
@@ -171,6 +171,9 @@ files:
171
171
  - README.markdown
172
172
  - Rakefile
173
173
  - exe/tmuxinator-bosh-console
174
+ - lib/tmuxinator/bosh/console/director_gateway.rb
175
+ - lib/tmuxinator/bosh/console/job.rb
176
+ - lib/tmuxinator/bosh/console/template.rb
174
177
  - lib/tmuxinator/bosh/console/version.rb
175
178
  - templates/bosh-console.yml
176
179
  - tmuxinator-bosh-console.gemspec
@@ -194,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
197
  version: '0'
195
198
  requirements: []
196
199
  rubyforge_project:
197
- rubygems_version: 2.5.1
200
+ rubygems_version: 2.6.8
198
201
  signing_key:
199
202
  specification_version: 4
200
203
  summary: Generates the tmuxinator configuration for all VMs of a BOSH deployment