Difference between revisions of "Piston: Command Line Cheatsheet Openstack"

From Define Wiki
Jump to navigation Jump to search
(Created page with "== Keystone (Identity Service) == # List all users keystone user-list # List identity service catalog keystone catalog # Discover keystone endpoints keystone discover #...")
 
Line 1: Line 1:
 
== Keystone (Identity Service) ==
 
== Keystone (Identity Service) ==
# List all users
+
List all users
 
   keystone user-list
 
   keystone user-list
  
# List identity service catalog
+
List identity service catalog
 
   keystone catalog
 
   keystone catalog
  
# Discover keystone endpoints
+
Discover keystone endpoints
keystone discover
+
  keystone discover
  
# List all services in service catalog
+
List all services in service catalog
keystone service-list
+
  keystone service-list
  
# Create new user
+
Create new user
keystone user-create --name --tenant-id --pass --email --enabled
+
  keystone user-create --name --tenant-id --pass --email --enabled
  
# Create new tenant
+
Create new tenant
keystone tenant-create --name --description --enabled
+
  keystone tenant-create --name --description --enabled
  
Nova (Compute Service)
+
== Nova (Compute Service) ==
# List instances, notice status of instance
+
List instances, notice status of instance
nova list
+
  nova list
  
# List images
+
List images
nova image-list
+
  nova image-list
  
# List flavors
+
List flavors
nova flavor-list
+
  nova flavor-list
  
# Boot an instance using flavor and image names (if names are unique)
+
Boot an instance using flavor and image names (if names are unique)
nova boot --image --flavor
+
  nova boot --image --flavor
nova boot --image cirros-0.3.1-x86_64-uec --flavor m1.tiny MyFirstInstance
+
  nova boot --image cirros-0.3.1-x86_64-uec --flavor m1.tiny MyFirstInstance
  
# Login to instance
+
Login to instance
ip netns
+
  ip netns
sudo ip netns exec ssh <user@server or use a key>
+
  sudo ip netns exec ssh <user@server or use a key>
sudo ip netns exec qdhcp-6021a3b4-8587-4f9c-8064-0103885dfba2 ssh cirros@10.0.0.2
+
  sudo ip netns exec qdhcp-6021a3b4-8587-4f9c-8064-0103885dfba2 ssh cirros@10.0.0.2
# if you are on devstack, password is “cubswin:)” without the quotes
+
  # if you are on devstack, password is “cubswin:)” without the quotes
  
# Show details of instance
+
Show details of instance
nova show <name>
+
  nova show <name>
nova show MyFirstInstance
+
  nova show MyFirstInstance
  
# View console log of instance
+
View console log of instance
nova console-log MyFirstInstance
+
  nova console-log MyFirstInstance
  
# Pause, suspend, stop, rescue, resize, rebuild, reboot an instance
+
=== Pause, suspend, stop, rescue, resize, rebuild, reboot an instance ===
# Pause
+
Pause
nova pause <name>
+
  nova pause <name>
nova pause volumeTwoImage
+
  nova pause volumeTwoImage
  
# Unpause
+
Unpause
nova unpause <name>
+
  nova unpause <name>
  
# Suspend
+
Suspend
nova suspend <name>
+
  nova suspend <name>
  
# Unsuspend
+
Unsuspend
nova resume <name>
+
  nova resume <name>
  
# Stop
+
Stop
nova stop <name>
+
  nova stop <name>
  
# Start
+
Start
nova start <name>
+
  nova start <name>
  
# Rescue
+
Rescue
nova rescue <name>
+
  nova rescue <name>
  
# Resize
+
Resize
nova resize <name> <flavor>
+
  nova resize <name> <flavor>
nova resize my-pem-server m1.small
+
  nova resize my-pem-server m1.small
nova resize-confirm server1
+
  nova resize-confirm server1
  
# Rebuild
+
Rebuild
nova rebuild <name> <image>
+
  nova rebuild <name> <image>
nova rebuild newtinny cirros-qcow2
+
  nova rebuild newtinny cirros-qcow2
  
# Reboot
+
Reboot
nova reboot <name>
+
  nova reboot <name>
nova reboot newtinny
+
  nova reboot newtinny
  
# Inject user data and files into an instance
+
Inject user data and files into an instance
nova boot --user-data ./userdata.txt MyUserdataInstance
+
  nova boot --user-data ./userdata.txt MyUserdataInstance
nova boot --user-data userdata.txt --image cirros-qcow2 --flavor m1.tiny MyUserdataInstance2
+
  nova boot --user-data userdata.txt --image cirros-qcow2 --flavor m1.tiny MyUserdataInstance2
# to validate file is there, ssh into instance, go to /var/lib/cloud look for file
+
  # to validate file is there, ssh into instance, go to /var/lib/cloud look for file
  
# Inject a keypair into an instance and access the instance with that keypair
+
=== Inject a keypair into an instance and access the instance with that keypair ===
# Create keypair
+
Create keypair
nova keypair-add test > test.pem
+
  nova keypair-add test > test.pem
chmod 600 test.pem
+
  chmod 600 test.pem
  
# Boot
+
Boot
nova boot --image cirros-0.3.0-x86_64 --flavor m1.small --key_name test my-first-server
+
  nova boot --image cirros-0.3.0-x86_64 --flavor m1.small --key_name test my-first-server
  
# ssh into instance
+
ssh into instance
sudo ip netns exec qdhcp-98f09f1e-64c4-4301-a897-5067ee6d544f ssh -i test.pem cirros@10.0.0.4
+
  sudo ip netns exec qdhcp-98f09f1e-64c4-4301-a897-5067ee6d544f ssh -i test.pem cirros@10.0.0.4
  
# Set metadata on an instance
+
Set metadata on an instance
nova meta volumeTwoImage set newmeta=’my meta data’
+
  nova meta volumeTwoImage set newmeta=’my meta data’
  
# Create an instance snapshot
+
Create an instance snapshot
nova image-create volumeTwoImage snapshotOfVolumeImage
+
  nova image-create volumeTwoImage snapshotOfVolumeImage
nova image-show snapshotOfVolumeImage
+
  nova image-show snapshotOfVolumeImage
  
# Manage security groups
+
=== Manage security groups ===
# Add rules to default security group allowing ping and ssh between #instances in the default security group
+
Add rules to default security group allowing ping and ssh between #instances in the default security group
 
nova secgroup-add-group-rule default default icmp -1 -1
 
nova secgroup-add-group-rule default default icmp -1 -1
 
nova secgroup-add-group-rule default default tcp 22 22
 
nova secgroup-add-group-rule default default tcp 22 22
  
Glance (Image Service)
+
== Glance (Image Service) ==
# List images you can access
+
List images you can access
glance image-list
+
  glance image-list
  
# Delete specified image
+
Delete specified image
glance image-delete <image>
+
  glance image-delete <image>
  
# Describe a specific image
+
Describe a specific image
glance image-show <image>
+
  glance image-show <image>
  
# update image
+
update image
glance image-update <image>
+
  glance image-update <image>
  
# Manage images
+
=== Manage images ===
# Kernel image
+
Kernel image
glance image-create --name “cirros-threepart-kernel” --disk-format aki --container-format aki --is-public True --file ~/images/cirros-0.3.1~pre4-x86_64-vmlinuz
+
  glance image-create --name “cirros-threepart-kernel” --disk-format aki --container-format aki --is-public True --file ~/images/cirros-0.3.1~pre4-x86_64-vmlinuz
  
# Ram image
+
Ram image
glance image-create—name “cirros-threepart-ramdisk” --disk-format ari --container-format ari --is-public True --file ~/images/cirros-0.3.1~pre4-x86_64-initrd
+
  glance image-create—name “cirros-threepart-ramdisk” --disk-format ari --container-format ari --is-public True --file ~/images/cirros-0.3.1~pre4-x86_64-initrd
  
# 3-part image
+
3-part image
glance image-create—name “cirros-threepart” --disk-format ami --container-format ami --is-public True --property kernel_id=$KID—property ramdisk_id=$RID --file ~/images/cirros-0.3.1~pre4-x86_64-blank.img
+
  glance image-create—name “cirros-threepart” --disk-format ami --container-format ami --is-public True --property kernel_id=$KID—property ramdisk_id=$RID --file ~/images/cirros-0.3.1~pre4-x86_64-blank.img
  
# Register raw image
+
Register raw image
glance image-create --name “cirros-qcow2” --disk-format qcow2 --container-format bare --is-public True --file ~/images/cirros-0.3.1~pre4-x86_64-disk.img
+
  glance image-create --name “cirros-qcow2” --disk-format qcow2 --container-format bare --is-public True --file ~/images/cirros-0.3.1~pre4-x86_64-disk.img
  
Neutron (Networking Service)
+
== Neutron (Networking Service) ==
# Create network
+
Create network
neutron net-create <name>
+
  neutron net-create <name>
neutron net-create my-network
+
  neutron net-create my-network
  
# Create a subnet
+
Create a subnet
neutron subnet-create <network name> <cidr>
+
  neutron subnet-create <network name> <cidr>
neutron subnet-create my-network 10.0.0.0/29
+
  neutron subnet-create my-network 10.0.0.0/29
  
# List network and subnet
+
List network and subnet
neutron net-list
+
  neutron net-list
neutron subnet-list
+
  neutron subnet-list
  
# Examine details of network and subnet
+
Examine details of network and subnet
neutron net-show <id or name of network>
+
  neutron net-show <id or name of network>
neutron subnet-show <id or name of subnet>
+
  neutron subnet-show <id or name of subnet>
  
Cinder (Block Storage)
+
== Cinder (Block Storage) ==
# Manage volumes and volume snapshots
+
Manage volumes and volume snapshots
# Create a new volume
+
Create a new volume
cinder create <size in GB> --display-name
+
  cinder create <size in GB> --display-name
cinder create 1 --display-name MyFirstVolume
+
  cinder create 1 --display-name MyFirstVolume
  
# Boot an instance and attach to volume
+
Boot an instance and attach to volume
nova boot—image cirros-qcow2 --flavor m1.tiny MyVolumeInstance
+
  nova boot—image cirros-qcow2 --flavor m1.tiny MyVolumeInstance
  
# List volumes, notice status of volume
+
List volumes, notice status of volume
cinder list
+
  cinder list
  
# Attach volume to instance after instance is active, and volume is available
+
Attach volume to instance after instance is active, and volume is available
nova volume-attach <instance-id> <volume-id> auto
+
  nova volume-attach <instance-id> <volume-id> auto
nova volume-attach MyVolumeInstance /dev/vdb auto
+
  nova volume-attach MyVolumeInstance /dev/vdb auto
  
# Login into instance, list storage devices
+
Login into instance, list storage devices
sudo fdisk -l
+
  sudo fdisk -l
  
# On the instance, make filesystem on volume
+
On the instance, make filesystem on volume
sudo mkfs.ext3 /dev/vdb
+
  sudo mkfs.ext3 /dev/vdb
  
# Create a mountpoint
+
Create a mountpoint
sudo mkdir /myspace
+
  sudo mkdir /myspace
  
# Mount the volume at the mountpoint
+
Mount the volume at the mountpoint
sudo mount /dev/vdc /myspace
+
  sudo mount /dev/vdc /myspace
  
# Create a file on the volume
+
Create a file on the volume
sudo touch /myspace/helloworld.txt
+
  sudo touch /myspace/helloworld.txt
sudo ls /myspace
+
  sudo ls /myspace
  
# Unmount the volume
+
Unmount the volume
sudo umount /myspace
+
  sudo umount /myspace
  
Swift (Object Store)
+
== Swift (Object Store) ==
# Displays information for the account, container, or object
+
Displays information for the account, container, or object
swift stat
+
  swift stat
swift stat <account>
+
  swift stat <account>
swift stat <container>
+
  swift stat <container>
swift stat <object>
+
  swift stat <object>
  
# List containers
+
List containers
swift list
+
  swift list
  
# Create a container
+
Create a container
swift post mycontainer
+
  swift post mycontainer
  
# Upload file to a container
+
Upload file to a container
swift upload <containder name> <file name>
+
  swift upload <containder name> <file name>
swift upload mycontainer myfile.txt
+
  swift upload mycontainer myfile.txt
  
# List objects in container
+
List objects in container
swift list container
+
  swift list container
  
# Download object from container
+
Download object from container
swift download <containder name> <file name>
+
  swift download <containder name> <file name>
  
# Upload with chunks, for large file
+
Upload with chunks, for large file
swift upload -S <size> <containder name> <file name>
+
  swift upload -S <size> <containder name> <file name>
swift upload -S 64 container largeFile
+
  swift upload -S 64 container largeFile

Revision as of 23:14, 7 March 2015

Keystone (Identity Service)

List all users

 keystone user-list

List identity service catalog

 keystone catalog

Discover keystone endpoints

 keystone discover

List all services in service catalog

 keystone service-list

Create new user

 keystone user-create --name --tenant-id --pass --email --enabled

Create new tenant

 keystone tenant-create --name --description --enabled

Nova (Compute Service)

List instances, notice status of instance

 nova list

List images

 nova image-list

List flavors

 nova flavor-list

Boot an instance using flavor and image names (if names are unique)

 nova boot --image --flavor
 nova boot --image cirros-0.3.1-x86_64-uec --flavor m1.tiny MyFirstInstance

Login to instance

 ip netns
 sudo ip netns exec ssh <user@server or use a key>
 sudo ip netns exec qdhcp-6021a3b4-8587-4f9c-8064-0103885dfba2 ssh cirros@10.0.0.2
 # if you are on devstack, password is “cubswin:)” without the quotes

Show details of instance

 nova show <name>
 nova show MyFirstInstance

View console log of instance

 nova console-log MyFirstInstance

Pause, suspend, stop, rescue, resize, rebuild, reboot an instance

Pause

 nova pause <name>
 nova pause volumeTwoImage

Unpause

 nova unpause <name>

Suspend

 nova suspend <name>

Unsuspend

 nova resume <name>

Stop

 nova stop <name>

Start

 nova start <name>

Rescue

 nova rescue <name>

Resize

 nova resize <name> <flavor>
 nova resize my-pem-server m1.small
 nova resize-confirm server1

Rebuild

 nova rebuild <name> <image>
 nova rebuild newtinny cirros-qcow2

Reboot

 nova reboot <name>
 nova reboot newtinny

Inject user data and files into an instance

 nova boot --user-data ./userdata.txt MyUserdataInstance
 nova boot --user-data userdata.txt --image cirros-qcow2 --flavor m1.tiny MyUserdataInstance2
 # to validate file is there, ssh into instance, go to /var/lib/cloud look for file

Inject a keypair into an instance and access the instance with that keypair

Create keypair

 nova keypair-add test > test.pem
 chmod 600 test.pem

Boot

 nova boot --image cirros-0.3.0-x86_64 --flavor m1.small --key_name test my-first-server

ssh into instance

 sudo ip netns exec qdhcp-98f09f1e-64c4-4301-a897-5067ee6d544f ssh -i test.pem cirros@10.0.0.4

Set metadata on an instance

 nova meta volumeTwoImage set newmeta=’my meta data’

Create an instance snapshot

 nova image-create volumeTwoImage snapshotOfVolumeImage
 nova image-show snapshotOfVolumeImage

Manage security groups

Add rules to default security group allowing ping and ssh between #instances in the default security group nova secgroup-add-group-rule default default icmp -1 -1 nova secgroup-add-group-rule default default tcp 22 22

Glance (Image Service)

List images you can access

 glance image-list

Delete specified image

 glance image-delete <image>

Describe a specific image

 glance image-show <image>

update image

 glance image-update <image>

Manage images

Kernel image

 glance image-create --name “cirros-threepart-kernel” --disk-format aki --container-format aki --is-public True --file ~/images/cirros-0.3.1~pre4-x86_64-vmlinuz

Ram image

 glance image-create—name “cirros-threepart-ramdisk” --disk-format ari --container-format ari --is-public True --file ~/images/cirros-0.3.1~pre4-x86_64-initrd

3-part image

 glance image-create—name “cirros-threepart” --disk-format ami --container-format ami --is-public True --property kernel_id=$KID—property ramdisk_id=$RID --file ~/images/cirros-0.3.1~pre4-x86_64-blank.img

Register raw image

 glance image-create --name “cirros-qcow2” --disk-format qcow2 --container-format bare --is-public True --file ~/images/cirros-0.3.1~pre4-x86_64-disk.img

Neutron (Networking Service)

Create network

 neutron net-create <name>
 neutron net-create my-network

Create a subnet

 neutron subnet-create <network name> <cidr>
 neutron subnet-create my-network 10.0.0.0/29

List network and subnet

 neutron net-list
 neutron subnet-list

Examine details of network and subnet

 neutron net-show <id or name of network>
 neutron subnet-show <id or name of subnet>

Cinder (Block Storage)

Manage volumes and volume snapshots Create a new volume

 cinder create <size in GB> --display-name
 cinder create 1 --display-name MyFirstVolume

Boot an instance and attach to volume

 nova boot—image cirros-qcow2 --flavor m1.tiny MyVolumeInstance

List volumes, notice status of volume

 cinder list

Attach volume to instance after instance is active, and volume is available

 nova volume-attach <instance-id> <volume-id> auto
 nova volume-attach MyVolumeInstance /dev/vdb auto

Login into instance, list storage devices

 sudo fdisk -l

On the instance, make filesystem on volume

 sudo mkfs.ext3 /dev/vdb

Create a mountpoint

 sudo mkdir /myspace

Mount the volume at the mountpoint

 sudo mount /dev/vdc /myspace

Create a file on the volume

 sudo touch /myspace/helloworld.txt
 sudo ls /myspace

Unmount the volume

 sudo umount /myspace

Swift (Object Store)

Displays information for the account, container, or object

 swift stat
 swift stat <account>
 swift stat <container>
 swift stat <object>

List containers

 swift list

Create a container

 swift post mycontainer

Upload file to a container

 swift upload <containder name> <file name>
 swift upload mycontainer myfile.txt

List objects in container

 swift list container

Download object from container

 swift download <containder name> <file name>

Upload with chunks, for large file

 swift upload -S <size> <containder name> <file name>
 swift upload -S 64 container largeFile