Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to only list running VMs #517

Merged
merged 1 commit into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion lib/vm-core
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,20 @@
# list virtual machines
#
core::list(){
local _running_only
local _name _loader _cpu _our_host
local _memory _run _vm _auto _num _vnc _pid
local _state _pcpu _rss _uptime
local _format="%s^%s^%s^%s^%s^%s^%s^%s\n"

cmd::parse_args "$@"
while getopts r _opt ; do
case $_opt in
r) _running_only='true' ;;

*) util::usage ;;
esac
done

shift $?

_our_host=$(hostname)
Expand Down Expand Up @@ -109,6 +117,10 @@ core::list(){
_run="Locked (${_run})"
fi

if [ "${_run}" = "Stopped" -a -n "${_running_only}" ]; then
continue
fi

if [ -n "${VM_OPT_VERBOSE}" ]; then
printf "${_format}" "${_name}" "${_ds}" "${_loader}" "${_cpu}" "${_memory}" "${_vnc}" "${_auto}" "${_pcpu}" "${_rss}" "${_uptime}" "${_run}"
else
Expand Down
2 changes: 1 addition & 1 deletion lib/vm-util
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ Usage: vm ...
datastore add <name> <spec>
datastore remove <name>
datastore add <name> <path>
list
list [-r]
info [name] [...]
create [-d datastore] [-t template] [-s size] [-m memory] [-c vCPUs] <name>
install [-fi] <name> <iso>
Expand Down
10 changes: 9 additions & 1 deletion vm.8
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
.Ar name
.Nm
.Cm list
.Op Fl r
.Nm
.Cm info
.Op Ar name
Expand Down Expand Up @@ -643,13 +644,20 @@ Unless specified, the guest image will be a sparse file 20GB in size.
.It Cm destroy Ar name
Removes the specified virtual machine from the system, deleting all associated
disk images & configuration.
.It Cm list
.It Xo
.Cm list
.Op Fl r
.Xc
.br
List all the virtual machines in the
.Pa $vm_dir
directory.
This will show the basic configuration for each virtual machine, and whether
they are currently running.
.Pp
If the
.Ar -r
option is specified, only running guests are listed.
.It Cm info Op Ar name Op Ar ...
Shows detailed information about the specified virtual machine(s).
If no names are given, information for all virtual machines is displayed.
Expand Down