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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 83fc3dcd87b04014048017771a8aa048d24afbd0
4
- data.tar.gz: 3308830d0c6486b688ea7715208fd56d931badf4
3
+ metadata.gz: e87545b4ceeb2375b37856c107092824afb24dca
4
+ data.tar.gz: 9b2b57f73f09c98bf7164e5c29a8577ca6725064
5
5
  SHA512:
6
- metadata.gz: 209fca308c3c55f44081995f781101a37e6aa72efdfab9ce02c62753300e9d6877050b396fe10626594f2af1ea269703c6baa456bf9c35862e811d8e3b7d2d80
7
- data.tar.gz: a30f119114ff811527fdc987eade59e681f845f8c9cdbc0e1420b783c33c2fe6ca8175f5d95da38fd2373d11b95537f8d6c619d9fd39d45ff196a09c128c449d
6
+ metadata.gz: 4be7d934d5e2dccd1072c6f9b5a3950b4758cb643b262448909fe8ec66ef6a576bab1210e9f1ad5e4950e95c2a9a43406e72d7612dcf2a6770fe82d9bab942e5
7
+ data.tar.gz: dc7fa3a0ce1fed4c334cfd29cdcef9ffc5f3eec9461c977e18b9f539bc89c900075289973d0338dc92db91058552728e3f5d48b4525c5e5694fa8ed5ad0186b2
data/.gitignore CHANGED
@@ -10,3 +10,4 @@
10
10
 
11
11
  # rspec failure tracking
12
12
  .rspec_status
13
+ /*.gem
data/Gemfile CHANGED
@@ -1,4 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in vagrantomatic.gemspec
4
+ gem 'derelict', :git => 'https://github.com/GeoffWilliams/derelict', :ref => 'preserve_real_status'
4
5
  gemspec
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
- @config = config
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 false if error encountered
40
+ # return a hash of the configfile or empty hash if error encountered
38
41
  def configfile_hash
39
42
 
40
- config = false
43
+ config = {}
41
44
  begin
42
45
  json = File.read(configfile)
43
46
  config = JSON.parse(json)
44
47
  rescue Errno::ENOENT
45
- @logger.error("#{configfile} does not exist")
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
- json = File.read(configfile)
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::VAGRANT_DIR)
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(@vm_instance_dir)
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
- get_vm.execute(:up).success?
122
+ execute_and_log(:up)
113
123
  end
114
124
 
115
125
  def stop
116
- get_vm.execute(:suspend).success?
126
+ execute_and_log(:suspend)
117
127
  end
118
128
 
119
129
  def purge
120
- get_vm.execute(:destroy)
121
- FileUtils::rm_rf(@vm_instance_dir)
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
- set_vm.execute(:reload)
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
@@ -9,6 +9,9 @@ module Vagrantomatic
9
9
  @logger = logger
10
10
  else
11
11
  @logger = ::Logger.new(STDOUT)
12
+ @logger.formatter = proc do |severity, datetime, progname, msg|
13
+ "#{severity}: #{msg}"
14
+ end
12
15
  end
13
16
  end
14
17
 
@@ -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::Vagrantfile::VAGRANTFILE)
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)
@@ -1,3 +1,3 @@
1
1
  module Vagrantomatic
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
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
- # srv.vm.synced_folder "./", "/home/vagrant/#{servers['name']}"
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
@@ -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
- spec.add_dependency "derelict", "0.6.2"
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.1.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-09 00:00:00.000000000 Z
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