vagrant-zones 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.
Files changed (67) hide show
  1. checksums.yaml +7 -0
  2. data/.github/ISSUE_TEMPLATE/bug_report.md +27 -0
  3. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  4. data/.github/dependabot.yml +6 -0
  5. data/.github/workflows/codeql-analysis.yml +72 -0
  6. data/.github/workflows/lint-release-and-publish.yml +70 -0
  7. data/.github/workflows/ruby-lint.yml +35 -0
  8. data/.gitignore +35 -0
  9. data/.rspec +2 -0
  10. data/.rubocop.yml +143 -0
  11. data/CHANGELOG.md +0 -0
  12. data/CODE_OF_CONDUCT.md +128 -0
  13. data/CONTRIBUTING.md +96 -0
  14. data/Gemfile +14 -0
  15. data/LICENSE +651 -0
  16. data/PULL_REQUEST_TEMPLATE.md +39 -0
  17. data/README.md +81 -0
  18. data/RELEASE.md +15 -0
  19. data/Rakefile +32 -0
  20. data/SECURITY.md +19 -0
  21. data/docs/CNAME +1 -0
  22. data/docs/_config.yml +1 -0
  23. data/docs/css/main.css +55 -0
  24. data/docs/css/styles.css +8678 -0
  25. data/docs/index.html +127 -0
  26. data/lib/vagrant-zones/action/create.rb +29 -0
  27. data/lib/vagrant-zones/action/destroy.rb +27 -0
  28. data/lib/vagrant-zones/action/halt.rb +24 -0
  29. data/lib/vagrant-zones/action/import.rb +112 -0
  30. data/lib/vagrant-zones/action/is_created.rb +22 -0
  31. data/lib/vagrant-zones/action/network.rb +26 -0
  32. data/lib/vagrant-zones/action/not_created.rb +20 -0
  33. data/lib/vagrant-zones/action/package.rb +134 -0
  34. data/lib/vagrant-zones/action/prepare_nfs_valid_ids.rb +24 -0
  35. data/lib/vagrant-zones/action/restart.rb +53 -0
  36. data/lib/vagrant-zones/action/setup.rb +26 -0
  37. data/lib/vagrant-zones/action/shutdown.rb +47 -0
  38. data/lib/vagrant-zones/action/start.rb +25 -0
  39. data/lib/vagrant-zones/action/wait_till_boot.rb +59 -0
  40. data/lib/vagrant-zones/action/wait_till_up.rb +65 -0
  41. data/lib/vagrant-zones/action.rb +204 -0
  42. data/lib/vagrant-zones/command/configure_snapshots.rb +49 -0
  43. data/lib/vagrant-zones/command/console.rb +63 -0
  44. data/lib/vagrant-zones/command/create_snapshots.rb +46 -0
  45. data/lib/vagrant-zones/command/delete_snapshots.rb +38 -0
  46. data/lib/vagrant-zones/command/guest_power_controls.rb +58 -0
  47. data/lib/vagrant-zones/command/list_snapshots.rb +44 -0
  48. data/lib/vagrant-zones/command/restart_guest.rb +29 -0
  49. data/lib/vagrant-zones/command/shutdown_guest.rb +29 -0
  50. data/lib/vagrant-zones/command/vnc_console.rb +48 -0
  51. data/lib/vagrant-zones/command/webvnc_console.rb +49 -0
  52. data/lib/vagrant-zones/command/zfssnapshot.rb +67 -0
  53. data/lib/vagrant-zones/command/zlogin_console.rb +40 -0
  54. data/lib/vagrant-zones/command/zone.rb +73 -0
  55. data/lib/vagrant-zones/config.rb +78 -0
  56. data/lib/vagrant-zones/driver.rb +1710 -0
  57. data/lib/vagrant-zones/errors.rb +61 -0
  58. data/lib/vagrant-zones/executor.rb +38 -0
  59. data/lib/vagrant-zones/plugin.rb +79 -0
  60. data/lib/vagrant-zones/provider.rb +83 -0
  61. data/lib/vagrant-zones/util/subprocess.rb +31 -0
  62. data/lib/vagrant-zones/util/timer.rb +19 -0
  63. data/lib/vagrant-zones/version.rb +7 -0
  64. data/lib/vagrant-zones.rb +29 -0
  65. data/locales/en.yml +326 -0
  66. data/vagrant-zones.gemspec +51 -0
  67. metadata +412 -0
data/docs/index.html ADDED
@@ -0,0 +1,127 @@
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 Zones</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="index.html">Home</a>
25
+ </div>
26
+ <div class="menu-link col-md-auto fs-3 p-3 text-center">
27
+ <a href="own-your-data.html">Create your Automation</a>
28
+ </div>
29
+ <div class="menu-link col-md-auto fs-3 p-3 text-center">
30
+ <a href="contact-us.html">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-Zone is a plugin for Vagrant which
43
+ will allow you to sping up bhyve, kvm,
44
+ LX, illumos, and other zone types as
45
+ you would a VirtualBox vagrant machine.
46
+ </p>
47
+ </div>
48
+ </div>
49
+ </div>
50
+ </div>
51
+ </div>
52
+
53
+ <div class="container">
54
+ <div class="row">
55
+ <!-- Card 1 -->
56
+ <div class="col-md-6 col-lg-3 my-4">
57
+ <div class="card shadow">
58
+ <div class="card-body">
59
+ <h5 class="card-title mb-4">Manage with Confidence</h5>
60
+ <p class="card-text">
61
+ Versioning, and automated deployment controls
62
+ allow you to build your Virtual Machines
63
+ with confidence the process will be transparent.
64
+ </p>
65
+ </div>
66
+ </div>
67
+ </div>
68
+
69
+ <!-- Card 2 -->
70
+ <div class="col-md-6 col-lg-3 my-4">
71
+ <div class="card shadow">
72
+ <div class="card-body">
73
+ <h5 class="card-title mb-4">Create your Automation</h5>
74
+ <p class="card-text">
75
+ The ability to quickly spin up zones of any type
76
+ in a repeatable fashion allows, portable, versioned
77
+ and automatable packages ensuring your projects environments
78
+ are uniform and debuggable.
79
+ </p>
80
+ </div>
81
+ </div>
82
+ </div>
83
+
84
+ <!-- Card 3 -->
85
+ <div class="col-md-6 col-lg-3 my-4">
86
+ <div class="card shadow">
87
+ <div class="card-body">
88
+ <h5 class="card-title mb-4">Share with Others</h5>
89
+ <p class="card-text">
90
+ This tool will allow you to package and share boxes
91
+ with other users, helping you develope on a wide
92
+ array of Hypervisors and Operating Systems.
93
+ </p>
94
+ </div>
95
+ </div>
96
+ </div>
97
+
98
+ <!-- Card 4 -->
99
+ <div class="col-md-6 col-lg-3 my-4">
100
+ <div class="card shadow">
101
+ <div class="card-body">
102
+ <h5 class="card-title mb-4">Feature Requests</h5>
103
+ <p class="card-text">
104
+ Reach out to use in a GitHub issue and let us know what
105
+ your projects goals are. If you can commit to testing
106
+ we can work on getting your feature commited.
107
+ </p>
108
+ </div>
109
+ </div>
110
+ </div>
111
+ </div>
112
+ </div>
113
+
114
+ <div class="container">
115
+ <div class="card shadow footer mt-5">
116
+ <img
117
+ src="assets/logo-small.png"
118
+ class="logo-small mx-auto my-4"
119
+ alt="..."
120
+ />
121
+ <p class="copyright text-center pb-4 mb-0">
122
+ ©2022 STARTcloud, Inc.
123
+ </p>
124
+ </div>
125
+ </div>
126
+ </body>
127
+ </html>
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'log4r'
4
+ require 'securerandom'
5
+ require 'digest/md5'
6
+
7
+ module VagrantPlugins
8
+ module ProviderZone
9
+ module Action
10
+ # This will create the zone
11
+ class Create
12
+ def initialize(app, _env)
13
+ @logger = Log4r::Logger.new('vagrant_zones::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.create_dataset(env[:ui])
22
+ @driver.zonecfg(env[:ui])
23
+ @driver.install(env[:ui])
24
+ @app.call(env)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'log4r'
4
+ require 'securerandom'
5
+ require 'digest/md5'
6
+ module VagrantPlugins
7
+ module ProviderZone
8
+ module Action
9
+ # This will destroy the zone
10
+ class Destroy
11
+ def initialize(app, _env)
12
+ @logger = Log4r::Logger.new('vagrant_zones::action::import')
13
+ @app = app
14
+ end
15
+
16
+ def call(env)
17
+ @machine = env[:machine]
18
+ @driver = @machine.provider.driver
19
+ @driver.halt(env[:ui])
20
+ @driver.destroy(env[:ui])
21
+ @driver.delete_dataset(env[:ui])
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
+
5
+ module VagrantPlugins
6
+ module ProviderZone
7
+ module Action
8
+ # This will halt the zone
9
+ class Halt
10
+ def initialize(app, _env)
11
+ @logger = Log4r::Logger.new('vagrant_zones::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,112 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'net/http'
4
+ require 'vagrant-zones/util/subprocess'
5
+ require 'pp'
6
+ require 'vagrant/box_metadata'
7
+ require 'vagrant/util/downloader'
8
+ require 'vagrant/util/platform'
9
+ require 'vagrant/util/safe_chdir'
10
+ require 'vagrant/util/subprocess'
11
+
12
+ module VagrantPlugins
13
+ module ProviderZone
14
+ module Action
15
+ # This will import the zone boot image from the cloud, cache or file
16
+ class Import
17
+ def initialize(app, _env)
18
+ @logger = Log4r::Logger.new('vagrant_zones::action::import')
19
+ @joyent_images_url = 'https://images.joyent.com/images/'
20
+ @app = app
21
+ end
22
+
23
+ def validate_uuid_format(uuid)
24
+ uuid_regex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/
25
+ return true if uuid_regex.match?(uuid.to_s.downcase)
26
+ end
27
+
28
+ def call(env)
29
+ @machine = env[:machine]
30
+ @executor = Executor::Exec.new
31
+ image = @machine.config.vm.box
32
+ curdir = Dir.pwd
33
+ datadir = @machine.data_dir
34
+ @driver = @machine.provider.driver
35
+ ui = env[:ui]
36
+ ui.info(I18n.t('vagrant_zones.meeting'))
37
+ ui.info(I18n.t('vagrant_zones.datadir'))
38
+ ui.info(" #{datadir}")
39
+ ui.info(I18n.t('vagrant_zones.detecting_box'))
40
+
41
+ # If image ends on '.zss' it's a local ZFS snapshot which should be used
42
+ if image[-4, 4] == '.zss'
43
+ if File.exist?("#{curdir}/#{image}")
44
+ FileUtils.cp("#{curdir}/#{image}", "#{datadir}/#{image}")
45
+ ui.info(I18n.t('vagrant_zones.zfs_snapshot_stream_detected'))
46
+ elsif !File.exist?("#{datadir}/#{image}")
47
+ raise Vagrant::Errors::BoxNotFound
48
+ end
49
+ ## If image looks like an UUID, download the ZFS snapshot from Joyent images server
50
+ elsif validate_uuid_format(image)
51
+ raise Vagrant::Errors::BoxNotFound unless check(image, ui)
52
+
53
+ uri = URI("#{@joyent_images_url}#{image}/file")
54
+ Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
55
+ request = Net::HTTP::Get.new uri
56
+ http.request request do |response|
57
+ file_size = response['content-length'].to_i
58
+ amount_downloaded = 0
59
+ ratelimit = 0
60
+ rate = 500
61
+ large_file = "#{datadir}/#{image}"
62
+ File.open(large_file, 'wb') do |io|
63
+ response.read_body do |chunk|
64
+ io.write chunk
65
+ amount_downloaded += chunk.size
66
+ ui.rewriting do |uiprogress|
67
+ ratelimit += 1
68
+ if ratelimit >= rate
69
+ uiprogress.clear_line
70
+ status = format('%.2f%%', (amount_downloaded.to_f / file_size * 100))
71
+ uiprogress.info(I18n.t('vagrant_zones.importing_joyent_image') + "#{image} ==> ", new_line: false)
72
+ uiprogress.report_progress(status, 100, false)
73
+ ratelimit = 0
74
+ end
75
+ end
76
+ end
77
+ ui.clear_line
78
+ end
79
+ end
80
+ end
81
+ ui.info(I18n.t('vagrant_zones.joyent_image_uuid_detected') + image)
82
+
83
+ ## If it's a regular name (everything else), try to find it on Vagrant Cloud
84
+ else
85
+ # Support zss maybe zst? Same thing? format only for now, use other images and convert later
86
+ box_format = env[:machine].box.metadata['format'] unless env[:machine].box.nil?
87
+
88
+ if box_format == 'ovf'
89
+ ## Insert Future Code to try to convert existing box
90
+ ui.info(I18n.t('vagrant_zones.detected_ovf_format'))
91
+ end
92
+
93
+ ## No Local box template exists, Lets use Vagrant HandleBox to download the Box template
94
+ ui.info(I18n.t('vagrant_zones.vagrant_cloud_box_detected'))
95
+ ui.info(" #{image}")
96
+ ui.clear_line
97
+ end
98
+ @app.call(env)
99
+ end
100
+
101
+ def execute(*cmd, **opts, &block)
102
+ @executor.execute(*cmd, **opts, &block)
103
+ end
104
+
105
+ def check(uuid, env_ui)
106
+ execute(true, "curl --output /dev/null --silent -r 0-0 --fail #{@joyent_images_url}/#{uuid}")
107
+ env_ui.info(I18n.t('vagrant_zones.joyent_image_uuid_verified') + @joyent_images_url + uuid)
108
+ end
109
+ end
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'log4r'
4
+ module VagrantPlugins
5
+ module ProviderZone
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_zones::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,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'log4r'
4
+ require 'securerandom'
5
+ require 'digest/md5'
6
+
7
+ module VagrantPlugins
8
+ module ProviderZone
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_zones::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], 'create')
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 ProviderZone
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_zones.states.not_created'))
15
+ @app.call(env)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,134 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'log4r'
4
+ module VagrantPlugins
5
+ module ProviderZone
6
+ module Action
7
+ # This is used to package the VM into a box
8
+ class Package
9
+ def initialize(app, env)
10
+ @logger = Log4r::Logger.new('vagrant_zones::action::import')
11
+ @app = app
12
+ @executor = Executor::Exec.new
13
+ @pfexec = if Process.uid.zero?
14
+ ''
15
+ elsif system('sudo -v')
16
+ 'sudo'
17
+ else
18
+ 'pfexec'
19
+ end
20
+ env['package.output'] ||= 'package.box'
21
+ end
22
+
23
+ def execute(*cmd, **opts, &block)
24
+ @executor.execute(*cmd, **opts, &block)
25
+ end
26
+
27
+ def call(env)
28
+ @machine = env[:machine]
29
+ @driver = @machine.provider.driver
30
+ name = @machine.name
31
+ boxname = env['package.output']
32
+ brand = @machine.provider_config.brand
33
+ kernel = @machine.provider_config.kernel
34
+ vcc = @machine.provider_config.vagrant_cloud_creator
35
+ boxshortname = @machine.provider_config.boxshortname
36
+ raise "#{boxname}: Already exists" if File.exist?(boxname)
37
+
38
+ ## Create Snapshot
39
+ tmp_dir = "#{Dir.pwd}/_tmp_package"
40
+ Dir.mkdir(tmp_dir)
41
+ datasetpath = "#{@machine.provider_config.boot['array']}/#{@machine.provider_config.boot['dataset']}/#{name}"
42
+ t = Time.new
43
+ d = '-'
44
+ c = ':'
45
+ datetime = %(#{t.year}#{d}#{t.month}#{d}#{t.day}#{d}#{t.hour}#{c}#{t.min}#{c}#{t.sec})
46
+ snapshot_create(datasetpath, datetime, env[:ui], @machine.provider_config)
47
+ snapshot_send(datasetpath, "#{tmp_dir}/box.zss", datetime, env[:ui], @machine.provider_config)
48
+ ## snapshot_delete(datasetpath, env[:ui], datetime)
49
+
50
+ # Package VM
51
+ extra = ''
52
+
53
+ ## Include User Extra Files
54
+ @tmp_include = "#{tmp_dir}/_include"
55
+ if env['package.include']
56
+ extra = './_include'
57
+ Dir.mkdir(@tmp_include)
58
+ env['package.include'].each do |f|
59
+ env[:ui].info("Including user file: #{f}")
60
+ FileUtils.cp(f, @tmp_include)
61
+ end
62
+ end
63
+
64
+ ## Include Vagrant file
65
+ if env['package.vagrantfile']
66
+ extra = './_include'
67
+ Dir.mkdir(@tmp_include) unless File.directory?(@tmp_include)
68
+ env[:ui].info('Including user Vagrantfile')
69
+ FileUtils.cp(env['package.vagrantfile'], "#{@tmp_include}/Vagrantfile")
70
+ end
71
+
72
+ ## Create the Metadata and Vagrantfile
73
+ Dir.chdir(tmp_dir)
74
+ File.write('./metadata.json', metadata_content(brand, kernel, vcc, boxshortname))
75
+ File.write('./Vagrantfile', vagrantfile_content(brand, kernel, datasetpath))
76
+
77
+ ## Create the Box file
78
+ assemble_box(boxname, extra)
79
+ FileUtils.mv("#{tmp_dir}/#{boxname}", "../#{boxname}")
80
+ Dir.chdir('../')
81
+ FileUtils.rm_rf(tmp_dir)
82
+
83
+ env[:ui].info("Box created, You can now add the box: 'vagrant box add #{boxname} --nameofnewbox'")
84
+ @app.call(env)
85
+ end
86
+
87
+ def snapshot_create(datasetpath, datetime, uii, config)
88
+ uii.info('Creating a Snapshot of the box.')
89
+ result = execute(true, "#{@pfexec} zfs snapshot -r #{datasetpath}/boot@vagrant_box#{datetime}")
90
+ uii.info("#{@pfexec} zfs snapshot -r #{datasetpath}/boot@vagrant_box#{datetime}") if result.zero? && config.debug
91
+ end
92
+
93
+ def snapshot_delete(datasetpath, uii, datetime)
94
+ result = execute(true, "#{@pfexec} zfs destroy -r -f #{datasetpath}/boot@vagrant_box#{datetime}")
95
+ uii.info("#{@pfexec} zfs destroy -r -f #{datasetpath}/boot@vagrant_box#{datetime}") if result.zero? && config.debug
96
+ end
97
+
98
+ def snapshot_send(datasetpath, destination, datetime, uii, config)
99
+ uii.info('Sending Snapshot to ZFS Send Stream image.')
100
+ result = execute(true, "#{@pfexec} zfs send #{datasetpath}/boot@vagrant_box#{datetime} > #{destination}")
101
+ puts "#{@pfexec} zfs send -r #{datasetpath}/boot@vagrant_box#{datetime} > #{destination}" if result.zero? && config.debug
102
+ end
103
+
104
+ def metadata_content(brand, _kernel, vcc, boxshortname)
105
+ <<-ZONEBOX
106
+ {
107
+ "provider": "zone",
108
+ "format": "zss",
109
+ "brand": "#{brand}",
110
+ "url": "https://app.vagrantup.com/#{vcc}/boxes/#{boxshortname}"
111
+ }
112
+ ZONEBOX
113
+ end
114
+
115
+ def vagrantfile_content(brand, _kernel, datasetpath)
116
+ <<-ZONEBOX
117
+ Vagrant.configure('2') do |config|
118
+ config.vm.provider :zone do |zone|
119
+ zone.brand = "#{brand}"
120
+ zone.datasetpath = "#{datasetpath}"
121
+ end
122
+ end
123
+ user_vagrantfile = File.expand_path('../_include/Vagrantfile', __FILE__)
124
+ load user_vagrantfile if File.exists?(user_vagrantfile)
125
+ ZONEBOX
126
+ end
127
+
128
+ def assemble_box(boxname, extra)
129
+ `tar -cvzEf "#{boxname}" ./metadata.json ./Vagrantfile ./box.zss #{extra}`
130
+ end
131
+ end
132
+ end
133
+ end
134
+ 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 ProviderZone
9
+ module Action
10
+ # This is used to prepare NFS ids for NFS Sharing
11
+ class PrepareNFSValidIds
12
+ def initialize(app, _env)
13
+ @logger = Log4r::Logger.new('vagrant_zones::action::prepare_nfs_valid_ids')
14
+ @app = app
15
+ end
16
+
17
+ def call(env)
18
+ env[:nfs_valid_ids] = [env[:machine].id]
19
+ @app.call(env)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'log4r'
4
+ require 'vagrant-zones/util/timer'
5
+ require 'vagrant/util/retryable'
6
+
7
+ module VagrantPlugins
8
+ module ProviderZone
9
+ module Action
10
+ # This is used to restart the zone
11
+ class Restart
12
+ include Vagrant::Util::Retryable
13
+ def initialize(app, _env)
14
+ @logger = Log4r::Logger.new('vagrant_zones::action::restart')
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_zones.graceful_restart'))
23
+ @driver.control(ui, 'restart')
24
+
25
+ env[:metrics] ||= {}
26
+ env[:metrics]['instance_ssh_time'] = Util::Timer.time do
27
+ retryable(on: Errors::TimeoutError, tries: 300) do
28
+ # If we're interrupted don't worry about waiting
29
+ next if env[:interrupted]
30
+
31
+ loop do
32
+ break if env[:interrupted]
33
+ break unless env[:machine].communicate.ready?
34
+ end
35
+ end
36
+ end
37
+
38
+ ui.info(I18n.t('vagrant_zones.zone_gracefully_stopped_waiting_for_boot'))
39
+ env[:metrics] ||= {}
40
+ env[:metrics]['instance_ssh_time'] = Util::Timer.time do
41
+ retryable(on: Errors::TimeoutError, tries: 300) do
42
+ # If we're interrupted don't worry about waiting
43
+ next if env[:interrupted]
44
+ break if env[:machine].communicate.ready?
45
+ end
46
+ end
47
+ ui.info(I18n.t('vagrant_zones.zone_gracefully_restarted'))
48
+ @app.call(env)
49
+ end
50
+ end
51
+ end
52
+ end
53
+ 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 ProviderZone
9
+ module Action
10
+ # This is used to setup the zone
11
+ class Setup
12
+ def initialize(app, _env)
13
+ @logger = Log4r::Logger.new('vagrant_zones::action::import')
14
+ @app = app
15
+ end
16
+
17
+ def call(env)
18
+ @machine = env[:machine]
19
+ @driver = @machine.provider.driver
20
+ @driver.setup(env[:ui])
21
+ @app.call(env)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'log4r'
4
+ require 'vagrant-zones/util/timer'
5
+ require 'vagrant/util/retryable'
6
+
7
+ module VagrantPlugins
8
+ module ProviderZone
9
+ module Action
10
+ # This is used to shutdown the zone
11
+ class Shutdown
12
+ include Vagrant::Util::Retryable
13
+ def initialize(app, _env)
14
+ @logger = Log4r::Logger.new('vagrant_zones::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_zones.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_zones.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