vagrant-tagprovision 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7cfb9caf67c9eee524dfc5aae9c0d32aa5d05845
4
- data.tar.gz: 1debb99d197770733e64dc8c720a7be8c7d58efa
3
+ metadata.gz: c2426fbf2e6aad5ce46e1b3bc6f6e59a05fb5ec0
4
+ data.tar.gz: e7819b73c70ef1b51367df00b474161848ca1010
5
5
  SHA512:
6
- metadata.gz: be6fdfdb80961f68c548e92f9c1705033016af6ee5eaf8c7ae158ab3edda37c46c8c3fbc727c3432ff61ddbb25387ac6df8bdcb36ecb5b55cf4c1ebf006041e2
7
- data.tar.gz: 18773e8fba8f71ececd565735fe14f11aade1997896156b28cbf83f9eb8c291bfbe376d155106b3be42feea999fb0b3c0de6f622573b3323bea4d47e21b678bc
6
+ metadata.gz: 7ff905a64726fa736c749bf20807f17eb7e16aa1d79b1a86fef8fd260ee249f462df753c155577f75d7e8732afd38da1f018c63e75deb0f7d00ad8194cfc4f0e
7
+ data.tar.gz: a04add565f33486a176adaeab3e3df7ed457ec81deee48176954630c205418699b2b6372529286d38d08504ff3354222874157308432c3b5242a37db47b2276a
data/.gitignore CHANGED
@@ -9,11 +9,11 @@ _yardoc
9
9
  coverage
10
10
  doc/
11
11
  lib/bundler/man
12
- pkg
13
12
  rdoc
14
13
  spec/reports
15
14
  test/tmp
16
15
  test/version_tmp
17
16
  tmp
18
17
  .vagrant
19
- vendor/bundle
18
+ vendor/bundle
19
+ vendor
data/README.md CHANGED
@@ -1,57 +1,69 @@
1
- # Vagrant Pushbullet
1
+ # Vagrant TagProvision
2
2
 
3
- This gem is a [Vagrant](http://www.vagrantup.com/) plugin that adds Pushbullet notifications to configured devices.
3
+ This gem is a [Vagrant](http://www.vagrantup.com/) plugin that tags and logs provisioning information
4
4
 
5
- ## Setup Pushbullet
6
-
7
- * First get a Pushbullet Account, and add devices to it.
8
- - [Pushbullet.com](https://www.pushbullet.com/)
9
- * Download the *iOS* app, *Chrome* plugin, *Android* app, and more. Add those to your Pushbullet account.
10
- * Get your HTTP API Token: http://pushbullet.com/account
11
5
 
12
6
  ## Install Plugin
13
7
 
14
8
  ```bash
15
- $ vagrant plugin install vagrant-pushbullet
9
+ $ vagrant plugin install vagrant-tagprovision
16
10
  ```
17
11
 
18
12
  ## Plugin Usage
19
13
 
20
- This plugin is configured purely by a configuration file in your home directory.
21
- The plugin will create this file for you, but you will have to edit it manually (for now).
14
+ You will need to create a section in your Vagrantfile to enable this plugin and use the various features.
22
15
 
23
- `~/.vagrant.d/pushbullet.rb`
24
- ```ruby
25
- module PushbulletConfig
26
- TOKEN = "replace this text with token from pushbullet.com/account" #required
27
- DEVICES = ['asdfasdfasdf','asdfasdfasdf'] #optional
16
+ ```
17
+ Vagrant.configure("2") do |config|
18
+ ...
19
+ config.tagprovision.enabled = true
20
+ config.tagprovision.log_provision = true
21
+ config.tagprovision.tag_provision = true
22
+ config.tagprovision.push_tag = true
23
+ ...
28
24
  end
29
25
  ```
30
26
 
31
- Run `vagrant pushbullet-config` to retrieve your Device ID's. Add those to the DEVICES array in the config file to limit which devices are notified.
32
-
33
-
34
- ## Notifications
27
+ config.tagprovision.enabled - This enables and disables the plugin
28
+ config.tagprovision.log_provision - This creates an entry in /var/provision_log on the guest machine with the following format:
35
29
 
36
- A notification is sent after these commands complete:
30
+ 2016-01-11 11:31:42 +0000 Provisioned a41c6eb98bd069f85bc205fae24298e644a9b877 username
37
31
 
38
- * note there is currently a bug where if an exception occurs in the provisioning, the notification is not sent.
39
-
40
- - `vagrant up`
41
- - `vagrant reload --provision`
42
- - `vagrant provision`
32
+ config.tagprovision.tag_provision - This will create a git tag with provisioning information
33
+ config.tagprovision.push_tag - This automatically pushes the tag to the origin your current branch is tracking
43
34
 
44
35
  ## Contributing
45
36
 
46
37
  * use feature branches please. Prefer feature/your_feature_name
47
38
  * submit pull requests to the `develop` branch
48
39
 
40
+ ### Testing
49
41
 
50
- ## Author
42
+ To install dependencies use:
43
+ ```
44
+ bundle install
45
+ ```
46
+
47
+ Then use
48
+ ```
49
+ bundle exec vagrant provision
50
+ ```
51
+ To test on the test VM.
51
52
 
52
- Brett Swift
53
+ ### Building and deploying gem packages
53
54
 
54
- ## Kudos
55
+ Use
56
+
57
+ ```
58
+ rake build
59
+ ```
60
+
61
+ Then
62
+
63
+ ```
64
+ gem push pkg/vagrant-tagprovision-0.vagrant-tagprovision-0.1.1.gem
65
+ ```
66
+
67
+ ## Author
55
68
 
56
- [tcnksm](https://twitter.com/deeeet)
57
- - for his vagrant-pushover plugin. This plugin is modeled after his.
69
+ Jim Robinson
data/Vagrantfile CHANGED
@@ -10,4 +10,14 @@ Vagrant.configure("2") do |config|
10
10
  db.vm.box_url = "http://files.vagrantup.com/precise64.box"
11
11
  db.vm.box = "precise64"
12
12
  end
13
+
14
+ config.vm.define "db" do |db|
15
+ db.vm.box_url = "http://files.vagrantup.com/precise64.box"
16
+ db.vm.box = "precise64"
17
+ end
18
+
19
+ config.tagprovision.enabled = true
20
+ config.tagprovision.log_provision = true
21
+ config.tagprovision.tag_provision = true
22
+ config.tagprovision.push_tag = true
13
23
  end
@@ -1,5 +1,5 @@
1
1
  require "net/https"
2
-
2
+ require 'vagrant-tagprovision/util'
3
3
  module VagrantPlugins
4
4
  module Tagprovision
5
5
  class Action
@@ -14,8 +14,9 @@ module VagrantPlugins
14
14
  @current_user = `whoami`
15
15
  @time = Time.new
16
16
  @tag = "provisioned_#{@machine}_#{@time.year}#{@time.month}#{@time.day}#{@time.hour}#{@time.min}#{@time.sec}"
17
- machine_env = @machinfo.env;
18
- @tmp_path = machine_env.tmp_path;
17
+ @machine_env = @machinfo.env;
18
+ @tmp_path = @machine_env.tmp_path;
19
+ @config = Util.get_config(@machine_env)
19
20
 
20
21
  end
21
22
 
@@ -37,48 +38,65 @@ module VagrantPlugins
37
38
  #env[:ui].info("Vagrant Hook Reload: #{@machine}")
38
39
 
39
40
  when :provision
40
- env[:ui].info("Logging provisioning information to guest machine: #{@machine}")
41
-
42
- if (@machinfo.communicate.test("uname -s | grep SunOS"))
43
- reallogfile = '/var/log/provision_log'
44
- move_cmd = 'mv'
45
- elsif (@machinfo.communicate.test("test -d $Env:SystemRoot"))
46
- windir = ""
47
- @machinfo.communicate.execute("echo %SYSTEMROOT%", {:shell => :cmd}) do |type, contents|
48
- windir << contents.gsub("\r\n", '') if type == :stdout
41
+ if(@config.tagprovision.enabled)
42
+ if(@config.tagprovision.log_provision)
43
+ log_provision(env)
44
+ end
45
+ if(@config.tagprovision.log_provision)
46
+ tag_provision(env)
49
47
  end
50
- reallogfile = "#{windir}\\System32\\drivers\\var\\provision_log"
51
- move_cmd = 'mv -force'
52
- else
53
- reallogfile = '/var/log/provision_log'
54
- move_cmd = 'mv -f'
55
48
  end
49
+ end
50
+ end
51
+
52
+ def tag_provision(env)
53
+ env[:ui].info("Tagging provisioning information: #{@machine}")
54
+ `git tag #{@tag}`
55
+ if(@config.tagprovision.push_tag)
56
+ `git push --tags`
57
+ end
58
+ end
59
+
60
+ def log_provision(env)
61
+ env[:ui].info("Logging provisioning information to guest machine: #{@machine}")
56
62
 
57
- file = @tmp_path.join("hosts.#{@machinfo.name}_#{@commit_hash}")
63
+ if (@machinfo.communicate.test("uname -s | grep SunOS"))
64
+ reallogfile = '/var/log/provision_log'
65
+ move_cmd = 'mv'
66
+ elsif (@machinfo.communicate.test("test -d $Env:SystemRoot"))
67
+ windir = ""
68
+ @machinfo.communicate.execute("echo %SYSTEMROOT%", {:shell => :cmd}) do |type, contents|
69
+ windir << contents.gsub("\r\n", '') if type == :stdout
70
+ end
71
+ reallogfile = "#{windir}\\System32\\drivers\\var\\provision_log"
72
+ move_cmd = 'mv -force'
73
+ else
74
+ reallogfile = '/var/log/provision_log'
75
+ move_cmd = 'mv -f'
76
+ end
58
77
 
59
- # Make sure the log files exist and are writable.
60
- @machinfo.communicate.sudo("touch #{reallogfile}")
61
- @machinfo.communicate.sudo("chmod 666 #{reallogfile}")
62
- @machinfo.communicate.sudo("touch /tmp/provision_logs")
63
- @machinfo.communicate.sudo("chmod 666 /tmp/provision_logs")
78
+ file = @tmp_path.join("hosts.#{@machinfo.name}_#{@commit_hash}")
64
79
 
65
- # download the current log file
66
- @machinfo.communicate.download(reallogfile, file)
67
-
68
- if update_file(file, @machinfo, false)
80
+ # Make sure the log files exist and are writable.
81
+ @machinfo.communicate.sudo("touch #{reallogfile}")
82
+ @machinfo.communicate.sudo("chmod 666 #{reallogfile}")
83
+ @machinfo.communicate.sudo("touch /tmp/provision_logs")
84
+ @machinfo.communicate.sudo("chmod 666 /tmp/provision_logs")
69
85
 
70
- # upload modified file and remove temporary file
71
- @machinfo.communicate.upload(file, '/tmp/provision_logs')
72
- if windir
73
- @machinfo.communicate.sudo("#{move_cmd} /tmp/provision_logs/hosts.#{@machinfo.name} #{reallogfile}")
74
- elsif @machinfo.communicate.test('test -f /.dockerinit')
75
- @machinfo.communicate.sudo("cat /tmp/provision_logs > #{reallogfile}")
76
- else
77
- @machinfo.communicate.sudo("#{move_cmd} /tmp/provision_logs #{reallogfile}")
78
- end
79
- end
80
- env[:ui].info("Finished logging provisioning information to guest machine: #{@machine}")
81
- end
86
+ # download the current log file
87
+ @machinfo.communicate.download(reallogfile, file)
88
+
89
+ if update_file(file, @machinfo, false)
90
+ # upload modified file and remove temporary file
91
+ @machinfo.communicate.upload(file, '/tmp/provision_logs')
92
+ if windir
93
+ @machinfo.communicate.sudo("#{move_cmd} /tmp/provision_logs/hosts.#{@machinfo.name} #{reallogfile}")
94
+ elsif @machinfo.communicate.test('test -f /.dockerinit')
95
+ @machinfo.communicate.sudo("cat /tmp/provision_logs > #{reallogfile}")
96
+ else
97
+ @machinfo.communicate.sudo("#{move_cmd} /tmp/provision_logs #{reallogfile}")
98
+ end
99
+ end
82
100
  end
83
101
 
84
102
  def update_file(file, resolving_machine = nil, include_id = true)
@@ -0,0 +1,51 @@
1
+ module VagrantPlugins
2
+ module Tagprovision
3
+ class Config < Vagrant.plugin('2', :config)
4
+ attr_accessor :enabled
5
+ attr_accessor :log_provision
6
+ attr_accessor :tag_provision
7
+ attr_accessor :push_tag
8
+
9
+ def initialize
10
+ @enabled = UNSET_VALUE
11
+ @log_provision = UNSET_VALUE
12
+ @tag_provision = UNSET_VALUE
13
+ @push_tag = UNSET_VALUE
14
+
15
+ end
16
+
17
+ def finalize!
18
+ @enabled = false if @enabled == UNSET_VALUE
19
+ @log_provision = false if @log_provision == UNSET_VALUE
20
+ @tag_provision = false if @tag_provision == UNSET_VALUE
21
+ @push_tag = false if @push_tag == UNSET_VALUE
22
+ end
23
+
24
+ def validate(machine)
25
+ errors = []
26
+
27
+ errors << validate_bool('hostmanager.enabled', @enabled)
28
+ errors << validate_bool('hostmanager.log_provision', @log_provision)
29
+ errors << validate_bool('hostmanager.tag_provision', @tag_provision)
30
+ errors << validate_bool('hostmanager.push_tag', @push_tag)
31
+ errors.compact!
32
+
33
+ { "Tagprovision configuration" => errors }
34
+ end
35
+
36
+ private
37
+
38
+ def validate_bool(key, value)
39
+ if ![TrueClass, FalseClass].include?(value.class) &&
40
+ value != UNSET_VALUE
41
+ I18n.t('vagrant_tagprovision.config.not_a_bool', {
42
+ :config_key => key,
43
+ :value => value.class.to_s
44
+ })
45
+ else
46
+ nil
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -13,7 +13,17 @@ module VagrantPlugins
13
13
  This plugin tags the git repo when a server is provisioned.
14
14
  DESC
15
15
 
16
-
16
+ config(:tagprovision) do
17
+ require_relative 'config'
18
+ Config
19
+ end
20
+
21
+ # Work-around for vagrant >= 1.5
22
+ # It breaks without a provisioner config, so we provide a dummy one
23
+ config(:tagprovision, :provisioner) do
24
+ ::Vagrant::Config::V2::DummyConfig.new
25
+ end
26
+
17
27
  action_hook("Tagprovision_hook", :machine_action_up) do |hook|
18
28
  require_relative "action"
19
29
  hook.prepend(Action)
@@ -0,0 +1,14 @@
1
+ module VagrantPlugins
2
+ module Tagprovision
3
+ module Util
4
+ def self.get_config(env)
5
+ # config_global has been removed from v1.5
6
+ if Gem::Version.new(::Vagrant::VERSION) >= Gem::Version.new('1.5')
7
+ env.vagrantfile.config
8
+ else
9
+ env.config_global
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module Tagprovision
3
- VERSION = "0.1.1"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -4,6 +4,10 @@ require "vagrant-tagprovision/plugin"
4
4
 
5
5
  module VagrantPlugins
6
6
  module Tagprovision
7
-
7
+ def self.source_root
8
+ @source_root ||= Pathname.new(File.expand_path('../../', __FILE__))
9
+ end
10
+ I18n.load_path << File.expand_path('locales/en.yml', source_root)
11
+ I18n.reload!
8
12
  end
9
13
  end
data/locales/en.yml ADDED
@@ -0,0 +1,6 @@
1
+ en:
2
+ vagrant_tagprovision:
3
+ config:
4
+ not_a_bool: "A value for %{config_key} can only be true or false, not type '%{value}'"
5
+ not_an_array_or_string: "A value for %{config_key} must be an Array or String, not type '%{is_class}'"
6
+ not_a_proc: "A value for %{config_key} must be a Proc, not type '%{is_class}'"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-tagprovision
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - jimrobinson
@@ -53,8 +53,11 @@ files:
53
53
  - Vagrantfile
54
54
  - lib/vagrant-tagprovision.rb
55
55
  - lib/vagrant-tagprovision/action.rb
56
+ - lib/vagrant-tagprovision/config.rb
56
57
  - lib/vagrant-tagprovision/plugin.rb
58
+ - lib/vagrant-tagprovision/util.rb
57
59
  - lib/vagrant-tagprovision/version.rb
60
+ - locales/en.yml
58
61
  - vagrant-tagprovision.gemspec
59
62
  homepage: https://github.com/jscrobinson/vagrant-tagprovision
60
63
  licenses: