OpenStack: server

List
# List instances / VMs
openstack server list
openstack server list -c ID -c Name -c Status -c Networks -c Host --long

Create
openstack server create foo-vm1 \
--image "Ubuntu 18.04" \
--flavor m1.small \
--key-name foo-key \
--network foo-net

# delete instance
openstack server delete "vm-u1804"
# list all servers from all projects
openstack server list --all-projects --os-cloud=stage-admin
# get IDs only from server
openstack server list --os-cloud=dev-foo -c ID -f value
# get all servers using windows images
for IMAGE in $(openstack image list --long --os-cloud=prod-admin -c ID -c Name -f value | grep -i "Windows" | cut -d" " -f 1); do
openstack server list --long --all-projects --os-cloud=prod-admin --image ${IMAGE}
done

# snapshot and restore
openstack server image create --name vm1-snap1 vm1 --os-cloud=dev
openstack image list --os-cloud=dev
openstack server rebuild --image vm1-snap1 vm1 --os-cloud=dev
openstack server show vm1 -c name -c status --os-cloud=dev

Add floating IP
openstack server add floating ip vm1 $(openstack floating ip create public -c floating_ip_address -f value)

# get VM count by hypervisor
openstack server list --all --long -c Host -f value --os-cloud=stage-admin | sort | uniq -c

# resize
openstack server resize ...
openstack server resize --confirm SERVER_ID

# attach port to VM
openstack server add port VM1 NET1-PORT1

# list instances / server
openstack server list
openstack console log show foo-vm1
openstack console url show foo-vm1 --xvpvnc

# get hypervisor
openstack server list
ssh compute1 ps axf | grep e107c4a4-2812-407e-a6ee-c293b6f78e44

Links
https://docs.openstack.org/python-openstackclient/pike/cli/command-objects/server.html