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

From Define Wiki
Jump to navigation Jump to search
 
Line 86: Line 86:
 
   # 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
  
 +
Check nodes/instances/hypervisors
 +
<syntaxhighlight>
 +
(openstack)[root@piston-gateway ~]# nova hypervisor-list
 +
+----+---------------------+
 +
| ID | Hypervisor hostname |
 +
+----+---------------------+
 +
| 2  | node-172-16-0-13    |
 +
| 1  | node-172-16-0-15    |
 +
| 3  | node-172-16-0-14    |
 +
| 4  | node-172-16-0-16    |
 +
| 5  | node-172-16-0-17    |
 +
| 6  | node-172-16-0-18    |
 +
+----+---------------------+
 +
(openstack)[root@piston-gateway ~]# nova hypervisor-servers node-172-16-0-13
 +
+--------------------------------------+-------------------+---------------+---------------------+
 +
| ID                                  | Name              | Hypervisor ID | Hypervisor Hostname |
 +
+--------------------------------------+-------------------+---------------+---------------------+
 +
| 73a9c465-6ec1-4f66-b6ea-cae24dac8be9 | instance-00000018 | 2            | node-172-16-0-13    |
 +
| 172dfd24-9f7e-4872-971b-b8541d7fa074 | instance-0000001a | 2            | node-172-16-0-13    |
 +
+--------------------------------------+-------------------+---------------+---------------------+
 +
(openstack)[root@piston-gateway ~]# nova hypervisor-servers node-172-16-0-14
 +
+--------------------------------------+-------------------+---------------+---------------------+
 +
| ID                                  | Name              | Hypervisor ID | Hypervisor Hostname |
 +
+--------------------------------------+-------------------+---------------+---------------------+
 +
| e3dec805-c849-4277-a592-098db6af999d | instance-00000014 | 3            | node-172-16-0-14    |
 +
+--------------------------------------+-------------------+---------------+---------------------+
 +
(openstack)[root@piston-gateway ~]# nova hypervisor-servers node-172-16-0-15
 +
+--------------------------------------+-------------------+---------------+---------------------+
 +
| ID                                  | Name              | Hypervisor ID | Hypervisor Hostname |
 +
+--------------------------------------+-------------------+---------------+---------------------+
 +
| fc6da5be-06ee-46af-bb20-533eb6b57543 | instance-0000000d | 1            | node-172-16-0-15    |
 +
| 673bc324-cd6c-44e4-96f6-f51c6f20cff5 | instance-00000019 | 1            | node-172-16-0-15    |
 +
+--------------------------------------+-------------------+---------------+---------------------+
 +
(openstack)[root@piston-gateway ~]# nova hypervisor-servers node-172-16-0-16
 +
+--------------------------------------+-------------------+---------------+---------------------+
 +
| ID                                  | Name              | Hypervisor ID | Hypervisor Hostname |
 +
+--------------------------------------+-------------------+---------------+---------------------+
 +
| ba0c7bab-dc0a-43b1-9f52-b82d11ae3085 | instance-00000012 | 4            | node-172-16-0-16    |
 +
+--------------------------------------+-------------------+---------------+---------------------+
 +
(openstack)[root@piston-gateway ~]# nova hypervisor-servers node-172-16-0-17
 +
+--------------------------------------+-------------------+---------------+---------------------+
 +
| ID                                  | Name              | Hypervisor ID | Hypervisor Hostname |
 +
+--------------------------------------+-------------------+---------------+---------------------+
 +
| f1f6571a-b1b3-4995-b989-618f44c79889 | instance-00000017 | 5            | node-172-16-0-17    |
 +
+--------------------------------------+-------------------+---------------+---------------------+
 +
(openstack)[root@piston-gateway ~]# nova hypervisor-servers node-172-16-0-18
 +
+--------------------------------------+-------------------+---------------+---------------------+
 +
| ID                                  | Name              | Hypervisor ID | Hypervisor Hostname |
 +
+--------------------------------------+-------------------+---------------+---------------------+
 +
| bacecfa9-0751-4b39-9771-f27f78d6e3b9 | instance-0000001c | 6            | node-172-16-0-18    |
 +
| fe1658fd-79df-4aff-9583-b92c6f39e687 | instance-0000001d | 6            | node-172-16-0-18    |
 +
+--------------------------------------+-------------------+---------------+---------------------+
 +
 +
</syntaxhighlight>
 
=== 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

Latest revision as of 10:40, 16 April 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

Check nodes/instances/hypervisors

(openstack)[root@piston-gateway ~]# nova hypervisor-list
+----+---------------------+
| ID | Hypervisor hostname |
+----+---------------------+
| 2  | node-172-16-0-13    |
| 1  | node-172-16-0-15    |
| 3  | node-172-16-0-14    |
| 4  | node-172-16-0-16    |
| 5  | node-172-16-0-17    |
| 6  | node-172-16-0-18    |
+----+---------------------+
(openstack)[root@piston-gateway ~]# nova hypervisor-servers node-172-16-0-13
+--------------------------------------+-------------------+---------------+---------------------+
| ID                                   | Name              | Hypervisor ID | Hypervisor Hostname |
+--------------------------------------+-------------------+---------------+---------------------+
| 73a9c465-6ec1-4f66-b6ea-cae24dac8be9 | instance-00000018 | 2             | node-172-16-0-13    |
| 172dfd24-9f7e-4872-971b-b8541d7fa074 | instance-0000001a | 2             | node-172-16-0-13    |
+--------------------------------------+-------------------+---------------+---------------------+
(openstack)[root@piston-gateway ~]# nova hypervisor-servers node-172-16-0-14
+--------------------------------------+-------------------+---------------+---------------------+
| ID                                   | Name              | Hypervisor ID | Hypervisor Hostname |
+--------------------------------------+-------------------+---------------+---------------------+
| e3dec805-c849-4277-a592-098db6af999d | instance-00000014 | 3             | node-172-16-0-14    |
+--------------------------------------+-------------------+---------------+---------------------+
(openstack)[root@piston-gateway ~]# nova hypervisor-servers node-172-16-0-15
+--------------------------------------+-------------------+---------------+---------------------+
| ID                                   | Name              | Hypervisor ID | Hypervisor Hostname |
+--------------------------------------+-------------------+---------------+---------------------+
| fc6da5be-06ee-46af-bb20-533eb6b57543 | instance-0000000d | 1             | node-172-16-0-15    |
| 673bc324-cd6c-44e4-96f6-f51c6f20cff5 | instance-00000019 | 1             | node-172-16-0-15    |
+--------------------------------------+-------------------+---------------+---------------------+
(openstack)[root@piston-gateway ~]# nova hypervisor-servers node-172-16-0-16
+--------------------------------------+-------------------+---------------+---------------------+
| ID                                   | Name              | Hypervisor ID | Hypervisor Hostname |
+--------------------------------------+-------------------+---------------+---------------------+
| ba0c7bab-dc0a-43b1-9f52-b82d11ae3085 | instance-00000012 | 4             | node-172-16-0-16    |
+--------------------------------------+-------------------+---------------+---------------------+
(openstack)[root@piston-gateway ~]# nova hypervisor-servers node-172-16-0-17
+--------------------------------------+-------------------+---------------+---------------------+
| ID                                   | Name              | Hypervisor ID | Hypervisor Hostname |
+--------------------------------------+-------------------+---------------+---------------------+
| f1f6571a-b1b3-4995-b989-618f44c79889 | instance-00000017 | 5             | node-172-16-0-17    |
+--------------------------------------+-------------------+---------------+---------------------+
(openstack)[root@piston-gateway ~]# nova hypervisor-servers node-172-16-0-18
+--------------------------------------+-------------------+---------------+---------------------+
| ID                                   | Name              | Hypervisor ID | Hypervisor Hostname |
+--------------------------------------+-------------------+---------------+---------------------+
| bacecfa9-0751-4b39-9771-f27f78d6e3b9 | instance-0000001c | 6             | node-172-16-0-18    |
| fe1658fd-79df-4aff-9583-b92c6f39e687 | instance-0000001d | 6             | node-172-16-0-18    |
+--------------------------------------+-------------------+---------------+---------------------+

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> <filename>
 swift upload mycontainer myfile.txt

List objects in container

 swift list container

Download object from container

 swift download <containder name> <filename>

Upload with chunks, for large file

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