Skip to content

Instantly share code, notes, and snippets.

@xuhang57
Last active August 5, 2019 13:27
Show Gist options
  • Save xuhang57/49946495b7f1e100355c73aac0fae717 to your computer and use it in GitHub Desktop.
Save xuhang57/49946495b7f1e100355c73aac0fae717 to your computer and use it in GitHub Desktop.
OpenStack Launch an VM via the OpenStack CLI
# create a flavor which would be used by the instance
openstack flavor create --id 0 --vcpus 1 --ram 2048 --disk 20 m1.small
#openstack flavor create --id 1 --vcpus 4 --ram 8192 --disk 80 m1.large
#openstack flavor create --id 2 --vcpus 8 --ram 16384 --disk 160 m1.xlarge
# create a network
openstack extension list -c Alias -c Name --network # list extensions within the system
openstack network create net1
#openstack network create net2 --provider-network-type vxlan
openstack subnet create subnet1 --network net1 --subnet-range 192.0.2.0/24
openstack router create router1
openstack router set ROUTER --external-gateway NETWORK #Link the router to the external provider network
openstack router add subnet ROUTER SUBNET
openstack port create --network net1 --fixed-ip subnet=subnet1,ip-address=192.0.2.40 port1
#openstack port create port2 --network net1
# create/upload an image
wget https://cloud-images.ubuntu.com/bionic/current/bionic-server-cloudimg-amd64.img
#wget https://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud.qcow2
qemu-img convert -f raw -O qcow2 bionic-server-cloudimg-amd64.img ubuntu18-04.qcow2
openstack image create --public --disk-format qcow2 --container-format bare --file ubuntu18-04.qcow2 Ubuntu18
#openstack image create --public --disk-format qcow2 --container-format bare --file centos7.qcow2 CentOS7
# create/import a SSH public key
openstack keypair create --public-key ~/.ssh/id_rsa.pub mykey
# add rules to the security group
# sometimes, you could have more than one security group named default
# if so, just use the UUID of the security group
openstack security group rule create --protocol icmp default
openstack security group rule create --protocol tcp --dst-port 22:22 default
openstack security group rule create --protocol tcp --dst-port 80:80 default
# launch a VM
openstack server create --flavor <UUID> --key-name <KeyName> --image <ImageName> --nic net-id=<PrivateNetworkID> node1
# Associate a floating IP with the instance
openstack floating ip create <PublicNetworkID>
openstack server add floating ip <InstanceName> <FIPAddress>
# launch a VM with bootable volume (cinder) (default backend)
openstack volume create --image IMAGE_ID --size SIZE_IN_GB bootable_volume
#openstack volume create --type ENCRYPTED_VOLUME_TYPE --image IMAGE_ID --size SIZE_IN_GB bootable_volume
openstack server create --flavor <FlavorID> --volume <VolumeID> --key-name <KeyName> --nic net-id=<PrivateNetworkID> myInstanceFromVolume
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment