bleach command helps me clean up my left over vagrant stuff.
Yes, vagrant global-status is not hard. I just dont' like the output. I like the output of bleach
LICENSE: MIT AUTHOR: Dayne Broderson broderson@gmail.com
| #!/usr/bin/env ruby | |
| # A silly tool to help manage and clean up vagrant vms' from the insanity | |
| # caused by rapid fire test kitchens from across your box | |
| # use only if you like to destroy your running test kitchen instances | |
| require 'colored' | |
| require 'commander/import' | |
| require 'fileutils' | |
| program :name, 'vag' | |
| program :version, '3.1.4' | |
| program :description, 'vagrant helper' | |
| $VERBOSE = false | |
| class Vagrant | |
| def initialize | |
| @machines = [] | |
| out = `vagrant global-status`.split("\n") | |
| # puts out.pop.red | |
| out.each do |l| | |
| #id name provider state directory | |
| a = l.split | |
| next unless a.size == 5 | |
| machine = { :id => a[0], :name => a[1], | |
| :provider => a[2],:state => a[3],:directory => a[4] } | |
| next if machine[:id] == 'id' | |
| @machines.push machine | |
| end | |
| end | |
| def puts_machine_array(machines) | |
| machines.each do |m| | |
| puts m.inspect if $VERBOSE | |
| puts "# " + m[:directory].split('/').last.sub('kitchen-','').green | |
| puts sprintf("%10s\t%s",m[:id],m[:directory].split('.kitchen')[0]) | |
| end | |
| end | |
| def status(verbose = false) | |
| puts "# #{@machines.size} VMs running according to " + 'vagrant global-status'.yellow | |
| puts_machine_array(@machines) | |
| end | |
| def clean(all=false,force=false) | |
| puts "starting cleaning" | |
| kdirs = {} | |
| @machines.each do |m| | |
| dir = m[:directory] | |
| kd = dir.split('.kitchen')[0] | |
| next if not File.directory?(kd) | |
| kdirs[kd] = [] unless kdirs[kd] | |
| kdirs[kd].push m | |
| end | |
| kdirs.each do |kd,ms| | |
| FileUtils.cd(kd) | |
| #puts "# " + m[:directory].split('/').last.sub('kitchen-','').green | |
| puts "# #{ms.size.to_s.green} VMs running in : #{kd.yellow}" | |
| puts_machine_array(ms) | |
| system("bash -l -c 'kitchen status'") | |
| if agree("run a kitchen destroy here?") | |
| puts "beginning the bleaching".red | |
| `kitchen destroy` | |
| else | |
| puts "no bleaching done".green | |
| end | |
| end | |
| end | |
| end | |
| vag = Vagrant.new | |
| command :clean do |c| | |
| c.syntax = 'vag clean' | |
| c.description = 'helper tool to clean out your test kitchen' | |
| c.option "--all", TrueClass, 'scrubs all the things' | |
| c.option "--force", TrueClass, 'force cleans' | |
| c.option "--verbose", TrueClass, 'verbose mode' | |
| c.action do |args, options| | |
| options.default :all => false, :force => false | |
| $VERBOSE = options.verbose | |
| vag.clean(options.all,options.force) | |
| end | |
| end | |
| command :status do |c| | |
| c.syntax = 'vag status' | |
| c.option "--verbose", TrueClass, 'verbose mode' | |
| c.description = 'vagrant global-status' | |
| c.action do |args, options| | |
| options.default :verbose => false | |
| $VERBOSE = options.verbose | |
| vag.status(options.verbose) | |
| end | |
| end | |
| default_command :status |
bleach command helps me clean up my left over vagrant stuff.
Yes, vagrant global-status is not hard. I just dont' like the output. I like the output of bleach
LICENSE: MIT AUTHOR: Dayne Broderson broderson@gmail.com
| source 'https://rubygems.org' do | |
| gem 'commander' | |
| gem 'colored' | |
| end |