govc: ❤

The '-type' flag value can be a managed entity type or one of the following aliases:a    VirtualApp
c ClusterComputeResource
d Datacenter
f Folder
g DistributedVirtualPortgroup
h HostSystem
m VirtualMachine
n Network
o OpaqueNetwork
p ResourcePool
r ComputeResource
s Datastore
w DistributedVirtualSwitch
govc find /Datacenter/vm/template_folder -type m 
govc object.collect -json /Datacenter/vm/template/template_folder/my_template 
govc object.collect -json /Datacenter/vm/template/template_folder/my_template tag | jq '.[].Annotation'
#!/bin/bashTEMPLATE_FOLDER=${TEMPLATE_FOLDER:-/templates}
PRUNE_PATTERN=${PRUNE_PATTERN:-XXXXXXX}
KEEP=${KEEP:-3}
templates=($(govc find "${TEMPLATE_FOLDER}" -name "${PRUNE_PATTERN}*" -type m -disabledMethod PowerOnVM_Task | sort))limit=$[${#templates[@]} - $KEEP]for template in "${templates[@]:0:$limit}"; do
if [[ "$(govc vm.info -json "$template" | jq '.VirtualMachines[].Config.Annotation')" =~ keep ]]; then
echo "keeping $template since it has been held"
else
echo "pruning $template"
govc vm.destroy -vm.ipath="$template"
fidone
export GOVC_DATASTORE=templates
govc datastore.upload rhel-server-7.6-x86_64-dvd.iso ISOs/rhel-server-7.6-x86_64-dvd.iso

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Greg Swallow

Greg Swallow

More from Medium

Blogging in Golang with WriteFreely and Caddy

FATA[0009] FAILED TO CREATE API: UNABLE TO RUN POST-SCAFFOLD TASKS OF “BASE.GO.KUBEBUILDER.IO/V3”:

Importing private repos from Github

Testing Terraform infrastructure as code using Terratest