-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.vagrantplugins
122 lines (93 loc) · 3.06 KB
/
.vagrantplugins
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# Xenith - Xen-based security hypervisor
# Copyright (C) 2025 Xenith contributors
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# This hack is not officially supported, see https://github.com/hashicorp/vagrant/issues/3775
# and https://stackoverflow.com/a/39693343
DEFAULT_XENITH_DOMAIN = "xenith_xenith"
DEFAULT_NAME = "xenith"
class XenithCustomCommands < Vagrant.plugin(2)
name "Xenith custom Vagrant commands"
command "virt-view" do
VirtView
end
end
class VirtView < Vagrant.plugin(2, :command)
def self.synopsis
"Automatically opens virt-viewer on Xenith VMs"
end
def ensure_vm_running
with_target_vms do |machine|
# Skip machines that aren't the default
unless machine.name != DEFAULT_NAME
next
end
# Ensure the machine is running
if machine.state.id != :running
@env.ui.error "Error: The VM #{DEFAULT_NAME} is not running."
exit 1
end
return
end
# If we get here, the machine doesn't exist
@env.ui.error "Error: The VM #{DEFAULT_NAME} does not exist."
exit 1
end
def execute
ensure_vm_running()
# Parse the options
options = {}
options[:dom0] = false
options[:domU] = false
opts = OptionParser.new do |o|
o.banner = "Usage: vagrant virt-view [--dom0 | --domU]"
o.separator ""
o.on("-0", "--dom0", "Open virt-viewer for the dom0") do
options[:dom0] = true
end
o.on("-U", "--domU", "Open virt-viewer for the domU") do
options[:domU] = true
end
end
argv = parse_options(opts)
# Ensure mutual exclusivity
if options[:dom0] && options[:domU]
@env.ui.error "Error: --dom0 and --domU cannot be used together (yet)."
return 1
end
# Dispatch to the appropriate handler
if options[:dom0]
handle_dom0
elsif options[:domU]
handle_domU
else
@env.ui.error "Error: You must specify either --dom0 or --domU."
return 1
end
0
end
private
def handle_dom0
@env.ui.info "Opening virt-viewer for dom0..."
child = fork do
cmd = system( "virt-manager --connect qemu:///system --show-domain-console #{DEFAULT_XENITH_DOMAIN}" )
exitstatus = $?.exitstatus
if exitstatus != 0
@env.ui.error "Error: Failed to open virt-viewer for dom0. Exit status: #{exitstatus}"
end
exit
end
end
def handle_domU
# @env.ui.info "Opening virt-viewer for domU..."
@env.ui.error "Error: --domU is not yet supported."
end
end