vagrant-timezone 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/.gitignore +3 -0
- data/.travis.yml +18 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +12 -0
- data/LICENSE.txt +21 -0
- data/README.md +38 -0
- data/Rakefile +14 -0
- data/lib/vagrant-timezone.rb +2 -0
- data/lib/vagrant-timezone/action/set_timezone.rb +34 -0
- data/lib/vagrant-timezone/cap/debian.rb +16 -0
- data/lib/vagrant-timezone/cap/redhat.rb +16 -0
- data/lib/vagrant-timezone/config.rb +24 -0
- data/lib/vagrant-timezone/logger.rb +11 -0
- data/lib/vagrant-timezone/plugin.rb +73 -0
- data/lib/vagrant-timezone/version.rb +5 -0
- data/locales/en.yml +9 -0
- data/spec/spec_helper.rb +18 -0
- data/vagrant-timezone.gemspec +20 -0
- metadata +63 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0cb2f52c3d1916a0e4d2b2f8dfbdd10c894a7c1f
|
4
|
+
data.tar.gz: 55a4334eeddab2f762c8f50d3db7fdf0af4ecf7e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 73dc18f9adeb3721f188cc946349fe2cf84795d846592f890d6afaa86959170ea7665971e96fdcbafb2abcf0614ce83e83bd2248613dd0e404de5b419cd7beed
|
7
|
+
data.tar.gz: 009b39f98fdfd27b22000edb82a8294c27da3f5b58e25bc992d3e4f34519b990b5a590d6c18417c0f23eb4426232bf8a2e322a61440bba5f0d614155e31a7dca
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
language: ruby
|
2
|
+
|
3
|
+
before_install:
|
4
|
+
- rvm @global do gem uninstall bundler --all --executables
|
5
|
+
- gem uninstall bundler --all --executables
|
6
|
+
- gem install bundler --version '~> 1.5.2'
|
7
|
+
- bundle --version
|
8
|
+
bundler_args: --without=development
|
9
|
+
|
10
|
+
rvm: 2.0.0
|
11
|
+
env: VAGRANT_VERSION=v1.6.5
|
12
|
+
matrix:
|
13
|
+
include:
|
14
|
+
- env: VAGRANT_VERSION=v1.2.7
|
15
|
+
rvm: 1.9.3
|
16
|
+
- env: VAGRANT_VERSION=master
|
17
|
+
allow_failures:
|
18
|
+
- env: VAGRANT_VERSION=master
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2014 Teemu Matilainen <teemu.matilainen@iki.fi>
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# Time Zone Configuration Plugin for Vagrant
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/vagrant-timezone.png)][gem]
|
4
|
+
[![Build Status](https://travis-ci.org/tmatilai/vagrant-timezone.png?branch=master)][travis]
|
5
|
+
|
6
|
+
[gem]: https://rubygems.org/gems/vagrant-timezone
|
7
|
+
[travis]: https://travis-ci.org/tmatilai/vagrant-timezone
|
8
|
+
|
9
|
+
A [Vagrant](http://www.vagrantup.com/) plugin that configures the time zone of a virtual machines.
|
10
|
+
|
11
|
+
If you want to use a specific time zone in a Vagrant VM, or if a third party base box comes with a non-standard time zone, this plugin is to the rescue. The configuration is done on `vagrant up` and `vagrant reload` actions. Note that no services are restarted automatically so they may keep using the old time zone information.
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
Install the plugin:
|
16
|
+
|
17
|
+
```sh
|
18
|
+
vagrant plugin install vagrant-timezone
|
19
|
+
```
|
20
|
+
|
21
|
+
To configure time zone for all Vagrant VMs, add the following to _$HOME/.vagrant.d/Vagrantfile_ (or to a project specific _Vagrantfile_):
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
Vagrant.configure("2") do |config|
|
25
|
+
if Vagrant.has_plugin?("vagrant-timezone")
|
26
|
+
config.timezone.value = "UTC"
|
27
|
+
end
|
28
|
+
# ... other stuff
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
32
|
+
## Compatibility
|
33
|
+
|
34
|
+
This plugin requires Vagrant 1.2 or newer ([downloads](https://www.vagrantup.com/downloads)).
|
35
|
+
|
36
|
+
The plugin is supposed to be compatible with all Vagrant providers and other plugins. Please file an [issue](https://github.com/tmatilai/vagrant-timezone/issues) if this is not the case.
|
37
|
+
|
38
|
+
At the moment only Debian and RedHat based VMs are supported.
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
|
4
|
+
task default: 'test:unit'
|
5
|
+
|
6
|
+
# Remove 'install' task as the gem is installed to Vagrant, not to system
|
7
|
+
Rake::Task[:install].clear
|
8
|
+
|
9
|
+
namespace :test do
|
10
|
+
RSpec::Core::RakeTask.new('unit') do |task|
|
11
|
+
task.pattern = 'spec/unit/**/*_spec.rb'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
task spec: ['test:unit']
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require_relative '../logger'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module TimeZone
|
5
|
+
module Action
|
6
|
+
# Vagrant middleware action that sets the specified time zone
|
7
|
+
class SetTimeZone
|
8
|
+
def initialize(app, env)
|
9
|
+
@app = app
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(env)
|
13
|
+
@app.call(env)
|
14
|
+
|
15
|
+
machine = env[:machine]
|
16
|
+
timezone = machine.config.timezone.value
|
17
|
+
if timezone.nil?
|
18
|
+
logger.info I18n.t('vagrant_timezone.not_enabled')
|
19
|
+
elsif machine.guest.capability?(:change_timezone)
|
20
|
+
env[:ui].info I18n.t('vagrant_timezone.configuring')
|
21
|
+
machine.guest.capability(:change_timezone, timezone)
|
22
|
+
else
|
23
|
+
logger.info I18n.t('vagrant_timezone.not_supported')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# @return [Log4r::Logger]
|
28
|
+
def logger
|
29
|
+
TimeZone.logger
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module TimeZone
|
3
|
+
module Cap
|
4
|
+
# Debian capabilities for changing time zone
|
5
|
+
module Debian
|
6
|
+
# Set the time zone
|
7
|
+
def self.change_timezone(machine, timezone)
|
8
|
+
machine.communicate.tap do |comm|
|
9
|
+
comm.sudo("echo '#{timezone}' > /etc/timezone")
|
10
|
+
comm.sudo('dpkg-reconfigure --frontend noninteractive tzdata')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module TimeZone
|
3
|
+
module Cap
|
4
|
+
# RedHat capabilities for changing time zone
|
5
|
+
module RedHat
|
6
|
+
# Set the time zone
|
7
|
+
def self.change_timezone(machine, timezone)
|
8
|
+
machine.communicate.tap do |comm|
|
9
|
+
comm.sudo("echo 'ZONE=\"#{timezone}\"' > /etc/sysconfig/clock")
|
10
|
+
comm.sudo("ln -sf /usr/share/zoneinfo/#{timezone} /etc/localtime")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'vagrant'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module TimeZone
|
5
|
+
# Configuration for the Time Zone plugin
|
6
|
+
#
|
7
|
+
# @!parse class Config < Vagrant::Plugin::V2::Config; end
|
8
|
+
class Config < Vagrant.plugin('2', :config)
|
9
|
+
attr_accessor :value
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
super
|
13
|
+
|
14
|
+
@value = UNSET_VALUE
|
15
|
+
end
|
16
|
+
|
17
|
+
def finalize!
|
18
|
+
super
|
19
|
+
|
20
|
+
@value = nil if @value == UNSET_VALUE
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'vagrant'
|
2
|
+
require_relative 'logger'
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module TimeZone
|
6
|
+
# Vagrant Plugin class that registers configs, hooks, etc.
|
7
|
+
#
|
8
|
+
# @!parse class Plugin < Vagrant::Plugin::V2::Plugin; end
|
9
|
+
class Plugin < Vagrant.plugin('2')
|
10
|
+
# Compatible Vagrant versions
|
11
|
+
VAGRANT_VERSION_REQUIREMENT = '>= 1.2.0'
|
12
|
+
|
13
|
+
# Returns true if the Vagrant version fulfills the requirements
|
14
|
+
#
|
15
|
+
# @param requirements [String, Array<String>] the version requirement
|
16
|
+
# @return [Boolean]
|
17
|
+
def self.check_vagrant_version(*requirements)
|
18
|
+
Gem::Requirement.new(*requirements).satisfied_by?(
|
19
|
+
Gem::Version.new(Vagrant::VERSION))
|
20
|
+
end
|
21
|
+
|
22
|
+
# Verifies that the Vagrant version fulfills the requirements
|
23
|
+
#
|
24
|
+
# @raise [VagrantPlugins::TimeZone::VagrantVersionError] if this plugin
|
25
|
+
# is incompatible with the Vagrant version
|
26
|
+
def self.check_vagrant_version!
|
27
|
+
if !check_vagrant_version(VAGRANT_VERSION_REQUIREMENT)
|
28
|
+
msg = I18n.t(
|
29
|
+
'vagrant_timezone.errors.vagrant_version',
|
30
|
+
requirement: VAGRANT_VERSION_REQUIREMENT.inspect)
|
31
|
+
$stderr.puts msg
|
32
|
+
raise msg
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# Initializes the internationalization strings
|
37
|
+
def self.setup_i18n
|
38
|
+
I18n.load_path << File.expand_path('../../../locales/en.yml', __FILE__)
|
39
|
+
I18n.reload!
|
40
|
+
end
|
41
|
+
|
42
|
+
setup_i18n
|
43
|
+
check_vagrant_version!
|
44
|
+
|
45
|
+
name 'vagrant-timezone'
|
46
|
+
|
47
|
+
config 'timezone' do
|
48
|
+
require_relative 'config'
|
49
|
+
Config
|
50
|
+
end
|
51
|
+
|
52
|
+
action_hook 'timezone_configure', :machine_action_up do |hook|
|
53
|
+
require_relative 'action/set_timezone'
|
54
|
+
hook.after Vagrant::Action::Builtin::Provision, Action::SetTimeZone
|
55
|
+
end
|
56
|
+
|
57
|
+
action_hook 'timezone_configure', :machine_action_reload do |hook|
|
58
|
+
require_relative 'action/set_timezone'
|
59
|
+
hook.after Vagrant::Action::Builtin::Provision, Action::SetTimeZone
|
60
|
+
end
|
61
|
+
|
62
|
+
guest_capability 'debian', 'change_timezone' do
|
63
|
+
require_relative 'cap/debian'
|
64
|
+
Cap::Debian
|
65
|
+
end
|
66
|
+
|
67
|
+
guest_capability 'redhat', 'change_timezone' do
|
68
|
+
require_relative 'cap/redhat'
|
69
|
+
Cap::RedHat
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/locales/en.yml
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
require 'coveralls'
|
3
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
4
|
+
SimpleCov::Formatter::HTMLFormatter,
|
5
|
+
Coveralls::SimpleCov::Formatter
|
6
|
+
]
|
7
|
+
SimpleCov.start do
|
8
|
+
coverage_dir('tmp/coverage')
|
9
|
+
add_filter '/spec/'
|
10
|
+
end
|
11
|
+
|
12
|
+
RSpec.configure do |config|
|
13
|
+
config.expect_with :rspec do |c|
|
14
|
+
c.syntax = :expect
|
15
|
+
end
|
16
|
+
config.color = true
|
17
|
+
config.tty = true
|
18
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'vagrant-timezone/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'vagrant-timezone'
|
8
|
+
spec.version = VagrantPlugins::TimeZone::VERSION
|
9
|
+
spec.authors = ['Teemu Matilainen']
|
10
|
+
spec.email = ['teemu.matilainen@iki.fi']
|
11
|
+
spec.description = 'A Vagrant plugin that configures the time zone of a virtual machine'
|
12
|
+
spec.summary = spec.description
|
13
|
+
spec.homepage = 'http://github.com/tmatilai/vagrant-timezone'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vagrant-timezone
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Teemu Matilainen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-26 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A Vagrant plugin that configures the time zone of a virtual machine
|
14
|
+
email:
|
15
|
+
- teemu.matilainen@iki.fi
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".gitignore"
|
21
|
+
- ".travis.yml"
|
22
|
+
- CHANGELOG.md
|
23
|
+
- Gemfile
|
24
|
+
- LICENSE.txt
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- lib/vagrant-timezone.rb
|
28
|
+
- lib/vagrant-timezone/action/set_timezone.rb
|
29
|
+
- lib/vagrant-timezone/cap/debian.rb
|
30
|
+
- lib/vagrant-timezone/cap/redhat.rb
|
31
|
+
- lib/vagrant-timezone/config.rb
|
32
|
+
- lib/vagrant-timezone/logger.rb
|
33
|
+
- lib/vagrant-timezone/plugin.rb
|
34
|
+
- lib/vagrant-timezone/version.rb
|
35
|
+
- locales/en.yml
|
36
|
+
- spec/spec_helper.rb
|
37
|
+
- vagrant-timezone.gemspec
|
38
|
+
homepage: http://github.com/tmatilai/vagrant-timezone
|
39
|
+
licenses:
|
40
|
+
- MIT
|
41
|
+
metadata: {}
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
requirements: []
|
57
|
+
rubyforge_project:
|
58
|
+
rubygems_version: 2.2.2
|
59
|
+
signing_key:
|
60
|
+
specification_version: 4
|
61
|
+
summary: A Vagrant plugin that configures the time zone of a virtual machine
|
62
|
+
test_files:
|
63
|
+
- spec/spec_helper.rb
|