2
2
# shellcheck shell=sh disable=2034,2154,1091
3
3
#v13.0.8
4
4
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"
6
6
MYDESC="list of available profiles for virtual machine"
7
- CBSDMODULE="bhyve,xen"
7
+ CBSDMODULE="bhyve,jail, xen"
8
8
ADDHELP="
9
9
${H3_COLOR}Description${N0_COLOR}:
10
10
@@ -15,7 +15,7 @@ Files have a strictly defined name vm-<vm_os_type>-<name-of-profile>.conf and ar
15
15
located in directories:
16
16
17
17
- ~cbsd/etc/defaults/ (official/contrib profiles);
18
- ~ cbsd/etc/ (custom user's profiles);
18
+ - ~ cbsd/etc/ (custom user's profiles);
19
19
20
20
You can create virtual machines via API or command line (e.g. 'cbsd bcreate' for bhyve).
21
21
The 'cbsd get-profiles' script will help parse the names of existing profiles and issue
@@ -27,11 +27,12 @@ cache the output.
27
27
Hint: you may want to override some (_max) parameters ( {imgsize,vm_ram,vm_cpus}_max= )
28
28
in the output, depending on your capabilities. To override globbaly per-host, you can
29
29
use ~cbsd/etc/get-profiles.conf (sample: ~cbsd/etc/defaults/get-profiles.conf)
30
-
30
+
31
31
${H3_COLOR}Options${N0_COLOR}:
32
32
33
33
${N2_COLOR}cache_sum${N0_COLOR} - show cache CRC sum for src=XXX only (used to detect when content changes);
34
34
${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', ...;
35
36
${N2_COLOR}imgsize_max${N0_COLOR} - show this values in 'imgsize_max' field, e.g.: '100g'.
36
37
when empty = inherit hoster datapool size;
37
38
${N2_COLOR}json${N0_COLOR} - json output when 'json=1', default: 0;
@@ -52,8 +53,7 @@ ${H3_COLOR}Examples${N0_COLOR}:
52
53
# cbsd get-profiles src=cloud json=1
53
54
# cbsd get-profiles src=cloud json=0 warm=1 vm_os_type=freebsd show_iso=1
54
55
# 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
57
57
58
58
${H3_COLOR}See also${N0_COLOR}:
59
59
@@ -87,8 +87,11 @@ oimgsize_max=
87
87
ovm_cpus_max=
88
88
cache_sum=0
89
89
ovm_ram=
90
+ emulator=
91
+ oemulator=
90
92
. ${cbsdinit}
91
93
94
+ [ -n "${emulator}" ] && oemulator="${emulator}"
92
95
[ -n "${vm_cpus_max}" ] && ovm_cpus_max="${vm_cpus_max}"
93
96
[ -n "${vm_ram_max}" ] && ovm_ram_max="${vm_ram_max}"
94
97
[ -n "${vm_ram_min}" ] && ovm_ram_min="${vm_ram_min}"
@@ -136,7 +139,9 @@ get_all_profile_list()
136
139
{
137
140
local _prefix=
138
141
139
- case ${src} in
142
+ [ -n "${oemulator}" ] && emulator="${oemulator}"
143
+
144
+ case ${emulator} in
140
145
jail)
141
146
_prefix="jail-freebsd"
142
147
;;
@@ -145,13 +150,11 @@ get_all_profile_list()
145
150
;;
146
151
esac
147
152
148
-
149
153
if [ -z "${search_vm_os_type}" ]; then
150
154
${FIND_CMD} ${workdir}/etc/defaults ${workdir}/etc -maxdepth 1 -mindepth 1 -type f -name ${_prefix}\-*\.conf 2>/dev/null
151
155
else
152
156
${FIND_CMD} ${workdir}/etc/defaults ${workdir}/etc -mindepth 1 -maxdepth 1 -type f -name ${_prefix}\-${search_vm_os_type}\-*\.conf 2>/dev/null
153
157
fi
154
-
155
158
}
156
159
157
160
get_vm_info()
@@ -235,13 +238,17 @@ get_vm_info()
235
238
fi
236
239
237
240
name="${long_description}"
238
- if [ "${src}" = "jail" ]; then
241
+
242
+ [ -n "${oemulator}" ] && emulator="${oemulator}"
243
+
244
+ if [ "${emulator}" = "jail" ]; then
239
245
profile="${jail_profile}"
240
246
type="jail"
241
247
else
242
248
profile="${vm_profile}"
243
249
type="${vm_os_type}"
244
250
fi
251
+
245
252
[ -z "${iso_img}" ] && iso_img="-"
246
253
[ -z "${name}" ] && name="-"
247
254
[ -z "${profile}" ] && profile="unkpro"
@@ -382,7 +389,9 @@ show_plain()
382
389
local _skip_list=
383
390
local _basename=
384
391
385
- case "${src}" in
392
+ [ -n "${oemulator}" ] && emulator="${oemulator}"
393
+
394
+ case "${emulator}" in
386
395
jail)
387
396
_skip_list="jail-freebsd-default.conf jail-freebsd-puppet.conf jail-freebsd-trusted.conf jail-freebsd-vnet.conf jail-freebsd-cbsdpuppet.conf"
388
397
;;
@@ -493,40 +502,27 @@ show_json()
493
502
done
494
503
495
504
echo "]"
496
-
497
505
}
498
506
499
507
500
508
## MAIN
501
- #src="cloud"
502
- #src="clonos"
503
- #src="iso"
504
-
505
509
cloud=0
506
510
iso=0
507
- jail=0
508
511
509
512
# cloud or iso?
510
513
vm_filter="^is_cloud="
511
514
512
515
case "${src}" in
513
- " cloud" )
516
+ cloud)
514
517
cloud=1
515
518
iso=0
516
- jail=0
517
519
;;
518
520
iso)
519
521
cloud=0
520
522
iso=1
521
- jail=0
522
- ;;
523
- jail)
524
- cloud=0
525
- iso=0
526
- jail=1
527
523
;;
528
524
*)
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}"
530
526
;;
531
527
esac
532
528
@@ -541,7 +537,18 @@ if [ ${cache_sum} -eq 1 ]; then
541
537
exit 0
542
538
fi
543
539
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}"
545
552
546
553
# first pass: select for 'iso' or 'cloud'
547
554
for profile_path in ${all_profile_path}; do
@@ -551,7 +558,7 @@ for profile_path in ${all_profile_path}; do
551
558
[ $? -ne 0 ] && continue
552
559
553
560
[ -z "${is_cloud}" ] && is_cloud=0
554
- [ ${cloud} -ne ${is_cloud} ] && continue
561
+ [ "${emulator}" != "jail" -a ${cloud} -ne ${is_cloud} ] && continue
555
562
556
563
if [ -z "${all_filtered_profile_path}" ]; then
557
564
all_filtered_profile_path="${profile_path}"
@@ -560,10 +567,19 @@ for profile_path in ${all_profile_path}; do
560
567
fi
561
568
done
562
569
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
564
580
565
581
#mandatory filter
566
- case "${src }" in
582
+ case "${emulator }" in
567
583
jail)
568
584
vm_filter="(^long_description=|^jail_profile=|^vm_os_type=|^clonos_active=|^is_template=|^is_cloud=|^imgsize=|^imgsize_min=|^vm_ram=|^vm_cpus="
569
585
;;
0 commit comments