vagrantomatic 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile +1 -0
- data/README.md +1 -1
- data/lib/vagrantomatic/instance.rb +45 -18
- data/lib/vagrantomatic/logger.rb +3 -0
- data/lib/vagrantomatic/vagrantomatic.rb +1 -2
- data/lib/vagrantomatic/version.rb +1 -1
- data/res/Vagrantfile +7 -1
- data/vagrantomatic.gemspec +2 -1
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e87545b4ceeb2375b37856c107092824afb24dca
|
4
|
+
data.tar.gz: 9b2b57f73f09c98bf7164e5c29a8577ca6725064
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4be7d934d5e2dccd1072c6f9b5a3950b4758cb643b262448909fe8ec66ef6a576bab1210e9f1ad5e4950e95c2a9a43406e72d7612dcf2a6770fe82d9bab942e5
|
7
|
+
data.tar.gz: dc7fa3a0ce1fed4c334cfd29cdcef9ffc5f3eec9461c977e18b9f539bc89c900075289973d0338dc92db91058552728e3f5d48b4525c5e5694fa8ed5ad0186b2
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/GeoffWilliams/vagrantomatic.svg?branch=master)](https://travis-ci.org/GeoffWilliams/vagrantomatic)
|
1
2
|
# Vagrantomatic
|
2
3
|
|
3
4
|
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/vagrantomatic`. To experiment with that code, run `bin/console` for an interactive prompt.
|
@@ -33,4 +34,3 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
33
34
|
## Contributing
|
34
35
|
|
35
36
|
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/vagrantomatic.
|
36
|
-
|
@@ -1,7 +1,3 @@
|
|
1
|
-
# require "json"
|
2
|
-
# require "vagrantomatic/vagrantfile"
|
3
|
-
# require "vagrantomatic/logger"
|
4
|
-
#
|
5
1
|
require "derelict"
|
6
2
|
require "fileutils"
|
7
3
|
require "json"
|
@@ -15,11 +11,18 @@ module Vagrantomatic
|
|
15
11
|
|
16
12
|
attr_accessor :config
|
17
13
|
|
18
|
-
def initialize(vagrant_vm_dir, name, logger: nil, config:
|
14
|
+
def initialize(vagrant_vm_dir, name, logger: nil, config:nil)
|
19
15
|
@name = name
|
20
16
|
@vagrant_vm_dir = vagrant_vm_dir
|
21
17
|
@logger = ::Vagrantomatic::Logger.new(logger).logger
|
22
|
-
|
18
|
+
|
19
|
+
# use supplied config if present, otherwise load from file
|
20
|
+
if config
|
21
|
+
@config = config
|
22
|
+
else
|
23
|
+
@config = configfile_hash
|
24
|
+
end
|
25
|
+
@logger.debug "initialized vagrantomatic instance for #{name}"
|
23
26
|
end
|
24
27
|
|
25
28
|
def vm_instance_dir
|
@@ -34,15 +37,15 @@ module Vagrantomatic
|
|
34
37
|
File.join(vm_instance_dir, VAGRANTFILE_JSON)
|
35
38
|
end
|
36
39
|
|
37
|
-
# return a hash of the configfile or
|
40
|
+
# return a hash of the configfile or empty hash if error encountered
|
38
41
|
def configfile_hash
|
39
42
|
|
40
|
-
config =
|
43
|
+
config = {}
|
41
44
|
begin
|
42
45
|
json = File.read(configfile)
|
43
46
|
config = JSON.parse(json)
|
44
47
|
rescue Errno::ENOENT
|
45
|
-
@logger.
|
48
|
+
@logger.debug("#{configfile} does not exist")
|
46
49
|
rescue JSON::ParserError
|
47
50
|
@logger.error("JSON parser error in #{configfile}")
|
48
51
|
end
|
@@ -52,13 +55,13 @@ module Vagrantomatic
|
|
52
55
|
def configured?
|
53
56
|
configured = false
|
54
57
|
if Dir.exists? (vm_instance_dir) and File.exists?(configfile) and File.exists?(vagrantfile)
|
55
|
-
|
56
|
-
configured = !! configfile_hash
|
58
|
+
configured = configfile_hash.has_key?("box")
|
57
59
|
end
|
58
60
|
configured
|
59
61
|
end
|
60
62
|
|
61
63
|
def save
|
64
|
+
@logger.debug("saving vm settings...")
|
62
65
|
FileUtils.mkdir_p(vm_instance_dir)
|
63
66
|
ensure_config
|
64
67
|
ensure_vagrantfile
|
@@ -85,11 +88,11 @@ module Vagrantomatic
|
|
85
88
|
|
86
89
|
def get_vm
|
87
90
|
# Create an instance (represents a Vagrant **installation**)
|
88
|
-
instance = Derelict.instance(Vagrantomatic::Vagrantomatic::
|
91
|
+
instance = Derelict.instance(::Vagrantomatic::Vagrantomatic::DEFAULT_VAGRANT_DIR)
|
89
92
|
result = instance.execute('--version') # Derelict::Executer object (vagrant --version)
|
90
93
|
if result.success?
|
91
94
|
# vagrant present and working, connect to our vm INSTANCE
|
92
|
-
vm = instance.connect(
|
95
|
+
vm = instance.connect(vm_instance_dir)
|
93
96
|
else
|
94
97
|
raise "Error connecting to vagrant! (vagrant --version failed)"
|
95
98
|
end
|
@@ -97,6 +100,13 @@ module Vagrantomatic
|
|
97
100
|
vm
|
98
101
|
end
|
99
102
|
|
103
|
+
def execute_and_log(op)
|
104
|
+
get_vm.execute(op) { |stdout, stderr|
|
105
|
+
# only one of these will ever be set at a time, other one is nil
|
106
|
+
@logger.debug "#{stdout}#{stderr}"
|
107
|
+
}.success?
|
108
|
+
end
|
109
|
+
|
100
110
|
def in_sync?
|
101
111
|
configured = false
|
102
112
|
have_config = configfile_hash
|
@@ -109,20 +119,37 @@ module Vagrantomatic
|
|
109
119
|
end
|
110
120
|
|
111
121
|
def start
|
112
|
-
|
122
|
+
execute_and_log(:up)
|
113
123
|
end
|
114
124
|
|
115
125
|
def stop
|
116
|
-
|
126
|
+
execute_and_log(:suspend)
|
117
127
|
end
|
118
128
|
|
119
129
|
def purge
|
120
|
-
|
121
|
-
|
130
|
+
execute_and_log(:destroy)
|
131
|
+
if Dir.exists? vm_instance_dir
|
132
|
+
FileUtils::rm_rf(vm_instance_dir)
|
133
|
+
end
|
122
134
|
end
|
123
135
|
|
124
136
|
def reload
|
125
|
-
|
137
|
+
execute_and_log(:reload)
|
138
|
+
end
|
139
|
+
|
140
|
+
def run(command)
|
141
|
+
# arrayify
|
142
|
+
command = [command]
|
143
|
+
|
144
|
+
# throw the command over the wall to derelect whatever the state of instance
|
145
|
+
command.unshift("-c")
|
146
|
+
messages = []
|
147
|
+
vm = get_vm
|
148
|
+
executor = vm.execute(:ssh, command) { |stdout,stderr|
|
149
|
+
@logger.debug "#{stdout}#{stderr}"
|
150
|
+
messages << stdout << stderr
|
151
|
+
}
|
152
|
+
{ :status => executor.status, :messages => messages}
|
126
153
|
end
|
127
154
|
|
128
155
|
end
|
data/lib/vagrantomatic/logger.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require "vagrantomatic/version"
|
2
|
-
require "vagrantomatic/vagrantfile"
|
3
2
|
require "vagrantomatic/logger"
|
4
3
|
require "vagrantomatic/instance"
|
5
4
|
require "json"
|
@@ -34,7 +33,7 @@ module Vagrantomatic
|
|
34
33
|
|
35
34
|
# Return a has of instances
|
36
35
|
def instances_metadata()
|
37
|
-
instance_wildcard = File.join(@vagrant_vm_dir, "*", ::Vagrantomatic::
|
36
|
+
instance_wildcard = File.join(@vagrant_vm_dir, "*", ::Vagrantomatic::Instance::VAGRANTFILE)
|
38
37
|
instances = {}
|
39
38
|
Dir.glob(instance_wildcard).each { |f|
|
40
39
|
elements = f.split(File::SEPARATOR)
|
data/res/Vagrantfile
CHANGED
@@ -17,6 +17,7 @@ config_ip = config["ip"]
|
|
17
17
|
config_memory = config["memory"]
|
18
18
|
config_cpu = config["cpu"]
|
19
19
|
config_provision = config["provision"]
|
20
|
+
config_folders = config["folders"] ? Array(config["folders"]) : false
|
20
21
|
|
21
22
|
# Create boxes
|
22
23
|
Vagrant.configure("2") do |config|
|
@@ -36,7 +37,12 @@ Vagrant.configure("2") do |config|
|
|
36
37
|
end
|
37
38
|
end
|
38
39
|
|
39
|
-
|
40
|
+
if config_folders
|
41
|
+
config_folders.each do |folder|
|
42
|
+
folder_split = folder.split(':')
|
43
|
+
config.vm.synced_folder folder_split[0], folder_split[1]
|
44
|
+
end
|
45
|
+
end
|
40
46
|
if config_provision
|
41
47
|
config.vm.provision "shell", inline: config_provision
|
42
48
|
end
|
data/vagrantomatic.gemspec
CHANGED
@@ -23,5 +23,6 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency "rake", "~> 10.0"
|
24
24
|
spec.add_development_dependency "rspec", "~> 3.0"
|
25
25
|
|
26
|
-
|
26
|
+
# https://github.com/bradfeehan/derelict/issues/16
|
27
|
+
# spec.add_dependency "derelict", "0.6.2"
|
27
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrantomatic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Geoff Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,20 +52,6 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: derelict
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - '='
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: 0.6.2
|
62
|
-
type: :runtime
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - '='
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: 0.6.2
|
69
55
|
description:
|
70
56
|
email:
|
71
57
|
- geoff@geoffwilliams.me.uk
|