vagrantomatic 0.3.0 → 0.3.1
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 +4 -4
- data/lib/vagrantomatic/instance.rb +46 -31
- data/lib/vagrantomatic/vagrantomatic.rb +3 -2
- data/lib/vagrantomatic/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e60f11c1f26149c77fd2cb98e52d7c8e1980010
|
4
|
+
data.tar.gz: c89b32d0413205a2c59fba38badf117f98f5f499
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2214044f3ad2e21dfcdccd82eed9bd50354ae3c8801155ef8492be620f18c5b4021ec4129559ab4ef8828d552d797042467cfb7e85f300438ba778aed6afdbc
|
7
|
+
data.tar.gz: b3f4af927fb78ba8616136b33ec86c3fbd31199dc64f1654c75b49e9b7446793b248e774498e82479ef24a4c8dca37d0205dc0d7afbead73db3ecdacc3fea469
|
@@ -9,7 +9,17 @@ module Vagrantomatic
|
|
9
9
|
# gem and get it into position by symlinking B-)
|
10
10
|
MASTER_VAGRANTFILE = File.join(File.dirname(File.expand_path(__FILE__)), "../../res/#{VAGRANTFILE}")
|
11
11
|
|
12
|
-
|
12
|
+
def config
|
13
|
+
@config
|
14
|
+
end
|
15
|
+
|
16
|
+
# ruby convention is to use `config=` but this doesn't work properly inside
|
17
|
+
# a constructor, it declarates a local variable `config`. Calling from
|
18
|
+
# outside the constructor works fine...
|
19
|
+
def set_config(config)
|
20
|
+
@config = config
|
21
|
+
validate_config
|
22
|
+
end
|
13
23
|
|
14
24
|
def validate_config(fatal = true)
|
15
25
|
valid = true
|
@@ -23,27 +33,36 @@ module Vagrantomatic
|
|
23
33
|
valid
|
24
34
|
end
|
25
35
|
|
26
|
-
|
27
|
-
|
36
|
+
# Add a new folder to @config in the correct place. Folders must be
|
37
|
+
# specified as colon delimited strings: `HOST_PATH:VM_PATH`, eg
|
38
|
+
# `/home/geoff:/stuff` would mount `/home/geoff` from the main computer and
|
39
|
+
# would mount it inside the VM at /stuff. Vagrant expects the `HOST_PATH`
|
40
|
+
# to be an absolute path, however, you may specify a relative path here and
|
41
|
+
# vagrantomatic will attempt to extract a fully qualified path by prepending
|
42
|
+
# the present working directory. If this is incorrect its up to the
|
43
|
+
# programmer to fix this by passing in a fully qualified path in the first
|
44
|
+
# place
|
45
|
+
def add_shared_folder(folders)
|
46
|
+
folders=Array(folders)
|
28
47
|
# can't use dig() might not be ruby 2.3
|
29
|
-
if @config.has_key?("folders")
|
30
|
-
@config["folders"] = Array(@config["folders"])
|
31
|
-
|
32
|
-
# all paths must be fully qualified. If we were asked to do a relative path, change
|
33
|
-
# it to the current directory since that's probably what the user wanted. Not right?
|
34
|
-
# user supply correct path!
|
35
|
-
@config["folders"] = @config["folders"].map { |folder|
|
36
|
-
if ! folder.start_with? '/'
|
37
|
-
folder = "#{Dir.pwd}/#{folder}"
|
38
|
-
end
|
39
|
-
folder
|
40
|
-
}
|
41
|
-
else
|
48
|
+
if ! @config.has_key?("folders")
|
42
49
|
@config["folders"] = []
|
43
50
|
end
|
51
|
+
|
52
|
+
|
53
|
+
# all paths must be fully qualified. If we were asked to do a relative path, change
|
54
|
+
# it to the current directory since that's probably what the user wanted. Not right?
|
55
|
+
# user supply correct path!
|
56
|
+
folders.each { |folder|
|
57
|
+
if ! folder.start_with? '/'
|
58
|
+
folder = "#{Dir.pwd}/#{folder}"
|
59
|
+
end
|
60
|
+
|
61
|
+
@config["folders"] << folder
|
62
|
+
}
|
44
63
|
end
|
45
64
|
|
46
|
-
def initialize(vagrant_vm_dir, name, logger:
|
65
|
+
def initialize(vagrant_vm_dir, name, logger:nil, config:nil)
|
47
66
|
@name = name
|
48
67
|
@vagrant_vm_dir = vagrant_vm_dir
|
49
68
|
@logger = Logger.new(logger).logger
|
@@ -57,23 +76,18 @@ module Vagrantomatic
|
|
57
76
|
|
58
77
|
# use supplied config if present, otherwise load from file
|
59
78
|
if config
|
60
|
-
@config = config
|
61
|
-
|
62
79
|
# validate a user-supplied config now, at the point of insertion
|
63
80
|
# by this point we have a config either from file or supplied by user it
|
64
81
|
# must be valid for us to proceed!
|
65
|
-
|
66
|
-
validate_config
|
67
|
-
|
68
|
-
# user may have specified relative folders at time of creation - if so
|
69
|
-
# we must now expand all paths in them and write them forever to config
|
70
|
-
# file
|
71
|
-
fix_folders
|
82
|
+
set_config(config)
|
72
83
|
else
|
73
|
-
@config = configfile_hash
|
74
84
|
|
75
85
|
# this passed-in config could still be bad - we will validate it before
|
76
|
-
# use on either save() or get_vm()
|
86
|
+
# use on either save() or get_vm(). We DONT validate it right away
|
87
|
+
# because this would cause the constructor to explode when we are trying
|
88
|
+
# to introspec intances - we would never be able to fix anything
|
89
|
+
# automatically
|
90
|
+
@config = configfile_hash
|
77
91
|
end
|
78
92
|
|
79
93
|
@logger.debug "initialized vagrantomatic instance for #{name}"
|
@@ -144,6 +158,8 @@ module Vagrantomatic
|
|
144
158
|
FileUtils.mkdir_p(vm_instance_dir)
|
145
159
|
ensure_config
|
146
160
|
ensure_vagrantfile
|
161
|
+
|
162
|
+
@force_save = false
|
147
163
|
end
|
148
164
|
|
149
165
|
# Vagrant to be driven from a .json config file, all
|
@@ -168,7 +184,7 @@ module Vagrantomatic
|
|
168
184
|
def get_vm
|
169
185
|
# Create an instance (represents a Vagrant **installation**)
|
170
186
|
if ! in_sync?
|
171
|
-
raise "get_vm called for instance but it is not in_sync! (call save() first?)"
|
187
|
+
raise "get_vm called for instance #{@name}but it is not in_sync! (call save() first?)"
|
172
188
|
end
|
173
189
|
|
174
190
|
validate_config
|
@@ -195,7 +211,6 @@ module Vagrantomatic
|
|
195
211
|
def in_sync?
|
196
212
|
configured = false
|
197
213
|
have_config = configfile_hash
|
198
|
-
|
199
214
|
if (! @force_save) and (have_config == @config )
|
200
215
|
configured = true
|
201
216
|
end
|
@@ -242,7 +257,7 @@ module Vagrantomatic
|
|
242
257
|
@logger.debug line
|
243
258
|
messages << line
|
244
259
|
}
|
245
|
-
@logger.info("command '#{command}' resulted in #{messages.size} lines")
|
260
|
+
@logger.info("command '#{command}' resulted in #{messages.size} lines (exit status: #{executor.status})")
|
246
261
|
return executor.status, messages
|
247
262
|
end
|
248
263
|
|
@@ -10,6 +10,7 @@ module Vagrantomatic
|
|
10
10
|
|
11
11
|
def initialize(vagrant_vm_dir: nil, logger: nil)
|
12
12
|
@vagrant_vm_dir = vagrant_vm_dir || DEFAULT_VAGRANT_VM_DIR
|
13
|
+
FileUtils.mkdir_p(@vagrant_vm_dir)
|
13
14
|
@logger = Logger.new(logger).logger
|
14
15
|
end
|
15
16
|
|
@@ -47,8 +48,8 @@ module Vagrantomatic
|
|
47
48
|
instances
|
48
49
|
end
|
49
50
|
|
50
|
-
def instance(name)
|
51
|
-
Instance.new(@vagrant_vm_dir, name, logger: @logger)
|
51
|
+
def instance(name,logger:nil, config:nil)
|
52
|
+
Instance.new(@vagrant_vm_dir, name, logger: @logger, config:config)
|
52
53
|
end
|
53
54
|
|
54
55
|
end
|