-
Notifications
You must be signed in to change notification settings - Fork 0
/
rrcconf.subr
156 lines (137 loc) · 4.21 KB
/
rrcconf.subr
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#v11.2.1
# this is a temporary wrapper for version 9.2.2 is intended to make the transition to sqlite3 version if rc.conf more painless
# serve remote data only
# required:
# strings.subr
#
if [ ! "$_CBSD_RRCCONF_SUBR" ]; then
_CBSD_RRCCONF_SUBR=1
###
# load data from local bhyve settings
# $1 - jname
init_bhyve_rrcconf()
{
local jname="${1}"
local _sqlite="${2}"
if [ -z "${jname}" ]; then
echo "init_bhyve_rrconf: no jname"
return 0
fi
if [ ! -r "${_sqlite}" ]; then
echo "init_bhyve_rrconf: no sqlite ${_sqlite}"
return 0
fi
local sqldelimer="|"
local A
A=$( cbsdsqlro ${_sqlite} "SELECT astart,vm_cpus,vm_ram,vm_os_type,vm_boot,vm_os_profile,vm_vnc_port,virtio_type,bhyve_vnc_tcp_bind,bhyve_vnc_resolution,cd_vnc_wait,protected,hidden,maintenance,ip4_addr,vnc_password,vm_hostbridge,vm_iso_path,vm_console,vm_efi,bhyve_generate_acpi,bhyve_wire_memory,bhyve_rts_keeps_utc,bhyve_force_msi_irq,bhyve_x2apic_mode,bhyve_mptable_gen,bhyve_ignore_msr_acc,bhyve_vnc_vgaconf,vm_cpu_topology,debug_engine FROM settings ORDER BY (created) DESC LIMIT 1;" 2>/dev/null )
if [ -n "${A}" ]; then
OIFS="${IFS}"
IFS="|"
astart=
vm_cpus=
vm_ram=
vm_os_type=
vm_boot=
vm_os_profile=
vm_vnc_port=
virtio_type=
bhyve_vnc_tcp_bind=
bhyve_vnc_resolution=
cd_vnc_wait=
protected=
hidden=
maintenance=
ip4_addr=
vnc_password=
vm_hostbridge=
vm_iso_path=
vm_console=
vm_efi=
bhyve_generate_acpi=
bhyve_wire_memory=
bhyve_rts_keeps_utc=
bhyve_force_msi_irq=
bhyve_x2apic_mode=
bhyve_mptable_gen=
bhyve_ignore_msr_acc=
bhyve_vnc_vgaconf=
vm_cpu_topology=
debug_engine=
sqllist "${A}" astart vm_cpus vm_ram vm_os_type vm_boot vm_os_profile vm_vnc_port virtio_type bhyve_vnc_tcp_bind bhyve_vnc_resolution cd_vnc_wait protected hidden maintenance ip4_addr vnc_password vm_hostbridge vm_iso_path vm_console vm_efi bhyve_generate_acpi bhyve_wire_memory bhyve_rts_keeps_utc bhyve_force_msi_irq bhyve_x2apic_mode bhyve_mptable_gen bhyve_ignore_msr_acc bhyve_vnc_vgaconf vm_cpu_topology debug_engine
IFS="${OIFS}"
else
err 1 "${N1_COLOR}Unable to fetch vm data from: ${N2_COLOR}${jailsysdir}/${jname}/local.sqlite${N0_COLOR}"
fi
jid=$( cbsdsqlro ${dbdir}/${RHST}.sqlite SELECT jid FROM jails WHERE jname=\"${jname}\" )
if [ "${jid}" = "0" ]; then
status="0"
else
status="1"
fi
}
# load data from local XEN settings
# $jname
init_xen_rrcconf()
{
local jname="${1}"
[ -z "${jname}" ] && return 0
local sqldelimer="|"
local A
A=$( cbsdsqlro ${jailsysdir}/${jname}/local.sqlite "SELECT vm_cpus,vm_ram,vm_os_type,vm_boot,vm_os_profile,vm_vnc_port,xen_vnc_tcp_bind,xen_vnc_resolution,cd_vnc_wait,protected,hidden,maintenance,ip4_addr,vnc_password,spice_default,xen_spice_tcp_bind,xen_spice_resolution,spice_password,soundhw FROM settings ORDER BY (created) DESC LIMIT 1;" )
if [ -n "${A}" ]; then
OIFS="${IFS}"
IFS="|"
vm_cpus=
vm_ram=
vm_os_type=
vm_boot=
vm_os_profile=
vm_vnc_port=
xen_vnc_tcp_bind=
xen_vnc_resolution=
cd_vnc_wait=
protected=
hidden=
maintenance=
ip4_addr=
vnc_password=
spice_default=
xen_spice_tcp_bind=
xen_spice_resolution=
spice_password=
soundhw=
sqllist "${A}" vm_cpus vm_ram vm_os_type vm_boot vm_os_profile vm_vnc_port xen_vnc_tcp_bind xen_vnc_resolution cd_vnc_wait protected hidden maintenance ip4_addr vnc_password spice_default xen_spice_tcp_bind xen_spice_resolution spice_password soundhw
IFS="${OIFS}"
else
err 1 "${N1_COLOR}Unable to fetch vm data from: ${N2_COLOR}${jailsysdir}/${jname}/local.sqlite${N0_COLOR}"
fi
}
init_rrcconf()
{
local emulator="bhyve" # only bhyve was tested
local _sqlfile
local RHST
RHST=$( bwhereis ${jname} | ${HEAD_CMD} -n1 )
if [ -z "${RHST}" ]; then
echo "rrcconf: no remote host"
return 1
fi
_sqlfile="${tmpdir}/${RHST}/${jname}/local.sqlite"
if [ ! -r "${_sqlfile}" ]; then
#echo "init_rrconf: no sqlite ${_sqlfile}"
return 0
fi
case "${emulator}" in
bhyve|xen)
init_${emulator}_rrcconf ${jname} ${_sqlfile}
esac
init_jail_path
}
###
fi
# $RHST variable should be pointed to $nodename
# todo: check for $emulator here?
# export ${remote_local_sqlite}
remote_local_sqlite="${tmpdir}/${RHST}/${jname}/local.sqlite"
_sqlfile="${remote_local_sqlite}/local.sqlite"
init_rrcconf ${jname}