Skip to content

Commit e131dd8

Browse files
author
olevole
committed
use emulator= as filter instead of src=jail
1 parent 70633b2 commit e131dd8

File tree

1 file changed

+46
-30
lines changed

1 file changed

+46
-30
lines changed

tools/get-profiles

Lines changed: 46 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
# shellcheck shell=sh disable=2034,2154,1091
33
#v13.0.8
44
MYARG="src"
5-
MYOPTARG="cache_sum clonos imgsize_max json myb show_iso vm_os_type vm_cpus_max vm_ram_max warmed"
5+
MYOPTARG="cache_sum clonos emulator imgsize_max json myb show_iso vm_os_type vm_cpus_max vm_ram_max warmed"
66
MYDESC="list of available profiles for virtual machine"
7-
CBSDMODULE="bhyve,xen"
7+
CBSDMODULE="bhyve,jail,xen"
88
ADDHELP="
99
${H3_COLOR}Description${N0_COLOR}:
1010

@@ -15,7 +15,7 @@ Files have a strictly defined name vm-<vm_os_type>-<name-of-profile>.conf and ar
1515
located in directories:
1616

1717
- ~cbsd/etc/defaults/ (official/contrib profiles);
18-
~ cbsd/etc/ (custom user's profiles);
18+
- ~cbsd/etc/ (custom user's profiles);
1919

2020
You can create virtual machines via API or command line (e.g. 'cbsd bcreate' for bhyve).
2121
The 'cbsd get-profiles' script will help parse the names of existing profiles and issue
@@ -27,11 +27,12 @@ cache the output.
2727
Hint: you may want to override some (_max) parameters ( {imgsize,vm_ram,vm_cpus}_max= )
2828
in the output, depending on your capabilities. To override globbaly per-host, you can
2929
use ~cbsd/etc/get-profiles.conf (sample: ~cbsd/etc/defaults/get-profiles.conf)
30-
30+
3131
${H3_COLOR}Options${N0_COLOR}:
3232

3333
${N2_COLOR}cache_sum${N0_COLOR} - show cache CRC sum for src=XXX only (used to detect when content changes);
3434
${N2_COLOR}clonos${N0_COLOR} - show profiles marked as 'clonos_active=1' only;
35+
${N2_COLOR}emulator${N0_COLOR} - filter by emulator: 'bhyve', 'xen', 'qemu', 'jail', ...;
3536
${N2_COLOR}imgsize_max${N0_COLOR} - show this values in 'imgsize_max' field, e.g.: '100g'.
3637
when empty = inherit hoster datapool size;
3738
${N2_COLOR}json${N0_COLOR} - json output when 'json=1', default: 0;
@@ -52,8 +53,7 @@ ${H3_COLOR}Examples${N0_COLOR}:
5253
# cbsd get-profiles src=cloud json=1
5354
# cbsd get-profiles src=cloud json=0 warm=1 vm_os_type=freebsd show_iso=1
5455
# cbsd get-profiles src=cloud json=0 warm=1 vm_os_type=freebsd myb=1
55-
# cbsd get-profiles src=jail
56-
# cbsd get-profiles src=jail cache_sum=1
56+
# cbsd get-profiles src=cloud emulator=jail cache_sum=1
5757

5858
${H3_COLOR}See also${N0_COLOR}:
5959

@@ -87,8 +87,11 @@ oimgsize_max=
8787
ovm_cpus_max=
8888
cache_sum=0
8989
ovm_ram=
90+
emulator=
91+
oemulator=
9092
. ${cbsdinit}
9193

94+
[ -n "${emulator}" ] && oemulator="${emulator}"
9295
[ -n "${vm_cpus_max}" ] && ovm_cpus_max="${vm_cpus_max}"
9396
[ -n "${vm_ram_max}" ] && ovm_ram_max="${vm_ram_max}"
9497
[ -n "${vm_ram_min}" ] && ovm_ram_min="${vm_ram_min}"
@@ -136,7 +139,9 @@ get_all_profile_list()
136139
{
137140
local _prefix=
138141

139-
case ${src} in
142+
[ -n "${oemulator}" ] && emulator="${oemulator}"
143+
144+
case ${emulator} in
140145
jail)
141146
_prefix="jail-freebsd"
142147
;;
@@ -145,13 +150,11 @@ get_all_profile_list()
145150
;;
146151
esac
147152

148-
149153
if [ -z "${search_vm_os_type}" ]; then
150154
${FIND_CMD} ${workdir}/etc/defaults ${workdir}/etc -maxdepth 1 -mindepth 1 -type f -name ${_prefix}\-*\.conf 2>/dev/null
151155
else
152156
${FIND_CMD} ${workdir}/etc/defaults ${workdir}/etc -mindepth 1 -maxdepth 1 -type f -name ${_prefix}\-${search_vm_os_type}\-*\.conf 2>/dev/null
153157
fi
154-
155158
}
156159

157160
get_vm_info()
@@ -235,13 +238,17 @@ get_vm_info()
235238
fi
236239

237240
name="${long_description}"
238-
if [ "${src}" = "jail" ]; then
241+
242+
[ -n "${oemulator}" ] && emulator="${oemulator}"
243+
244+
if [ "${emulator}" = "jail" ]; then
239245
profile="${jail_profile}"
240246
type="jail"
241247
else
242248
profile="${vm_profile}"
243249
type="${vm_os_type}"
244250
fi
251+
245252
[ -z "${iso_img}" ] && iso_img="-"
246253
[ -z "${name}" ] && name="-"
247254
[ -z "${profile}" ] && profile="unkpro"
@@ -382,7 +389,9 @@ show_plain()
382389
local _skip_list=
383390
local _basename=
384391

385-
case "${src}" in
392+
[ -n "${oemulator}" ] && emulator="${oemulator}"
393+
394+
case "${emulator}" in
386395
jail)
387396
_skip_list="jail-freebsd-default.conf jail-freebsd-puppet.conf jail-freebsd-trusted.conf jail-freebsd-vnet.conf jail-freebsd-cbsdpuppet.conf"
388397
;;
@@ -493,40 +502,27 @@ show_json()
493502
done
494503

495504
echo "]"
496-
497505
}
498506

499507

500508
## MAIN
501-
#src="cloud"
502-
#src="clonos"
503-
#src="iso"
504-
505509
cloud=0
506510
iso=0
507-
jail=0
508511

509512
# cloud or iso?
510513
vm_filter="^is_cloud="
511514

512515
case "${src}" in
513-
"cloud")
516+
cloud)
514517
cloud=1
515518
iso=0
516-
jail=0
517519
;;
518520
iso)
519521
cloud=0
520522
iso=1
521-
jail=0
522-
;;
523-
jail)
524-
cloud=0
525-
iso=0
526-
jail=1
527523
;;
528524
*)
529-
err 1 "${N1_COLOR}${CBSD_APP}: unknown filter: ${src}, valid: ${N2_COLOR}'cloud', 'iso', 'jail'${N0_COLOR}"
525+
err 1 "${N1_COLOR}${CBSD_APP}: unknown filter: ${src}, valid: ${N2_COLOR}'cloud', 'iso'${N0_COLOR}"
530526
;;
531527
esac
532528

@@ -541,7 +537,18 @@ if [ ${cache_sum} -eq 1 ]; then
541537
exit 0
542538
fi
543539

544-
[ -z "${all_profile_path}" ] && err 0 "{}"
540+
if [ -z "${all_profile_path}" ]; then
541+
case ${json} in
542+
1)
543+
err 0 "{}"
544+
;;
545+
*)
546+
err 0 ""
547+
;;
548+
esac
549+
fi
550+
551+
[ -n "${oemulator}" ] && emulator="${oemulator}"
545552

546553
# first pass: select for 'iso' or 'cloud'
547554
for profile_path in ${all_profile_path}; do
@@ -551,7 +558,7 @@ for profile_path in ${all_profile_path}; do
551558
[ $? -ne 0 ] && continue
552559

553560
[ -z "${is_cloud}" ] && is_cloud=0
554-
[ ${cloud} -ne ${is_cloud} ] && continue
561+
[ "${emulator}" != "jail" -a ${cloud} -ne ${is_cloud} ] && continue
555562

556563
if [ -z "${all_filtered_profile_path}" ]; then
557564
all_filtered_profile_path="${profile_path}"
@@ -560,10 +567,19 @@ for profile_path in ${all_profile_path}; do
560567
fi
561568
done
562569

563-
[ -z "${all_filtered_profile_path}" ] && err 0 "{}"
570+
if [ -z "${all_filtered_profile_path}" ]; then
571+
case ${json} in
572+
1)
573+
err 0 "{}"
574+
;;
575+
*)
576+
err 0 ""
577+
;;
578+
esac
579+
fi
564580

565581
#mandatory filter
566-
case "${src}" in
582+
case "${emulator}" in
567583
jail)
568584
vm_filter="(^long_description=|^jail_profile=|^vm_os_type=|^clonos_active=|^is_template=|^is_cloud=|^imgsize=|^imgsize_min=|^vm_ram=|^vm_cpus="
569585
;;

0 commit comments

Comments
 (0)