命令实际执行基于OpenStack Queens版本,更高版本亦可,长时间未使用openstack有些遗忘,整理后方便自己回顾学习,仅供各位参考,详细命令及参数可以参考openstack官方网址
openstack endpoint list
openstack catalog list
openstack project list
openstack user list
openstack role list
openstack project create PROJECT_NAME
openstack user create --project PROJECT_NAME USER_NAME
openstack role add --project PROJECT_NAME --user USER_NAME _member_
openstack role assignment list
openstack project delete PROJECT_NAME
openstack user delete USER_NAME
openstack image list
openstack image show IMAGE_NAME
openstack image set --public IMAGE_NAME
openstack image create --file IMAGE_NAME.qcow2 --disk-format qcow2 --container-format bare --property hw_scsi_model=virtio-scsi --property hw_disk_bus=virtio --public IMAGE_NAME
openstack image create "cirros-threepart-kernel" --disk-format aki --container-format aki --public --file ~/images/cirros-0.3.5-x86_64-kernel
openstack image create "cirros-threepart-ramdisk" --disk-format ari --container-format ari --public --file ~/images/cirros-0.3.5-x86_64-initramfs
openstack image create "cirros-threepart" --disk-format ami --container-format ami --public --property kernel_id=$KID-property ramdisk_id=$RID --file ~/images/cirros-0.3.5-x86_64-rootfs.img
openstack image save IMAGE_NAME --file IMAGE_NAME.qcow2
glance md-namespace-list
glance md-property-show NAMESPACE
glance md-namespace-show OS::Compute::LibvirtImage
结果如下:
+----------------------------+----------------------------------------------------------------------------------+
| Property | Value |
+----------------------------+----------------------------------------------------------------------------------+
| created_at | 2023-01-11T16:58:18Z |
| description | Libvirt驱动相关配置 |
| display_name | libvirt Driver Options for Images |
| namespace | OS::Compute::LibvirtImage |
| owner | admin |
| properties | ["hw_machine_type", "hw_qemu_guest_agent", "hw_vif_model", "os_command_line", |
| | "hw_scsi_model", "hw_video_ram", "hw_video_model", "hw_rng_model", |
| | "img_hide_hypervisor_id", "hw_disk_bus", "hw_pointer_model"] |
| protected | True |
| resource_type_associations | ["OS::Glance::Image"] |
| schema | /v2/schemas/metadefs/namespace |
| visibility | public |
+----------------------------+----------------------------------------------------------------------------------+
openstack image set --property IMAGE_NAME
openstack image unset --property IMAGE_NAME
openstack image delete IMAGE_NAME
openstack network agent list
openstack network list
openstack subnet list
根据配置文件tenant_network_types顺序选择第一个
openstack network create NETWORK_NAME
openstack network create NETWORK_NAME --provider-network-type vxlan
openstack network create NETWORK_NAME --provider-network-type vxlan --provider-segment 1000 --shared
openstack network create NETWORK_NAME --provider-network-type vlan
openstack network create NETWORK_NAME --provider-network-type vlan --provider-physical-network physnet1 --provider-segment 101 --shared
openstack network create NETWORK_EXTRERNAL --provider-network-type flat --provider-physical-network external --external --shared
openstack subnet create SUBNET_NAME --network NETWORK_NAME --subnet-range 192.0.2.0/24
openstack router create ROUTER_NAME
openstack router set ROUTER_NAME --external-gateway NETWORK_NAME
openstack router add subnet ROUTER_NAME SUBNET_NAME
openstack port create PORT_NAME --network NETWORK_NAME
openstack port create --network NETWORK_NAME --fixed-ip subnet=SUBNET_NAME,ip-address=192.0.2.40 PORT_NAME
neutron port-list --fixed-ips ip_address=192.0.2.2 ip_address=192.0.2.40
openstack network list --external
openstack floating ip list
openstack floating ip create NETWORK_EXTRERNAL
openstack floating ip delete FLOATING_IP_ADDRESS
openstack subnet delete SUBNET_NAME
openstack network delete NETWORK_NAME
openstack compute service list
openstack compute service set --enable/--disable HOSTNAME nova-compute
openstack hypervisor list
openstack hypervisor show HYPERVISOR_ID
查看所有虚拟化节点统计信息如下:
openstack hypervisor stats show
openstack server list --all
openstack server show INSTANCE_NAME
openstack console log show INSTANCE_NAME
openstack console url show INSTANCE_NAME/INSTANCE_ID --novnc
openstack server create --flavor FLAVOR_ID --image IMAGE_ID --network NETWORK_ID --wait INSTANCE_NAME
openstack server suspend INSTANCE_NAME
openstack server resume INSTANCE_NAME
openstack server pause INSTANCE_NAME
openstack server unpause INSTANCE_NAME
openstack server stop INSTANCE_NAME
openstack server start INSTANCE_NAME
软重启
openstack server reboot --soft INSTANCE_NAME
硬重启
openstack server reboot --hard INSTANCE_NAME
openstack server set --state active INSTANCE_NAME
openstack server resize --flavor FLAVOR_ID INSTANCE_NAME
手动确认调整大小
openstack server resize --confirm INSTANCE_ID
如果调整失败或未按预期运行,可以恢复调整大小
openstack server resize --revert INSTANCE_ID
openstack server rebuild --image IMAGE_ID INSTANCE_NAME
openstack server add volume INSTANCE_ID VOLUME_ID
openstack server add volume --device /dev/vdb INSTANCE_ID VOLUME_ID
openstack server remove volume INSTANCE_ID VOLUME_ID
openstack server add floating ip INSTANCE_NAME/INSTANCE_ID FLOATING_IP_ADDRESS
openstack server remove floating ip INSTANCE_NAME/INSTANCE_ID FLOATING_IP_ADDRESS
openstack server add fixed ip --fixed-ip-address FIXED_IP_ADDRESS INSTANCE_NAME/INSTANCE_ID NETWORK_NAME
openstack server remove fixed ip INSTANCE_NAME/INSTANCE_ID FIXED_IP_ADDRESS
openstack server add network INSTANCE_NAME/INSTANCE_ID NETWORK_NAME
openstack server remove network INSTANCE_NAME/INSTANCE_ID NETWORK_NAME
openstack server add port INSTANCE_NAME/INSTANCE_ID PORT_NAME
openstack server remove port INSTANCE_NAME/INSTANCE_ID PORT_NAME
openstack server add security group INSTANCE_NAME/INSTANCE_ID SECURITY_GROUP_ID
openstack server remove security group INSTANCE_NAME/INSTANCE_ID SECURITY_GROUP_ID
openstack server image create INSTANCE_NAME --name INSTANCE_NAME_SNAPSHOT
从失败的计算节点撤离该云主机,若为共享存储则保留原系统数据,若非共享存储,则基于原镜像和原端口重建虚拟机,挂载的共享盘保留。
openstack server evacuate INSTANCE_NAME/INSTANCE_ID
openstack server migrate --live-migration INSTANCE_ID
openstack server delete INSTANCE_NAME
openstack volume service list
openstack volume list
openstack volume create --size SIZE_IN_GB VOLUME_NAME
openstack volume create --image IMAGE_ID --size SIZE_IN_GB VOLUME_NAME
openstack volume show VOLUME_ID
卸载卷后再调整
openstack volume set VOLUME_ID --size NEW_SIZE_IN_GB
openstack volume set --state available VOLUME_ID
openstack volume set --bootable VOLUME_ID
openstack volume delete VOLUME_ID
openstack security group list
openstack security group rule list
openstack security group show SECURITY_GROUP_ID
openstack security group create SECURITY_GROUP_NAME
openstack security group create SECURITY_GROUP_NAME --project PROJECT_ID
openstack security group rule create default --dst-port 22 --description ssh SECURITY_GROUP_ID
openstack security group rule create default --protocol icmp --description icmp SECURITY_GROUP_ID
openstack security group rule create default --protocol tcp --description tcp SECURITY_GROUP_ID
openstack security group rule create default --protocol udp --description udp SECURITY_GROUP_ID
openstack security group rule show SECURITY_GROUP_RULE_ID
openstack security group rule delete SECURITY_GROUP_RULE_ID
openstack security group delete SECURITY_GROUP_ID
openstack keypair list
openstack keypair create KEY_PAIR_NAME > KEY_PAIR_NAME.pem
openstack server create --flavor FLAVOR_ID --image IMAGE_ID --network NETWORK_ID --key-name KEY_PAIR_NAME INSTANCE_NAME
chmod 600 KEY_PAIR_NAME.pem
ip netns exec qdhcp-xxxxxx ssh -i KEY_PAIR_NAME.pem [email protected]
openstack keypair delete KEY_PAIR_NAME
openstack flavor list
openstack flavor create --ram 8192 --disk 200 --vcpus 4 FLAVOR_NAME
openstack flavor delete FLAVOR_NAME
openstack usage list
openstack usage show --project
https://docs.openstack.org/zh_CN/user-guide/index.html
https://docs.openstack.org/python-openstackclient/latest/cli/command-objects/hypervisor.html
https://blog.csdn.net/sun2333/article/details/78559182