vagrant-local 0.0.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 +7 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +27 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- data/.github/dependabot.yml +6 -0
- data/.github/workflows/codeql-analysis.yml +72 -0
- data/.github/workflows/lint-release-and-publish-nightly.yml +73 -0
- data/.github/workflows/lint-release-and-publish.yml +71 -0
- data/.github/workflows/ruby-lint.yml +35 -0
- data/.gitignore +35 -0
- data/.rspec +2 -0
- data/.rubocop.yml +143 -0
- data/CHANGELOG.md +32 -0
- data/CODE_OF_CONDUCT.md +128 -0
- data/CONTRIBUTING.md +97 -0
- data/Gemfile +26 -0
- data/LICENSE +651 -0
- data/PULL_REQUEST_TEMPLATE.md +39 -0
- data/README.md +92 -0
- data/RELEASE.md +22 -0
- data/Rakefile +32 -0
- data/SECURITY.md +19 -0
- data/ansible.cfg +5 -0
- data/docs/CNAME +1 -0
- data/docs/_config.yml +1 -0
- data/docs/css/main.css +55 -0
- data/docs/css/styles.css +8678 -0
- data/docs/index.html +125 -0
- data/lib/vagrant-local/action/create.rb +27 -0
- data/lib/vagrant-local/action/destroy.rb +25 -0
- data/lib/vagrant-local/action/halt.rb +24 -0
- data/lib/vagrant-local/action/import.rb +27 -0
- data/lib/vagrant-local/action/is_created.rb +22 -0
- data/lib/vagrant-local/action/network.rb +24 -0
- data/lib/vagrant-local/action/network_cleanup.rb +26 -0
- data/lib/vagrant-local/action/not_created.rb +20 -0
- data/lib/vagrant-local/action/package.rb +135 -0
- data/lib/vagrant-local/action/restart.rb +27 -0
- data/lib/vagrant-local/action/setup.rb +24 -0
- data/lib/vagrant-local/action/shutdown.rb +47 -0
- data/lib/vagrant-local/action/start.rb +25 -0
- data/lib/vagrant-local/action/wait_till_boot.rb +47 -0
- data/lib/vagrant-local/action/wait_till_up.rb +65 -0
- data/lib/vagrant-local/action.rb +187 -0
- data/lib/vagrant-local/command/guest_power_controls.rb +58 -0
- data/lib/vagrant-local/command/local.rb +69 -0
- data/lib/vagrant-local/command/restart_guest.rb +29 -0
- data/lib/vagrant-local/command/shutdown_guest.rb +29 -0
- data/lib/vagrant-local/command/vnc_console.rb +48 -0
- data/lib/vagrant-local/command/webvnc_console.rb +49 -0
- data/lib/vagrant-local/config.rb +55 -0
- data/lib/vagrant-local/driver.rb +208 -0
- data/lib/vagrant-local/errors.rb +84 -0
- data/lib/vagrant-local/executor.rb +38 -0
- data/lib/vagrant-local/plugin.rb +76 -0
- data/lib/vagrant-local/provider.rb +83 -0
- data/lib/vagrant-local/util/subprocess.rb +31 -0
- data/lib/vagrant-local/util/timer.rb +19 -0
- data/lib/vagrant-local/version.rb +8 -0
- data/lib/vagrant-local.rb +29 -0
- data/locales/en.yml +187 -0
- data/vagrant-zones.gemspec +37 -0
- metadata +191 -0
data/docs/index.html
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html lang="en">
|
3
|
+
<head>
|
4
|
+
<meta charset="UTF-8" />
|
5
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
7
|
+
<title>Vagrant Local</title>
|
8
|
+
<link rel="stylesheet" href="css/styles.css" />
|
9
|
+
<link rel="stylesheet" href="css/main.css" />
|
10
|
+
</head>
|
11
|
+
|
12
|
+
<body>
|
13
|
+
<div class="header">
|
14
|
+
<div class="container">
|
15
|
+
<div class="row d-flex">
|
16
|
+
<img
|
17
|
+
src="assets/logo-big.jpg"
|
18
|
+
class="logo-big img-fluid mx-auto mt-4"
|
19
|
+
alt="..."
|
20
|
+
/>
|
21
|
+
</div>
|
22
|
+
<div class="row justify-content-md-center">
|
23
|
+
<div class="menu-link col-md-auto fs-3 p-3 text-center">
|
24
|
+
<a href="https://github.com/STARTcloud/vagrant-local">Home</a>
|
25
|
+
</div>
|
26
|
+
<div class="menu-link col-md-auto fs-3 p-3 text-center">
|
27
|
+
<a href="http://rubydoc.info/gems/vagrant-local">Ruby Docs</a>
|
28
|
+
</div>
|
29
|
+
<div class="menu-link col-md-auto fs-3 p-3 text-center">
|
30
|
+
<a href="https://github.com/STARTcloud/vagrant-local/issues">Issue Tracking</a>
|
31
|
+
</div>
|
32
|
+
</div>
|
33
|
+
</div>
|
34
|
+
</div>
|
35
|
+
|
36
|
+
<div class="container">
|
37
|
+
<div class="row my-4">
|
38
|
+
<div class="col">
|
39
|
+
<div class="card shadow">
|
40
|
+
<div class="card-body">
|
41
|
+
<p class="card-text fs-3 text-center">
|
42
|
+
vagrant-local is a provider plugin for
|
43
|
+
Vagrant which will allow you to manage as
|
44
|
+
host as vm you would a VirtualBox vagrant machine.
|
45
|
+
</p>
|
46
|
+
</div>
|
47
|
+
</div>
|
48
|
+
</div>
|
49
|
+
</div>
|
50
|
+
</div>
|
51
|
+
|
52
|
+
<div class="container">
|
53
|
+
<div class="row">
|
54
|
+
<!-- Card 1 -->
|
55
|
+
<div class="col-md-6 col-lg-3 my-4">
|
56
|
+
<div class="card shadow">
|
57
|
+
<div class="card-body">
|
58
|
+
<h5 class="card-title mb-4">Manage with Confidence</h5>
|
59
|
+
<p class="card-text">
|
60
|
+
Versioning, and automated deployment controls
|
61
|
+
allow you to build your Virtual Machines
|
62
|
+
with confidence the process will be transparent.
|
63
|
+
</p>
|
64
|
+
</div>
|
65
|
+
</div>
|
66
|
+
</div>
|
67
|
+
|
68
|
+
<!-- Card 2 -->
|
69
|
+
<div class="col-md-6 col-lg-3 my-4">
|
70
|
+
<div class="card shadow">
|
71
|
+
<div class="card-body">
|
72
|
+
<h5 class="card-title mb-4">Create your Automation</h5>
|
73
|
+
<p class="card-text">
|
74
|
+
vagrant-local is a provider plugin for
|
75
|
+
Vagrant which will allow you to manage as
|
76
|
+
host as vm you would a VirtualBox vagrant machine.
|
77
|
+
</p>
|
78
|
+
</div>
|
79
|
+
</div>
|
80
|
+
</div>
|
81
|
+
|
82
|
+
<!-- Card 3 -->
|
83
|
+
<div class="col-md-6 col-lg-3 my-4">
|
84
|
+
<div class="card shadow">
|
85
|
+
<div class="card-body">
|
86
|
+
<h5 class="card-title mb-4">Share with Others</h5>
|
87
|
+
<p class="card-text">
|
88
|
+
This tool will allow you to package and share boxes
|
89
|
+
with other users, helping you develope on a wide
|
90
|
+
array of Hypervisors and Operating Systems.
|
91
|
+
</p>
|
92
|
+
</div>
|
93
|
+
</div>
|
94
|
+
</div>
|
95
|
+
|
96
|
+
<!-- Card 4 -->
|
97
|
+
<div class="col-md-6 col-lg-3 my-4">
|
98
|
+
<div class="card shadow">
|
99
|
+
<div class="card-body">
|
100
|
+
<h5 class="card-title mb-4">Feature Requests</h5>
|
101
|
+
<p class="card-text">
|
102
|
+
Reach out to use in a GitHub issue and let us know what
|
103
|
+
your projects goals are. If you can commit to testing
|
104
|
+
we can work on getting your feature commited.
|
105
|
+
</p>
|
106
|
+
</div>
|
107
|
+
</div>
|
108
|
+
</div>
|
109
|
+
</div>
|
110
|
+
</div>
|
111
|
+
|
112
|
+
<div class="container">
|
113
|
+
<div class="card shadow footer mt-5">
|
114
|
+
<img
|
115
|
+
src="assets/logo-small.png"
|
116
|
+
class="logo-small mx-auto my-4"
|
117
|
+
alt="..."
|
118
|
+
/>
|
119
|
+
<p class="copyright text-center pb-4 mb-0">
|
120
|
+
©2022 STARTcloud, Inc.
|
121
|
+
</p>
|
122
|
+
</div>
|
123
|
+
</div>
|
124
|
+
</body>
|
125
|
+
</html>
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'log4r'
|
4
|
+
require 'securerandom'
|
5
|
+
require 'digest/md5'
|
6
|
+
|
7
|
+
module VagrantPlugins
|
8
|
+
module ProviderLocal
|
9
|
+
module Action
|
10
|
+
# This will create the Instance
|
11
|
+
class Create
|
12
|
+
def initialize(app, _env)
|
13
|
+
@logger = Log4r::Logger.new('vagrant_local::action::import')
|
14
|
+
@app = app
|
15
|
+
end
|
16
|
+
|
17
|
+
def call(env)
|
18
|
+
@machine = env[:machine]
|
19
|
+
@driver = @machine.provider.driver
|
20
|
+
@machine.id = SecureRandom.uuid
|
21
|
+
@driver.install(env[:ui])
|
22
|
+
@app.call(env)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'log4r'
|
4
|
+
require 'securerandom'
|
5
|
+
require 'digest/md5'
|
6
|
+
module VagrantPlugins
|
7
|
+
module ProviderLocal
|
8
|
+
module Action
|
9
|
+
# This will destroy the instance
|
10
|
+
class Destroy
|
11
|
+
def initialize(app, _env)
|
12
|
+
@logger = Log4r::Logger.new('vagrant_local::action::import')
|
13
|
+
@app = app
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(env)
|
17
|
+
@machine = env[:machine]
|
18
|
+
@driver = @machine.provider.driver
|
19
|
+
@driver.destroy(env[:ui])
|
20
|
+
@app.call(env)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'log4r'
|
4
|
+
|
5
|
+
module VagrantPlugins
|
6
|
+
module ProviderLocal
|
7
|
+
module Action
|
8
|
+
# This will halt the instance
|
9
|
+
class Halt
|
10
|
+
def initialize(app, _env)
|
11
|
+
@logger = Log4r::Logger.new('vagrant_local::action::import')
|
12
|
+
@app = app
|
13
|
+
end
|
14
|
+
|
15
|
+
def call(env)
|
16
|
+
@machine = env[:machine]
|
17
|
+
@driver = @machine.provider.driver
|
18
|
+
@driver.halt(env[:ui])
|
19
|
+
@app.call(env)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
require 'vagrant-local/util/subprocess'
|
5
|
+
require 'vagrant/box_metadata'
|
6
|
+
require 'vagrant/util/downloader'
|
7
|
+
require 'vagrant/util/platform'
|
8
|
+
require 'vagrant/util/safe_chdir'
|
9
|
+
require 'vagrant/util/subprocess'
|
10
|
+
|
11
|
+
module VagrantPlugins
|
12
|
+
module ProviderLocal
|
13
|
+
module Action
|
14
|
+
# This will import the instance boot image from the cloud, cache or file
|
15
|
+
class Import
|
16
|
+
def initialize(app, _env)
|
17
|
+
@logger = Log4r::Logger.new('vagrant_local::action::import')
|
18
|
+
@app = app
|
19
|
+
end
|
20
|
+
|
21
|
+
def call(env)
|
22
|
+
@app.call(env)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'log4r'
|
4
|
+
module VagrantPlugins
|
5
|
+
module ProviderLocal
|
6
|
+
module Action
|
7
|
+
# This can be used with 'Call' built-in to check if the machine
|
8
|
+
# is created and branch in the middleware.
|
9
|
+
class IsCreated
|
10
|
+
def initialize(app, _env)
|
11
|
+
@app = app
|
12
|
+
@logger = Log4r::Logger.new('vagrant_local::action')
|
13
|
+
end
|
14
|
+
|
15
|
+
def call(env)
|
16
|
+
env[:result] = env[:machine].state.id != :not_created
|
17
|
+
@app.call(env)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'log4r'
|
4
|
+
require 'securerandom'
|
5
|
+
require 'digest/md5'
|
6
|
+
|
7
|
+
module VagrantPlugins
|
8
|
+
module ProviderLocal
|
9
|
+
module Action
|
10
|
+
# This is use to define the network
|
11
|
+
class Network
|
12
|
+
def initialize(app, _env)
|
13
|
+
@logger = Log4r::Logger.new('vagrant_local::action::import')
|
14
|
+
@app = app
|
15
|
+
end
|
16
|
+
|
17
|
+
def call(env)
|
18
|
+
@machine = env[:machine]
|
19
|
+
@app.call(env)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'log4r'
|
4
|
+
require 'securerandom'
|
5
|
+
require 'digest/md5'
|
6
|
+
|
7
|
+
module VagrantPlugins
|
8
|
+
module ProviderLocal
|
9
|
+
module Action
|
10
|
+
# This is use to define the network
|
11
|
+
class NetworkingCleanup
|
12
|
+
def initialize(app, _env)
|
13
|
+
@logger = Log4r::Logger.new('vagrant_local::action::import')
|
14
|
+
@app = app
|
15
|
+
end
|
16
|
+
|
17
|
+
def call(env)
|
18
|
+
@machine = env[:machine]
|
19
|
+
@driver = @machine.provider.driver
|
20
|
+
@driver.network(env[:ui], 'delete_provisional')
|
21
|
+
@app.call(env)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'log4r'
|
4
|
+
module VagrantPlugins
|
5
|
+
module ProviderLocal
|
6
|
+
module Action
|
7
|
+
# This is used to determine if the VM is created
|
8
|
+
class NotCreated
|
9
|
+
def initialize(app, _env)
|
10
|
+
@app = app
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(env)
|
14
|
+
env[:ui].info(I18n.t('vagrant_local.states.not_created'))
|
15
|
+
@app.call(env)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
require 'pathname'
|
5
|
+
require 'log4r'
|
6
|
+
require 'json'
|
7
|
+
module VagrantPlugins
|
8
|
+
module ProviderLocal
|
9
|
+
module Action
|
10
|
+
# This is used to package the VM into a box
|
11
|
+
class Package
|
12
|
+
def initialize(app, env)
|
13
|
+
@logger = Log4r::Logger.new('vagrant_local::action::import')
|
14
|
+
@app = app
|
15
|
+
@executor = Executor::Exec.new
|
16
|
+
@pfexec = if Process.uid.zero?
|
17
|
+
''
|
18
|
+
elsif system('sudo -v')
|
19
|
+
'sudo'
|
20
|
+
else
|
21
|
+
'pfexec'
|
22
|
+
end
|
23
|
+
env['package.output'] ||= 'package.box'
|
24
|
+
end
|
25
|
+
|
26
|
+
def execute(...)
|
27
|
+
@executor.execute(...)
|
28
|
+
end
|
29
|
+
|
30
|
+
def call(env)
|
31
|
+
boxname = env['package.output']
|
32
|
+
mpc = env[:machine].provider_config
|
33
|
+
files = {}
|
34
|
+
raise "#{boxname}: Already exists" if File.exist?(boxname)
|
35
|
+
|
36
|
+
## Create Snapshot
|
37
|
+
FileUtils.mkdir_p("#{Dir.pwd}/_tmp_package")
|
38
|
+
datasetpath = "#{mpc.boot['array']}/#{mpc.boot['dataset']}/#{env[:machine].name}"
|
39
|
+
datetime = Time.new.strftime('%Y-%m-%d-%H:%M:%S')
|
40
|
+
snapshot_create(datasetpath, datetime, env[:ui], mpc)
|
41
|
+
snapshot_send(datasetpath, "#{Dir.pwd}/_tmp_package/box.zss", datetime, env[:ui], mpc)
|
42
|
+
|
43
|
+
## Include User Extra Files
|
44
|
+
env['package.include'].each do |file|
|
45
|
+
source = Pathname.new(file)
|
46
|
+
dest = if source.relative?
|
47
|
+
source
|
48
|
+
else
|
49
|
+
source.basename
|
50
|
+
end
|
51
|
+
files[file] = dest
|
52
|
+
end
|
53
|
+
|
54
|
+
# Verify the mapping
|
55
|
+
files.each_key do |from|
|
56
|
+
raise Vagrant::Errors::PackageIncludeMissing, file: from unless File.exist?(from)
|
57
|
+
end
|
58
|
+
|
59
|
+
files.each do |from, dest|
|
60
|
+
include_directory = Pathname.new("#{Dir.pwd}/_tmp_package/")
|
61
|
+
to = include_directory.join(dest)
|
62
|
+
FileUtils.mkdir_p(to.parent)
|
63
|
+
if File.directory?(from)
|
64
|
+
FileUtils.cp_r(Dir.glob(from), to.parent, preserve: true)
|
65
|
+
else
|
66
|
+
FileUtils.cp(from, to, preserve: true)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
## Create a Vagrantfile or load from Users Defined File
|
71
|
+
vagrantfile_content = <<~'CODE'
|
72
|
+
require 'yaml'
|
73
|
+
require_relative 'Hosts'
|
74
|
+
settings = YAML::load(File.read("#{File.dirname(__FILE__)}/Hosts.yml"))
|
75
|
+
Vagrant.configure("2") do |config|
|
76
|
+
Hosts.configure(config, settings)
|
77
|
+
end
|
78
|
+
CODE
|
79
|
+
File.write("#{Dir.pwd}/_tmp_package/Vagrantfile", vagrantfile_content)
|
80
|
+
files[env['package.vagrantfile']] = '_Vagrantfile' if env['package.vagrantfile']
|
81
|
+
|
82
|
+
info_content_hash = {
|
83
|
+
'boxname' => boxname,
|
84
|
+
'Author' => mpc.vagrant_cloud_creator,
|
85
|
+
'vagrant-local' => 'This box was built with vagrant-local: https://github.com/STARTcloud/vagrant-local'
|
86
|
+
}
|
87
|
+
File.write("#{Dir.pwd}/_tmp_package/info.json", info_content_hash.to_json)
|
88
|
+
|
89
|
+
metadata_content_hash = {
|
90
|
+
'provider' => 'local',
|
91
|
+
'architecture' => 'amd64',
|
92
|
+
'brand' => mpc.brand,
|
93
|
+
'format' => 'zss',
|
94
|
+
'url' => "https://app.vagrantup.com/#{mpc.vagrant_cloud_creator}/boxes/#{mpc.boxshortname}"
|
95
|
+
}
|
96
|
+
metadata_content_hash['kernel'] = mpc.kernel if !mpc.kernel.nil? && mpc.kernel != false
|
97
|
+
File.write("#{Dir.pwd}/_tmp_package/metadata.json", metadata_content_hash.to_json)
|
98
|
+
|
99
|
+
## Create the Box file
|
100
|
+
assemble_box(boxname, "#{Dir.pwd}/_tmp_package")
|
101
|
+
FileUtils.rm_rf("#{Dir.pwd}/_tmp_package")
|
102
|
+
|
103
|
+
env[:ui].info("Box created, You can now add the box: 'vagrant box add #{boxname} --name newbox'")
|
104
|
+
@app.call(env)
|
105
|
+
end
|
106
|
+
|
107
|
+
def snapshot_create(datasetpath, datetime, uii, config)
|
108
|
+
uii.info('Creating a Snapshot of the box.')
|
109
|
+
result = execute(true, "#{@pfexec} zfs snapshot -r #{datasetpath}/boot@vagrant_box#{datetime}")
|
110
|
+
uii.info("#{@pfexec} zfs snapshot -r #{datasetpath}/boot@vagrant_box#{datetime}") if result.zero? && config.debug
|
111
|
+
end
|
112
|
+
|
113
|
+
def snapshot_delete(datasetpath, uii, datetime)
|
114
|
+
result = execute(true, "#{@pfexec} zfs destroy -r -f #{datasetpath}/boot@vagrant_box#{datetime}")
|
115
|
+
uii.info("#{@pfexec} zfs destroy -r -f #{datasetpath}/boot@vagrant_box#{datetime}") if result.zero? && config.debug
|
116
|
+
end
|
117
|
+
|
118
|
+
def snapshot_send(datasetpath, destination, datetime, uii, config)
|
119
|
+
uii.info('Sending Snapshot to ZFS Send Stream image.')
|
120
|
+
result = execute(true, "#{@pfexec} zfs send #{datasetpath}/boot@vagrant_box#{datetime} > #{destination}")
|
121
|
+
uii.info("#{@pfexec} zfs send -r #{datasetpath}/boot@vagrant_box#{datetime} > #{destination}") if result.zero? && config.debug
|
122
|
+
end
|
123
|
+
|
124
|
+
def assemble_box(boxname, tmp_dir)
|
125
|
+
is_linux = `bash -c '[[ "$(uname -a)" =~ "Linux" ]]'`
|
126
|
+
Dir.chdir(tmp_dir) do
|
127
|
+
files = Dir.glob(File.join('.', '*'))
|
128
|
+
tar_command = is_linux ? 'tar -cvzf' : 'tar -cvzEf'
|
129
|
+
`#{tar_command} ../#{boxname} #{files.join(' ')}`
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'log4r'
|
4
|
+
require 'vagrant-local/util/timer'
|
5
|
+
require 'vagrant/util/retryable'
|
6
|
+
|
7
|
+
module VagrantPlugins
|
8
|
+
module ProviderLocal
|
9
|
+
module Action
|
10
|
+
# This is used to restart the instance
|
11
|
+
class Restart
|
12
|
+
include Vagrant::Util::Retryable
|
13
|
+
def initialize(app, _env)
|
14
|
+
@logger = Log4r::Logger.new('vagrant_local::action::restart')
|
15
|
+
@app = app
|
16
|
+
end
|
17
|
+
|
18
|
+
def call(env)
|
19
|
+
@machine = env[:machine]
|
20
|
+
@driver = @machine.provider.driver
|
21
|
+
@driver.control(env[:ui], 'restart')
|
22
|
+
@app.call(env)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'log4r'
|
4
|
+
require 'securerandom'
|
5
|
+
require 'digest/md5'
|
6
|
+
|
7
|
+
module VagrantPlugins
|
8
|
+
module ProviderLocal
|
9
|
+
module Action
|
10
|
+
# This is used to setup the instance
|
11
|
+
class Setup
|
12
|
+
def initialize(app, _env)
|
13
|
+
@logger = Log4r::Logger.new('vagrant_local::action::import')
|
14
|
+
@app = app
|
15
|
+
end
|
16
|
+
|
17
|
+
def call(env)
|
18
|
+
@machine = env[:machine]
|
19
|
+
@app.call(env)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'log4r'
|
4
|
+
require 'vagrant-local/util/timer'
|
5
|
+
require 'vagrant/util/retryable'
|
6
|
+
|
7
|
+
module VagrantPlugins
|
8
|
+
module ProviderLocal
|
9
|
+
module Action
|
10
|
+
# This is used to shutdown the instance
|
11
|
+
class Shutdown
|
12
|
+
include Vagrant::Util::Retryable
|
13
|
+
def initialize(app, _env)
|
14
|
+
@logger = Log4r::Logger.new('vagrant_local::action::shutdown')
|
15
|
+
@app = app
|
16
|
+
end
|
17
|
+
|
18
|
+
def call(env)
|
19
|
+
@machine = env[:machine]
|
20
|
+
@driver = @machine.provider.driver
|
21
|
+
ui = env[:ui]
|
22
|
+
ui.info(I18n.t('vagrant_local.graceful_shutdown_started'))
|
23
|
+
@driver.control(ui, 'shutdown')
|
24
|
+
env[:metrics] ||= {}
|
25
|
+
env[:metrics]['instance_ssh_time'] = Util::Timer.time do
|
26
|
+
retryable(on: Errors::TimeoutError, tries: 300) do
|
27
|
+
# If we're interrupted don't worry about waiting
|
28
|
+
break if env[:interrupted]
|
29
|
+
break unless env[:machine].communicate.ready?
|
30
|
+
end
|
31
|
+
end
|
32
|
+
env[:metrics]['instance_ssh_time'] = Util::Timer.time do
|
33
|
+
300.times do
|
34
|
+
state_id = @driver.state(@machine)
|
35
|
+
ui.info(I18n.t('vagrant_local.graceful_shutdown_complete')) unless state_id == :running
|
36
|
+
sleep 1 if state_id == :running
|
37
|
+
break unless state_id == :running
|
38
|
+
break if env[:interrupted]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
@driver.halt(env[:ui])
|
42
|
+
@app.call(env)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'log4r'
|
4
|
+
|
5
|
+
module VagrantPlugins
|
6
|
+
module ProviderLocal
|
7
|
+
module Action
|
8
|
+
# This is used to start the instance
|
9
|
+
class Start
|
10
|
+
def initialize(app, _env)
|
11
|
+
@logger = Log4r::Logger.new('vagrant_local::action::start')
|
12
|
+
@app = app
|
13
|
+
end
|
14
|
+
|
15
|
+
def call(env)
|
16
|
+
@machine = env[:machine]
|
17
|
+
@driver = @machine.provider.driver
|
18
|
+
@driver.check_support(env[:ui])
|
19
|
+
@driver.boot(env[:ui])
|
20
|
+
@app.call(env)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'log4r'
|
4
|
+
require 'vagrant-local/util/timer'
|
5
|
+
require 'vagrant/util/retryable'
|
6
|
+
|
7
|
+
module VagrantPlugins
|
8
|
+
module ProviderLocal
|
9
|
+
module Action
|
10
|
+
# This is used wait till the instance is booted
|
11
|
+
class WaitTillBoot
|
12
|
+
include Vagrant::Util::Retryable
|
13
|
+
|
14
|
+
def initialize(app, _env)
|
15
|
+
@logger = Log4r::Logger.new('vagrant_local::action::import')
|
16
|
+
@app = app
|
17
|
+
end
|
18
|
+
|
19
|
+
def terminate(env)
|
20
|
+
return unless env[:machine].state.id != :not_created
|
21
|
+
|
22
|
+
# If we're not supposed to destroy on error then just return
|
23
|
+
return unless env[:destroy_on_error]
|
24
|
+
|
25
|
+
if env[:halt_on_error]
|
26
|
+
halt_env = env.dup
|
27
|
+
halt_env.delete(:interrupted)
|
28
|
+
halt_env[:config_validate] = false
|
29
|
+
env[:action_runner].run(Action.action_halt, halt_env)
|
30
|
+
else
|
31
|
+
destroy_env = env.dup
|
32
|
+
destroy_env.delete(:interrupted)
|
33
|
+
destroy_env[:config_validate] = false
|
34
|
+
destroy_env[:force_confirm_destroy] = true
|
35
|
+
env[:action_runner].run(Action.action_destroy, destroy_env)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def call(env)
|
40
|
+
@machine = env[:machine]
|
41
|
+
@driver = @machine.provider.driver
|
42
|
+
@app.call(env)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|