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.
- 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.yml +70 -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 +0 -0
- data/CODE_OF_CONDUCT.md +128 -0
- data/CONTRIBUTING.md +96 -0
- data/Gemfile +14 -0
- data/LICENSE +651 -0
- data/PULL_REQUEST_TEMPLATE.md +39 -0
- data/README.md +81 -0
- data/RELEASE.md +15 -0
- data/Rakefile +32 -0
- data/SECURITY.md +19 -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 +127 -0
- data/lib/vagrant-zones/action/create.rb +29 -0
- data/lib/vagrant-zones/action/destroy.rb +27 -0
- data/lib/vagrant-zones/action/halt.rb +24 -0
- data/lib/vagrant-zones/action/import.rb +112 -0
- data/lib/vagrant-zones/action/is_created.rb +22 -0
- data/lib/vagrant-zones/action/network.rb +26 -0
- data/lib/vagrant-zones/action/not_created.rb +20 -0
- data/lib/vagrant-zones/action/package.rb +134 -0
- data/lib/vagrant-zones/action/prepare_nfs_valid_ids.rb +24 -0
- data/lib/vagrant-zones/action/restart.rb +53 -0
- data/lib/vagrant-zones/action/setup.rb +26 -0
- data/lib/vagrant-zones/action/shutdown.rb +47 -0
- data/lib/vagrant-zones/action/start.rb +25 -0
- data/lib/vagrant-zones/action/wait_till_boot.rb +59 -0
- data/lib/vagrant-zones/action/wait_till_up.rb +65 -0
- data/lib/vagrant-zones/action.rb +204 -0
- data/lib/vagrant-zones/command/configure_snapshots.rb +49 -0
- data/lib/vagrant-zones/command/console.rb +63 -0
- data/lib/vagrant-zones/command/create_snapshots.rb +46 -0
- data/lib/vagrant-zones/command/delete_snapshots.rb +38 -0
- data/lib/vagrant-zones/command/guest_power_controls.rb +58 -0
- data/lib/vagrant-zones/command/list_snapshots.rb +44 -0
- data/lib/vagrant-zones/command/restart_guest.rb +29 -0
- data/lib/vagrant-zones/command/shutdown_guest.rb +29 -0
- data/lib/vagrant-zones/command/vnc_console.rb +48 -0
- data/lib/vagrant-zones/command/webvnc_console.rb +49 -0
- data/lib/vagrant-zones/command/zfssnapshot.rb +67 -0
- data/lib/vagrant-zones/command/zlogin_console.rb +40 -0
- data/lib/vagrant-zones/command/zone.rb +73 -0
- data/lib/vagrant-zones/config.rb +78 -0
- data/lib/vagrant-zones/driver.rb +1710 -0
- data/lib/vagrant-zones/errors.rb +61 -0
- data/lib/vagrant-zones/executor.rb +38 -0
- data/lib/vagrant-zones/plugin.rb +79 -0
- data/lib/vagrant-zones/provider.rb +83 -0
- data/lib/vagrant-zones/util/subprocess.rb +31 -0
- data/lib/vagrant-zones/util/timer.rb +19 -0
- data/lib/vagrant-zones/version.rb +7 -0
- data/lib/vagrant-zones.rb +29 -0
- data/locales/en.yml +326 -0
- data/vagrant-zones.gemspec +51 -0
- metadata +412 -0
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'log4r'
|
4
|
+
|
5
|
+
module VagrantPlugins
|
6
|
+
module ProviderZone
|
7
|
+
module Action
|
8
|
+
# This is used to start the zone
|
9
|
+
class Start
|
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.check_zone_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,59 @@
|
|
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 wait till the zone is booted
|
11
|
+
class WaitTillBoot
|
12
|
+
include Vagrant::Util::Retryable
|
13
|
+
|
14
|
+
def initialize(app, _env)
|
15
|
+
@logger = Log4r::Logger.new('vagrant_zones::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
|
+
ui = env[:ui]
|
43
|
+
# Initialize metrics if they haven't been
|
44
|
+
env[:metrics] ||= {}
|
45
|
+
env[:metrics]['instance_boot_time'] = Util::Timer.time do
|
46
|
+
next if env[:interrupted]
|
47
|
+
|
48
|
+
breakwait = @driver.waitforboot(ui, env[:metrics], env[:interrupted])
|
49
|
+
ui.info(I18n.t('vagrant_zones.boot_ready') + " in #{env[:metrics]['instance_boot_time']} Seconds") if breakwait
|
50
|
+
break if breakwait
|
51
|
+
end
|
52
|
+
return terminate(env) if env[:interrupted]
|
53
|
+
|
54
|
+
@app.call(env)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,65 @@
|
|
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 wait till the zone is booted
|
11
|
+
class WaitTillUp
|
12
|
+
include Vagrant::Util::Retryable
|
13
|
+
|
14
|
+
def initialize(app, _env)
|
15
|
+
@logger = Log4r::Logger.new('vagrant_zones::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
|
+
ui = env[:ui]
|
43
|
+
# Initialize metrics if they haven't been
|
44
|
+
env[:metrics] ||= {}
|
45
|
+
env[:metrics]['instance_ssh_time'] = Util::Timer.time do
|
46
|
+
retryable(on: Errors::TimeoutError, tries: 60) do
|
47
|
+
# If we're interrupted don't worry about waiting
|
48
|
+
next if env[:interrupted]
|
49
|
+
|
50
|
+
loop do
|
51
|
+
break if env[:interrupted]
|
52
|
+
break if env[:machine].communicate.ready?
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
# if interrupted above, just terminate immediately
|
57
|
+
return terminate(env) if env[:interrupted]
|
58
|
+
|
59
|
+
ui.info(I18n.t('vagrant_zones.ssh_ready') + " in #{env[:metrics]['instance_ssh_time']} Seconds")
|
60
|
+
@app.call(env)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,204 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'vagrant/action/builder'
|
4
|
+
require 'log4r'
|
5
|
+
|
6
|
+
module VagrantPlugins
|
7
|
+
module ProviderZone
|
8
|
+
# Run actions against the machine
|
9
|
+
module Action
|
10
|
+
include Vagrant::Action::Builtin
|
11
|
+
@logger = Log4r::Logger.new('vagrant_zones::action')
|
12
|
+
|
13
|
+
# This action is called to bring the box up from nothing.
|
14
|
+
def self.action_up
|
15
|
+
Vagrant::Action::Builder.new.tap do |b|
|
16
|
+
b.use Call, IsCreated do |env, b2|
|
17
|
+
if env[:result]
|
18
|
+
env[:halt_on_error] = true
|
19
|
+
b2.use action_start
|
20
|
+
elsif !env[:result]
|
21
|
+
b2.use Import
|
22
|
+
b2.use HandleBox
|
23
|
+
b2.use BoxCheckOutdated
|
24
|
+
b2.use Create
|
25
|
+
b2.use Network
|
26
|
+
b2.use Start
|
27
|
+
b2.use WaitTillBoot
|
28
|
+
b2.use Setup
|
29
|
+
b2.use WaitTillUp
|
30
|
+
b2.use Provision
|
31
|
+
b2.use SetHostname
|
32
|
+
b2.use SyncedFolders
|
33
|
+
b2.use SyncedFolderCleanup
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Assuming VM is created, just start it. This action is not called directly by any subcommand.
|
40
|
+
def self.action_start
|
41
|
+
Vagrant::Action::Builder.new.tap do |b|
|
42
|
+
b.use Call, IsState, :running do |env, b1|
|
43
|
+
if env[:result]
|
44
|
+
b1.use Message, I18n.t('vagrant_zones.states.is_running')
|
45
|
+
next
|
46
|
+
end
|
47
|
+
b1.use Call, IsState, :uncleaned do |env2, b2|
|
48
|
+
b2.use Cleanup if env2[:result]
|
49
|
+
end
|
50
|
+
b1.use Start
|
51
|
+
b1.use WaitTillUp
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.action_restart
|
57
|
+
Vagrant::Action::Builder.new.tap do |b|
|
58
|
+
b.use Call, IsCreated do |_env, b2|
|
59
|
+
b2.use Call, IsState, :stopped do |env2, b3|
|
60
|
+
unless env2[:result]
|
61
|
+
b3.use WaitTillUp
|
62
|
+
b3.use Restart
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.action_shutdown
|
70
|
+
Vagrant::Action::Builder.new.tap do |b|
|
71
|
+
b.use Call, IsCreated do |_env, b2|
|
72
|
+
b2.use Call, IsState, :stopped do |env2, b3|
|
73
|
+
unless env2[:result]
|
74
|
+
b3.use WaitTillUp
|
75
|
+
b3.use Shutdown
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# This is the action that is primarily responsible for halting the virtual machine.
|
83
|
+
def self.action_halt
|
84
|
+
Vagrant::Action::Builder.new.tap do |b|
|
85
|
+
b.use Call, IsCreated do |env, b2|
|
86
|
+
unless env[:result]
|
87
|
+
b2.use NotCreated
|
88
|
+
next
|
89
|
+
end
|
90
|
+
b2.use Halt if env[:result]
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
# This action is called to SSH into the machine.
|
96
|
+
def self.action_ssh
|
97
|
+
Vagrant::Action::Builder.new.tap do |b|
|
98
|
+
b.use SSHExec
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def self.action_ssh_run
|
103
|
+
Vagrant::Action::Builder.new.tap do |b|
|
104
|
+
b.use SSHRun
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
# This action is called when you try to package an existing virtual machine to an box image.
|
109
|
+
def self.action_package
|
110
|
+
Vagrant::Action::Builder.new.tap do |b|
|
111
|
+
b.use Package
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
# This is the action that is primarily responsible for completely freeing the resources of the underlying virtual machine.
|
116
|
+
def self.action_destroy
|
117
|
+
Vagrant::Action::Builder.new.tap do |b|
|
118
|
+
b.use Call, IsCreated do |_env, b2|
|
119
|
+
b2.use Destroy
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
# This action is called when `vagrant provision` is called.
|
125
|
+
def self.action_provision
|
126
|
+
Vagrant::Action::Builder.new.tap do |b|
|
127
|
+
b.use Call, IsCreated do |_env, b2|
|
128
|
+
b2.use Call, IsState, :running do |_env2, b3|
|
129
|
+
b3.use Provision
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
# This is the action implements the reload command It uses the halt and start actions
|
136
|
+
def self.action_reload
|
137
|
+
Vagrant::Action::Builder.new.tap do |b|
|
138
|
+
b.use Call, IsCreated do |env, b2|
|
139
|
+
unless env[:result]
|
140
|
+
b2.use NotCreated
|
141
|
+
next
|
142
|
+
end
|
143
|
+
b2.use action_halt
|
144
|
+
b2.use action_start
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
def self.action_create_zfs_snapshots
|
150
|
+
Vagrant::Action::Builder.new.tap do |b|
|
151
|
+
# b.use ConfigValidate # is this per machine?
|
152
|
+
b.use CreateSnapshots
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
def self.action_delete_zfs_snapshots
|
157
|
+
Vagrant::Action::Builder.new.tap do |b|
|
158
|
+
b.use DeleteSnapshots
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
def self.action_configure_zfs_snapshots
|
163
|
+
Vagrant::Action::Builder.new.tap do |b|
|
164
|
+
b.use ConfigureSnapshots
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
def self.action_box_outdated
|
169
|
+
Builder.new.tap do |b|
|
170
|
+
b.use Builtin::BoxCheckOutdated
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
# This is the action that will remove a box given a name (and optionally
|
175
|
+
# a provider). This middleware sequence is built-in to Vagrant. Plugins
|
176
|
+
# can hook into this like any other middleware sequence.
|
177
|
+
def self.action_box_remove
|
178
|
+
Builder.new.tap do |b|
|
179
|
+
b.use Builtin::BoxRemove
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
action_root = Pathname.new(File.expand_path('action', __dir__))
|
184
|
+
autoload :Import, action_root.join('import')
|
185
|
+
autoload :Create, action_root.join('create')
|
186
|
+
autoload :Network, action_root.join('network')
|
187
|
+
autoload :Setup, action_root.join('setup')
|
188
|
+
autoload :Start, action_root.join('start')
|
189
|
+
autoload :IsCreated, action_root.join('is_created')
|
190
|
+
autoload :NotCreated, action_root.join('not_created')
|
191
|
+
autoload :CreateSnapshots, action_root.join('create_zfs_snapshots')
|
192
|
+
autoload :DeleteSnapshots, action_root.join('delete_zfs_snapshots')
|
193
|
+
autoload :ConfigureSnapshots, action_root.join('configure_zfs_snapshots')
|
194
|
+
autoload :Halt, action_root.join('halt')
|
195
|
+
autoload :Destroy, action_root.join('destroy')
|
196
|
+
autoload :WaitTillBoot, action_root.join('wait_till_boot')
|
197
|
+
autoload :WaitTillUp, action_root.join('wait_till_up')
|
198
|
+
autoload :Restart, action_root.join('restart')
|
199
|
+
autoload :Shutdown, action_root.join('shutdown')
|
200
|
+
autoload :PrepareNFSValidIds, action_root.join('prepare_nfs_valid_ids.rb')
|
201
|
+
autoload :Package, action_root.join('package.rb')
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module ProviderZone
|
5
|
+
module Command
|
6
|
+
# This is used to configure snapshots for the zone
|
7
|
+
class ConfigureSnapshots < Vagrant.plugin('2', :command)
|
8
|
+
def execute
|
9
|
+
options = {}
|
10
|
+
opts = OptionParser.new do |o|
|
11
|
+
o.banner = 'Usage: vagrant zone zfssnapshot list [options]'
|
12
|
+
o.on('--dataset DATASETPATH/ALL', 'Specify path to enable snapshots on, defaults to ALL') do |p|
|
13
|
+
options[:dataset] = p
|
14
|
+
end
|
15
|
+
frequencymsg = 'Set a policy with one of the available optional frequencies'
|
16
|
+
o.on('--set_frequency <hourly/daily/weekly/monthly/all>', frequencymsg) do |p|
|
17
|
+
options[:set_frequency] = p
|
18
|
+
end
|
19
|
+
frequency_rtnmsg = 'Number of snapshots to take for the frequency policy'
|
20
|
+
o.on('--set_frequency_rtn <#>/defaults ', frequency_rtnmsg) do |p|
|
21
|
+
options[:set_frequency_rtn] = p
|
22
|
+
end
|
23
|
+
deletemsg = 'Delete frequency policy'
|
24
|
+
o.on('--delete <hourly/daily/weekly/monthly/all>', deletemsg) do |p|
|
25
|
+
options[:delete] = p
|
26
|
+
end
|
27
|
+
listmsg = 'Show Cron Policies'
|
28
|
+
o.on('--list <hourly/daily/weekly/monthly/all>', listmsg) do |p|
|
29
|
+
options[:list] = p
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
argv = parse_options(opts)
|
34
|
+
return unless argv
|
35
|
+
|
36
|
+
unless argv.length <= 4
|
37
|
+
@env.ui.info(opts.help)
|
38
|
+
return
|
39
|
+
end
|
40
|
+
|
41
|
+
with_target_vms(argv, provider: :zone) do |machine|
|
42
|
+
driver = machine.provider.driver
|
43
|
+
driver.zfs(@env.ui, 'cron', options)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module ProviderZone
|
5
|
+
module Command
|
6
|
+
# This is used to start a console to the zone via WebVNC, VNC or Serial/Telnet
|
7
|
+
class Console < Vagrant.plugin('2', :command)
|
8
|
+
def initialize(argv, env)
|
9
|
+
@main_args, @sub_command, @sub_args = split_main_and_subcommand(argv)
|
10
|
+
|
11
|
+
@subcommands = Vagrant::Registry.new
|
12
|
+
@subcommands.register(:vnc) do
|
13
|
+
require File.expand_path('vnc_console', __dir__)
|
14
|
+
VNCConsole
|
15
|
+
end
|
16
|
+
@subcommands.register(:zlogin) do
|
17
|
+
require File.expand_path('zlogin_console', __dir__)
|
18
|
+
ZloginConsole
|
19
|
+
end
|
20
|
+
@subcommands.register(:webvnc) do
|
21
|
+
require File.expand_path('webvnc_console', __dir__)
|
22
|
+
WebVNCConsole
|
23
|
+
end
|
24
|
+
super(argv, env)
|
25
|
+
end
|
26
|
+
|
27
|
+
def execute
|
28
|
+
if @main_args.include?('-h') || @main_args.include?('--help')
|
29
|
+
# Print the help for all the vagrant-zones commands.
|
30
|
+
return help
|
31
|
+
end
|
32
|
+
|
33
|
+
with_target_vms(@main_args, provider: :zone) do |machine|
|
34
|
+
@sub_command = machine.provider_config.console.to_sym unless machine.provider_config.console.nil? || @sub_command
|
35
|
+
command_class = @subcommands.get(@sub_command.to_sym) if @sub_command
|
36
|
+
@logger.debug("Invoking command class: #{command_class} #{machine.provider_config.console.to_sym}")
|
37
|
+
return help if !command_class || !@sub_command
|
38
|
+
|
39
|
+
# Initialize and execute the command class
|
40
|
+
command_class.new(@sub_args, @env).execute
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def help
|
45
|
+
opts = OptionParser.new do |subopts|
|
46
|
+
subopts.banner = 'Usage: vagrant zone console <subcommand> [<args>]'
|
47
|
+
subopts.separator ''
|
48
|
+
subopts.separator 'Available subcommands:'
|
49
|
+
# Add the available subcommands as separators in order to print them
|
50
|
+
# out as well.
|
51
|
+
keys = []
|
52
|
+
@subcommands.each { |key, _value| keys << key.to_s }
|
53
|
+
keys.sort.each do |key|
|
54
|
+
subopts.separator " #{key}"
|
55
|
+
end
|
56
|
+
subopts.separator 'For help on any individual subcommand run `vagrant zone console <subcommand> -h`'
|
57
|
+
end
|
58
|
+
@env.ui.info(opts.help, :prefix => false)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module ProviderZone
|
5
|
+
module Command
|
6
|
+
# This is used to create zfs snapshots the zone
|
7
|
+
class CreateSnapshots < Vagrant.plugin('2', :command)
|
8
|
+
def execute
|
9
|
+
options = {}
|
10
|
+
opts = OptionParser.new do |o|
|
11
|
+
o.banner = 'Usage: vagrant zone zfssnapshot list [options]'
|
12
|
+
o.on('--dataset SNAPSHOTPATH', 'Specify snapshot path') do |p|
|
13
|
+
options[:dataset] = p
|
14
|
+
end
|
15
|
+
o.on('--snapshot_name @SNAPSHOTNAME', 'Specify snapshot name') do |p|
|
16
|
+
options[:snapshot_name] = p
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
argv = parse_options(opts)
|
21
|
+
return unless argv
|
22
|
+
|
23
|
+
unless argv.length <= 4
|
24
|
+
@env.ui.info(opts.help)
|
25
|
+
return
|
26
|
+
end
|
27
|
+
|
28
|
+
options[:dataset] = 'all' if options[:dataset].nil?
|
29
|
+
|
30
|
+
if options[:snapshot_name].nil?
|
31
|
+
t = Time.new
|
32
|
+
dash = '-'
|
33
|
+
colon = ':'
|
34
|
+
datetime = t.year.to_s + dash + t.month.to_s + dash + t.day.to_s + dash + t.hour.to_s + colon + t.min.to_s + colon + t.sec.to_s
|
35
|
+
options[:snapshot_name] = datetime
|
36
|
+
end
|
37
|
+
|
38
|
+
with_target_vms(argv, provider: :zone) do |machine|
|
39
|
+
driver = machine.provider.driver
|
40
|
+
driver.zfs(@env.ui, 'create', options)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module ProviderZone
|
5
|
+
module Command
|
6
|
+
# This is used to delete zfs snapshots the zone
|
7
|
+
class DeleteSnapshots < Vagrant.plugin('2', :command)
|
8
|
+
def execute
|
9
|
+
options = {}
|
10
|
+
opts = OptionParser.new do |o|
|
11
|
+
o.banner = 'Usage: vagrant zone zfssnapshot list [options]'
|
12
|
+
o.on('--dataset DATASETPATH', 'Specify snapshot path') do |p|
|
13
|
+
options[:dataset] = p
|
14
|
+
end
|
15
|
+
o.on('--snapshot_name @SNAPSHOTNAME', 'Specify snapshot name') do |p|
|
16
|
+
options[:snapshot_name] = p
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
argv = parse_options(opts)
|
21
|
+
return unless argv
|
22
|
+
|
23
|
+
unless argv.length <= 4
|
24
|
+
@env.ui.info(opts.help)
|
25
|
+
return
|
26
|
+
end
|
27
|
+
|
28
|
+
options[:dataset] = 'all' if options[:dataset].nil?
|
29
|
+
options[:snapshot_name] = 'all' if options[:snapshot_name].nil?
|
30
|
+
with_target_vms(argv, provider: :zone) do |machine|
|
31
|
+
driver = machine.provider.driver
|
32
|
+
driver.zfs(@env.ui, 'destroy', options)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module ProviderZone
|
5
|
+
module Command
|
6
|
+
# This is used to manage the power controls for the zone
|
7
|
+
class GuestPowerControls < Vagrant.plugin('2', :command)
|
8
|
+
def initialize(argv, env)
|
9
|
+
@main_args, @sub_command, @sub_args = split_main_and_subcommand(argv)
|
10
|
+
|
11
|
+
@subcommands = Vagrant::Registry.new
|
12
|
+
@subcommands.register(:restart) do
|
13
|
+
require File.expand_path('restart_guest', __dir__)
|
14
|
+
RestartGuest
|
15
|
+
end
|
16
|
+
@subcommands.register(:shutdown) do
|
17
|
+
require File.expand_path('shutdown_guest', __dir__)
|
18
|
+
ShutdownGuest
|
19
|
+
end
|
20
|
+
super(argv, env)
|
21
|
+
end
|
22
|
+
|
23
|
+
def execute
|
24
|
+
if @main_args.include?('-h') || @main_args.include?('--help')
|
25
|
+
# Print the help for all the vagrant-zones commands.
|
26
|
+
return help
|
27
|
+
end
|
28
|
+
|
29
|
+
command_class = @subcommands.get(@sub_command.to_sym) if @sub_command
|
30
|
+
return help if !command_class || !@sub_command
|
31
|
+
|
32
|
+
@logger.debug("Invoking command class: #{command_class} #{@sub_args.inspect}")
|
33
|
+
|
34
|
+
# Initialize and execute the command class
|
35
|
+
command_class.new(@sub_args, @env).execute
|
36
|
+
end
|
37
|
+
|
38
|
+
def help
|
39
|
+
opts = OptionParser.new do |subopts|
|
40
|
+
subopts.banner = 'Usage: vagrant zone control <subcommand> [<args>]'
|
41
|
+
subopts.separator ''
|
42
|
+
subopts.separator 'Available subcommands:'
|
43
|
+
# Add the available subcommands as separators in order to print them
|
44
|
+
# out as well.
|
45
|
+
keys = []
|
46
|
+
@subcommands.each { |key, _value| keys << key.to_s }
|
47
|
+
keys.sort.each do |key|
|
48
|
+
subopts.separator " #{key}"
|
49
|
+
end
|
50
|
+
subopts.separator ''
|
51
|
+
subopts.separator 'For help on any individual subcommand run `vagrant zone control <subcommand> -h`'
|
52
|
+
end
|
53
|
+
@env.ui.info(opts.help, :prefix => false)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module ProviderZone
|
5
|
+
module Command
|
6
|
+
# This is used to list snapshots for the zone
|
7
|
+
class ListSnapshots < Vagrant.plugin('2', :command)
|
8
|
+
def execute
|
9
|
+
options = {}
|
10
|
+
opts = OptionParser.new do |o|
|
11
|
+
o.banner = 'Usage: vagrant zone zfssnapshot list [options]'
|
12
|
+
o.on('--dataset SNAPSHOTPATH', 'Specify snapshot path') do |p|
|
13
|
+
options[:dataset] = p
|
14
|
+
end
|
15
|
+
o.on('--snapshot_name @SNAPSHOTNAME', 'Specify snapshot name') do |p|
|
16
|
+
options[:snapshot_name] = p
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
argv = parse_options(opts)
|
21
|
+
return unless argv
|
22
|
+
|
23
|
+
unless argv.length <= 2
|
24
|
+
@env.ui.info(opts.help)
|
25
|
+
return
|
26
|
+
end
|
27
|
+
|
28
|
+
if options[:snapshot_name].nil?
|
29
|
+
t = Time.new
|
30
|
+
dash = '-'
|
31
|
+
colon = ':'
|
32
|
+
datetime = t.year.to_s + dash + t.month.to_s + dash + t.day.to_s + dash + t.hour.to_s + colon + t.min.to_s + colon + t.sec.to_s
|
33
|
+
options[:snapshot_name] = datetime
|
34
|
+
end
|
35
|
+
|
36
|
+
with_target_vms(argv, provider: :zone) do |machine|
|
37
|
+
driver = machine.provider.driver
|
38
|
+
driver.zfs(@env.ui, 'list', options)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module ProviderZone
|
5
|
+
module Command
|
6
|
+
# This is used to restart the guest from inside the guest
|
7
|
+
class RestartGuest < Vagrant.plugin('2', :command)
|
8
|
+
def execute
|
9
|
+
opts = OptionParser.new do |o|
|
10
|
+
o.banner = 'Usage: vagrant zone control restart [options]'
|
11
|
+
end
|
12
|
+
|
13
|
+
argv = parse_options(opts)
|
14
|
+
return unless argv
|
15
|
+
|
16
|
+
unless argv.empty?
|
17
|
+
@env.ui.info(opts.help)
|
18
|
+
return
|
19
|
+
end
|
20
|
+
|
21
|
+
## Wait for VM up
|
22
|
+
with_target_vms(argv, provider: :zone) do |machine|
|
23
|
+
machine.action('restart')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|